MNG-5805: Custom packaging types: configuring DefaultLifecycleMapping mojo executions

Signed-off-by: Jason van Zyl <jason@tesla.io>
This commit is contained in:
Anton Tanasenko 2015-04-18 22:01:16 +03:00 committed by Jason van Zyl
parent d8ae13fd7b
commit 1d148be82b
7 changed files with 186 additions and 52 deletions

View File

@ -22,6 +22,8 @@ package org.apache.maven.lifecycle;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.maven.lifecycle.mapping.LifecyclePhase;
/** /**
* Class Lifecycle. * Class Lifecycle.
*/ */
@ -31,7 +33,7 @@ public class Lifecycle
{ {
} }
public Lifecycle( String id, List<String> phases, Map<String, String> defaultPhases ) public Lifecycle( String id, List<String> phases, Map<String, LifecyclePhase> defaultPhases )
{ {
this.id = id; this.id = id;
this.phases = phases; this.phases = phases;
@ -54,7 +56,7 @@ public class Lifecycle
private List<String> phases; private List<String> phases;
private Map<String, String> defaultPhases; private Map<String, LifecyclePhase> defaultPhases;
public String getId() public String getId()
{ {
@ -66,7 +68,7 @@ public class Lifecycle
return this.phases; return this.phases;
} }
public Map<String, String> getDefaultPhases() public Map<String, LifecyclePhase> getDefaultPhases()
{ {
return defaultPhases; return defaultPhases;
} }

View File

@ -23,6 +23,8 @@ import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer; import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
import org.apache.maven.lifecycle.Lifecycle; import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.lifecycle.mapping.LifecycleMojo;
import org.apache.maven.lifecycle.mapping.LifecyclePhase;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -98,7 +100,7 @@ public class DefaultLifecyclePluginAnalyzer
org.apache.maven.lifecycle.mapping.Lifecycle lifecycleConfiguration = org.apache.maven.lifecycle.mapping.Lifecycle lifecycleConfiguration =
lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() ); lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() );
Map<String, String> phaseToGoalMapping = null; Map<String, LifecyclePhase> phaseToGoalMapping = null;
if ( lifecycleConfiguration != null ) if ( lifecycleConfiguration != null )
{ {
@ -111,14 +113,10 @@ public class DefaultLifecyclePluginAnalyzer
if ( phaseToGoalMapping != null ) if ( phaseToGoalMapping != null )
{ {
// These are of the form: for ( Map.Entry<String, LifecyclePhase> goalsForLifecyclePhase : phaseToGoalMapping.entrySet() )
//
// compile -> org.apache.maven.plugins:maven-compiler-plugin:compile[,gid:aid:goal,...]
//
for ( Map.Entry<String, String> goalsForLifecyclePhase : phaseToGoalMapping.entrySet() )
{ {
String phase = goalsForLifecyclePhase.getKey(); String phase = goalsForLifecyclePhase.getKey();
String goals = goalsForLifecyclePhase.getValue(); LifecyclePhase goals = goalsForLifecyclePhase.getValue();
if ( goals != null ) if ( goals != null )
{ {
parseLifecyclePhaseDefinitions( plugins, phase, goals ); parseLifecyclePhaseDefinitions( plugins, phase, goals );
@ -149,47 +147,54 @@ public class DefaultLifecyclePluginAnalyzer
return lifecycles; return lifecycles;
} }
private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, String phase, String goals ) private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals )
{ {
String[] mojos = StringUtils.split( goals, "," ); List<LifecycleMojo> mojos = goals.getMojos();
if ( mojos != null )
for ( int i = 0; i < mojos.length; i++ )
{ {
GoalSpec gs = parseGoalSpec( mojos[i].trim() );
for ( int i = 0; i < mojos.size(); i++ )
if ( gs == null )
{ {
logger.warn( "Ignored invalid goal specification '" + mojos[i] + "' from lifecycle mapping for phase " LifecycleMojo mojo = mojos.get( i );
+ phase );
continue; GoalSpec gs = parseGoalSpec( mojo.getGoal() );
}
if ( gs == null )
Plugin plugin = new Plugin();
plugin.setGroupId( gs.groupId );
plugin.setArtifactId( gs.artifactId );
plugin.setVersion( gs.version );
Plugin existing = plugins.get( plugin );
if ( existing != null )
{
if ( existing.getVersion() == null )
{ {
existing.setVersion( plugin.getVersion() ); logger.warn( "Ignored invalid goal specification '" + mojo.getGoal()
+ "' from lifecycle mapping for phase " + phase );
continue;
} }
plugin = existing;
Plugin plugin = new Plugin();
plugin.setGroupId( gs.groupId );
plugin.setArtifactId( gs.artifactId );
plugin.setVersion( gs.version );
Plugin existing = plugins.get( plugin );
if ( existing != null )
{
if ( existing.getVersion() == null )
{
existing.setVersion( plugin.getVersion() );
}
plugin = existing;
}
else
{
plugins.put( plugin, plugin );
}
PluginExecution execution = new PluginExecution();
execution.setId( getExecutionId( plugin, gs.goal ) );
execution.setPhase( phase );
execution.setPriority( i - mojos.size() );
execution.getGoals().add( gs.goal );
execution.setConfiguration( mojo.getConfiguration() );
plugin.setDependencies( mojo.getDependencies() );
plugin.getExecutions().add( execution );
} }
else
{
plugins.put( plugin, plugin );
}
PluginExecution execution = new PluginExecution();
execution.setId( getExecutionId( plugin, gs.goal ) );
execution.setPhase( phase );
execution.setPriority( i - mojos.length );
execution.getGoals().add( gs.goal );
plugin.getExecutions().add( execution );
} }
} }

View File

@ -32,7 +32,7 @@ public class DefaultLifecycleMapping
private Map<String, Lifecycle> lifecycleMap; private Map<String, Lifecycle> lifecycleMap;
/** @deprecated use lifecycles instead */ /** @deprecated use lifecycles instead */
private Map<String, String> phases; private Map<String, LifecyclePhase> phases;
/** /**
* Populates the lifecycle map from the injected list of lifecycle mappings (if not already done). * Populates the lifecycle map from the injected list of lifecycle mappings (if not already done).
@ -61,7 +61,7 @@ public class DefaultLifecycleMapping
for ( String lifecycleId : lifecycleIds ) for ( String lifecycleId : lifecycleIds )
{ {
Map<String, String> phases = getPhases( lifecycleId ); Map<String, LifecyclePhase> phases = getPhases( lifecycleId );
if ( phases != null ) if ( phases != null )
{ {
Lifecycle lifecycle = new Lifecycle(); Lifecycle lifecycle = new Lifecycle();
@ -88,7 +88,7 @@ public class DefaultLifecycleMapping
return null; return null;
} }
public Map<String, String> getPhases( String lifecycle ) public Map<String, LifecyclePhase> getPhases( String lifecycle )
{ {
initLifecycleMap(); initLifecycleMap();

View File

@ -35,7 +35,7 @@ public class Lifecycle
/** /**
* Field phases * Field phases
*/ */
private Map<String, String> phases; private Map<String, LifecyclePhase> phases;
/* /*
* NOTE: This exists merely for backward-compat with legacy-style lifecycle definitions and allows configuration * NOTE: This exists merely for backward-compat with legacy-style lifecycle definitions and allows configuration
@ -55,7 +55,7 @@ public class Lifecycle
/** /**
* Method getPhases * Method getPhases
*/ */
public Map<String, String> getPhases() public Map<String, LifecyclePhase> getPhases()
{ {
return this.phases; return this.phases;
} }
@ -75,7 +75,7 @@ public class Lifecycle
* *
* @param phases * @param phases
*/ */
public void setPhases( Map<String, String> phases ) public void setPhases( Map<String, LifecyclePhase> phases )
{ {
this.phases = phases; this.phases = phases;
} //-- void setPhases(java.util.List) } //-- void setPhases(java.util.List)

View File

@ -34,6 +34,6 @@ public interface LifecycleMapping
List<String> getOptionalMojos( String lifecycle ); List<String> getOptionalMojos( String lifecycle );
@Deprecated @Deprecated
Map<String, String> getPhases( String lifecycle ); Map<String, LifecyclePhase> getPhases( String lifecycle );
} }

View File

@ -0,0 +1,63 @@
package org.apache.maven.lifecycle.mapping;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
import org.apache.maven.model.Dependency;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class LifecycleMojo
{
private String goal;
private Xpp3Dom configuration;
private List<Dependency> dependencies;
public String getGoal()
{
return goal;
}
public Xpp3Dom getConfiguration()
{
return configuration;
}
public List<Dependency> getDependencies()
{
return dependencies;
}
public void setGoal( String goal )
{
this.goal = goal;
}
public void setConfiguration( Xpp3Dom configuration )
{
this.configuration = configuration;
}
public void setDependencies( List<Dependency> dependencies )
{
this.dependencies = dependencies;
}
}

View File

@ -0,0 +1,64 @@
package org.apache.maven.lifecycle.mapping;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList;
import java.util.List;
import org.codehaus.plexus.util.StringUtils;
public class LifecyclePhase
{
private List<LifecycleMojo> mojos;
public LifecyclePhase()
{
}
public LifecyclePhase( String goals )
{
set( goals );
}
public List<LifecycleMojo> getMojos()
{
return mojos;
}
public void setMojos( List<LifecycleMojo> mojos )
{
this.mojos = mojos;
}
public void set( String goals )
{
mojos = new ArrayList<LifecycleMojo>();
String[] mojoGoals = StringUtils.split( goals, "," );
for ( String mojoGoal: mojoGoals )
{
LifecycleMojo lifecycleMojo = new LifecycleMojo();
lifecycleMojo.setGoal( mojoGoal.trim() );
mojos.add( lifecycleMojo );
}
}
}