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 2022/04/02 15:25:32 UTC
[maven] 01/01: [MNG-7432] Proposed UT for maven-3.9.x and 3.8.x
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch maven-3.9.x-mng-7432-ut
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 87dfcb91e840ddd2fb760be5b9fb296abcc93d36
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Sat Apr 2 17:23:54 2022 +0200
[MNG-7432] Proposed UT for maven-3.9.x and 3.8.x
This UT makes sure that DefaultMaven sets up proper type
of WorkspaceReader in RepositorySystemSession.
For example, this UT fails with current maven-3.8.x and
maven-3.9.x branches.
---
.../java/org/apache/maven/DefaultMavenTest.java | 29 ++++++++++++++++++++++
.../src/test/projects/default-maven/simple/pom.xml | 10 ++++++++
2 files changed, 39 insertions(+)
diff --git a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
index 1360d8e..a0a0b92 100644
--- a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
+++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java
@@ -4,11 +4,15 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.repository.internal.MavenWorkspaceReader;
+import org.codehaus.plexus.component.annotations.Component;
import java.io.File;
import java.nio.file.Files;
+import java.util.concurrent.atomic.AtomicReference;
import static java.util.Arrays.asList;
@@ -33,6 +37,31 @@ import static java.util.Arrays.asList;
public class DefaultMavenTest
extends AbstractCoreMavenComponentTestCase
{
+ @Component( role = AbstractMavenLifecycleParticipant.class, hint = "WsrClassCatcher" )
+ private static final class WsrClassCatcher extends AbstractMavenLifecycleParticipant
+ {
+ private final AtomicReference<Class<?>> wsrClassRef = new AtomicReference<>( null );
+
+ @Override
+ public void afterProjectsRead( MavenSession session ) throws MavenExecutionException
+ {
+ wsrClassRef.set( session.getRepositorySession().getWorkspaceReader().getClass() );
+ }
+ }
+
+ public void testEnsureResolverSessionHasMavenWorkspaceReader() throws Exception
+ {
+ WsrClassCatcher wsrClassCatcher = ( WsrClassCatcher ) getContainer()
+ .lookup( AbstractMavenLifecycleParticipant.class, "WsrClassCatcher" );
+ Maven maven = getContainer().lookup( Maven.class );
+ MavenExecutionRequest request = createMavenExecutionRequest( getProject( "simple" ) ).setGoals( asList("validate") );
+
+ MavenExecutionResult result = maven.execute( request );
+
+ Class<?> wsrClass = wsrClassCatcher.wsrClassRef.get();
+ assertTrue( "is null", wsrClass != null );
+ assertTrue( String.valueOf( wsrClass ), MavenWorkspaceReader.class.isAssignableFrom( wsrClass ) );
+ }
public void testThatErrorDuringProjectDependencyGraphCreationAreStored()
throws Exception
diff --git a/maven-core/src/test/projects/default-maven/simple/pom.xml b/maven-core/src/test/projects/default-maven/simple/pom.xml
new file mode 100644
index 0000000..0221f82
--- /dev/null
+++ b/maven-core/src/test/projects/default-maven/simple/pom.xml
@@ -0,0 +1,10 @@
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>simple</groupId>
+ <artifactId>simple</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+</project>