mirror of https://github.com/apache/maven.git
MNG-5805: Custom packaging types: configuring DefaultLifecycleMapping mojo executions
Signed-off-by: Jason van Zyl <jason@tesla.io>
This commit is contained in:
parent
d8ae13fd7b
commit
1d148be82b
|
@ -22,6 +22,8 @@ package org.apache.maven.lifecycle;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.lifecycle.mapping.LifecyclePhase;
|
||||
|
||||
/**
|
||||
* 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.phases = phases;
|
||||
|
@ -54,7 +56,7 @@ public class Lifecycle
|
|||
|
||||
private List<String> phases;
|
||||
|
||||
private Map<String, String> defaultPhases;
|
||||
private Map<String, LifecyclePhase> defaultPhases;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
|
@ -66,7 +68,7 @@ public class Lifecycle
|
|||
return this.phases;
|
||||
}
|
||||
|
||||
public Map<String, String> getDefaultPhases()
|
||||
public Map<String, LifecyclePhase> getDefaultPhases()
|
||||
{
|
||||
return defaultPhases;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.apache.maven.lifecycle.DefaultLifecycles;
|
|||
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
|
||||
import org.apache.maven.lifecycle.Lifecycle;
|
||||
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.PluginExecution;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
@ -98,7 +100,7 @@ public class DefaultLifecyclePluginAnalyzer
|
|||
org.apache.maven.lifecycle.mapping.Lifecycle lifecycleConfiguration =
|
||||
lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() );
|
||||
|
||||
Map<String, String> phaseToGoalMapping = null;
|
||||
Map<String, LifecyclePhase> phaseToGoalMapping = null;
|
||||
|
||||
if ( lifecycleConfiguration != null )
|
||||
{
|
||||
|
@ -111,14 +113,10 @@ public class DefaultLifecyclePluginAnalyzer
|
|||
|
||||
if ( phaseToGoalMapping != null )
|
||||
{
|
||||
// These are of the form:
|
||||
//
|
||||
// compile -> org.apache.maven.plugins:maven-compiler-plugin:compile[,gid:aid:goal,...]
|
||||
//
|
||||
for ( Map.Entry<String, String> goalsForLifecyclePhase : phaseToGoalMapping.entrySet() )
|
||||
for ( Map.Entry<String, LifecyclePhase> goalsForLifecyclePhase : phaseToGoalMapping.entrySet() )
|
||||
{
|
||||
String phase = goalsForLifecyclePhase.getKey();
|
||||
String goals = goalsForLifecyclePhase.getValue();
|
||||
LifecyclePhase goals = goalsForLifecyclePhase.getValue();
|
||||
if ( goals != null )
|
||||
{
|
||||
parseLifecyclePhaseDefinitions( plugins, phase, goals );
|
||||
|
@ -149,47 +147,54 @@ public class DefaultLifecyclePluginAnalyzer
|
|||
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, "," );
|
||||
|
||||
for ( int i = 0; i < mojos.length; i++ )
|
||||
List<LifecycleMojo> mojos = goals.getMojos();
|
||||
if ( mojos != null )
|
||||
{
|
||||
GoalSpec gs = parseGoalSpec( mojos[i].trim() );
|
||||
|
||||
if ( gs == null )
|
||||
|
||||
for ( int i = 0; i < mojos.size(); i++ )
|
||||
{
|
||||
logger.warn( "Ignored invalid goal specification '" + mojos[i] + "' from lifecycle mapping for phase "
|
||||
+ phase );
|
||||
continue;
|
||||
}
|
||||
|
||||
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 )
|
||||
LifecycleMojo mojo = mojos.get( i );
|
||||
|
||||
GoalSpec gs = parseGoalSpec( mojo.getGoal() );
|
||||
|
||||
if ( gs == 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class DefaultLifecycleMapping
|
|||
private Map<String, Lifecycle> lifecycleMap;
|
||||
|
||||
/** @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).
|
||||
|
@ -61,7 +61,7 @@ public class DefaultLifecycleMapping
|
|||
|
||||
for ( String lifecycleId : lifecycleIds )
|
||||
{
|
||||
Map<String, String> phases = getPhases( lifecycleId );
|
||||
Map<String, LifecyclePhase> phases = getPhases( lifecycleId );
|
||||
if ( phases != null )
|
||||
{
|
||||
Lifecycle lifecycle = new Lifecycle();
|
||||
|
@ -88,7 +88,7 @@ public class DefaultLifecycleMapping
|
|||
return null;
|
||||
}
|
||||
|
||||
public Map<String, String> getPhases( String lifecycle )
|
||||
public Map<String, LifecyclePhase> getPhases( String lifecycle )
|
||||
{
|
||||
initLifecycleMap();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class Lifecycle
|
|||
/**
|
||||
* 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
|
||||
|
@ -55,7 +55,7 @@ public class Lifecycle
|
|||
/**
|
||||
* Method getPhases
|
||||
*/
|
||||
public Map<String, String> getPhases()
|
||||
public Map<String, LifecyclePhase> getPhases()
|
||||
{
|
||||
return this.phases;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class Lifecycle
|
|||
*
|
||||
* @param phases
|
||||
*/
|
||||
public void setPhases( Map<String, String> phases )
|
||||
public void setPhases( Map<String, LifecyclePhase> phases )
|
||||
{
|
||||
this.phases = phases;
|
||||
} //-- void setPhases(java.util.List)
|
||||
|
|
|
@ -34,6 +34,6 @@ public interface LifecycleMapping
|
|||
List<String> getOptionalMojos( String lifecycle );
|
||||
|
||||
@Deprecated
|
||||
Map<String, String> getPhases( String lifecycle );
|
||||
Map<String, LifecyclePhase> getPhases( String lifecycle );
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue