From 677e3b01bbaf2135698c0c251bd6fd4a6f6465b1 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sat, 28 Dec 2024 14:27:01 +0100 Subject: [PATCH] [MNG-8461] Integrate reproducer as IT (#2009) Integrate the reproducer into ITs. --- https://issues.apache.org/jira/browse/MNG-8461 --- .../MavenITmng8461SpySettingsEventTest.java | 64 +++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../resources/mng-8461/extension/README.md | 18 ++++++ .../test/resources/mng-8461/extension/pom.xml | 50 +++++++++++++++ .../main/java/org/example/SimpleEventSpy.java | 64 +++++++++++++++++++ .../mng-8461/project/.mvn/extensions.xml | 7 ++ .../test/resources/mng-8461/project/pom.xml | 10 +++ 7 files changed, 214 insertions(+) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8461SpySettingsEventTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-8461/extension/README.md create mode 100644 its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-8461/extension/src/main/java/org/example/SimpleEventSpy.java create mode 100644 its/core-it-suite/src/test/resources/mng-8461/project/.mvn/extensions.xml create mode 100644 its/core-it-suite/src/test/resources/mng-8461/project/pom.xml 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 000000000000..a34cb1f7dd69 --- /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 MNG-8461. + */ +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 4f26dab735c9..139598e82ed5 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 TestSuiteOrdering() { * 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 000000000000..63baf3f9c635 --- /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 + + + org.example + maven4-reproducer + 1.0-SNAPSHOT + + +``` +- 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 000000000000..592f459d48a2 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + org.apache.maven.its.mng8461 + reproducer + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + org.apache.maven + maven-core + 4.0.0-rc-2 + provided + + + + + javax.inject + javax.inject + 1 + provided + + + + + + + + org.eclipse.sisu + sisu-maven-plugin + + + index-project + + main-index + test-index + + + + + + + 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 000000000000..d2ca3d3893b4 --- /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 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 000000000000..7dfef8a11d44 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8461/project/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + org.apache.maven.its.mng8461 + reproducer + 1.0-SNAPSHOT + + 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 000000000000..4f79d3ab3f4c --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8461/project/pom.xml @@ -0,0 +1,10 @@ + + + + 4.0.0 + + org.apache.maven.its.mng8461 + project + 1.0.0-SNAPSHOT + +