mirror of https://github.com/apache/maven.git
o cleaning up the path translator and adding a method to allow arbitrary
path translation given a path and basedir o moved the component configuration for the path translator into the plexus.xml so that the DefaultPluginManager can use it as a dependency o DefaultPluginManager.createParameters() will now look for parameters with the type = java.io.File and translate the path to the basedir of the project. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163543 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1d51c88c1
commit
a501f4c08a
|
@ -35,6 +35,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.ArtifactEnabledContainer;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -77,6 +78,8 @@ public class DefaultPluginManager
|
|||
|
||||
protected ArtifactFilter artifactFilter;
|
||||
|
||||
protected PathTranslator pathTranslator;
|
||||
|
||||
public DefaultPluginManager()
|
||||
{
|
||||
mojoDescriptors = new HashMap();
|
||||
|
@ -216,8 +219,6 @@ public class DefaultPluginManager
|
|||
{
|
||||
MavenProject project = session.getProject();
|
||||
|
||||
List projectPlugins = project.getPlugins();
|
||||
|
||||
org.apache.maven.model.Plugin pluginConfig = null;
|
||||
|
||||
for ( Iterator it = project.getPlugins().iterator(); it.hasNext(); )
|
||||
|
@ -227,6 +228,7 @@ public class DefaultPluginManager
|
|||
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
|
||||
{
|
||||
pluginConfig = plugin;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -277,6 +279,7 @@ public class DefaultPluginManager
|
|||
try
|
||||
{
|
||||
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
|
||||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
|
||||
|
@ -304,7 +307,8 @@ public class DefaultPluginManager
|
|||
// Plugin execution
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public PluginExecutionResponse executeMojo( MavenSession session, String goalName ) throws GoalExecutionException
|
||||
public PluginExecutionResponse executeMojo( MavenSession session, String goalName )
|
||||
throws GoalExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -363,9 +367,7 @@ public class DefaultPluginManager
|
|||
|
||||
try
|
||||
{
|
||||
// getLogger().info( "[" + mojoDescriptor.getId() + "]" );
|
||||
|
||||
request = new PluginExecutionRequest( DefaultPluginManager.createParameters( mojoDescriptor, session ) );
|
||||
request = new PluginExecutionRequest( createParameters( mojoDescriptor, session ) );
|
||||
|
||||
request.setLog( session.getLog() );
|
||||
}
|
||||
|
@ -444,7 +446,7 @@ public class DefaultPluginManager
|
|||
// Mojo Parameter Handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public static Map createParameters( MojoDescriptor goal, MavenSession session )
|
||||
public Map createParameters( MojoDescriptor goal, MavenSession session )
|
||||
throws PluginConfigurationException
|
||||
{
|
||||
Map map = null;
|
||||
|
@ -473,6 +475,14 @@ public class DefaultPluginManager
|
|||
}
|
||||
}
|
||||
|
||||
String type = parameter.getType();
|
||||
|
||||
if ( type != null && ( type.equals( "File" ) || type.equals( "java.io.File" ) ) )
|
||||
{
|
||||
value = pathTranslator.alignToBaseDirectory( (String)value,
|
||||
session.getProject().getFile().getParentFile() );
|
||||
}
|
||||
|
||||
map.put( key, value );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,85 +31,50 @@ public class DefaultPathTranslator
|
|||
|
||||
public void alignToBaseDirectory( Model model, File projectFile )
|
||||
{
|
||||
// build.directory
|
||||
// build.sourceDirectory
|
||||
// build.unitTestSourceDirectory
|
||||
// build.aspectSourceDirectory
|
||||
// build.resources.resource.directory
|
||||
// unitTest.resources.resource.directory
|
||||
|
||||
// build.output
|
||||
// build.testOutput
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
File basedir = projectFile.getParentFile();
|
||||
|
||||
if ( build != null )
|
||||
{
|
||||
String s = stripBasedirToken( build.getDirectory() );
|
||||
build.setDirectory( alignToBaseDirectory( build.getDirectory(), basedir ) );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
build.setDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
build.setSourceDirectory( alignToBaseDirectory( build.getSourceDirectory(), basedir ) );
|
||||
|
||||
s = stripBasedirToken( build.getSourceDirectory() );
|
||||
build.setTestSourceDirectory( alignToBaseDirectory( build.getTestSourceDirectory(), basedir ) );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
build.setSourceDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
|
||||
s = stripBasedirToken( build.getTestSourceDirectory() );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
build.setTestSourceDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
|
||||
List buildResources = build.getResources();
|
||||
|
||||
for ( Iterator i = buildResources.iterator(); i.hasNext(); )
|
||||
for ( Iterator i = build.getResources().iterator(); i.hasNext(); )
|
||||
{
|
||||
Resource resource = (Resource) i.next();
|
||||
|
||||
s = stripBasedirToken( resource.getDirectory() );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
resource.setDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
resource.setDirectory( alignToBaseDirectory( resource.getDirectory(), basedir ) );
|
||||
}
|
||||
|
||||
List unitTestResources = build.getTestResources();
|
||||
|
||||
for ( Iterator i = unitTestResources.iterator(); i.hasNext(); )
|
||||
for ( Iterator i = build.getTestResources().iterator(); i.hasNext(); )
|
||||
{
|
||||
Resource resource = (Resource) i.next();
|
||||
|
||||
s = stripBasedirToken( resource.getDirectory() );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
resource.setDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
resource.setDirectory( alignToBaseDirectory( resource.getDirectory(), basedir ) );
|
||||
}
|
||||
|
||||
s = stripBasedirToken( build.getOutputDirectory() );
|
||||
build.setOutputDirectory( alignToBaseDirectory( build.getOutputDirectory(), basedir ) );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
build.setOutputDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
|
||||
s = stripBasedirToken( build.getTestOutputDirectory() );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
build.setTestOutputDirectory( new File( projectFile.getParentFile(), s ).getPath() );
|
||||
}
|
||||
build.setTestOutputDirectory( alignToBaseDirectory( build.getTestOutputDirectory(), basedir ) );
|
||||
}
|
||||
}
|
||||
|
||||
public String alignToBaseDirectory( String path, File basedir )
|
||||
{
|
||||
String s = stripBasedirToken( path );
|
||||
|
||||
if ( requiresBaseDirectoryAlignment( s ) )
|
||||
{
|
||||
s = new File( basedir, s ).getPath();
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private String stripBasedirToken( String s )
|
||||
{
|
||||
if ( s != null )
|
||||
|
|
|
@ -30,4 +30,6 @@ public interface PathTranslator
|
|||
static final String ROLE = PathTranslator.class.getName();
|
||||
|
||||
void alignToBaseDirectory( Model model, File projectFile );
|
||||
|
||||
String alignToBaseDirectory( String path, File basedir );
|
||||
}
|
||||
|
|
|
@ -103,15 +103,6 @@
|
|||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
<implementation>org.apache.maven.project.validation.DefaultModelValidator</implementation>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|
|
||||
|
|
||||
-->
|
||||
<component>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
<implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|
|
||||
|
|
|
@ -20,6 +20,15 @@
|
|||
<component>
|
||||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
<implementation>org.apache.maven.plugin.DefaultPluginManager</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
<implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
|
||||
</component>
|
||||
</components>
|
||||
</plexus>
|
||||
|
|
Loading…
Reference in New Issue