Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDEP-894] Use @Component only - fix tests #360

Merged
merged 4 commits into from
Mar 22, 2024
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
22 changes: 9 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,12 @@ under the License.
<project.build.outputTimestamp>2023-10-20T21:21:50Z</project.build.outputTimestamp>
<slf4j.version>1.7.36</slf4j.version>
<plexus-archiver.version>4.9.2</plexus-archiver.version>
<!-- TODO remove with next parent version -->
<version.maven-plugin-tools>3.11.0</version.maven-plugin-tools>
</properties>

<dependencyManagement>
<dependencies>
<!-- TODO check with Maven Api upgrade -->
<!-- the same version as in Maven 3.1.1 -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>0.3.0.M1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.3.0.M1</version>
</dependency>
<!-- override the version from maven-reporting-impl -->
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -321,6 +311,12 @@ under the License.
<artifactId>maven-plugin-testing-harness</artifactId>
<version>${pluginTestingVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -414,7 +410,7 @@ under the License.
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Need more heap space in order to run the unit tests !-->
<argLine>-Xmx384m</argLine>
<argLine>-Xmx512m</argLine>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.testing.SilentLog;
import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
import org.apache.maven.project.MavenProject;

Expand All @@ -32,6 +34,11 @@ public class TestCollectMojo extends AbstractDependencyMojoTestCase {
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.eclipse.jetty.security.ConstraintMapping;
Expand All @@ -49,21 +50,25 @@ public class TestGetMojo extends AbstractDependencyMojoTestCase {
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
mojo = (GetMojo) lookupMojo("get", testPom);

assertNotNull(mojo);

LegacySupport legacySupport = lookup(LegacySupport.class);
MavenSession mavenSession = newMavenSession(new MavenProjectStub());
Settings settings = mavenSession.getSettings();
Settings settings = session.getSettings();
Server server = new Server();
server.setId("myserver");
server.setUsername("foo");
server.setPassword("bar");
settings.addServer(server);
legacySupport.setSession(mavenSession);
legacySupport.setSession(session);

installLocalRepository(legacySupport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.junit.Assert;
Expand All @@ -39,6 +40,13 @@ public class TestListClassesMojo extends AbstractDependencyMojoTestCase {

protected void setUp() throws Exception {
super.setUp("markers", false);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");

assertTrue(testPom.exists());
Expand All @@ -47,7 +55,6 @@ protected void setUp() throws Exception {
assertNotNull(mojo);

LegacySupport legacySupport = lookup(LegacySupport.class);
MavenSession session = newMavenSession(new MavenProjectStub());
Settings settings = session.getSettings();
Server server = new Server();
server.setId("myserver");
Expand All @@ -57,8 +64,6 @@ protected void setUp() throws Exception {
legacySupport.setSession(session);

installLocalRepository(legacySupport);

setVariableValueToObject(mojo, "session", legacySupport.getSession());
}

public void testListClassesNotTransitive() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.project.MavenProject;

public class TestPropertiesMojo extends AbstractDependencyMojoTestCase {
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", true);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/apache/maven/plugins/dependency/TestSkip.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@

import java.io.File;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.project.MavenProject;
import org.mockito.ArgumentCaptor;

import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class TestSkip extends AbstractDependencyMojoTestCase {

@Override
protected void setUp() throws Exception {
super.setUp();
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());
}

public void testSkipAnalyze() throws Exception {
doTest("analyze");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@
import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DuplicateDependencies2ProjectStub;
import org.apache.maven.plugins.dependency.testUtils.stubs.DuplicateDependenciesProjectStub;
import org.apache.maven.project.MavenProject;

/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id$
*/
public class TestAnalyzeDuplicateMojo extends AbstractDependencyMojoTestCase {
public void testDuplicate() throws Exception {
MavenProject project = new DuplicateDependenciesProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config.xml");
AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo("analyze-duplicate", testPom);
assertNotNull(mojo);
Expand All @@ -44,6 +54,12 @@ public void testDuplicate() throws Exception {
}

public void testDuplicate2() throws Exception {
MavenProject project = new DuplicateDependencies2ProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config2.xml");
AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo("analyze-duplicate", testPom);
assertNotNull(mojo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.MavenProject;

Expand All @@ -39,6 +40,11 @@ public class TestCopyMojo extends AbstractDependencyMojoTestCase {

protected void setUp() throws Exception {
super.setUp("copy", false, false);
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml");
mojo = (CopyMojo) lookupMojo("copy", testPom);
Expand All @@ -48,9 +54,6 @@ protected void setUp() throws Exception {
assertNotNull(mojo);
assertNotNull(mojo.getProject());

MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);

LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
installLocalRepository(legacySupport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
import org.apache.maven.project.MavenProject;

public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase {
private final String PACKED_FILE = "test.zip";
Expand All @@ -45,6 +47,12 @@ protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack", true, false);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
mojo = (UnpackMojo) lookupMojo("unpack", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
Expand All @@ -63,9 +71,6 @@ protected void setUp() throws Exception {
mojo.setMarkersDirectory(new File(this.testDir, "markers"));
mojo.setArtifactItems(list);

MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);

LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
installLocalRepository(legacySupport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
Expand All @@ -45,6 +46,12 @@ public class TestUnpackMojo extends AbstractDependencyMojoTestCase {
protected void setUp() throws Exception {
super.setUp("unpack", true, false);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
mojo = (UnpackMojo) lookupMojo("unpack", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
Expand All @@ -62,9 +69,6 @@ protected void setUp() throws Exception {
stubFactory.setSrcFile(new File(
getBasedir() + File.separatorChar + "target/test-classes/unit/unpack-dependencies-test/test.txt"));

MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);

LegacySupport legacySupport = lookup(LegacySupport.class);

legacySupport.setSession(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.MavenProject;

Expand All @@ -36,6 +37,12 @@ protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("build-classpath", true);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml");
mojo = (BuildClasspathMojo) lookupMojo("build-classpath", testPom);

Expand Down Expand Up @@ -101,11 +108,9 @@ public void testEnvironment() throws Exception {
}

public void testPath() throws Exception {
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);

LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
legacySupport.setSession(lookup(MavenSession.class));
installLocalRepository(legacySupport);

Artifact artifact = stubFactory.getReleaseArtifact();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.project.MavenProject;
Expand All @@ -44,17 +45,19 @@ protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true, false);

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

MavenSession session = newMavenSession(project);
getContainer().addComponent(session, MavenSession.class.getName());

File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;

assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();

MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);

LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
Expand Down
Loading