From ab3b68a650a40aa0a27c61b1efede8df3590e655 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 8 Mar 2009 16:15:10 +0000 Subject: [PATCH] o don't need a separate module anymore, simplified to the point where I'm back to something similar to 2.x git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@751455 13f79535-47bb-0310-9956-ffa450edef68 --- maven-lifecycle/pom.xml | 59 - .../ClassLoaderXmlBindingLoader.java | 84 - .../lifecycle/LifecycleBindingLoader.java | 13 - .../maven/lifecycle/LifecycleException.java | 17 - .../lifecycle/LifecycleLoaderException.java | 17 - .../LifecycleSpecificationException.java | 17 - .../maven/lifecycle/LifecycleUtils.java | 714 --------- .../maven/lifecycle/MojoBindingUtils.java | 43 - .../lifecycle/NoSuchLifecycleException.java | 26 - .../maven/lifecycle/NoSuchPhaseException.java | 26 - .../src/main/mdo/maven-lifecycle.mdo | 708 --------- maven-lifecycle/src/site/site.xml | 6 - .../ClassLoaderXmlBindingLoaderTest.java | 61 - .../maven/lifecycle/LifecycleUtilsTest.java | 1371 ----------------- .../resources/META-INF/plexus/components.xml | 12 - .../test/resources/single-clean-mapping.xml | 15 - 16 files changed, 3189 deletions(-) delete mode 100644 maven-lifecycle/pom.xml delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoader.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleBindingLoader.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleLoaderException.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleSpecificationException.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleUtils.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingUtils.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchLifecycleException.java delete mode 100644 maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchPhaseException.java delete mode 100644 maven-lifecycle/src/main/mdo/maven-lifecycle.mdo delete mode 100644 maven-lifecycle/src/site/site.xml delete mode 100644 maven-lifecycle/src/test/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoaderTest.java delete mode 100644 maven-lifecycle/src/test/java/org/apache/maven/lifecycle/LifecycleUtilsTest.java delete mode 100644 maven-lifecycle/src/test/resources/META-INF/plexus/components.xml delete mode 100644 maven-lifecycle/src/test/resources/single-clean-mapping.xml diff --git a/maven-lifecycle/pom.xml b/maven-lifecycle/pom.xml deleted file mode 100644 index 9daedd7bb3..0000000000 --- a/maven-lifecycle/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - maven - org.apache.maven - 3.0-SNAPSHOT - - 4.0.0 - maven-lifecycle - Maven Lifecycle Model - - - - org.codehaus.plexus - plexus-container-default - test - - - org.codehaus.plexus - plexus-utils - - - - - - - org.codehaus.modello - modello-maven-plugin - - 1.0.0 - - src/main/mdo/maven-lifecycle.mdo - - - - - - - diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoader.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoader.java deleted file mode 100644 index 2cad2aa63f..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoader.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.LifecycleBindings; -import org.apache.maven.lifecycle.model.io.xpp3.LifecycleBindingsXpp3Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; - -/** - * @author jdcasey - */ -public class ClassLoaderXmlBindingLoader - implements LifecycleBindingLoader -{ - - // configuration. - private String path; - - public ClassLoaderXmlBindingLoader() - { - // for plexus init. - } - - public ClassLoaderXmlBindingLoader( String path ) - { - this.path = path; - } - - public LifecycleBindings getBindings() - throws LifecycleLoaderException, LifecycleSpecificationException - { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - URL url = loader.getResource( getPath() ); - - if ( url == null ) - { - throw new LifecycleLoaderException( "Classpath resource: " + getPath() + " could not be found." ); - } - - InputStreamReader reader; - try - { - reader = new InputStreamReader( url.openStream() ); - } - catch ( IOException e ) - { - throw new LifecycleLoaderException( "Failed to open stream for classpath resource: " + getPath() + ". Reason: " - + e.getMessage(), e ); - } - - LifecycleBindings bindings; - try - { - bindings = new LifecycleBindingsXpp3Reader().read( reader ); - } - catch ( IOException e ) - { - throw new LifecycleLoaderException( "Classpath resource: " + getPath() + " could not be read. Reason: " - + e.getMessage(), e ); - } - catch ( XmlPullParserException e ) - { - throw new LifecycleLoaderException( "Classpath resource: " + getPath() + " could not be parsed. Reason: " - + e.getMessage(), e ); - } - - LifecycleUtils.setOrigin( bindings, url.toExternalForm() ); - - return bindings; - } - - public String getPath() - { - return path; - } - - public void setPath( String path ) - { - this.path = path; - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleBindingLoader.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleBindingLoader.java deleted file mode 100644 index 9f38975f25..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleBindingLoader.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.LifecycleBindings; - -public interface LifecycleBindingLoader -{ - - String ROLE = LifecycleBindingLoader.class.getName(); - - LifecycleBindings getBindings() - throws LifecycleLoaderException, LifecycleSpecificationException; - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java deleted file mode 100644 index 8d11e1df35..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleException.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.apache.maven.lifecycle; - -public abstract class LifecycleException - extends Exception -{ - - protected LifecycleException( String message, Throwable cause ) - { - super( message, cause ); - } - - protected LifecycleException( String message ) - { - super( message ); - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleLoaderException.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleLoaderException.java deleted file mode 100644 index f8f7202f7c..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleLoaderException.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.apache.maven.lifecycle; - -public class LifecycleLoaderException - extends LifecycleException -{ - - public LifecycleLoaderException( String message, Throwable cause ) - { - super( message, cause ); - } - - public LifecycleLoaderException( String message ) - { - super( message ); - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleSpecificationException.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleSpecificationException.java deleted file mode 100644 index 9d0a4d826e..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleSpecificationException.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.apache.maven.lifecycle; - -public class LifecycleSpecificationException - extends LifecycleException -{ - - public LifecycleSpecificationException( String message, Throwable cause ) - { - super( message, cause ); - } - - public LifecycleSpecificationException( String message ) - { - super( message ); - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleUtils.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleUtils.java deleted file mode 100644 index 4415f4de78..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/LifecycleUtils.java +++ /dev/null @@ -1,714 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.BuildBinding; -import org.apache.maven.lifecycle.model.CleanBinding; -import org.apache.maven.lifecycle.model.LifecycleBinding; -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.lifecycle.model.SiteBinding; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class LifecycleUtils -{ - - private LifecycleUtils() - { - } - - public static void setupTrackingInfo( final LifecycleBindings bindings ) - { - for ( Iterator bindingIt = bindings.getBindingList().iterator(); bindingIt.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) bindingIt.next(); - - if ( binding == null ) - { - continue; - } - - LinkedHashMap phaseMap = binding.getOrderedPhaseMapping(); - for ( Iterator phaseIt = phaseMap.entrySet().iterator(); phaseIt.hasNext(); ) - { - Map.Entry entry = (Entry) phaseIt.next(); - Phase phase = (Phase) entry.getValue(); - - String phaseName = (String) entry.getKey(); - - if ( phase != null ) - { - phase.setLifecycleInfo( phaseName, binding ); - } - } - } - } - - public static void setOrigin( final LifecycleBindings bindings, final String origin ) - { - for ( Iterator bindingIt = bindings.getBindingList().iterator(); bindingIt.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) bindingIt.next(); - - if ( binding == null ) - { - continue; - } - - for ( Iterator phaseIt = binding.getPhasesInOrder().iterator(); phaseIt.hasNext(); ) - { - Phase phase = (Phase) phaseIt.next(); - - if ( phase == null ) - { - continue; - } - - for ( Iterator mojoIt = phase.getBindings().iterator(); mojoIt.hasNext(); ) - { - MojoBinding mojoBinding = (MojoBinding) mojoIt.next(); - - mojoBinding.setOrigin( origin ); - } - } - } - } - - public static List getMojoBindingListForLifecycle( final String stopPhase, final LifecycleBindings bindings ) - throws NoSuchPhaseException - { - LifecycleBinding binding = findLifecycleBindingForPhase( stopPhase, bindings ); - - if ( binding == null ) - { - throw new NoSuchPhaseException( stopPhase, "Phase not found in any lifecycle." ); - } - - return getMojoBindingListForLifecycle( stopPhase, binding ); - } - - public static List getMojoBindingListForLifecycle( final String stopPhase, final LifecycleBinding lifecycle ) - throws NoSuchPhaseException - { - List phaseNames = lifecycle.getPhaseNamesInOrder(); - - int idx = phaseNames.indexOf( stopPhase ); - - if ( idx < 0 ) - { - throw new NoSuchPhaseException( stopPhase, "Phase not found in lifecycle: " + lifecycle.getId() ); - } - - List phases = lifecycle.getPhasesInOrder(); - - List bindings = new ArrayList(); - for ( int i = 0; i <= idx; i++ ) - { - Phase phase = (Phase) phases.get( i ); - List phaseBindings = phase.getBindings(); - - if ( ( phaseBindings != null ) && !phaseBindings.isEmpty() ) - { - bindings.addAll( phaseBindings ); - } - } - - return bindings; - } - - /** - * @return null if the phase is not contained in any of the lifecycles. - */ - public static LifecycleBinding findLifecycleBindingForPhase( final String phaseName, - final LifecycleBindings lifecycles ) - { - List lifecyclesAvailable = lifecycles.getBindingList(); - - for ( Iterator it = lifecyclesAvailable.iterator(); it.hasNext(); ) - { - LifecycleBinding lifecycle = (LifecycleBinding) it.next(); - - if ( lifecycle.getPhaseNamesInOrder().indexOf( phaseName ) > -1 ) - { - return lifecycle; - } - } - - return null; - } - - public static void removeMojoBinding( final String phaseName, final MojoBinding mojoBinding, - final LifecycleBinding lifecycleBinding, final boolean considerExecutionId ) - throws NoSuchPhaseException - { - List phaseNames = lifecycleBinding.getPhaseNamesInOrder(); - - int idx = phaseNames.indexOf( phaseName ); - - if ( idx < 0 ) - { - throw new NoSuchPhaseException( phaseName, "Phase: " + phaseName + " not found in lifecycle: " - + lifecycleBinding.getId() ); - } - - List phases = lifecycleBinding.getPhasesInOrder(); - - Phase phase = (Phase) phases.get( idx ); - - if ( phase != null ) - { - List mojoBindings = phase.getBindings(); - - String targetKey = MojoBindingUtils.createMojoBindingKey( mojoBinding, considerExecutionId ); - - for ( Iterator it = mojoBindings.iterator(); it.hasNext(); ) - { - MojoBinding candidate = (MojoBinding) it.next(); - - String candidateKey = MojoBindingUtils.createMojoBindingKey( candidate, considerExecutionId ); - if ( candidateKey.equals( targetKey ) ) - { - it.remove(); - } - } - - phase.setBindings( mojoBindings ); - } - } - - public static void addMojoBinding( final String phaseName, final MojoBinding mojoBinding, - final LifecycleBinding lifecycleBinding ) throws NoSuchPhaseException - { - List phaseNames = lifecycleBinding.getPhaseNamesInOrder(); - - int idx = phaseNames.indexOf( phaseName ); - - if ( idx < 0 ) - { - throw new NoSuchPhaseException( phaseName, "Phase: " + phaseName + " not found in lifecycle: " - + lifecycleBinding.getId() ); - } - - List phases = lifecycleBinding.getPhasesInOrder(); - - Phase phase = (Phase) phases.get( idx ); - phase.addBinding( mojoBinding ); - mojoBinding.setLifecycleInfo( phase ); - } - - public static void addMojoBinding( final String phaseName, final MojoBinding mojo, final LifecycleBindings bindings ) - throws LifecycleSpecificationException - { - LifecycleBinding binding = findLifecycleBindingForPhase( phaseName, bindings ); - - if ( binding == null ) - { - throw new NoSuchPhaseException( phaseName, "Phase not found in any lifecycle: " + phaseName ); - } - - addMojoBinding( phaseName, mojo, binding ); - } - - public static LifecycleBindings mergeBindings( final LifecycleBindings existingBindings, - final LifecycleBindings newBindings, - final LifecycleBindings defaultBindings, - final boolean mergeConfigIfExecutionIdMatches ) - { - return mergeBindings( existingBindings, newBindings, defaultBindings, mergeConfigIfExecutionIdMatches, false ); - } - - public static LifecycleBindings mergeBindings( final LifecycleBindings existingBindings, - final LifecycleBindings newBindings, - final LifecycleBindings defaultBindings, - final boolean mergeConfigIfExecutionIdMatches, - final boolean reverseConfigMergeDirection ) - { - LifecycleBindings result = new LifecycleBindings(); - result.setPackaging( newBindings.getPackaging() ); - - CleanBinding cb = (CleanBinding) cloneBinding( existingBindings.getCleanBinding() ); - if ( ( defaultBindings != null ) && isNullOrEmpty( cb ) ) - { - cb = (CleanBinding) cloneBinding( defaultBindings.getCleanBinding() ); - } - - if ( cb == null ) - { - cb = new CleanBinding(); - } - - result.setCleanBinding( cb ); - - BuildBinding bb = (BuildBinding) cloneBinding( existingBindings.getBuildBinding() ); - if ( ( defaultBindings != null ) && isNullOrEmpty( bb ) ) - { - bb = (BuildBinding) cloneBinding( defaultBindings.getBuildBinding() ); - } - - if ( bb == null ) - { - bb = new BuildBinding(); - } - - result.setBuildBinding( bb ); - - SiteBinding sb = (SiteBinding) cloneBinding( existingBindings.getSiteBinding() ); - if ( ( defaultBindings != null ) && isNullOrEmpty( sb ) ) - { - sb = (SiteBinding) cloneBinding( defaultBindings.getSiteBinding() ); - } - - if ( sb == null ) - { - sb = new SiteBinding(); - } - - result.setSiteBinding( sb ); - - for ( Iterator bindingIt = newBindings.getBindingList().iterator(); bindingIt.hasNext(); ) - { - LifecycleBinding lifecycleBinding = (LifecycleBinding) bindingIt.next(); - - if ( lifecycleBinding != null ) - { - List phaseNames = lifecycleBinding.getPhaseNamesInOrder(); - List phases = lifecycleBinding.getPhasesInOrder(); - - for ( int i = 0; i < phases.size(); i++ ) - { - Phase phase = (Phase) phases.get( i ); - String name = (String) phaseNames.get( i ); - - if ( ( phase != null ) && ( phase.getBindings() != null ) && !phase.getBindings().isEmpty() ) - { - for ( Iterator phaseIt = phase.getBindings().iterator(); phaseIt.hasNext(); ) - { - MojoBinding mojoBinding = (MojoBinding) phaseIt.next(); - - mojoBinding = cloneMojoBinding( mojoBinding ); - - if ( mergeConfigIfExecutionIdMatches ) - { - MojoBinding matchingBinding = - findMatchingMojoBinding( mojoBinding, existingBindings, true ); - - if ( matchingBinding != null ) - { - Xpp3Dom existingConfig = new Xpp3Dom( (Xpp3Dom) matchingBinding.getConfiguration() ); - - Xpp3Dom configuration; - if ( reverseConfigMergeDirection ) - { - configuration = - Xpp3Dom.mergeXpp3Dom( existingConfig, - (Xpp3Dom) mojoBinding.getConfiguration() ); - } - else - { - configuration = - Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) mojoBinding.getConfiguration(), - existingConfig ); - } - - mojoBinding.setConfiguration( configuration ); - - if ( ( mojoBinding.getOrigin() == null ) && ( matchingBinding.getOrigin() != null ) ) - { - mojoBinding.setOrigin( matchingBinding.getOrigin() ); - } - - LifecycleBinding resultBinding = findLifecycleBindingForPhase( name, result ); - - try - { - removeMojoBinding( name, matchingBinding, resultBinding, true ); - } - catch ( NoSuchPhaseException e ) - { - IllegalStateException error = - new IllegalStateException( - e.getMessage() - + "\nSomething strange is going on. Merging should not encounter such inconsistencies." ); - - error.initCause( e ); - - throw error; - } - } - } - - try - { - addMojoBinding( name, mojoBinding, result ); - } - catch ( LifecycleSpecificationException e ) - { - // NOTE: this shouldn't happen as long as normal components are used - // to create/read these LifecycleBindings instances. - IllegalArgumentException error = - new IllegalArgumentException( "Project bindings are invalid. Reason: " - + e.getMessage() ); - - error.initCause( e ); - - throw error; - } - } - } - } - } - } - - return result; - } - - private static boolean isNullOrEmpty( final LifecycleBinding binding ) - { - if ( binding == null ) - { - return true; - } - - for ( Iterator it = binding.getPhasesInOrder().iterator(); it.hasNext(); ) - { - Phase phase = (Phase) it.next(); - - if ( !phase.getBindings().isEmpty() ) - { - return false; - } - } - - return true; - } - - public static MojoBinding findMatchingMojoBinding( final MojoBinding mojoBinding, - final LifecycleBindings inBindings, - final boolean considerExecutionId ) - { - String key = MojoBindingUtils.createMojoBindingKey( mojoBinding, considerExecutionId ); - - return (MojoBinding) mapMojoBindingsByKey( inBindings, considerExecutionId ).get( key ); - } - - private static Map mapMojoBindingsByKey( final LifecycleBindings bindings, final boolean considerExecutionId ) - { - Map byKey = new HashMap(); - - for ( Iterator bindingIt = bindings.getBindingList().iterator(); bindingIt.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) bindingIt.next(); - - if ( binding != null ) - { - for ( Iterator phaseIt = binding.getPhasesInOrder().iterator(); phaseIt.hasNext(); ) - { - Phase phase = (Phase) phaseIt.next(); - - if ( phase != null ) - { - for ( Iterator mojoIt = phase.getBindings().iterator(); mojoIt.hasNext(); ) - { - MojoBinding mojoBinding = (MojoBinding) mojoIt.next(); - - byKey.put( MojoBindingUtils.createMojoBindingKey( mojoBinding, considerExecutionId ), - mojoBinding ); - } - } - } - } - } - - return byKey; - } - - public static void removeMojoBindings( final List toRemove, final LifecycleBindings bindings, - final boolean considerExecutionId ) throws NoSuchPhaseException - { - if ( bindings.getCleanBinding() != null ) - { - removeMojoBindings( toRemove, bindings.getCleanBinding(), considerExecutionId ); - } - - if ( bindings.getBuildBinding() != null ) - { - removeMojoBindings( toRemove, bindings.getBuildBinding(), considerExecutionId ); - } - - if ( bindings.getSiteBinding() != null ) - { - removeMojoBindings( toRemove, bindings.getSiteBinding(), considerExecutionId ); - } - } - - public static void removeMojoBindings( final List toRemove, final LifecycleBinding removeFrom, - final boolean considerExecutionId ) throws NoSuchPhaseException - { - // remove where gid:aid:goal matches. - List targets = new ArrayList(); - for ( Iterator it = toRemove.iterator(); it.hasNext(); ) - { - MojoBinding binding = (MojoBinding) it.next(); - - targets.add( MojoBindingUtils.createMojoBindingKey( binding, considerExecutionId ) ); - } - - List phases = removeFrom.getPhasesInOrder(); - - for ( int i = 0; i < phases.size(); i++ ) - { - Phase phase = (Phase) phases.get( i ); - List phaseBindings = phase.getBindings(); - - for ( Iterator mojoIt = phaseBindings.iterator(); mojoIt.hasNext(); ) - { - MojoBinding binding = (MojoBinding) mojoIt.next(); - String key = MojoBindingUtils.createMojoBindingKey( binding, considerExecutionId ); - if ( targets.contains( key ) ) - { - mojoIt.remove(); - } - } - - phase.setBindings( phaseBindings ); - } - } - - public static LifecycleBindings cloneBindings( final LifecycleBindings bindings ) - { - LifecycleBindings result = new LifecycleBindings(); - - if ( bindings.getCleanBinding() != null ) - { - result.setCleanBinding( (CleanBinding) cloneBinding( bindings.getCleanBinding() ) ); - } - - if ( bindings.getBuildBinding() != null ) - { - result.setBuildBinding( (BuildBinding) cloneBinding( bindings.getBuildBinding() ) ); - } - - if ( bindings.getSiteBinding() != null ) - { - result.setSiteBinding( (SiteBinding) cloneBinding( bindings.getSiteBinding() ) ); - } - - return result; - } - - public static LifecycleBinding cloneBinding( final LifecycleBinding binding ) - { - if ( binding == null ) - { - return null; - } - - LifecycleBinding result; - if ( binding instanceof CleanBinding ) - { - result = new CleanBinding(); - } - else if ( binding instanceof SiteBinding ) - { - result = new SiteBinding(); - } - else if ( binding instanceof BuildBinding ) - { - result = new BuildBinding(); - } - else - { - throw new IllegalArgumentException( "Unrecognized LifecycleBinding type: " + binding.getClass().getName() - + "; cannot clone." ); - } - - List phases = binding.getPhasesInOrder(); - List names = binding.getPhaseNamesInOrder(); - - for ( int i = 0; i < phases.size(); i++ ) - { - Phase phase = (Phase) phases.get( i ); - String phaseName = (String) names.get( i ); - - for ( Iterator mojoIt = phase.getBindings().iterator(); mojoIt.hasNext(); ) - { - MojoBinding originalBinding = (MojoBinding) mojoIt.next(); - - MojoBinding newBinding = cloneMojoBinding( originalBinding ); - - try - { - addMojoBinding( phaseName, newBinding, result ); - } - catch ( NoSuchPhaseException e ) - { - IllegalStateException error = - new IllegalStateException( - e.getMessage() - + "\nSomething strange is going on. Cloning should not encounter such inconsistencies." ); - - error.initCause( e ); - - throw error; - } - } - } - - return result; - } - - public static MojoBinding cloneMojoBinding( final MojoBinding binding ) - { - MojoBinding result = new MojoBinding(); - - result.setGroupId( binding.getGroupId() ); - result.setArtifactId( binding.getArtifactId() ); - result.setVersion( binding.getVersion() ); - result.setConfiguration( binding.getConfiguration() ); - result.setExecutionId( binding.getExecutionId() ); - result.setGoal( binding.getGoal() ); - result.setOrigin( binding.getOrigin() ); - - return result; - } - - public static Phase findPhaseForMojoBinding( final MojoBinding mojoBinding, - final LifecycleBindings lifecycleBindings, - final boolean considerExecutionId ) - { - String targetKey = MojoBindingUtils.createMojoBindingKey( mojoBinding, considerExecutionId ); - - for ( Iterator lifecycleIt = lifecycleBindings.getBindingList().iterator(); lifecycleIt.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) lifecycleIt.next(); - - for ( Iterator phaseIt = binding.getPhasesInOrder().iterator(); phaseIt.hasNext(); ) - { - Phase phase = (Phase) phaseIt.next(); - - for ( Iterator mojoIt = phase.getBindings().iterator(); mojoIt.hasNext(); ) - { - MojoBinding candidate = (MojoBinding) mojoIt.next(); - String key = MojoBindingUtils.createMojoBindingKey( candidate, considerExecutionId ); - if ( key.equals( targetKey ) ) - { - return phase; - } - } - } - } - - return null; - } - - public static boolean isMojoBindingPresent( final MojoBinding binding, final List candidates, - final boolean considerExecutionId ) - { - String key = MojoBindingUtils.createMojoBindingKey( binding, considerExecutionId ); - - for ( Iterator it = candidates.iterator(); it.hasNext(); ) - { - MojoBinding candidate = (MojoBinding) it.next(); - - String candidateKey = MojoBindingUtils.createMojoBindingKey( candidate, considerExecutionId ); - - if ( candidateKey.equals( key ) ) - { - return true; - } - } - - return false; - } - - public static boolean isValidPhaseName( final String phaseName ) - { - LifecycleBindings test = new LifecycleBindings(); - for ( Iterator it = test.getBindingList().iterator(); it.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) it.next(); - - if ( binding.getPhaseNamesInOrder().contains( phaseName ) ) - { - return true; - } - } - - return false; - } - - public static List getValidPhaseNames() - { - List phaseNames = new ArrayList(); - - LifecycleBindings bindings = new LifecycleBindings(); - for ( Iterator bindingIt = bindings.getBindingList().iterator(); bindingIt.hasNext(); ) - { - LifecycleBinding binding = (LifecycleBinding) bindingIt.next(); - - for ( Iterator phaseNameIt = binding.getPhaseNamesInOrder().iterator(); phaseNameIt.hasNext(); ) - { - phaseNames.add( phaseNameIt.next() ); - } - } - - return phaseNames; - } - - public static List getValidBuildPhaseNames() - { - List phaseNames = new ArrayList(); - - LifecycleBinding binding = new BuildBinding(); - - for ( Iterator phaseNameIt = binding.getPhaseNamesInOrder().iterator(); phaseNameIt.hasNext(); ) - { - phaseNames.add( phaseNameIt.next() ); - } - - return phaseNames; - } - - public static List getValidCleanPhaseNames() - { - List phaseNames = new ArrayList(); - - LifecycleBinding binding = new CleanBinding(); - - for ( Iterator phaseNameIt = binding.getPhaseNamesInOrder().iterator(); phaseNameIt.hasNext(); ) - { - phaseNames.add( phaseNameIt.next() ); - } - - return phaseNames; - } - - public static List getValidSitePhaseNames() - { - List phaseNames = new ArrayList(); - - LifecycleBinding binding = new SiteBinding(); - - for ( Iterator phaseNameIt = binding.getPhaseNamesInOrder().iterator(); phaseNameIt.hasNext(); ) - { - phaseNames.add( phaseNameIt.next() ); - } - - return phaseNames; - } - - /** - * @deprecated Use {@link MojoBindingUtils#createMojoBindingKey(MojoBinding, boolean)} instead. - */ - public static String createMojoBindingKey( final MojoBinding mojoBinding, final boolean considerExecutionId ) - { - return MojoBindingUtils.createMojoBindingKey( mojoBinding, considerExecutionId ); - } -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingUtils.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingUtils.java deleted file mode 100644 index 1e1e7beec0..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/MojoBindingUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.MojoBinding; - -public final class MojoBindingUtils -{ - - private MojoBindingUtils() - { - } - - public static String toString( final MojoBinding mojoBinding ) - { - return mojoBinding.getGroupId() + ":" + mojoBinding.getArtifactId() + ":" - + ( mojoBinding.getVersion() == null ? "" : mojoBinding.getVersion() + ":" ) - + mojoBinding.getGoal(); - } - - public static String createMojoBindingKey( final MojoBinding mojoBinding, final boolean considerExecutionId ) - { - String key = mojoBinding.getGroupId() + ":" + mojoBinding.getArtifactId() + ":" + mojoBinding.getGoal(); - - if ( considerExecutionId ) - { - key += ":" + mojoBinding.getExecutionId(); - } - - return key; - } - - public static String createPluginKey( final MojoBinding binding ) - { - String result = binding.getGroupId() + ":" + binding.getArtifactId(); - - if ( binding.getVersion() != null ) - { - result += ":" + binding.getVersion(); - } - - return result; - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchLifecycleException.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchLifecycleException.java deleted file mode 100644 index 3868bd4584..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchLifecycleException.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apache.maven.lifecycle; - -public class NoSuchLifecycleException - extends LifecycleSpecificationException -{ - - private final String packaging; - - public NoSuchLifecycleException( String packaging, String message, Throwable cause ) - { - super( message, cause ); - this.packaging = packaging; - } - - public NoSuchLifecycleException( String phase, String message ) - { - super( message ); - this.packaging = phase; - } - - public String getPackaging() - { - return packaging; - } - -} diff --git a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchPhaseException.java b/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchPhaseException.java deleted file mode 100644 index 5808faf772..0000000000 --- a/maven-lifecycle/src/main/java/org/apache/maven/lifecycle/NoSuchPhaseException.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apache.maven.lifecycle; - -public class NoSuchPhaseException - extends LifecycleSpecificationException -{ - - private final String phase; - - public NoSuchPhaseException( String phase, String message, Throwable cause ) - { - super( message, cause ); - this.phase = phase; - } - - public NoSuchPhaseException( String phase, String message ) - { - super( message ); - this.phase = phase; - } - - public String getPhase() - { - return phase; - } - -} diff --git a/maven-lifecycle/src/main/mdo/maven-lifecycle.mdo b/maven-lifecycle/src/main/mdo/maven-lifecycle.mdo deleted file mode 100644 index 5cce25bd8b..0000000000 --- a/maven-lifecycle/src/main/mdo/maven-lifecycle.mdo +++ /dev/null @@ -1,708 +0,0 @@ - - - - - - - - build-lifecycle - LifecycleBindings - Model for lifecycle specifications starting in Maven 2.1 - - - package - org.apache.maven.lifecycle.model - - - - - LifecycleBindings - 1.0.0 - Specifies phase bindings for clean, site, and default lifecycles. - - - 1.0.0 - packaging - String - true - POM packaging to which this lifecycle specification applies. - - - 1.0.0 - cleanBinding - new CleanBinding() - The binding for the clean lifecycle - - CleanBinding - - - - 1.0.0 - buildBinding - new BuildBinding() - The binding for the main build (default) lifecycle - - BuildBinding - - - - 1.0.0 - siteBinding - new SiteBinding() - The binding for the site lifecycle - - SiteBinding - - - - - - 1.0.0 - - - - - - LifecycleBinding - 1.0.0 - Base-class for all lifecycle bindings. - - - 1.0.0 - - - - - - CleanBinding - LifecycleBinding - 1.0.0 - - - preClean - 1.0.0 - new Phase() - - Phase - - - - clean - 1.0.0 - new Phase() - - Phase - - - - postClean - 1.0.0 - new Phase() - - Phase - - - - - - 1.0.0 - - - - - - BuildBinding - LifecycleBinding - 1.0.0 - - - validate - 1.0.0 - new Phase() - - Phase - - - - initialize - 1.0.0 - new Phase() - - Phase - - - - generateSources - 1.0.0 - new Phase() - - Phase - - - - processSources - 1.0.0 - new Phase() - - Phase - - - - generateResources - 1.0.0 - new Phase() - - Phase - - - - processResources - 1.0.0 - new Phase() - - Phase - - - - compile - 1.0.0 - new Phase() - - Phase - - - - processClasses - 1.0.0 - new Phase() - - Phase - - - - generateTestSources - 1.0.0 - new Phase() - - Phase - - - - processTestSources - 1.0.0 - new Phase() - - Phase - - - - generateTestResources - 1.0.0 - new Phase() - - Phase - - - - processTestResources - 1.0.0 - new Phase() - - Phase - - - - testCompile - 1.0.0 - new Phase() - - Phase - - - - processTestClasses - 1.0.0 - new Phase() - - Phase - - - - test - 1.0.0 - new Phase() - - Phase - - - - preparePackage - 1.0.0 - new Phase() - - Phase - - - - createPackage - 1.0.0 - new Phase() - - Phase - - - - preIntegrationTest - 1.0.0 - new Phase() - - Phase - - - - integrationTest - 1.0.0 - new Phase() - - Phase - - - - postIntegrationTest - 1.0.0 - new Phase() - - Phase - - - - verify - 1.0.0 - new Phase() - - Phase - - - - install - 1.0.0 - new Phase() - - Phase - - - - deploy - 1.0.0 - new Phase() - - Phase - - - - - - 1.0.0 - - - - - - SiteBinding - LifecycleBinding - 1.0.0 - - - preSite - 1.0.0 - new Phase() - - Phase - - - - site - 1.0.0 - new Phase() - - Phase - - - - postSite - 1.0.0 - new Phase() - - Phase - - - - siteDeploy - 1.0.0 - new Phase() - - Phase - - - - - - 1.0.0 - - - - - - Phase - 1.0.0 - Contains a series of mojo bindings for a given phase of a lifecycle. - - - bindings - 1.0.0 - Collection of mojo bindings for a phase. - - MojoBinding - * - - - - - - 1.0.0 - - - - - - MojoBinding - 1.0.0 - A binding of one mojo to one lifecycle phase, possibly including configuration. - - - groupId - true - true - 1.0.0 - Plugin's groupId. - String - - - artifactId - true - true - 1.0.0 - Plugin's artifactId. - String - - - version - true - 1.0.0 - Plugin's version. - String - - - goal - true - true - 1.0.0 - Mojo's goal name. - String - - - executionId - 1.0.0 - true - default - A name for this mojo binding, for purposes of merging configurations via inheritance, etc. - String - - - configuration - 1.0.0 - Mojo binding's configuration. - DOM - - - optional - 1.0.0 - Marks a mojo binding as optional (not required for execution of the lifecycle). - boolean - - - - - 1.0.0 - - - - - - diff --git a/maven-lifecycle/src/site/site.xml b/maven-lifecycle/src/site/site.xml deleted file mode 100644 index 15f431a9c0..0000000000 --- a/maven-lifecycle/src/site/site.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoaderTest.java b/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoaderTest.java deleted file mode 100644 index 994a561f7b..0000000000 --- a/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/ClassLoaderXmlBindingLoaderTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.CleanBinding; -import org.apache.maven.lifecycle.model.LifecycleBindings; -import org.apache.maven.lifecycle.model.MojoBinding; -import org.apache.maven.lifecycle.model.Phase; -import org.codehaus.plexus.PlexusTestCase; - -import java.util.List; - -public class ClassLoaderXmlBindingLoaderTest - extends PlexusTestCase -{ - - public void testBeanAccess_ParseSingleCleanBinding() - throws LifecycleLoaderException, LifecycleSpecificationException - { - LifecycleBindings bindings = new ClassLoaderXmlBindingLoader( "single-clean-mapping.xml" ).getBindings(); - - CleanBinding cleanBinding = bindings.getCleanBinding(); - assertNotNull( cleanBinding ); - - Phase preClean = cleanBinding.getPreClean(); - assertNotNull( preClean ); - - List mojos = preClean.getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding mojo = (MojoBinding) mojos.get( 0 ); - assertEquals( "group", mojo.getGroupId() ); - assertEquals( "artifact", mojo.getArtifactId() ); - assertNull( mojo.getVersion() ); - assertEquals( "goalOne", mojo.getGoal() ); - } - - public void testComponentAccess_ParseSingleCleanBinding() - throws Exception - { - LifecycleBindingLoader loader = lookup( LifecycleBindingLoader.class, "single-clean-mapping" ); - - LifecycleBindings bindings = loader.getBindings(); - - CleanBinding cleanBinding = bindings.getCleanBinding(); - assertNotNull( cleanBinding ); - - Phase preClean = cleanBinding.getPreClean(); - assertNotNull( preClean ); - - List mojos = preClean.getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding mojo = (MojoBinding) mojos.get( 0 ); - assertEquals( "group", mojo.getGroupId() ); - assertEquals( "artifact", mojo.getArtifactId() ); - assertNull( mojo.getVersion() ); - assertEquals( "goalOne", mojo.getGoal() ); - } - -} diff --git a/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/LifecycleUtilsTest.java b/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/LifecycleUtilsTest.java deleted file mode 100644 index 31e2b58412..0000000000 --- a/maven-lifecycle/src/test/java/org/apache/maven/lifecycle/LifecycleUtilsTest.java +++ /dev/null @@ -1,1371 +0,0 @@ -package org.apache.maven.lifecycle; - -import org.apache.maven.lifecycle.model.BuildBinding; -import org.apache.maven.lifecycle.model.CleanBinding; -import org.apache.maven.lifecycle.model.LifecycleBinding; -import org.apache.maven.lifecycle.model.LifecycleBindings; -import org.apache.maven.lifecycle.model.MojoBinding; -import org.apache.maven.lifecycle.model.Phase; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -public class LifecycleUtilsTest - extends TestCase -{ - - public void testSetOrigin_ShouldSetMojoBindingOrigin() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setOrigin( "original" ); - - LifecycleBindings bindings = new LifecycleBindings(); - bindings.getCleanBinding().getClean().addBinding( binding ); - - LifecycleUtils.setOrigin( bindings, "changed" ); - - assertEquals( "changed", binding.getOrigin() ); - } - - public void testCreateMojoBindingKey_NoExecId() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - String key = LifecycleUtils.createMojoBindingKey( binding, false ); - - assertEquals( "group:artifact:goal", key ); - } - - public void testCreateMojoBindingKey_WithExecId() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setExecutionId( "execution" ); - - String key = LifecycleUtils.createMojoBindingKey( binding, true ); - - assertEquals( "group:artifact:goal:execution", key ); - } - - public void testFindLifecycleBindingForPhase_ShouldFindMojoBindingInPhase() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - bindings.getCleanBinding().getClean().addBinding( binding ); - - LifecycleBinding result = LifecycleUtils.findLifecycleBindingForPhase( "clean", bindings ); - - assertTrue( result instanceof CleanBinding ); - - CleanBinding cb = (CleanBinding) result; - Phase clean = cb.getClean(); - - assertNotNull( clean ); - assertEquals( 1, clean.getBindings().size() ); - - MojoBinding resultBinding = (MojoBinding) clean.getBindings().get( 0 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testFindLifecycleBindingForPhase_ShouldReturnNullForInvalidPhase() - { - LifecycleBindings bindings = new LifecycleBindings(); - - LifecycleBinding result = LifecycleUtils.findLifecycleBindingForPhase( "dud", bindings ); - - assertNull( result ); - } - - public void testFindMatchingMojoBinding_ShouldFindMatchWithoutExecId() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - - BuildBinding bb = new BuildBinding(); - - Phase phase = new Phase(); - phase.addBinding( binding ); - - bb.setCompile( phase ); - - bindings.setBuildBinding( bb ); - - MojoBinding binding2 = LifecycleUtils.findMatchingMojoBinding( binding, bindings, false ); - - assertNotNull( binding2 ); - assertEquals( "goal", binding2.getGoal() ); - assertEquals( "group", binding2.getGroupId() ); - assertEquals( "artifact", binding2.getArtifactId() ); - } - - public void testFindMatchingMojoBinding_ShouldFindMatchWithExecId() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - binding2.setExecutionId( "non-default" ); - - LifecycleBindings bindings = new LifecycleBindings(); - - BuildBinding bb = new BuildBinding(); - - Phase phase = new Phase(); - phase.addBinding( binding ); - - bb.setCompile( phase ); - - bindings.setBuildBinding( bb ); - - MojoBinding binding3 = LifecycleUtils.findMatchingMojoBinding( binding2, bindings, true ); - - assertNotNull( binding3 ); - assertEquals( "goal", binding3.getGoal() ); - assertEquals( "group", binding3.getGroupId() ); - assertEquals( "artifact", binding3.getArtifactId() ); - assertEquals( "non-default", binding3.getExecutionId() ); - } - - public void testFindMatchingMojoBinding_ShouldReturnNullNoMatchWithoutExecId() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - MojoBinding binding2 = newMojoBinding( "group2", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - - BuildBinding bb = new BuildBinding(); - - Phase phase = new Phase(); - phase.addBinding( binding ); - - bb.setCompile( phase ); - - bindings.setBuildBinding( bb ); - - MojoBinding binding3 = LifecycleUtils.findMatchingMojoBinding( binding2, bindings, true ); - - assertNull( binding3 ); - } - - public void testFindMatchingMojoBinding_ShouldReturnNullWhenExecIdsDontMatch() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - // default executionId == 'default' - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - binding2.setExecutionId( "execution" ); - - LifecycleBindings bindings = new LifecycleBindings(); - - BuildBinding bb = new BuildBinding(); - - Phase phase = new Phase(); - phase.addBinding( binding ); - - bb.setCompile( phase ); - - bindings.setBuildBinding( bb ); - - MojoBinding binding3 = LifecycleUtils.findMatchingMojoBinding( binding2, bindings, true ); - - assertNull( binding3 ); - } - - public void testRemoveMojoBinding_ThrowErrorWhenPhaseNotInLifecycleBinding() - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - String phase = "phase"; - - try - { - LifecycleUtils.removeMojoBinding( phase, binding, cleanBinding, false ); - - fail( "Should fail when phase doesn't exist in lifecycle binding." ); - } - catch ( NoSuchPhaseException e ) - { - // expected - } - } - - public void testRemoveMojoBinding_DoNothingWhenMojoBindingNotInLifecycleBinding() - throws NoSuchPhaseException - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - - Phase phase = new Phase(); - phase.addBinding( binding2 ); - - cleanBinding.setClean( phase ); - - String phaseName = "clean"; - - LifecycleUtils.removeMojoBinding( phaseName, binding, cleanBinding, false ); - - Phase result = cleanBinding.getClean(); - assertEquals( 1, result.getBindings().size() ); - } - - public void testRemoveMojoBinding_DoNothingWhenMojoPhaseIsNullInLifecycleBinding() - throws NoSuchPhaseException - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - - Phase phase = new Phase(); - phase.addBinding( binding2 ); - - cleanBinding.setPreClean( phase ); - - String phaseName = "clean"; - - LifecycleUtils.removeMojoBinding( phaseName, binding, cleanBinding, false ); - - Phase result = cleanBinding.getPreClean(); - assertEquals( 1, result.getBindings().size() ); - } - - public void testRemoveMojoBinding_RemoveMojoBindingWhenFoundInLifecycleBinding() - throws NoSuchPhaseException - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - Phase phase = new Phase(); - phase.addBinding( binding ); - - cleanBinding.setClean( phase ); - - String phaseName = "clean"; - - LifecycleUtils.removeMojoBinding( phaseName, binding, cleanBinding, false ); - - Phase result = cleanBinding.getClean(); - assertEquals( 0, result.getBindings().size() ); - } - - public void testMergeBindings_SingleMojoCloneFromEachIsPresentInResult_EmptyDefaults() - { - LifecycleBindings bOrig = new LifecycleBindings(); - CleanBinding cbOrig = bOrig.getCleanBinding(); - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( binding ); - - LifecycleBindings bOrig2 = new LifecycleBindings(); - CleanBinding cbOrig2 = bOrig2.getCleanBinding(); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - cbOrig2.getClean().addBinding( binding2 ); - - LifecycleBindings result = LifecycleUtils.mergeBindings( bOrig, bOrig2, new LifecycleBindings(), false, false ); - - assertNotNull( result ); - - CleanBinding cbResult = result.getCleanBinding(); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 2, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - - bResult = (MojoBinding) mojos.get( 1 ); - - assertNotSame( binding2, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal2", bResult.getGoal() ); - } - - public void testMergeBindings_SingleMojoCloneIsPresentFromExistingAndNotFromDefaultsInResult() - { - LifecycleBindings bOrig = new LifecycleBindings(); - CleanBinding cbOrig = bOrig.getCleanBinding(); - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( binding ); - - LifecycleBindings bOrig2 = new LifecycleBindings(); - CleanBinding cbOrig2 = bOrig2.getCleanBinding(); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - cbOrig2.getClean().addBinding( binding2 ); - - LifecycleBindings result = LifecycleUtils.mergeBindings( bOrig, new LifecycleBindings(), bOrig2, false, false ); - - assertNotNull( result ); - - CleanBinding cbResult = result.getCleanBinding(); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - } - - public void testMergeBindings_MojoCloneIsPresentFromDefaultsInResult() - { - LifecycleBindings bOrig = new LifecycleBindings(); - CleanBinding cbOrig = bOrig.getCleanBinding(); - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( binding ); - - LifecycleBindings bOrig2 = new LifecycleBindings(); - BuildBinding bbOrig = bOrig2.getBuildBinding(); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - bbOrig.getCompile().addBinding( binding2 ); - - LifecycleBindings result = LifecycleUtils.mergeBindings( bOrig, new LifecycleBindings(), bOrig2, false, false ); - - assertNotNull( result ); - - CleanBinding cbResult = result.getCleanBinding(); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - - BuildBinding bbResult = result.getBuildBinding(); - assertNotSame( bbOrig, bbResult ); - - mojos = bbResult.getCompile().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal2", bResult.getGoal() ); - } - - public void testMergeBindings_MergeConfigsWithNewAsDominant_EmptyDefaults() - { - LifecycleBindings bOrig = new LifecycleBindings(); - CleanBinding cbOrig = bOrig.getCleanBinding(); - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setOrigin( "non-default" ); - - Xpp3Dom config = new Xpp3Dom( "configuration" ); - Xpp3Dom child = new Xpp3Dom( "child" ); - child.setValue( "value" ); - config.addChild( child ); - - binding.setConfiguration( config ); - - cbOrig.getClean().addBinding( binding ); - - LifecycleBindings bOrig2 = new LifecycleBindings(); - CleanBinding cbOrig2 = bOrig2.getCleanBinding(); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - - Xpp3Dom config2 = new Xpp3Dom( "configuration" ); - - Xpp3Dom child2 = new Xpp3Dom( "child" ); - child2.setValue( "value2" ); - - Xpp3Dom child3 = new Xpp3Dom( "key" ); - child3.setValue( "val" ); - - config2.addChild( child2 ); - config2.addChild( child3 ); - - binding2.setConfiguration( config2 ); - - cbOrig2.getClean().addBinding( binding2 ); - - LifecycleBindings result = LifecycleUtils.mergeBindings( bOrig, bOrig2, new LifecycleBindings(), true, false ); - - assertNotNull( result ); - - CleanBinding cbResult = result.getCleanBinding(); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - assertEquals( "non-default", bResult.getOrigin() ); - - Xpp3Dom cResult = (Xpp3Dom) bResult.getConfiguration(); - - assertNotNull( cResult ); - assertEquals( "value2", cResult.getChild( "child" ).getValue() ); - assertEquals( "val", cResult.getChild( "key" ).getValue() ); - } - - public void testMergeBindings_MergeConfigsWithExistingAsDominant_EmptyDefaults() - { - LifecycleBindings bOrig = new LifecycleBindings(); - CleanBinding cbOrig = bOrig.getCleanBinding(); - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setOrigin( "non-default" ); - - Xpp3Dom config = new Xpp3Dom( "configuration" ); - Xpp3Dom child = new Xpp3Dom( "child" ); - child.setValue( "value" ); - config.addChild( child ); - - binding.setConfiguration( config ); - - cbOrig.getClean().addBinding( binding ); - - LifecycleBindings bOrig2 = new LifecycleBindings(); - CleanBinding cbOrig2 = bOrig2.getCleanBinding(); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - - Xpp3Dom config2 = new Xpp3Dom( "configuration" ); - - Xpp3Dom child2 = new Xpp3Dom( "child" ); - child2.setValue( "value2" ); - - Xpp3Dom child3 = new Xpp3Dom( "key" ); - child3.setValue( "val" ); - - config2.addChild( child2 ); - config2.addChild( child3 ); - - binding2.setConfiguration( config2 ); - - cbOrig2.getClean().addBinding( binding2 ); - - LifecycleBindings result = LifecycleUtils.mergeBindings( bOrig, bOrig2, new LifecycleBindings(), true, true ); - - assertNotNull( result ); - - CleanBinding cbResult = result.getCleanBinding(); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - - assertNotSame( binding, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - assertEquals( "non-default", bResult.getOrigin() ); - - Xpp3Dom cResult = (Xpp3Dom) bResult.getConfiguration(); - - assertNotNull( cResult ); - assertEquals( "value", cResult.getChild( "child" ).getValue() ); - assertEquals( "val", cResult.getChild( "key" ).getValue() ); - } - - public void testCloneBinding_SingleMojoCloneIsPresentInNewInstance() - { - CleanBinding cbOrig = new CleanBinding(); - MojoBinding bOrig = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( bOrig ); - - LifecycleBinding result = LifecycleUtils.cloneBinding( cbOrig ); - - assertNotNull( result ); - assertTrue( result instanceof CleanBinding ); - assertNotSame( cbOrig, result ); - - List mojos = ( (CleanBinding) result ).getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - assertNotSame( bOrig, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - } - - public void testCloneBinding_OrderIsPreservedBetweenTwoMojoBindingsInNewInstance() - { - CleanBinding cbOrig = new CleanBinding(); - MojoBinding bOrig = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( bOrig ); - - MojoBinding bOrig2 = newMojoBinding( "group", "artifact", "goal2" ); - cbOrig.getClean().addBinding( bOrig2 ); - - LifecycleBinding result = LifecycleUtils.cloneBinding( cbOrig ); - - assertNotNull( result ); - assertTrue( result instanceof CleanBinding ); - assertNotSame( cbOrig, result ); - - List mojos = ( (CleanBinding) result ).getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 2, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - assertNotSame( bOrig, bResult ); - - assertEquals( bOrig.getGroupId(), bResult.getGroupId() ); - assertEquals( bOrig.getArtifactId(), bResult.getArtifactId() ); - assertEquals( bOrig.getGoal(), bResult.getGoal() ); - - MojoBinding bResult2 = (MojoBinding) mojos.get( 1 ); - assertNotSame( bOrig2, bResult2 ); - - assertEquals( bOrig2.getGroupId(), bResult2.getGroupId() ); - assertEquals( bOrig2.getArtifactId(), bResult2.getArtifactId() ); - assertEquals( bOrig2.getGoal(), bResult2.getGoal() ); - } - - public void testCloneBindings_SingleMojoCloneIsPresentInNewInstance() - { - LifecycleBindings bindings = new LifecycleBindings(); - - CleanBinding cbOrig = bindings.getCleanBinding(); - MojoBinding bOrig = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( bOrig ); - - LifecycleBindings result = LifecycleUtils.cloneBindings( bindings ); - - assertNotNull( result ); - assertNotSame( bindings, result ); - - CleanBinding cbResult = result.getCleanBinding(); - - assertNotNull( cbResult ); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 1, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - assertNotSame( bOrig, bResult ); - - assertEquals( "group", bResult.getGroupId() ); - assertEquals( "artifact", bResult.getArtifactId() ); - assertEquals( "goal", bResult.getGoal() ); - } - - public void testCloneBindings_OrderIsPreservedBetweenTwoMojoBindingsInNewInstance() - { - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cbOrig = bindings.getCleanBinding(); - MojoBinding bOrig = newMojoBinding( "group", "artifact", "goal" ); - cbOrig.getClean().addBinding( bOrig ); - - MojoBinding bOrig2 = newMojoBinding( "group", "artifact", "goal2" ); - cbOrig.getClean().addBinding( bOrig2 ); - - LifecycleBindings result = LifecycleUtils.cloneBindings( bindings ); - - assertNotNull( result ); - assertNotSame( bindings, result ); - - CleanBinding cbResult = result.getCleanBinding(); - - assertNotNull( cbResult ); - assertNotSame( cbOrig, cbResult ); - - List mojos = cbResult.getClean().getBindings(); - assertNotNull( mojos ); - assertEquals( 2, mojos.size() ); - - MojoBinding bResult = (MojoBinding) mojos.get( 0 ); - assertNotSame( bOrig, bResult ); - - assertEquals( bOrig.getGroupId(), bResult.getGroupId() ); - assertEquals( bOrig.getArtifactId(), bResult.getArtifactId() ); - assertEquals( bOrig.getGoal(), bResult.getGoal() ); - - MojoBinding bResult2 = (MojoBinding) mojos.get( 1 ); - assertNotSame( bOrig2, bResult2 ); - - assertEquals( bOrig2.getGroupId(), bResult2.getGroupId() ); - assertEquals( bOrig2.getArtifactId(), bResult2.getArtifactId() ); - assertEquals( bOrig2.getGoal(), bResult2.getGoal() ); - } - - public void testCloneMojoBinding_NullVersionIsPropagated() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - MojoBinding binding2 = LifecycleUtils.cloneMojoBinding( binding ); - - assertNotNull( binding2 ); - assertEquals( "goal", binding2.getGoal() ); - assertEquals( "group", binding2.getGroupId() ); - assertEquals( "artifact", binding2.getArtifactId() ); - assertNull( binding.getVersion() ); - assertNull( binding2.getVersion() ); - } - - public void testCloneMojoBinding_ExecutionIdIsPropagated() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = LifecycleUtils.cloneMojoBinding( binding ); - - assertNotNull( binding2 ); - assertEquals( "goal", binding2.getGoal() ); - assertEquals( "group", binding2.getGroupId() ); - assertEquals( "artifact", binding2.getArtifactId() ); - assertEquals( "non-default", binding2.getExecutionId() ); - } - - public void testCloneMojoBinding_VersionIsPropagated() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setVersion( "version" ); - - MojoBinding binding2 = LifecycleUtils.cloneMojoBinding( binding ); - - assertNotNull( binding2 ); - assertEquals( "goal", binding2.getGoal() ); - assertEquals( "group", binding2.getGroupId() ); - assertEquals( "artifact", binding2.getArtifactId() ); - assertEquals( "version", binding2.getVersion() ); - assertEquals( "default", binding2.getExecutionId() ); - } - - public void testAddMojoBinding_LifecycleBinding_AddOneMojoBindingToEmptyLifecycle() - throws NoSuchPhaseException - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleUtils.addMojoBinding( "clean", binding, cleanBinding ); - - Phase clean = cleanBinding.getClean(); - assertEquals( 1, clean.getBindings().size() ); - } - - public void testAddMojoBinding_LifecycleBinding_ThrowErrorWhenPhaseDoesntExist() - { - CleanBinding cleanBinding = new CleanBinding(); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - try - { - LifecycleUtils.addMojoBinding( "compile", binding, cleanBinding ); - - fail( "Should fail because compile phase isn't in the clean lifecycle." ); - } - catch ( NoSuchPhaseException e ) - { - // expected - } - } - - public void testAddMojoBinding_LifecycleBindings_AddOneMojoBindingToEmptyLifecycle() - throws LifecycleSpecificationException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - - LifecycleUtils.addMojoBinding( "clean", binding, bindings ); - - CleanBinding cleanBinding = bindings.getCleanBinding(); - assertNotNull( cleanBinding ); - - Phase clean = cleanBinding.getClean(); - assertNotNull( clean ); - assertEquals( 1, clean.getBindings().size() ); - } - - public void testAddMojoBinding_LifecycleBindings_ThrowErrorWhenPhaseDoesntExist() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - try - { - LifecycleUtils.addMojoBinding( "dud", binding, new LifecycleBindings() ); - - fail( "Should fail because dud phase isn't in the any lifecycle." ); - } - catch ( LifecycleSpecificationException e ) - { - // expected - } - } - - public void testGetMojoBindingListForLifecycle_LifecycleBinding_FailWithInvalidStopPhase() - { - try - { - LifecycleUtils.getMojoBindingListForLifecycle( "dud", new CleanBinding() ); - - fail( "Should fail when asked for an invalid phase." ); - } - catch ( NoSuchPhaseException e ) - { - // expected - } - } - - public void testGetMojoBindingListForLifecycle_LifecycleBinding_RetrieveMojoBindingInStopPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - CleanBinding cleanBinding = new CleanBinding(); - cleanBinding.getClean().addBinding( binding ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", cleanBinding ); - - assertNotNull( result ); - assertEquals( 1, result.size() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBinding_RetrieveMojoBindingInPreviousPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - CleanBinding cleanBinding = new CleanBinding(); - cleanBinding.getPreClean().addBinding( binding ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", cleanBinding ); - - assertNotNull( result ); - assertEquals( 1, result.size() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBinding_RetrieveTwoMojoBindings() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - - CleanBinding cleanBinding = new CleanBinding(); - cleanBinding.getClean().addBinding( binding ); - cleanBinding.getPreClean().addBinding( binding2 ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", cleanBinding ); - - assertNotNull( result ); - assertEquals( 2, result.size() ); - - MojoBinding resultBinding2 = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding2.getGroupId() ); - assertEquals( "artifact", resultBinding2.getArtifactId() ); - assertEquals( "goal2", resultBinding2.getGoal() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 1 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBinding_DontRetrieveMojoBindingsInPhaseAfterStopPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - MojoBinding binding3 = newMojoBinding( "group", "artifact", "goal3" ); - - CleanBinding cleanBinding = new CleanBinding(); - cleanBinding.getClean().addBinding( binding ); - cleanBinding.getPreClean().addBinding( binding2 ); - cleanBinding.getPostClean().addBinding( binding3 ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", cleanBinding ); - - assertNotNull( result ); - assertEquals( 2, result.size() ); - - MojoBinding resultBinding2 = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding2.getGroupId() ); - assertEquals( "artifact", resultBinding2.getArtifactId() ); - assertEquals( "goal2", resultBinding2.getGoal() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 1 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBindings_RetrieveMojoBindingInStopPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - bindings.getCleanBinding().getClean().addBinding( binding ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", bindings ); - - assertNotNull( result ); - assertEquals( 1, result.size() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBindings_FailWithInvalidStopPhase() - { - try - { - LifecycleUtils.getMojoBindingListForLifecycle( "dud", new LifecycleBindings() ); - - fail( "Should fail when asked for an invalid phase." ); - } - catch ( NoSuchPhaseException e ) - { - // expected - } - } - - public void testGetMojoBindingListForLifecycle_LifecycleBindings_RetrieveMojoBindingInPreviousPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - bindings.getCleanBinding().getPreClean().addBinding( binding ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", bindings ); - - assertNotNull( result ); - assertEquals( 1, result.size() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBindings_RetrieveTwoMojoBindings() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cleanBinding = bindings.getCleanBinding(); - cleanBinding.getClean().addBinding( binding ); - cleanBinding.getPreClean().addBinding( binding2 ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", bindings ); - - assertNotNull( result ); - assertEquals( 2, result.size() ); - - MojoBinding resultBinding2 = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding2.getGroupId() ); - assertEquals( "artifact", resultBinding2.getArtifactId() ); - assertEquals( "goal2", resultBinding2.getGoal() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 1 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testGetMojoBindingListForLifecycle_LifecycleBindings_DontRetrieveMojoBindingsInPhaseAfterStopPhase() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal2" ); - MojoBinding binding3 = newMojoBinding( "group", "artifact", "goal3" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cleanBinding = bindings.getCleanBinding(); - cleanBinding.getClean().addBinding( binding ); - cleanBinding.getPreClean().addBinding( binding2 ); - cleanBinding.getPostClean().addBinding( binding3 ); - - List result = LifecycleUtils.getMojoBindingListForLifecycle( "clean", bindings ); - - assertNotNull( result ); - assertEquals( 2, result.size() ); - - MojoBinding resultBinding2 = (MojoBinding) result.get( 0 ); - - assertEquals( "group", resultBinding2.getGroupId() ); - assertEquals( "artifact", resultBinding2.getArtifactId() ); - assertEquals( "goal2", resultBinding2.getGoal() ); - - MojoBinding resultBinding = (MojoBinding) result.get( 1 ); - - assertEquals( "group", resultBinding.getGroupId() ); - assertEquals( "artifact", resultBinding.getArtifactId() ); - assertEquals( "goal", resultBinding.getGoal() ); - } - - public void testIsMojoBindingPresent_ReturnFalseWhenMojoBindingIsMissing_WithoutExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - assertFalse( LifecycleUtils.isMojoBindingPresent( binding, new ArrayList(), false ) ); - } - - public void testIsMojoBindingPresent_ReturnFalseWhenMojoBindingIsMissing_WithExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - assertFalse( LifecycleUtils.isMojoBindingPresent( binding, new ArrayList(), true ) ); - } - - public void testIsMojoBindingPresent_ReturnTrueWhenMojoBindingExecIdDoesntMatch_WithoutExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - - List mojos = new ArrayList(); - mojos.add( binding ); - - assertTrue( LifecycleUtils.isMojoBindingPresent( binding2, mojos, false ) ); - } - - public void testIsMojoBindingPresent_ReturnFalseWhenMojoBindingExecIdDoesntMatch_WithExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - - List mojos = new ArrayList(); - mojos.add( binding ); - - assertFalse( LifecycleUtils.isMojoBindingPresent( binding2, mojos, true ) ); - } - - public void testFindPhaseForMojoBinding_ReturnNullIfBindingNotFound_WithoutExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - Phase phase = LifecycleUtils.findPhaseForMojoBinding( binding, bindings, false ); - - assertNull( phase ); - } - - public void testFindPhaseForMojoBinding_ReturnPhaseContainingBinding_WithoutExecIdCompare() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - Phase cleanPhase = bindings.getCleanBinding().getClean(); - cleanPhase.addBinding( binding ); - - Phase phase = LifecycleUtils.findPhaseForMojoBinding( binding, bindings, false ); - - assertNotNull( phase ); - assertSame( cleanPhase, phase ); - } - - public void testFindPhaseForMojoBinding_ReturnPhaseContainingSimilarBindingWithOtherExecId_WithoutExecIdCompare() - { - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - binding2.setExecutionId( "non-default" ); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - Phase cleanPhase = bindings.getCleanBinding().getClean(); - cleanPhase.addBinding( binding ); - - Phase phase = LifecycleUtils.findPhaseForMojoBinding( binding2, bindings, false ); - - assertNotNull( phase ); - assertSame( cleanPhase, phase ); - } - - public void testFindPhaseForMojoBinding_ReturnNullWhenBindingExecIdsDontMatch_WithExecIdCompare() - { - MojoBinding binding2 = newMojoBinding( "group", "artifact", "goal" ); - binding2.setExecutionId( "non-default" ); - - MojoBinding binding = newMojoBinding( "group", "artifact", "goal" ); - - LifecycleBindings bindings = new LifecycleBindings(); - Phase cleanPhase = bindings.getCleanBinding().getClean(); - cleanPhase.addBinding( binding ); - - Phase phase = LifecycleUtils.findPhaseForMojoBinding( binding2, bindings, true ); - - assertNull( phase ); - } - - public void testRemoveMojoBinding_ReturnLifecycleWithoutMojo_WithoutExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBinding( "clean", binding2, cb, false ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - } - - public void testRemoveMojoBinding_ReturnLifecycleWithoutMojo_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBinding( "clean", binding2, cb, true ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - } - - public void testRemoveMojoBinding_DontRemoveMojoIfExecIdDoesntMatch_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBinding( "clean", binding2, cb, true ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - } - - public void testRemoveMojoBinding_FailOnInvalidPhaseName() - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - CleanBinding cb = new CleanBinding(); - - try - { - LifecycleUtils.removeMojoBinding( "dud", binding, cb, false ); - - fail( "Should fail because phase does not exist in the clean lifecycle." ); - } - catch ( NoSuchPhaseException e ) - { - // expected - } - } - - public void testRemoveMojoBindings_LifecycleBinding_RemoveOneMojo_WithoutExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), cb, false ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - } - - public void testRemoveMojoBindings_LifecycleBinding_RemoveOneMojo_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), cb, true ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - } - - public void testRemoveMojoBindings_LifecycleBinding_RemoveTwoMojos_WithoutExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean2" ); - MojoBinding binding3 = newMojoBinding( "group", "artifact", "clean" ); - MojoBinding binding4 = newMojoBinding( "group", "artifact", "clean4" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding2 ); - cb.getClean().addBinding( binding3 ); - cb.getClean().addBinding( binding4 ); - - assertEquals( 3, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding ), cb, false ); - - List cleanBindings = cb.getClean().getBindings(); - - assertEquals( 2, cleanBindings.size() ); - - assertEquals( binding2.getGoal(), ( (MojoBinding) cleanBindings.get( 0 ) ).getGoal() ); - assertEquals( binding4.getGoal(), ( (MojoBinding) cleanBindings.get( 1 ) ).getGoal() ); - } - - public void testRemoveMojoBindings_LifecycleBinding_DontRemoveIfNoExecIdMatch_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - CleanBinding cb = new CleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), cb, true ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - } - - public void testRemoveMojoBindings_LifecycleBindings_RemoveOneMojo_WithoutExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cb = bindings.getCleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), bindings, false ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - } - - public void testRemoveMojoBindings_LifecycleBindings_RemoveOneMojo_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - binding.setExecutionId( "non-default" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cb = bindings.getCleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), bindings, true ); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - } - - public void testRemoveMojoBindings_LifecycleBindings_RemoveTwoMojos_WithoutExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean2" ); - MojoBinding binding3 = newMojoBinding( "group", "artifact", "clean" ); - MojoBinding binding4 = newMojoBinding( "group", "artifact", "clean4" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cb = bindings.getCleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding2 ); - cb.getClean().addBinding( binding3 ); - cb.getClean().addBinding( binding4 ); - - assertEquals( 3, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding ), bindings, false ); - - List cleanBindings = cb.getClean().getBindings(); - - assertEquals( 2, cleanBindings.size() ); - - assertEquals( binding2.getGoal(), ( (MojoBinding) cleanBindings.get( 0 ) ).getGoal() ); - assertEquals( binding4.getGoal(), ( (MojoBinding) cleanBindings.get( 1 ) ).getGoal() ); - } - - public void testRemoveMojoBindings_LifecycleBindings_DontRemoveIfNoExecIdMatch_WithExecIdCompare() - throws NoSuchPhaseException - { - MojoBinding binding = newMojoBinding( "group", "artifact", "clean" ); - - MojoBinding binding2 = newMojoBinding( "group", "artifact", "clean" ); - binding2.setExecutionId( "non-default" ); - - LifecycleBindings bindings = new LifecycleBindings(); - CleanBinding cb = bindings.getCleanBinding(); - - assertEquals( 0, cb.getClean().getBindings().size() ); - - cb.getClean().addBinding( binding ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - LifecycleUtils.removeMojoBindings( Collections.singletonList( binding2 ), bindings, true ); - - assertEquals( 1, cb.getClean().getBindings().size() ); - - } - - public void testIsValidPhaseName_ReturnTrueForPhaseInCleanLifecycle() - { - assertTrue( LifecycleUtils.isValidPhaseName( "clean" ) ); - } - - public void testIsValidPhaseName_ReturnTrueForPhaseInBuildLifecycle() - { - assertTrue( LifecycleUtils.isValidPhaseName( "compile" ) ); - } - - public void testIsValidPhaseName_ReturnTrueForPhaseInSiteLifecycle() - { - assertTrue( LifecycleUtils.isValidPhaseName( "site" ) ); - } - - public void testIsValidPhaseName_ReturnFalseForInvalidPhaseName() - { - assertFalse( LifecycleUtils.isValidPhaseName( "dud" ) ); - } - - private MojoBinding newMojoBinding( String groupId, String artifactId, String goal ) - { - MojoBinding binding = new MojoBinding(); - binding.setGroupId( groupId ); - binding.setArtifactId( artifactId ); - binding.setGoal( goal ); - - return binding; - } - -} diff --git a/maven-lifecycle/src/test/resources/META-INF/plexus/components.xml b/maven-lifecycle/src/test/resources/META-INF/plexus/components.xml deleted file mode 100644 index 50133333d2..0000000000 --- a/maven-lifecycle/src/test/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - org.apache.maven.lifecycle.LifecycleBindingLoader - single-clean-mapping - org.apache.maven.lifecycle.ClassLoaderXmlBindingLoader - - single-clean-mapping.xml - - - - \ No newline at end of file diff --git a/maven-lifecycle/src/test/resources/single-clean-mapping.xml b/maven-lifecycle/src/test/resources/single-clean-mapping.xml deleted file mode 100644 index fe499aa2ac..0000000000 --- a/maven-lifecycle/src/test/resources/single-clean-mapping.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - group - artifact - goalOne - - - - - \ No newline at end of file