diff --git a/maven-core/pom.xml b/maven-core/pom.xml index c5e82bb5ff..da100be1e1 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -26,6 +26,7 @@ under the License. org.apache.maven 2.1-SNAPSHOT + 4.0.0 maven-core Maven Core diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java index 611fb29be1..ee0617edad 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java @@ -21,9 +21,14 @@ import org.apache.maven.plugin.loader.PluginLoader; import org.apache.maven.plugin.loader.PluginLoaderException; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -43,7 +48,7 @@ import java.util.StringTokenizer; * */ public class DefaultLifecycleBindingManager - implements LifecycleBindingManager, LogEnabled + implements LifecycleBindingManager, LogEnabled, Contextualizable { private Map bindingsByPackaging; @@ -63,31 +68,45 @@ public class DefaultLifecycleBindingManager // configured. Moved out of DefaultLifecycleExecutor... private List defaultReports; + // contextualized, used for setting lookup realm before retrieving lifecycle bindings for packaging. + private PlexusContainer container; + /** * Retrieve the LifecycleBindings given by the lifecycle mapping component/file for the project's packaging. Any * applicable mojo configuration will be injected into the LifecycleBindings from the POM. */ - public LifecycleBindings getBindingsForPackaging( final MavenProject project ) + public LifecycleBindings getBindingsForPackaging( final MavenProject project, final MavenSession session ) throws LifecycleLoaderException, LifecycleSpecificationException { String packaging = project.getPackaging(); LifecycleBindings bindings = null; - LifecycleBindingLoader loader = (LifecycleBindingLoader) bindingsByPackaging.get( packaging ); - if ( loader != null ) - { - bindings = loader.getBindings(); - } + ClassRealm projectRealm = session.getRealmManager().getProjectRealm( project.getGroupId(), project.getArtifactId(), project.getVersion() ); - // TODO: Remove this once we no longer have to support legacy-style lifecycle mappings - if ( bindings == null ) + ClassRealm oldRealm = container.setLookupRealm( projectRealm ); + + try { - LifecycleMapping mapping = (LifecycleMapping) legacyMappingsByPackaging.get( packaging ); - if ( mapping != null ) + LifecycleBindingLoader loader = (LifecycleBindingLoader) bindingsByPackaging.get( packaging ); + if ( loader != null ) { - bindings = legacyLifecycleMappingParser.parseMappings( mapping, packaging ); + bindings = loader.getBindings(); } + + // TODO: Remove this once we no longer have to support legacy-style lifecycle mappings + if ( bindings == null ) + { + LifecycleMapping mapping = (LifecycleMapping) legacyMappingsByPackaging.get( packaging ); + if ( mapping != null ) + { + bindings = legacyLifecycleMappingParser.parseMappings( mapping, packaging ); + } + } + } + finally + { + container.setLookupRealm( oldRealm ); } if ( bindings != null ) @@ -582,4 +601,10 @@ public class DefaultLifecycleBindingManager return reportClass.isAssignableFrom( mojoClass ); } + public void contextualize( Context ctx ) + throws ContextException + { + container = (PlexusContainer) ctx.get( PlexusConstants.PLEXUS_KEY ); + } + } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java index ae495f8060..1d867b499b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/LifecycleBindingManager.java @@ -31,8 +31,9 @@ public interface LifecycleBindingManager /** * Retrieve the LifecycleBindings given by the lifecycle mapping component/file for the project's packaging. Any * applicable mojo configuration will be injected into the LifecycleBindings from the POM. + * @param session */ - LifecycleBindings getBindingsForPackaging( MavenProject project ) + LifecycleBindings getBindingsForPackaging( MavenProject project, MavenSession session ) throws LifecycleLoaderException, LifecycleSpecificationException; /** diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java index 3ac2517c72..58d86b1d69 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java @@ -51,7 +51,7 @@ public class DefaultBuildPlanner throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException { LifecycleBindings defaultBindings = lifecycleBindingManager.getDefaultBindings( project ); - LifecycleBindings packagingBindings = lifecycleBindingManager.getBindingsForPackaging( project ); + LifecycleBindings packagingBindings = lifecycleBindingManager.getBindingsForPackaging( project, session ); LifecycleBindings projectBindings = lifecycleBindingManager.getProjectCustomBindings( project, session ); BuildPlan plan = new BuildPlan( packagingBindings, projectBindings, defaultBindings, tasks ); diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenRealmManagerTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenRealmManagerTest.java index 85c5c6ec29..20851969f3 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenRealmManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenRealmManagerTest.java @@ -3,7 +3,6 @@ package org.apache.maven.execution; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; @@ -25,7 +24,7 @@ public class DefaultMavenRealmManagerTest } public void test_ReuseSingleExtensionRealmFromMultipleProjectRealms_UsingTwoManagerInstances() - throws RealmManagementException, ComponentLookupException + throws Exception { ClassLoader cloader = Thread.currentThread().getContextClassLoader(); URL jarResource = cloader.getResource( "org/apache/maven/execution/test-extension-1.jar" ); diff --git a/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java b/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java index eb07b1cb84..2b1b13db64 100644 --- a/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/extension/DefaultExtensionManagerTest.java @@ -86,7 +86,7 @@ public class DefaultExtensionManagerTest if ( f.exists() ) { - try + try { FileUtils.forceDelete( f ); } @@ -207,6 +207,7 @@ public class DefaultExtensionManagerTest } private ExtensionManager newDefaultExtensionManager() + throws Exception { DefaultExtensionManager mgr = new DefaultExtensionManager( factory, resolver, metadataSource, container, diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManagerTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManagerTest.java index 74429322fe..21262fc119 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManagerTest.java @@ -1,29 +1,45 @@ package org.apache.maven.lifecycle.binding; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenRealmManager; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenRealmManager; +import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleLoaderException; import org.apache.maven.lifecycle.LifecycleSpecificationException; +import org.apache.maven.lifecycle.model.BuildBinding; import org.apache.maven.lifecycle.model.LifecycleBindings; import org.apache.maven.lifecycle.model.MojoBinding; +import org.apache.maven.lifecycle.model.Phase; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginManagement; import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.tools.easymock.MockManager; import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.easymock.MockControl; +import java.io.File; +import java.net.URL; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Properties; -public class DefaultLifecycleBindingManagerTest extends PlexusTestCase +public class DefaultLifecycleBindingManagerTest + extends PlexusTestCase { private LifecycleBindingManager mgr; - public void setUp() throws Exception + public void setUp() + throws Exception { super.setUp(); @@ -36,7 +52,7 @@ public class DefaultLifecycleBindingManagerTest extends PlexusTestCase } public void testGetBindingsForPackaging_TestMergePluginConfigToBinding() - throws LifecycleLoaderException, LifecycleSpecificationException + throws Exception { Model model = new Model(); model.setGroupId( "group" ); @@ -61,7 +77,19 @@ public class DefaultLifecycleBindingManagerTest extends PlexusTestCase MavenProject project = new MavenProject( model ); - LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project ); + MavenRealmManager realmManager = new DefaultMavenRealmManager( + getContainer(), + new ConsoleLogger( + Logger.LEVEL_DEBUG, + "test" ) ); + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager ); + + LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project, + new MavenSession( + getContainer(), + request, + null, + null ) ); List bindings = lifecycleBindings.getBuildBinding().getCompile().getBindings(); @@ -79,7 +107,7 @@ public class DefaultLifecycleBindingManagerTest extends PlexusTestCase } public void testGetBindingsForPackaging_TestMergePluginManagementConfigToBinding() - throws LifecycleLoaderException, LifecycleSpecificationException + throws Exception { Model model = new Model(); model.setGroupId( "group" ); @@ -107,7 +135,19 @@ public class DefaultLifecycleBindingManagerTest extends PlexusTestCase MavenProject project = new MavenProject( model ); - LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project ); + MavenRealmManager realmManager = new DefaultMavenRealmManager( + getContainer(), + new ConsoleLogger( + Logger.LEVEL_DEBUG, + "test" ) ); + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager ); + + LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project, + new MavenSession( + getContainer(), + request, + null, + null ) ); List bindings = lifecycleBindings.getBuildBinding().getCompile().getBindings(); @@ -178,6 +218,86 @@ public class DefaultLifecycleBindingManagerTest extends PlexusTestCase assertEquals( "other-value", config.getChild( "test2" ).getValue() ); } + public void test_GetBindingsForPackaging_CustomLifecycleIsUsedFromRealmManager() + throws Exception + { + Model model = new Model(); + + model.setPackaging( "test" ); + + MavenProject project = new MavenProject( model ); + + MavenRealmManager realmManager = new DefaultMavenRealmManager( + getContainer(), + new ConsoleLogger( + Logger.LEVEL_DEBUG, + "test" ) ); + + MockManager mockManager = new MockManager(); + + MockControl extArtifactCtl = MockControl.createControl( Artifact.class ); + mockManager.add( extArtifactCtl ); + + Artifact extensionArtifact = (Artifact) extArtifactCtl.getMock(); + + extensionArtifact.getGroupId(); + extArtifactCtl.setReturnValue( "group", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getArtifactId(); + extArtifactCtl.setReturnValue( "artifact", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getVersion(); + extArtifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getFile(); + extArtifactCtl.setReturnValue( getResourceFile( "org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar" ), + MockControl.ZERO_OR_MORE ); + + mockManager.replayAll(); + + realmManager.createExtensionRealm( extensionArtifact, Collections.EMPTY_SET ); + realmManager.importExtensionsIntoProjectRealm( "group", "project", "1", extensionArtifact ); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager ); + + MavenSession session = new MavenSession( getContainer(), request, null, null ); + + LifecycleBindings lifecycleBindings = mgr.getBindingsForPackaging( project, session ); + + BuildBinding buildBinding = lifecycleBindings.getBuildBinding(); + assertNotNull( buildBinding ); + + Phase installPhase = buildBinding.getInstall(); + Phase deployPhase = buildBinding.getDeploy(); + Phase packagePhase = buildBinding.getCreatePackage(); + + assertTrue( ( packagePhase.getBindings() == null ) || packagePhase.getBindings().isEmpty() ); + assertNotNull( installPhase.getBindings() ); + assertEquals( 1, installPhase.getBindings().size() ); + assertEquals( "maven-deploy-plugin", + ( (MojoBinding) installPhase.getBindings().get( 0 ) ).getArtifactId() ); + + assertNotNull( deployPhase.getBindings() ); + assertEquals( 1, deployPhase.getBindings().size() ); + assertEquals( "maven-install-plugin", + ( (MojoBinding) deployPhase.getBindings().get( 0 ) ).getArtifactId() ); + + mockManager.verifyAll(); + } + + private File getResourceFile( String path ) + { + ClassLoader cloader = Thread.currentThread().getContextClassLoader(); + URL resource = cloader.getResource( path ); + + if ( resource == null ) + { + fail( "Cannot find test resource: " + path ); + } + + return new File( resource.getPath() ); + } + private Object createConfiguration( final Properties configProperties ) { Xpp3Dom config = new Xpp3Dom( "configuration" ); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.java index 15c3b4f3eb..cb3f563a74 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.java @@ -1,8 +1,11 @@ package org.apache.maven.lifecycle.plan; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenRealmManager; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenRealmManager; import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.LifecycleLoaderException; -import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.MojoBindingUtils; import org.apache.maven.lifecycle.model.MojoBinding; import org.apache.maven.lifecycle.plan.testutils.TestPluginLoader; @@ -14,8 +17,14 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.loader.PluginLoader; import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.tools.easymock.MockManager; import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.console.ConsoleLogger; +import org.easymock.MockControl; +import java.io.File; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -29,6 +38,8 @@ public class DefaultBuildPlannerTest private TestPluginLoader pluginLoader; + private MockManager mockManager = new MockManager(); + protected void setUp() throws Exception { @@ -38,7 +49,7 @@ public class DefaultBuildPlannerTest } public void test_constructBuildPlan_ForkedPhaseFromMojoBoundInThatPhase() - throws LifecycleLoaderException, LifecycleSpecificationException, LifecyclePlannerException + throws Exception { Model model = new Model(); @@ -59,8 +70,10 @@ public class DefaultBuildPlannerTest plugin.addExecution( exec ); - PluginDescriptor pd = TestPluginLoader.createPluginDescriptor( plugin.getArtifactId(), "assembly", - plugin.getGroupId(), plugin.getVersion() ); + PluginDescriptor pd = TestPluginLoader.createPluginDescriptor( plugin.getArtifactId(), + "assembly", + plugin.getGroupId(), + plugin.getVersion() ); MojoDescriptor md = TestPluginLoader.createMojoDescriptor( pd, "assembly" ); md.setExecutePhase( "package" ); @@ -68,9 +81,14 @@ public class DefaultBuildPlannerTest MavenProject project = new MavenProject( model ); - MavenSession session = new MavenSession( getContainer(), null, null, null ); + MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ); + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager ); - BuildPlan plan = buildPlanner.constructBuildPlan( Collections.singletonList( "package" ), project, session ); + MavenSession session = new MavenSession( getContainer(), request, null, null ); + + BuildPlan plan = buildPlanner.constructBuildPlan( Collections.singletonList( "package" ), + project, + session ); List rendered = plan.renderExecutionPlan( new Stack() ); @@ -96,7 +114,75 @@ public class DefaultBuildPlannerTest assertBindingIds( rendered, checkIds ); } - private void assertBindingIds( List bindings, List checkIds ) + public void test_constructBuildPlan_CustomLifecycleIsUsedFromRealmManager() + throws Exception + { + Model model = new Model(); + + model.setPackaging( "test" ); + + MavenProject project = new MavenProject( model ); + + MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ); + + MockControl extArtifactCtl = MockControl.createControl( Artifact.class ); + mockManager.add( extArtifactCtl ); + + Artifact extensionArtifact = (Artifact) extArtifactCtl.getMock(); + + extensionArtifact.getGroupId(); + extArtifactCtl.setReturnValue( "group", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getArtifactId(); + extArtifactCtl.setReturnValue( "artifact", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getVersion(); + extArtifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE ); + + extensionArtifact.getFile(); + extArtifactCtl.setReturnValue( getResourceFile( "org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar" ), + MockControl.ZERO_OR_MORE ); + + mockManager.replayAll(); + + realmManager.createExtensionRealm( extensionArtifact, Collections.EMPTY_SET ); + realmManager.importExtensionsIntoProjectRealm( "group", "project", "1", extensionArtifact ); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager ); + + MavenSession session = new MavenSession( getContainer(), request, null, null ); + + BuildPlan plan = buildPlanner.constructBuildPlan( Collections.singletonList( "deploy" ), + project, + session ); + + List rendered = plan.renderExecutionPlan( new Stack() ); + + List checkIds = new ArrayList(); + + checkIds.add( "org.apache.maven.plugins:maven-deploy-plugin:deploy" ); + checkIds.add( "org.apache.maven.plugins:maven-install-plugin:install" ); + + assertBindingIds( rendered, checkIds ); + + mockManager.verifyAll(); + } + + private File getResourceFile( String path ) + { + ClassLoader cloader = Thread.currentThread().getContextClassLoader(); + URL resource = cloader.getResource( path ); + + if ( resource == null ) + { + fail( "Cannot find test resource: " + path ); + } + + return new File( resource.getPath() ); + } + + private void assertBindingIds( List bindings, + List checkIds ) { assertEquals( checkIds.size(), bindings.size() ); diff --git a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml new file mode 100644 index 0000000000..df5ae16dc0 --- /dev/null +++ b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven.core.test + test-custom-lifecycle-buildPlan + jar + 1 + test-custom-lifecycle-buildPlan + + diff --git a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000000..78c341784a --- /dev/null +++ b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,31 @@ + + + + org.apache.maven.artifact.handler.ArtifactHandler + test + org.apache.maven.artifact.handler.DefaultArtifactHandler + + test + jar + java + true + + + + org.apache.maven.lifecycle.mapping.LifecycleMapping + test + org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping + + + + default + + org.apache.maven.plugins:maven-deploy-plugin:deploy + org.apache.maven.plugins:maven-install-plugin:install + + + + + + + diff --git a/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar b/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar new file mode 100644 index 0000000000..5c9bef6e8d Binary files /dev/null and b/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar differ diff --git a/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java index c96ee23932..834b41985f 100644 --- a/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java +++ b/maven-project/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java @@ -27,7 +27,6 @@ import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.activation.DefaultProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationContext; -import org.apache.maven.profiles.activation.ProfileActivationException; import org.codehaus.plexus.PlexusTestCase; import java.util.List; @@ -37,28 +36,30 @@ public class DefaultProfileManagerTest extends PlexusTestCase { - public void setUp() throws Exception + public void setUp() + throws Exception { super.setUp(); } - public void testShouldActivateDefaultProfile() throws ProfileActivationException + public void testShouldActivateDefaultProfile() + throws Exception { Profile notActivated = new Profile(); - notActivated.setId("notActivated"); + notActivated.setId( "notActivated" ); Activation nonActivation = new Activation(); - nonActivation.setJdk("19.2"); + nonActivation.setJdk( "19.2" ); notActivated.setActivation( nonActivation ); Profile defaultActivated = new Profile(); - defaultActivated.setId("defaultActivated"); + defaultActivated.setId( "defaultActivated" ); Activation defaultActivation = new Activation(); - defaultActivation.setActiveByDefault(true); + defaultActivation.setActiveByDefault( true ); defaultActivated.setActivation( defaultActivation ); @@ -67,36 +68,37 @@ public class DefaultProfileManagerTest ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(notActivated); - profileManager.addProfile(defaultActivated); + profileManager.addProfile( notActivated ); + profileManager.addProfile( defaultActivated ); List active = profileManager.getActiveProfiles(); assertNotNull( active ); assertEquals( 1, active.size() ); - assertEquals("defaultActivated", ((Profile)active.get(0)).getId()); + assertEquals( "defaultActivated", ( (Profile) active.get( 0 ) ).getId() ); } - public void testShouldNotActivateDefaultProfile() throws ProfileActivationException + public void testShouldNotActivateDefaultProfile() + throws Exception { Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); + syspropActivated.setId( "syspropActivated" ); Activation syspropActivation = new Activation(); ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("java.version"); + syspropProperty.setName( "java.version" ); - syspropActivation.setProperty(syspropProperty); + syspropActivation.setProperty( syspropProperty ); syspropActivated.setActivation( syspropActivation ); Profile defaultActivated = new Profile(); - defaultActivated.setId("defaultActivated"); + defaultActivated.setId( "defaultActivated" ); Activation defaultActivation = new Activation(); - defaultActivation.setActiveByDefault(true); + defaultActivation.setActiveByDefault( true ); defaultActivated.setActivation( defaultActivation ); @@ -105,27 +107,28 @@ public class DefaultProfileManagerTest ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(syspropActivated); - profileManager.addProfile(defaultActivated); + profileManager.addProfile( syspropActivated ); + profileManager.addProfile( defaultActivated ); List active = profileManager.getActiveProfiles(); assertNotNull( active ); assertEquals( 1, active.size() ); - assertEquals("syspropActivated", ((Profile)active.get(0)).getId()); + assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() ); } - public void testShouldNotActivateReversalOfPresentSystemProperty() throws ProfileActivationException + public void testShouldNotActivateReversalOfPresentSystemProperty() + throws Exception { Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); + syspropActivated.setId( "syspropActivated" ); Activation syspropActivation = new Activation(); ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("!java.version"); + syspropProperty.setName( "!java.version" ); - syspropActivation.setProperty(syspropProperty); + syspropActivation.setProperty( syspropProperty ); syspropActivated.setActivation( syspropActivation ); @@ -134,7 +137,7 @@ public class DefaultProfileManagerTest ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(syspropActivated); + profileManager.addProfile( syspropActivated ); List active = profileManager.getActiveProfiles(); @@ -142,17 +145,18 @@ public class DefaultProfileManagerTest assertEquals( 0, active.size() ); } - public void testShouldOverrideAndActivateInactiveProfile() throws ProfileActivationException + public void testShouldOverrideAndActivateInactiveProfile() + throws Exception { Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); + syspropActivated.setId( "syspropActivated" ); Activation syspropActivation = new Activation(); ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("!java.version"); + syspropProperty.setName( "!java.version" ); - syspropActivation.setProperty(syspropProperty); + syspropActivation.setProperty( syspropProperty ); syspropActivated.setActivation( syspropActivation ); @@ -161,28 +165,29 @@ public class DefaultProfileManagerTest ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(syspropActivated); + profileManager.addProfile( syspropActivated ); - profileManager.explicitlyActivate("syspropActivated"); + profileManager.explicitlyActivate( "syspropActivated" ); List active = profileManager.getActiveProfiles(); assertNotNull( active ); assertEquals( 1, active.size() ); - assertEquals( "syspropActivated", ((Profile)active.get(0)).getId()); + assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() ); } - public void testShouldOverrideAndDeactivateActiveProfile() throws ProfileActivationException + public void testShouldOverrideAndDeactivateActiveProfile() + throws Exception { Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); + syspropActivated.setId( "syspropActivated" ); Activation syspropActivation = new Activation(); ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("java.version"); + syspropProperty.setName( "java.version" ); - syspropActivation.setProperty(syspropProperty); + syspropActivation.setProperty( syspropProperty ); syspropActivated.setActivation( syspropActivation ); @@ -191,9 +196,9 @@ public class DefaultProfileManagerTest ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(syspropActivated); + profileManager.addProfile( syspropActivated ); - profileManager.explicitlyDeactivate("syspropActivated"); + profileManager.explicitlyDeactivate( "syspropActivated" ); List active = profileManager.getActiveProfiles(); @@ -201,27 +206,28 @@ public class DefaultProfileManagerTest assertEquals( 0, active.size() ); } - public void testOsActivationProfile() throws ProfileActivationException + public void testOsActivationProfile() + throws Exception { Profile osActivated = new Profile(); - osActivated.setId("os-profile"); + osActivated.setId( "os-profile" ); Activation osActivation = new Activation(); ActivationOS activationOS = new ActivationOS(); - activationOS.setName("!dddd"); + activationOS.setName( "!dddd" ); - osActivation.setOs(activationOS); + osActivation.setOs( activationOS ); - osActivated.setActivation(osActivation); + osActivated.setActivation( osActivation ); Properties props = System.getProperties(); ProfileActivationContext ctx = new DefaultProfileActivationContext( props, false ); ProfileManager profileManager = new DefaultProfileManager( getContainer(), ctx ); - profileManager.addProfile(osActivated); + profileManager.addProfile( osActivated ); List active = profileManager.getActiveProfiles(); diff --git a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java index 06cc192073..5d2cf7e99a 100644 --- a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java @@ -42,7 +42,7 @@ public class SuperPomProjectBuilderTest } public void testStandaloneSuperPomContainsInjectedExternalProfileRepositories() - throws ProjectBuildingException + throws Exception { Profile profile = new Profile(); profile.setId( "test-profile" ); diff --git a/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java index 3e4131d9b0..f9698d41aa 100644 --- a/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/build/model/DefaultModelLineageBuilderTest.java @@ -388,7 +388,7 @@ public class DefaultModelLineageBuilderTest } public void testReadPOMWithParentInRepoBroughtInViaSettingsProfile() - throws IOException, ProjectBuildingException + throws Exception { // 1. create project-root directory. File projectRootDirectory = createTempDir( "projectRootDir" );