You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2024/12/28 13:27:07 UTC

(maven) branch master updated: [MNG-8461] Integrate reproducer as IT (#2009)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 677e3b01bb [MNG-8461] Integrate reproducer as IT (#2009)
677e3b01bb is described below

commit 677e3b01bbaf2135698c0c251bd6fd4a6f6465b1
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Sat Dec 28 14:27:01 2024 +0100

    [MNG-8461] Integrate reproducer as IT (#2009)
    
    Integrate the reproducer into ITs.
    
    ---
    
    https://issues.apache.org/jira/browse/MNG-8461
---
 .../it/MavenITmng8461SpySettingsEventTest.java     | 64 ++++++++++++++++++++++
 .../org/apache/maven/it/TestSuiteOrdering.java     |  1 +
 .../test/resources/mng-8461/extension/README.md    | 18 ++++++
 .../src/test/resources/mng-8461/extension/pom.xml  | 50 +++++++++++++++++
 .../src/main/java/org/example/SimpleEventSpy.java  | 64 ++++++++++++++++++++++
 .../resources/mng-8461/project/.mvn/extensions.xml |  7 +++
 .../src/test/resources/mng-8461/project/pom.xml    | 10 ++++
 7 files changed, 214 insertions(+)

diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8461SpySettingsEventTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8461SpySettingsEventTest.java
new file mode 100644
index 0000000000..a34cb1f7dd
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8461SpySettingsEventTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-8461">MNG-8461</a>.
+ */
+class MavenITmng8461SpySettingsEventTest extends AbstractMavenIntegrationTestCase {
+
+    MavenITmng8461SpySettingsEventTest() {
+        super("[4.0.0-rc-3-SNAPSHOT,)");
+    }
+
+    /**
+     *  Verify that settings building event is emitted.
+     */
+    @Test
+    void testIt() throws Exception {
+        Path basedir = extractResources("/mng-8461").getAbsoluteFile().toPath();
+        Verifier verifier;
+
+        Path extension = basedir.resolve("extension");
+        verifier = newVerifier(extension.toString());
+        verifier.setAutoclean(false);
+        verifier.addCliArgument("install");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        Path project = basedir.resolve("project");
+        verifier = newVerifier(project.toString());
+        verifier.setAutoclean(false);
+        verifier.setForkJvm(true);
+        verifier.addCliArgument("-X");
+        verifier.addCliArgument("validate");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        verifier.verifyTextInLog("Initializing Simple Event Spy");
+        verifier.verifyTextInLog("SettingsBuilderRequest event is present");
+        verifier.verifyTextInLog("SettingsBuilderResult event is present");
+        verifier.verifyTextInLog("ToolchainsBuilderRequest event is present");
+        verifier.verifyTextInLog("ToolchainsBuilderResult event is present");
+    }
+}
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index 4f26dab735..139598e82e 100644
--- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -100,6 +100,7 @@ public class TestSuiteOrdering implements ClassOrderer {
          * the tests are to finishing. Newer tests are also more likely to fail, so this is
          * a fail fast technique as well.
          */
+        suite.addTestSuite(MavenITmng8461SpySettingsEventTest.class);
         suite.addTestSuite(MavenITmng8414ConsumerPomWithNewFeaturesTest.class);
         suite.addTestSuite(MavenITmng8245BeforePhaseCliTest.class);
         suite.addTestSuite(MavenITmng8244PhaseAllTest.class);
diff --git a/its/core-it-suite/src/test/resources/mng-8461/extension/README.md b/its/core-it-suite/src/test/resources/mng-8461/extension/README.md
new file mode 100644
index 0000000000..63baf3f9c6
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8461/extension/README.md
@@ -0,0 +1,18 @@
+# Simple reproducer for SettingsBuilderRequest not emitted
+
+- Build this small extension
+`./mvnw clean install`
+- Use this extension in a project by `.mvn/extensions.xml`:
+```xml
+<extensions>
+    <extension>
+        <groupId>org.example</groupId>
+        <artifactId>maven4-reproducer</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </extension>
+</extensions>
+```
+- Run a build with Maven 4 rc-2:
+  `[INFO] [stdout] Closing Simple Event Spy, checking SettingsBuilderRequest event` => all good
+- Run a build with Maven 4 latest rc-3 snapshot:
+  `[WARNING] Failed to close spy org.example.SimpleEventSpy: No value present` => the SettingsBuilderRequest event is not there
\ No newline at end of file
diff --git a/its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml b/its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml
new file mode 100644
index 0000000000..592f459d48
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng8461</groupId>
+  <artifactId>reproducer</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <maven.compiler.source>17</maven.compiler.source>
+    <maven.compiler.target>17</maven.compiler.target>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>4.0.0-rc-2</version>
+      <scope>provided</scope>
+      <!-- always provided by the Maven Core Classloader -->
+    </dependency>
+    <!-- dependency for JSR 330 annotation -->
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <version>1</version>
+      <scope>provided</scope>
+      <!-- always provided by the Maven Core Classloader -->
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.eclipse.sisu</groupId>
+        <artifactId>sisu-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>index-project</id>
+            <goals>
+              <goal>main-index</goal>
+              <goal>test-index</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/its/core-it-suite/src/test/resources/mng-8461/extension/src/main/java/org/example/SimpleEventSpy.java b/its/core-it-suite/src/test/resources/mng-8461/extension/src/main/java/org/example/SimpleEventSpy.java
new file mode 100644
index 0000000000..d2ca3d3893
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8461/extension/src/main/java/org/example/SimpleEventSpy.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.example;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.api.services.SettingsBuilderRequest;
+import org.apache.maven.api.services.SettingsBuilderResult;
+import org.apache.maven.api.services.ToolchainsBuilderRequest;
+import org.apache.maven.api.services.ToolchainsBuilderResult;
+import org.apache.maven.eventspy.EventSpy;
+
+@Named("simple")
+@Singleton
+public class SimpleEventSpy implements EventSpy {
+    private final List<Object> events = new ArrayList<>();
+
+    @Override
+    public void init(Context context) throws Exception {
+        System.out.println("Initializing Simple Event Spy");
+    }
+
+    @Override
+    public void onEvent(Object o) throws Exception {
+        events.add(o);
+    }
+
+    @Override
+    public void close() throws Exception {
+        System.out.println("Closing Simple Event Spy, checking events");
+        checkEvent(SettingsBuilderRequest.class);
+        checkEvent(SettingsBuilderResult.class);
+        checkEvent(ToolchainsBuilderRequest.class);
+        checkEvent(ToolchainsBuilderResult.class);
+    }
+
+    private void checkEvent(Class<?> clazz) {
+        if (!events.stream().anyMatch(e -> clazz.isAssignableFrom(e.getClass()))) {
+            System.out.println(clazz.getSimpleName() + " event is absent");
+        } else {
+            System.out.println(clazz.getSimpleName() + " event is present");
+        }
+    }
+}
diff --git a/its/core-it-suite/src/test/resources/mng-8461/project/.mvn/extensions.xml b/its/core-it-suite/src/test/resources/mng-8461/project/.mvn/extensions.xml
new file mode 100644
index 0000000000..7dfef8a11d
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8461/project/.mvn/extensions.xml
@@ -0,0 +1,7 @@
+<extensions>
+    <extension>
+        <groupId>org.apache.maven.its.mng8461</groupId>
+        <artifactId>reproducer</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </extension>
+</extensions>
diff --git a/its/core-it-suite/src/test/resources/mng-8461/project/pom.xml b/its/core-it-suite/src/test/resources/mng-8461/project/pom.xml
new file mode 100644
index 0000000000..4f79d3ab3f
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-8461/project/pom.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng8461</groupId>
+  <artifactId>project</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+
+</project>