Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8461/extension/README.md
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8461/extension/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions>
<extension>
<groupId>org.apache.maven.its.mng8461</groupId>
<artifactId>reproducer</artifactId>
<version>1.0-SNAPSHOT</version>
</extension>
</extensions>
10 changes: 10 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8461/project/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Loading