diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 7c965cefba..661ae9bf12 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -131,6 +131,11 @@ under the License. org.apache.commons commons-lang3 + + org.slf4j + slf4j-simple + test + commons-jxpath commons-jxpath diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 8df987e5c0..de0f99beef 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -22,6 +22,7 @@ package org.apache.maven; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Properties; @@ -45,37 +46,39 @@ import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import javax.inject.Inject; + public abstract class AbstractCoreMavenComponentTestCase extends PlexusTestCase { - @Requirement + @Inject protected RepositorySystem repositorySystem; - @Requirement + @Inject protected org.apache.maven.project.ProjectBuilder projectBuilder; - protected void setUp() - throws Exception + @Override + protected void setUp() throws Exception { - repositorySystem = lookup( RepositorySystem.class ); - projectBuilder = lookup( org.apache.maven.project.ProjectBuilder.class ); + super.setUp(); + getContainer(); } @Override - protected void tearDown() - throws Exception + protected synchronized void setupContainer() { - repositorySystem = null; - projectBuilder = null; - super.tearDown(); + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); } abstract protected String getProjectsDirectory(); 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 1360d8e623..c63acbc146 100644 --- a/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java +++ b/maven-core/src/test/java/org/apache/maven/DefaultMavenTest.java @@ -1,17 +1,5 @@ package org.apache.maven; -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.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; - -import java.io.File; -import java.nio.file.Files; - -import static java.util.Arrays.asList; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -30,14 +18,31 @@ import static java.util.Arrays.asList; * specific language governing permissions and limitations * under the License. */ + +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.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; + +import java.io.File; +import java.nio.file.Files; + +import javax.inject.Inject; + +import static java.util.Arrays.asList; + public class DefaultMavenTest extends AbstractCoreMavenComponentTestCase { + @Inject + private Maven maven; + public void testThatErrorDuringProjectDependencyGraphCreationAreStored() throws Exception { - Maven maven = getContainer().lookup( Maven.class ); MavenExecutionRequest request = createMavenExecutionRequest( getProject( "cyclic-reference" ) ).setGoals( asList("validate") ); MavenExecutionResult result = maven.execute( request ); diff --git a/maven-core/src/test/java/org/apache/maven/MavenTest.java b/maven-core/src/test/java/org/apache/maven/MavenTest.java index 3e248604d1..711199a9de 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenTest.java +++ b/maven-core/src/test/java/org/apache/maven/MavenTest.java @@ -17,32 +17,31 @@ package org.apache.maven; import org.apache.maven.exception.ExceptionHandler; -import org.codehaus.plexus.component.annotations.Requirement; +import org.apache.maven.exception.ExceptionSummary; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.codehaus.plexus.DefaultPlexusContainer; + +import javax.inject.Inject; +import java.io.File; +import java.util.Collections; public class MavenTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private Maven maven; - @Requirement + @Inject private ExceptionHandler exceptionHandler; - protected void setUp() - throws Exception - { - super.setUp(); - maven = lookup( Maven.class ); - exceptionHandler = lookup( ExceptionHandler.class ); - } - @Override - protected void tearDown() - throws Exception + protected synchronized void setupContainer() { - maven = null; - exceptionHandler = null; - super.tearDown(); + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); } protected String getProjectsDirectory() @@ -53,7 +52,7 @@ public class MavenTest public void testLifecycleExecutionUsingADefaultLifecyclePhase() throws Exception { - /* +/* File pom = getProject( "project-with-additional-lifecycle-elements" ); MavenExecutionRequest request = createMavenExecutionRequest( pom ); MavenExecutionResult result = maven.execute( request ); @@ -64,6 +63,6 @@ public class MavenTest es.getException().printStackTrace(); fail( "Maven did not execute correctly." ); } - */ +*/ } } diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java index 0bc2978a66..d3b2eaa5b6 100644 --- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java @@ -27,29 +27,15 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Requirement; + +import javax.inject.Inject; public class ProjectDependenciesResolverTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private ProjectDependenciesResolver resolver; - protected void setUp() - throws Exception - { - super.setUp(); - resolver = lookup( ProjectDependenciesResolver.class ); - } - - @Override - protected void tearDown() - throws Exception - { - resolver = null; - super.tearDown(); - } - protected String getProjectsDirectory() { return "src/test/projects/project-dependencies-resolver"; diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index dfc5a8a983..28ffeda669 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java @@ -27,9 +27,13 @@ import java.util.List; import java.util.stream.Collectors; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.annotations.Requirement; + +import javax.inject.Inject; +import java.util.Collections; +import java.util.List; /** * @author Kristian Rosenvold @@ -38,7 +42,7 @@ import org.codehaus.plexus.component.annotations.Requirement; public class DefaultLifecyclesTest extends PlexusTestCase { - @Requirement + @Inject private DefaultLifecycles defaultLifeCycles; @Override @@ -49,19 +53,20 @@ public class DefaultLifecyclesTest configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); } - protected void setUp() - throws Exception + @Override + protected void setUp() throws Exception { super.setUp(); - defaultLifeCycles = lookup( DefaultLifecycles.class ); + getContainer(); } @Override - protected void tearDown() - throws Exception + protected synchronized void setupContainer() { - defaultLifeCycles = null; - super.tearDown(); + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); } public void testDefaultLifecycles() diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java index df585fbd00..dbf242e5e1 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java @@ -23,10 +23,11 @@ import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator; import org.apache.maven.lifecycle.internal.LifecycleModuleBuilder; import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; import org.apache.maven.lifecycle.internal.MojoExecutor; -import org.codehaus.plexus.component.annotations.Requirement; + +import javax.inject.Inject; /** - * Just asserts that it's able to create those components. Handy when plexus gets a nervous breakdown. + * Just asserts that it's able to create those components. Handy when CDI container gets a nervous breakdown. * * @author Kristian Rosenvold */ @@ -34,49 +35,29 @@ import org.codehaus.plexus.component.annotations.Requirement; public class LifecycleExecutorSubModulesTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private DefaultLifecycles defaultLifeCycles; - @Requirement + @Inject private MojoExecutor mojoExecutor; - @Requirement + @Inject private LifecycleModuleBuilder lifeCycleBuilder; - @Requirement + @Inject private LifecycleDependencyResolver lifeCycleDependencyResolver; - @Requirement + @Inject private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator; - @Requirement + @Inject private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer; - @Requirement + @Inject private LifecycleTaskSegmentCalculator lifeCycleTaskSegmentCalculator; - - protected void setUp() - throws Exception - { - super.setUp(); - defaultLifeCycles = lookup( DefaultLifecycles.class ); - mojoExecutor = lookup( MojoExecutor.class ); - lifeCycleBuilder = lookup( LifecycleModuleBuilder.class ); - lifeCycleDependencyResolver = lookup( LifecycleDependencyResolver.class ); - lifeCycleExecutionPlanCalculator = lookup( LifecycleExecutionPlanCalculator.class ); - lifeCyclePluginAnalyzer = lookup( LifeCyclePluginAnalyzer.class ); - lifeCycleTaskSegmentCalculator = lookup( LifecycleTaskSegmentCalculator.class ); - lookup( ExceptionHandler.class ); - } - - @Override - protected void tearDown() - throws Exception - { - defaultLifeCycles = null; - super.tearDown(); - } + @Inject + private ExceptionHandler exceptionHandler; protected String getProjectsDirectory() { @@ -93,6 +74,7 @@ public class LifecycleExecutorSubModulesTest assertNotNull( lifeCycleExecutionPlanCalculator ); assertNotNull( lifeCyclePluginAnalyzer ); assertNotNull( lifeCycleTaskSegmentCalculator ); + assertNotNull( exceptionHandler ); } } \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index 205538ac8f..d4a7e9b5b0 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -26,7 +26,6 @@ import java.util.HashSet; import java.util.List; import org.apache.maven.AbstractCoreMavenComponentTestCase; -import org.apache.maven.exception.ExceptionHandler; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.MojoExecutionListener; @@ -37,7 +36,6 @@ import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator import org.apache.maven.lifecycle.internal.ExecutionPlanItem; import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator; import org.apache.maven.lifecycle.internal.LifecycleTask; -import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.lifecycle.internal.TaskSegment; import org.apache.maven.model.Plugin; @@ -46,45 +44,25 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoNotFoundException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.xml.Xpp3Dom; +import javax.inject.Inject; + public class LifecycleExecutorTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private DefaultLifecycleExecutor lifecycleExecutor; - @Requirement + @Inject private DefaultLifecycleTaskSegmentCalculator lifeCycleTaskSegmentCalculator; - @Requirement + @Inject private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator; - @Requirement + @Inject private MojoDescriptorCreator mojoDescriptorCreator; - - protected void setUp() - throws Exception - { - super.setUp(); - lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class ); - lifeCycleTaskSegmentCalculator = - (DefaultLifecycleTaskSegmentCalculator) lookup( LifecycleTaskSegmentCalculator.class ); - lifeCycleExecutionPlanCalculator = lookup( LifecycleExecutionPlanCalculator.class ); - mojoDescriptorCreator = lookup( MojoDescriptorCreator.class ); - lookup( ExceptionHandler.class ); - } - - @Override - protected void tearDown() - throws Exception - { - lifecycleExecutor = null; - super.tearDown(); - } - protected String getProjectsDirectory() { return "src/test/projects/lifecycle-executor"; diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java index 89257d12aa..de02428675 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolverTest.java @@ -30,12 +30,12 @@ import org.apache.maven.AbstractCoreMavenComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Requirement; -import org.junit.Test; + +import javax.inject.Inject; public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private LifecycleDependencyResolver resolver; @Override @@ -44,15 +44,6 @@ public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentT return null; } - @Override - protected void setUp() - throws Exception - { - super.setUp(); - resolver = lookup( LifecycleDependencyResolver.class ); - } - - @Test public void testCachedReactorProjectDependencies() throws Exception { MavenSession session = createMavenSession( new File( "src/test/projects/lifecycle-dependency-resolver/pom.xml" ), new Properties(), true ); diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java index 8ef5c84491..b4b3b3ab04 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java @@ -31,29 +31,16 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDescriptor; +import javax.inject.Inject; + public class PluginManagerTest extends AbstractCoreMavenComponentTestCase { - @Requirement + @Inject private DefaultBuildPluginManager pluginManager; - protected void setUp() - throws Exception - { - super.setUp(); - pluginManager = (DefaultBuildPluginManager) lookup( BuildPluginManager.class ); - } - - @Override - protected void tearDown() - throws Exception - { - pluginManager = null; - super.tearDown(); - } protected String getProjectsDirectory() { diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 04a7ee5bc9..e579d691e2 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -47,6 +47,8 @@ import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.util.dag.CycleDetectedException; +import javax.inject.Inject; + /** * @author Jason van Zyl */ @@ -55,15 +57,9 @@ public class PluginParameterExpressionEvaluatorTest { private static final String FS = File.separator; + @Inject private RepositorySystem factory; - public void setUp() - throws Exception - { - super.setUp(); - factory = lookup( RepositorySystem.class ); - } - @Override protected void tearDown() throws Exception diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index ac3954dfc0..1456ead89f 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -21,6 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; +import java.util.Collections; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.building.ModelBuildingException; @@ -28,10 +29,13 @@ import org.apache.maven.model.building.ModelProblem; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; +import javax.inject.Inject; + /** * @author Jason van Zyl */ @@ -40,6 +44,7 @@ public abstract class AbstractMavenProjectTestCase { protected ProjectBuilder projectBuilder; + @Inject protected RepositorySystem repositorySystem; @Override @@ -50,6 +55,15 @@ public abstract class AbstractMavenProjectTestCase containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); } + @Override + protected synchronized void setupContainer() + { + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + protected void setUp() throws Exception { @@ -64,8 +78,6 @@ public abstract class AbstractMavenProjectTestCase // default over to the main project builder... projectBuilder = lookup( ProjectBuilder.class ); } - - repositorySystem = lookup( RepositorySystem.class ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index a078a81c3d..e953dbc8e2 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -22,6 +22,7 @@ package org.apache.maven.project; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; @@ -34,12 +35,15 @@ import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import javax.inject.Inject; + import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; @@ -53,12 +57,23 @@ public class PomConstructionTest private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins"; + @Inject private DefaultProjectBuilder projectBuilder; + @Inject private RepositorySystem repositorySystem; private File testDirectory; + @Override + protected synchronized void setupContainer() + { + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + @Override protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) { @@ -70,10 +85,9 @@ public class PomConstructionTest protected void setUp() throws Exception { + getContainer(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); new File( getBasedir(), BASE_MIXIN_DIR ); - projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class ); - repositorySystem = lookup( RepositorySystem.class ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java index 05d7d3e8bb..beaa1493a5 100644 --- a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java @@ -20,20 +20,34 @@ package org.apache.maven.project.artifact; */ import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusTestCase; import org.junit.Ignore; +import javax.inject.Inject; +import java.util.Collections; + @Ignore public class MavenMetadataSourceTest extends PlexusTestCase { + @Inject private RepositorySystem repositorySystem; - protected void setUp() - throws Exception + @Override + protected synchronized void setupContainer() + { + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + + @Override + protected void setUp() throws Exception { super.setUp(); - repositorySystem = lookup( RepositorySystem.class ); + getContainer(); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java index 68fbcb14e3..9e5d6eaadb 100644 --- a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java +++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java @@ -21,12 +21,18 @@ package org.apache.maven.rtinfo.internal; import org.apache.maven.rtinfo.RuntimeInformation; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; +import javax.inject.Inject; +import java.util.Collections; + public class DefaultRuntimeInformationTest extends PlexusTestCase { + @Inject + RuntimeInformation rtInfo; @Override protected void customizeContainerConfiguration( @@ -37,21 +43,30 @@ public class DefaultRuntimeInformationTest configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX); } - public void testGetMavenVersion() - throws Exception + @Override + protected void setUp() throws Exception { - RuntimeInformation rtInfo = lookup( RuntimeInformation.class ); + super.setUp(); + getContainer(); + } + @Override + protected synchronized void setupContainer() + { + super.setupContainer(); + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + + public void testGetMavenVersion() + { String mavenVersion = rtInfo.getMavenVersion(); assertNotNull( mavenVersion ); assertTrue( mavenVersion.length() > 0 ); } public void testIsMavenVersion() - throws Exception { - RuntimeInformation rtInfo = lookup( RuntimeInformation.class ); - assertTrue( rtInfo.isMavenVersion( "2.0" ) ); assertFalse( rtInfo.isMavenVersion( "9.9" ) ); diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index 78d0da8de6..4d66b0fe49 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -23,13 +23,13 @@ import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Profile; import org.apache.maven.project.DefaultProjectBuilder; import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.ReaderFactory; @@ -38,9 +38,11 @@ import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.io.Reader; +import java.util.Collections; public class PomConstructionWithSettingsTest extends PlexusTestCase @@ -49,8 +51,10 @@ public class PomConstructionWithSettingsTest private static final String BASE_POM_DIR = BASE_DIR + "/resources-settings"; + @Inject private DefaultProjectBuilder projectBuilder; + @Inject private RepositorySystem repositorySystem; private File testDirectory; @@ -63,12 +67,20 @@ public class PomConstructionWithSettingsTest containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); } + @Override + protected synchronized void setupContainer() + { + super.setupContainer(); + + ( (DefaultPlexusContainer) getContainer() ).addPlexusInjector( Collections.emptyList(), + binder -> binder.requestInjection( this ) ); + } + protected void setUp() throws Exception { + getContainer(); testDirectory = new File( getBasedir(), BASE_POM_DIR ); - projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class ); - repositorySystem = lookup( RepositorySystem.class ); } @Override diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index e60ee9d175..491fb0b9ce 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -386,15 +386,8 @@ public class MavenCliTest super.customizeContainer(container); container.addComponent(mock(Maven.class), "org.apache.maven.Maven"); - ((DefaultPlexusContainer)container).addPlexusInjector(Collections.emptyList(), - new Module() - { - public void configure( final Binder binder ) - { - binder.bind( EventSpyDispatcher.class ).toInstance( eventSpyDispatcherMock ); - } - } - ); + ( (DefaultPlexusContainer) container ).addPlexusInjector( Collections.emptyList(), + binder -> binder.bind( EventSpyDispatcher.class ).toInstance( eventSpyDispatcherMock ) ); } };