mirror of https://github.com/apache/maven.git
Replaced interpolator code.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@694907 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35cb991844
commit
7dc42ed958
|
@ -14,6 +14,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
|
|||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.extension.ExtensionManagerException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.apache.maven.lifecycle.LifecycleException;
|
||||
import org.apache.maven.lifecycle.LifecycleLoaderException;
|
||||
import org.apache.maven.lifecycle.LifecycleSpecificationException;
|
||||
|
@ -37,7 +38,6 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.errors.ProjectErrorReporter;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.reactor.MissingModuleException;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.apache.maven.errors;
|
||||
|
||||
import org.apache.maven.ProjectCycleException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
|
||||
|
@ -23,7 +24,6 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
|||
import org.apache.maven.project.DuplicateArtifactAttachmentException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.realm.RealmManagementException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
|||
import org.apache.maven.errors.DefaultProjectErrorReporter;
|
||||
import org.apache.maven.errors.ProjectErrorReporter;
|
||||
import org.apache.maven.errors.ProjectReporterManager;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.reactor.MissingModuleException;
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.ModelAndFile;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.ModelAndFile;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.apache.maven.profiles.activation.ProfileActivator;
|
|||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.InvalidProjectVersionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
|
|
@ -35,12 +35,13 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.extension.lineage.ModelLineage;
|
||||
import org.apache.maven.extension.lineage.ModelLineageBuilder;
|
||||
import org.apache.maven.extension.lineage.ModelLineageIterator;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
import org.apache.maven.reactor.MissingModuleException;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
||||
|
@ -68,8 +69,6 @@ public class DefaultBuildExtensionScanner
|
|||
|
||||
private ModelLineageBuilder modelLineageBuilder;
|
||||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
// cached.
|
||||
private MavenProject basicSuperProject;
|
||||
|
||||
|
@ -77,19 +76,6 @@ public class DefaultBuildExtensionScanner
|
|||
{
|
||||
}
|
||||
|
||||
protected DefaultBuildExtensionScanner( ExtensionManager extensionManager,
|
||||
MavenProjectBuilder projectBuilder,
|
||||
ModelLineageBuilder modelLineageBuilder,
|
||||
ModelInterpolator modelInterpolator,
|
||||
Logger logger )
|
||||
{
|
||||
this.extensionManager = extensionManager;
|
||||
this.projectBuilder = projectBuilder;
|
||||
this.modelLineageBuilder = modelLineageBuilder;
|
||||
this.modelInterpolator = modelInterpolator;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void scanForBuildExtensions( List files,
|
||||
MavenExecutionRequest request,
|
||||
boolean ignoreMissingModules )
|
||||
|
@ -176,8 +162,18 @@ public class DefaultBuildExtensionScanner
|
|||
|
||||
config.setExecutionProperties( execProps );
|
||||
|
||||
model = modelInterpolator.interpolate( model, modelPom.getParentFile(), config, getLogger().isDebugEnabled() );
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties()));
|
||||
model = PomClassicTransformer.interpolateModel( model, interpolatorProperties, modelPom.getParentFile());
|
||||
|
||||
/*
|
||||
try {
|
||||
model = modelInterpolator.interpolate( model, modelPom.getParentFile(), config, getLogger().isDebugEnabled() );
|
||||
} catch (ModelInterpolationException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
*/
|
||||
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
|
||||
|
||||
Properties modelProps = model.getProperties();
|
||||
|
@ -218,13 +214,14 @@ public class DefaultBuildExtensionScanner
|
|||
}
|
||||
}
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ExtensionScanningException( "Failed to interpolate model from: " + pom
|
||||
+ " prior to scanning for extensions.", pom, e );
|
||||
+ " prior to scanning for extensions.", pom, new ModelInterpolationException(e.getMessage()) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void grabManagedPluginsWithExtensionsFlagTurnedOn( Model model,
|
||||
Set managedPluginsWithExtensionsFlag )
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.apache.maven.model.Extension;
|
|||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.extension.ModelInterpolationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
package org.apache.maven.extension;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
@ -20,6 +20,7 @@ package org.apache.maven.plugin;
|
|||
*/
|
||||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
|
@ -58,10 +59,9 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.ModelUtils;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.realm.MavenRealmManager;
|
||||
import org.apache.maven.realm.RealmManagementException;
|
||||
|
@ -143,8 +143,6 @@ public class DefaultPluginManager
|
|||
|
||||
protected MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
protected ModelInterpolator modelInterpolator;
|
||||
|
||||
protected PluginMappingManager pluginMappingManager;
|
||||
|
||||
private PluginManagerSupport pluginManagerSupport;
|
||||
|
@ -560,23 +558,13 @@ public class DefaultPluginManager
|
|||
{
|
||||
try
|
||||
{
|
||||
String interpolatedDom = modelInterpolator.interpolate( String.valueOf( dom ),
|
||||
project.getModel(),
|
||||
project.getBasedir(),
|
||||
session.getProjectBuilderConfiguration(),
|
||||
getLogger().isDebugEnabled() );
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties()));
|
||||
String interpolatedDom =
|
||||
PomClassicTransformer.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
|
||||
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new PluginManagerException(
|
||||
mojoDescriptor,
|
||||
project,
|
||||
"Failed to calculate concrete state for configuration of: "
|
||||
+ mojoDescriptor.getHumanReadableKey(),
|
||||
e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new PluginManagerException(
|
||||
|
|
|
@ -191,9 +191,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.extension.ExtensionManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.extension.lineage.ModelLineageBuilder</role>
|
||||
<role-hint>default</role-hint>
|
||||
|
@ -239,9 +236,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginManagerSupport</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.ArtifactFilterManager</role>
|
||||
</requirement>
|
||||
|
|
|
@ -1,368 +0,0 @@
|
|||
package org.apache.maven.extension;
|
||||
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.extension.lineage.ModelLineageBuilder;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.reactor.MissingModuleException;
|
||||
import org.apache.maven.shared.tools.easymock.MockManager;
|
||||
import org.apache.maven.shared.tools.easymock.TestFileManager;
|
||||
import org.apache.maven.extension.lineage.DefaultModelLineage;
|
||||
import org.apache.maven.extension.lineage.ModelLineage;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
||||
import org.easymock.ArgumentsMatcher;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DefaultBuildExtensionScannerTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
private MockManager mockManager;
|
||||
|
||||
private TestFileManager fileManager;
|
||||
|
||||
private MockControl extensionManagerCtl;
|
||||
|
||||
private ExtensionManager extensionManager;
|
||||
|
||||
private MockControl projectBuilderCtl;
|
||||
|
||||
private MavenProjectBuilder projectBuilder;
|
||||
|
||||
private MockControl modelLineageBuilderCtl;
|
||||
|
||||
private ModelLineageBuilder modelLineageBuilder;
|
||||
|
||||
private MockControl modelInterpolatorCtl;
|
||||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
mockManager = new MockManager();
|
||||
fileManager = new TestFileManager( "DefaultBuildExtensionScannerTest", "" );
|
||||
|
||||
extensionManagerCtl = MockControl.createControl( ExtensionManager.class );
|
||||
mockManager.add( extensionManagerCtl );
|
||||
extensionManager = (ExtensionManager) extensionManagerCtl.getMock();
|
||||
|
||||
projectBuilderCtl = MockControl.createControl( MavenProjectBuilder.class );
|
||||
mockManager.add( projectBuilderCtl );
|
||||
projectBuilder = (MavenProjectBuilder) projectBuilderCtl.getMock();
|
||||
|
||||
modelLineageBuilderCtl = MockControl.createControl( ModelLineageBuilder.class );
|
||||
mockManager.add( modelLineageBuilderCtl );
|
||||
modelLineageBuilder = (ModelLineageBuilder) modelLineageBuilderCtl.getMock();
|
||||
|
||||
modelInterpolatorCtl = MockControl.createControl( ModelInterpolator.class );
|
||||
mockManager.add( modelInterpolatorCtl );
|
||||
modelInterpolator = (ModelInterpolator) modelInterpolatorCtl.getMock();
|
||||
}
|
||||
|
||||
public void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
fileManager.cleanUp();
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testIncludePluginWhenExtensionsFlagDirectlySet()
|
||||
throws ExtensionScanningException, ProjectBuildingException, ModelInterpolationException,
|
||||
ExtensionManagerException, MissingModuleException
|
||||
{
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
|
||||
File pomFile = new File( "pom" );
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
|
||||
Build build = new Build();
|
||||
model.setBuild( build );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "test" );
|
||||
plugin.setArtifactId( "artifact" );
|
||||
plugin.setExtensions( true );
|
||||
|
||||
ModelLineage ml = new DefaultModelLineage();
|
||||
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionManager.addPluginAsExtension( plugin, model, Collections.EMPTY_LIST, request );
|
||||
extensionManagerCtl.setVoidCallable( 1 );
|
||||
|
||||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
||||
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
|
||||
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
|
||||
"test" ) ).scanForBuildExtensions( pomFile,
|
||||
request,
|
||||
false );
|
||||
|
||||
mockManager.verifyAll();
|
||||
}
|
||||
|
||||
public void testIncludePluginWhenExtensionsFlagSetInPluginManagement()
|
||||
throws ExtensionScanningException, ProjectBuildingException, ModelInterpolationException,
|
||||
ExtensionManagerException, MissingModuleException
|
||||
{
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
|
||||
File pomFile = new File( "pom" );
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
|
||||
Build build = new Build();
|
||||
model.setBuild( build );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "test" );
|
||||
plugin.setArtifactId( "artifact" );
|
||||
|
||||
Parent parent = new Parent();
|
||||
parent.setGroupId( "group" );
|
||||
parent.setArtifactId( "parent" );
|
||||
model.setParent( parent );
|
||||
|
||||
Model parentModel = new Model();
|
||||
parentModel.setGroupId( "group" );
|
||||
parentModel.setArtifactId( "parent" );
|
||||
|
||||
Build parentBuild = new Build();
|
||||
parentModel.setBuild( parentBuild );
|
||||
|
||||
PluginManagement pMgmt = new PluginManagement();
|
||||
parentBuild.setPluginManagement( pMgmt );
|
||||
|
||||
Plugin parentPlugin = new Plugin();
|
||||
|
||||
pMgmt.addPlugin( parentPlugin );
|
||||
|
||||
parentPlugin.setGroupId( "test" );
|
||||
parentPlugin.setArtifactId( "artifact" );
|
||||
parentPlugin.setExtensions( true );
|
||||
|
||||
ModelLineage ml = new DefaultModelLineage();
|
||||
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
ml.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( new FirstArgFileMatcher() );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE);
|
||||
|
||||
modelInterpolator.interpolate( parentModel, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionManager.addPluginAsExtension( plugin, model, Collections.EMPTY_LIST, request );
|
||||
extensionManagerCtl.setVoidCallable( 1 );
|
||||
|
||||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
||||
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
|
||||
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
|
||||
"test" ) ).scanForBuildExtensions( pomFile,
|
||||
request,
|
||||
false );
|
||||
|
||||
mockManager.verifyAll();
|
||||
}
|
||||
|
||||
public void testIncludePluginWithExtensionsFlagDeclaredInParentPluginManagementReferencedFromModule()
|
||||
throws ModelInterpolationException, ProjectBuildingException, ExtensionManagerException,
|
||||
ExtensionScanningException, IOException, MissingModuleException
|
||||
{
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
|
||||
File projectDir = fileManager.createTempDir();
|
||||
File pomFile = fileManager.createFile( projectDir, "pom.xml", "Placeholder file." ).getCanonicalFile();
|
||||
File modulePomFile = fileManager.createFile( projectDir,
|
||||
"module/pom.xml",
|
||||
"Placeholder file." ).getCanonicalFile();
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
model.setGroupId( "group" );
|
||||
model.setArtifactId( "artifact" );
|
||||
model.setVersion( "1" );
|
||||
|
||||
Parent parent = new Parent();
|
||||
parent.setGroupId( "group" );
|
||||
parent.setArtifactId( "parent" );
|
||||
parent.setVersion( "1" );
|
||||
model.setParent( parent );
|
||||
|
||||
Model parentModel = new Model();
|
||||
parentModel.setGroupId( "group" );
|
||||
parentModel.setArtifactId( "parent" );
|
||||
parentModel.setVersion( "1" );
|
||||
|
||||
Build parentBuild = new Build();
|
||||
parentModel.setBuild( parentBuild );
|
||||
|
||||
PluginManagement pMgmt = new PluginManagement();
|
||||
parentBuild.setPluginManagement( pMgmt );
|
||||
|
||||
Plugin parentPlugin = new Plugin();
|
||||
|
||||
pMgmt.addPlugin( parentPlugin );
|
||||
|
||||
parentPlugin.setGroupId( "test" );
|
||||
parentPlugin.setArtifactId( "artifact" );
|
||||
parentPlugin.setExtensions( true );
|
||||
|
||||
Model module = new Model();
|
||||
module.setGroupId( "group" );
|
||||
module.setArtifactId( "module" );
|
||||
module.setVersion( "1" );
|
||||
|
||||
Parent moduleParent = new Parent();
|
||||
moduleParent.setGroupId( model.getGroupId() );
|
||||
moduleParent.setArtifactId( model.getArtifactId() );
|
||||
moduleParent.setVersion( model.getVersion() );
|
||||
|
||||
module.setParent( moduleParent );
|
||||
|
||||
Build build = new Build();
|
||||
module.setBuild( build );
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
plugin.setGroupId( "test" );
|
||||
plugin.setArtifactId( "artifact" );
|
||||
|
||||
model.addModule( "module" );
|
||||
|
||||
ModelLineage ml = new DefaultModelLineage();
|
||||
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
ml.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
|
||||
|
||||
ModelLineage moduleMl = new DefaultModelLineage();
|
||||
moduleMl.setOrigin( module, modulePomFile, Collections.EMPTY_LIST, true );
|
||||
moduleMl.addParent( model, pomFile, Collections.EMPTY_LIST, true );
|
||||
moduleMl.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( pomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setMatcher( new FirstArgFileMatcher() );
|
||||
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelLineageBuilder.buildModelLineage( modulePomFile, new DefaultProjectBuilderConfiguration(), null, false, true );
|
||||
modelLineageBuilderCtl.setReturnValue( moduleMl, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( model, null, null, false );
|
||||
modelInterpolatorCtl.setMatcher( new FirstArgModelIdMatcher() );
|
||||
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( parentModel, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
|
||||
|
||||
modelInterpolator.interpolate( module, null, null, false );
|
||||
modelInterpolatorCtl.setReturnValue( module, MockControl.ZERO_OR_MORE );
|
||||
|
||||
extensionManager.addPluginAsExtension( plugin, module, Collections.EMPTY_LIST, request );
|
||||
extensionManagerCtl.setVoidCallable( 1 );
|
||||
|
||||
MavenProject superProject = new MavenProject( new Model() );
|
||||
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
|
||||
|
||||
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
|
||||
projectBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
|
||||
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
|
||||
|
||||
mockManager.replayAll();
|
||||
|
||||
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
|
||||
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
|
||||
"test" ) ).scanForBuildExtensions( pomFile,
|
||||
request,
|
||||
false );
|
||||
|
||||
mockManager.verifyAll();
|
||||
}
|
||||
|
||||
private static final class FirstArgFileMatcher
|
||||
implements ArgumentsMatcher
|
||||
{
|
||||
public boolean matches( Object[] expected,
|
||||
Object[] actual )
|
||||
{
|
||||
return expected[0].equals( actual[0] );
|
||||
}
|
||||
|
||||
public String toString( Object[] arguments )
|
||||
{
|
||||
return "matcher for file: " + arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FirstArgModelIdMatcher
|
||||
implements ArgumentsMatcher
|
||||
{
|
||||
public boolean matches( Object[] expected,
|
||||
Object[] actual )
|
||||
{
|
||||
return ((Model)expected[0]).getId().equals( ((Model)actual[0]).getId() );
|
||||
}
|
||||
|
||||
public String toString( Object[] arguments )
|
||||
{
|
||||
return "matcher for: " + ( (Model) arguments[0] ).getId();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,9 +26,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
|
||||
</requirement>
|
||||
|
|
|
@ -27,9 +27,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.extension.ExtensionManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.extension.lineage.ModelLineageBuilder</role>
|
||||
<role-hint>default</role-hint>
|
||||
|
|
|
@ -23,9 +23,6 @@ under the License.
|
|||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -135,15 +135,6 @@ under the License.
|
|||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|
|
||||
|
|
||||
-->
|
||||
<component>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
<implementation>org.apache.maven.project.interpolation.RegexBasedModelInterpolator</implementation>
|
||||
</component>
|
||||
|
||||
<!--
|
||||
|
|
||||
|
@ -170,9 +161,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -91,9 +91,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.inheritance.ModelInheritanceAssembler</role>
|
||||
</requirement>
|
||||
|
|
|
@ -85,9 +85,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.MavenTools;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
|
@ -43,8 +44,6 @@ import org.apache.maven.profiles.build.ProfileAdvisor;
|
|||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.builder.PomArtifactResolver;
|
||||
import org.apache.maven.project.builder.ProjectBuilder;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.project.workspace.ProjectWorkspace;
|
||||
|
@ -90,8 +89,6 @@ public class DefaultMavenProjectBuilder
|
|||
// TODO: make it a component
|
||||
private MavenXpp3Reader modelReader;
|
||||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
private ProfileAdvisor profileAdvisor;
|
||||
|
||||
private MavenTools mavenTools;
|
||||
|
@ -273,7 +270,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
project = interpolateModel( project.getModel(), null, null, config );
|
||||
project = constructMavenProjectFromModel( project.getModel(), null, null, config );
|
||||
project.setActiveProfiles( activeProfiles );
|
||||
project.setRemoteArtifactRepositories(
|
||||
mavenTools.buildArtifactRepositories( superModel.getRepositories() ) );
|
||||
|
@ -285,11 +282,6 @@ public class DefaultMavenProjectBuilder
|
|||
throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
|
||||
"Maven super-POM contains an invalid repository!", e );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( STANDALONE_SUPERPOM_GROUPID + ":" + STANDALONE_SUPERPOM_ARTIFACTID,
|
||||
"Maven super-POM contains an invalid expressions!", e );
|
||||
}
|
||||
|
||||
project.setExecutionRoot( true );
|
||||
|
||||
|
@ -393,11 +385,7 @@ public class DefaultMavenProjectBuilder
|
|||
MavenProject project;
|
||||
try
|
||||
{
|
||||
project = interpolateModel( model, projectDescriptor, parentDescriptor, config );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new InvalidProjectModelException( projectId, e.getMessage(), projectDescriptor, e );
|
||||
project = constructMavenProjectFromModel( model, projectDescriptor, parentDescriptor, config );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
@ -417,19 +405,11 @@ public class DefaultMavenProjectBuilder
|
|||
return project;
|
||||
}
|
||||
|
||||
private MavenProject interpolateModel( Model model, File pomFile, File parentFile,
|
||||
private MavenProject constructMavenProjectFromModel( Model model, File pomFile, File parentFile,
|
||||
ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
|
||||
throws ProjectBuildingException, InvalidRepositoryException
|
||||
{
|
||||
File projectDir = null;
|
||||
if ( pomFile != null )
|
||||
{
|
||||
projectDir = pomFile.getAbsoluteFile().getParentFile();
|
||||
}
|
||||
|
||||
model = modelInterpolator.interpolate( model, projectDir, config, getLogger().isDebugEnabled() );
|
||||
|
||||
// We will return a different project object using the new model (hence the need to return a project, not just modify the parameter)
|
||||
MavenProject project = new MavenProject( model, artifactFactory, mavenTools, this, config );
|
||||
|
||||
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
|
||||
|
@ -551,11 +531,15 @@ public class DefaultMavenProjectBuilder
|
|||
throw new IllegalArgumentException( "projectBuilder: not initialized" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties()));
|
||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties()));
|
||||
|
||||
MavenProject mavenProject;
|
||||
try
|
||||
{
|
||||
mavenProject = projectBuilder.buildFromLocalPath( new FileInputStream( projectDescriptor ), Arrays.asList(
|
||||
getSuperProject( config, projectDescriptor, true ).getModel() ), null, null, resolver,
|
||||
getSuperProject( config, projectDescriptor, true ).getModel() ), null, interpolatorProperties, resolver,
|
||||
projectDescriptor.getParentFile(),
|
||||
config );
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
|
@ -68,20 +67,6 @@ public class InvalidProjectModelException
|
|||
this( projectId, message, new File( pomLocation ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link File} constructor for pomLocation
|
||||
*/
|
||||
public InvalidProjectModelException( String projectId, String pomLocation, String message,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
this( projectId, message, new File( pomLocation ), cause );
|
||||
}
|
||||
|
||||
public InvalidProjectModelException( String projectId, String message, File pomLocation,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
super( projectId, message, pomLocation, cause );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link File} constructor for pomLocation
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.apache.maven.project;
|
|||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -251,30 +250,6 @@ public class ProjectBuildingException
|
|||
pomFile = new File( pomLocation );
|
||||
}
|
||||
|
||||
protected ProjectBuildingException( String projectId, String message, File pomFile,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
this.pomFile = pomFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link File} constructor for pomLocation
|
||||
*/
|
||||
protected ProjectBuildingException( String projectId, String message, String pomLocation,
|
||||
ModelInterpolationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
pomFile = new File( pomLocation );
|
||||
}
|
||||
|
||||
public ProjectBuildingException( String projectId, String message, ModelInterpolationException cause )
|
||||
{
|
||||
super( message, cause );
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
public File getPomFile()
|
||||
{
|
||||
|
|
|
@ -95,19 +95,19 @@ public final class ArtifactModelContainerFactory
|
|||
{
|
||||
if ( version == null && mp.getUri().equals( uri + "/version" ) )
|
||||
{
|
||||
this.version = mp.getValue();
|
||||
this.version = mp.getResolvedValue();
|
||||
}
|
||||
else if ( artifactId == null && mp.getUri().equals( uri + "/artifactId" ) )
|
||||
{
|
||||
this.artifactId = mp.getValue();
|
||||
this.artifactId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( groupId == null && mp.getUri().equals( uri + "/groupId" ) )
|
||||
{
|
||||
this.groupId = mp.getValue();
|
||||
this.groupId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) && type == null )
|
||||
{
|
||||
this.type = mp.getValue();
|
||||
this.type = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
if ( groupId == null )
|
||||
|
|
|
@ -70,7 +70,7 @@ public class IdModelContainerFactory
|
|||
{
|
||||
if ( mp.getUri().endsWith( "/id" ) )
|
||||
{
|
||||
this.id = mp.getValue();
|
||||
this.id = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,8 @@ public final class PomClassicDomainModel
|
|||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -129,6 +131,21 @@ public final class PomClassicDomainModel
|
|||
this.parentFile = parentFile;
|
||||
}
|
||||
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
|
||||
* otherwise returns false.
|
||||
|
|
|
@ -20,18 +20,15 @@ package org.apache.maven.project.builder;
|
|||
*/
|
||||
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelDataSource;
|
||||
import org.apache.maven.shared.model.ModelMarshaller;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
import org.apache.maven.shared.model.ModelTransformer;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.shared.model.*;
|
||||
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -138,9 +135,9 @@ public final class PomClassicTransformer
|
|||
List<ModelProperty> props = new ArrayList<ModelProperty>();
|
||||
for ( ModelProperty mp : properties )
|
||||
{ //TODO: Resolved values
|
||||
if ( mp.getValue() != null && ( mp.getValue().contains( "=" ) || mp.getValue().contains( "<" ) ) )
|
||||
if ( mp.getResolvedValue() != null && ( mp.getResolvedValue().contains( "=" ) || mp.getResolvedValue().contains( "<" ) ) )
|
||||
{
|
||||
props.add( new ModelProperty( mp.getUri(), "<![CDATA[" + mp.getValue() + "]]>" ) );
|
||||
props.add( new ModelProperty( mp.getUri(), "<![CDATA[" + mp.getResolvedValue() + "]]>" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -257,9 +254,10 @@ public final class PomClassicTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* @see ModelTransformer#transformToModelProperties(java.util.List)
|
||||
* @see ModelTransformer#transformToModelProperties(java.util.List, java.util.List)
|
||||
*/
|
||||
public List<ModelProperty> transformToModelProperties( List<DomainModel> domainModels )
|
||||
public List<ModelProperty> transformToModelProperties( List<DomainModel> domainModels,
|
||||
List<InterpolatorProperty> interpolatorProperties)
|
||||
throws IOException
|
||||
{
|
||||
if ( domainModels == null || domainModels.isEmpty() )
|
||||
|
@ -303,7 +301,7 @@ public final class PomClassicTransformer
|
|||
ModelProperty parentVersion = getPropertyFor( ProjectUri.Parent.version, tmp );
|
||||
if ( parentVersion != null )
|
||||
{
|
||||
tmp.add( new ModelProperty( ProjectUri.version, parentVersion.getValue() ) );
|
||||
tmp.add( new ModelProperty( ProjectUri.version, parentVersion.getResolvedValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,7 +322,7 @@ public final class PomClassicTransformer
|
|||
ModelProperty parentGroupId = getPropertyFor( ProjectUri.Parent.groupId, tmp );
|
||||
if ( parentGroupId != null )
|
||||
{
|
||||
tmp.add( new ModelProperty( ProjectUri.groupId, parentGroupId.getValue() ) );
|
||||
tmp.add( new ModelProperty( ProjectUri.groupId, parentGroupId.getResolvedValue() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -342,7 +340,7 @@ public final class PomClassicTransformer
|
|||
for ( ModelProperty mp : container.getProperties() )
|
||||
{
|
||||
if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.Execution.inherited ) &&
|
||||
mp.getValue() != null && mp.getValue().equals( "false" ) )
|
||||
mp.getResolvedValue() != null && mp.getResolvedValue().equals( "false" ) )
|
||||
{
|
||||
removeProperties.addAll( container.getProperties() );
|
||||
for ( int j = tmp.indexOf( mp ); j >= 0; j-- )
|
||||
|
@ -370,8 +368,8 @@ public final class PomClassicTransformer
|
|||
{
|
||||
for ( ModelProperty mp : container.getProperties() )
|
||||
{
|
||||
if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.inherited ) && mp.getValue() != null &&
|
||||
mp.getValue().equals( "false" ) )
|
||||
if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.inherited ) && mp.getResolvedValue() != null &&
|
||||
mp.getResolvedValue().equals( "false" ) )
|
||||
{
|
||||
removeProperties.addAll( container.getProperties() );
|
||||
for ( int j = tmp.indexOf( mp ); j >= 0; j-- )
|
||||
|
@ -393,7 +391,7 @@ public final class PomClassicTransformer
|
|||
ModelProperty scmUrlProperty = getPropertyFor( ProjectUri.Scm.url, tmp );
|
||||
if ( scmUrl.length() == 0 && scmUrlProperty != null )
|
||||
{
|
||||
scmUrl.append( scmUrlProperty.getValue() );
|
||||
scmUrl.append( scmUrlProperty.getResolvedValue() );
|
||||
for ( String projectName : projectNames )
|
||||
{
|
||||
scmUrl.append( "/" ).append( projectName );
|
||||
|
@ -407,7 +405,7 @@ public final class PomClassicTransformer
|
|||
scmUrlProperty = getPropertyFor( ProjectUri.Scm.connection, tmp );
|
||||
if ( scmConnectionUrl.length() == 0 && scmUrlProperty != null )
|
||||
{
|
||||
scmConnectionUrl.append( scmUrlProperty.getValue() );
|
||||
scmConnectionUrl.append( scmUrlProperty.getResolvedValue() );
|
||||
for ( String projectName : projectNames )
|
||||
{
|
||||
scmConnectionUrl.append( "/" ).append( projectName );
|
||||
|
@ -420,7 +418,7 @@ public final class PomClassicTransformer
|
|||
scmUrlProperty = getPropertyFor( ProjectUri.Scm.developerConnection, tmp );
|
||||
if ( scmDeveloperUrl.length() == 0 && scmUrlProperty != null )
|
||||
{
|
||||
scmDeveloperUrl.append( scmUrlProperty.getValue() );
|
||||
scmDeveloperUrl.append( scmUrlProperty.getResolvedValue() );
|
||||
for ( String projectName : projectNames )
|
||||
{
|
||||
scmDeveloperUrl.append( "/" ).append( projectName );
|
||||
|
@ -489,31 +487,97 @@ public final class PomClassicTransformer
|
|||
ModelProperty artifactId = getPropertyFor( ProjectUri.artifactId, tmp );
|
||||
if ( artifactId != null )
|
||||
{
|
||||
projectNames.add( 0, artifactId.getValue() );
|
||||
projectNames.add( 0, artifactId.getResolvedValue() );
|
||||
}
|
||||
|
||||
tmp.removeAll( clearedProperties );
|
||||
modelProperties.addAll( tmp );
|
||||
modelProperties.removeAll( clearedProperties );
|
||||
|
||||
if ( domainModels.indexOf( domainModel ) == 0 )
|
||||
{
|
||||
//cache.put( pomDomainModel.getId(), modelProperties );
|
||||
}
|
||||
|
||||
//Remove Parent Info
|
||||
/*
|
||||
for (ModelProperty mp : tmp) {
|
||||
if (mp.getUri().startsWith(ProjectUri.Parent.xUri)) {
|
||||
modelProperties.remove(mp);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
interpolateModelProperties( modelProperties, interpolatorProperties, ((PomClassicDomainModel) domainModels.get(0)) );
|
||||
return modelProperties;
|
||||
}
|
||||
|
||||
public static String interpolateXmlString( String xml, List<InterpolatorProperty> interpolatorProperties )
|
||||
throws IOException
|
||||
{
|
||||
List<ModelProperty> modelProperties =
|
||||
ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream(xml.getBytes()), ProjectUri.baseUri, uris );
|
||||
|
||||
Map<String, String> aliases = new HashMap<String, String>();
|
||||
aliases.put( "project.", "pom.");
|
||||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips.addAll(ModelTransformerContext.createInterpolatorProperties(modelProperties, ProjectUri.baseUri, aliases,
|
||||
false, false));
|
||||
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(mp.getUri().startsWith(ProjectUri.properties) && mp.getValue() != null )
|
||||
{
|
||||
String uri = mp.getUri();
|
||||
ips.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1,
|
||||
uri.length() ) + "}", mp.getValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips );
|
||||
return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
}
|
||||
|
||||
public static String interpolateModelAsString(Model model, List<InterpolatorProperty> interpolatorProperties, File projectDirectory)
|
||||
throws IOException
|
||||
{
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( model );
|
||||
domainModel.setProjectDirectory( projectDirectory );
|
||||
List<ModelProperty> modelProperties =
|
||||
ModelMarshaller.marshallXmlToModelProperties( domainModel.getInputStream(), ProjectUri.baseUri, uris );
|
||||
interpolateModelProperties( modelProperties, interpolatorProperties, domainModel);
|
||||
|
||||
return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
}
|
||||
|
||||
public static Model interpolateModel(Model model, List<InterpolatorProperty> interpolatorProperties, File projectDirectory)
|
||||
throws IOException
|
||||
{
|
||||
String pomXml = interpolateModelAsString( model, interpolatorProperties, projectDirectory );
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( new ByteArrayInputStream( pomXml.getBytes() ));
|
||||
return domainModel.getModel();
|
||||
}
|
||||
|
||||
private static void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
PomClassicDomainModel domainModel)
|
||||
{
|
||||
Map<String, String> aliases = new HashMap<String, String>();
|
||||
aliases.put( "project.", "pom.");
|
||||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips.addAll(ModelTransformerContext.createInterpolatorProperties(modelProperties, ProjectUri.baseUri, aliases,
|
||||
false, false));
|
||||
|
||||
if(domainModel.isPomInBuild())
|
||||
{
|
||||
ips.add(new InterpolatorProperty("${project.basedir}", domainModel.getProjectDirectory().getAbsolutePath()));
|
||||
ips.add(new InterpolatorProperty("${basedir}", domainModel.getProjectDirectory().getAbsolutePath()));
|
||||
ips.add(new InterpolatorProperty("${pom.basedir}", domainModel.getProjectDirectory().getAbsolutePath()));
|
||||
|
||||
}
|
||||
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(mp.getUri().startsWith(ProjectUri.properties) && mp.getValue() != null )
|
||||
{
|
||||
String uri = mp.getUri();
|
||||
ips.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1,
|
||||
uri.length() ) + "}", mp.getValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips );
|
||||
}
|
||||
|
||||
private static boolean hasExecutionId( ModelContainer executionContainer )
|
||||
{
|
||||
for ( ModelProperty mp : executionContainer.getProperties() )
|
||||
|
@ -596,7 +660,7 @@ public final class PomClassicTransformer
|
|||
if ( mp.getUri().startsWith( ProjectUri.DependencyManagement.xUri ) )
|
||||
{
|
||||
transformedProperties.add( new ModelProperty(
|
||||
mp.getUri().replace( ProjectUri.DependencyManagement.xUri, ProjectUri.xUri ), mp.getValue() ) );
|
||||
mp.getUri().replace( ProjectUri.DependencyManagement.xUri, ProjectUri.xUri ), mp.getResolvedValue() ) );
|
||||
}
|
||||
}
|
||||
return transformedProperties;
|
||||
|
@ -611,7 +675,7 @@ public final class PomClassicTransformer
|
|||
{
|
||||
transformedProperties.add( new ModelProperty(
|
||||
mp.getUri().replace( ProjectUri.Build.PluginManagement.xUri, ProjectUri.Build.xUri ),
|
||||
mp.getValue() ) );
|
||||
mp.getResolvedValue() ) );
|
||||
}
|
||||
}
|
||||
return transformedProperties;
|
||||
|
|
|
@ -139,6 +139,8 @@ public final class DefaultProjectBuilder
|
|||
}
|
||||
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
|
||||
domainModel.setProjectDirectory( projectDirectory );
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
domainModels.add( domainModel );
|
||||
|
||||
|
@ -160,9 +162,6 @@ public final class DefaultProjectBuilder
|
|||
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
||||
parentFile = dm.getFile();
|
||||
domainModel.setParentFile( parentFile );
|
||||
// mavenParent = buildFromLocalPath( dm.getInputStream(), inheritedModels,
|
||||
// importModels, interpolatorProperties, resolver, projectDirectory);
|
||||
// mavenParent.setFile(dm.getFile());
|
||||
}
|
||||
|
||||
domainModels.addAll( mavenParents );
|
||||
|
@ -182,7 +181,6 @@ public final class DefaultProjectBuilder
|
|||
transformer,
|
||||
importModels,
|
||||
properties ) );
|
||||
// System.out.println(transformedDomainModel.asString());
|
||||
try
|
||||
{
|
||||
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
||||
|
@ -305,6 +303,8 @@ public final class DefaultProjectBuilder
|
|||
}
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
|
||||
parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
|
||||
{
|
||||
logger.warn( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() +
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.apache.maven.project.interpolation;
|
||||
|
||||
import org.codehaus.plexus.interpolation.ValueSource;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class BuildTimestampValueSource
|
||||
implements ValueSource
|
||||
{
|
||||
|
||||
private String formattedDate;
|
||||
|
||||
public BuildTimestampValueSource( Date startTime, String format )
|
||||
{
|
||||
if ( startTime != null )
|
||||
{
|
||||
formattedDate = new SimpleDateFormat( format ).format( startTime );
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValue( String expression )
|
||||
{
|
||||
if ( "build.timestamp".equals( expression ) || "maven.build.timestamp".equals( expression ) )
|
||||
{
|
||||
return formattedDate;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
* <p/>
|
||||
* Created on Feb 2, 2005
|
||||
*/
|
||||
public interface ModelInterpolator
|
||||
{
|
||||
String DEFAULT_BUILD_TIMESTAMP_FORMAT = "yyyyMMdd-hhmm";
|
||||
|
||||
String BUILD_TIMESTAMP_FORMAT_PROPERTY = "maven.build.timestamp.format";
|
||||
|
||||
String ROLE = ModelInterpolator.class.getName();
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Model interpolate( Model project, Map<String, ?> context )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
Model interpolate( Model model, Map<String, ?> context, boolean strict )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
String interpolate( String src, Model model, File projectDir, ProjectBuilderConfiguration config,
|
||||
boolean debugEnabled )
|
||||
throws ModelInterpolationException;
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version $Id: PathTranslatingPostProcessor.java 677447 2008-07-16 22:15:57Z jdcasey $
|
||||
*/
|
||||
public class PathTranslatingPostProcessor
|
||||
implements InterpolationPostProcessor
|
||||
{
|
||||
|
||||
private final List unprefixedPathKeys;
|
||||
|
||||
private final File projectDir;
|
||||
|
||||
private final PathTranslator pathTranslator;
|
||||
|
||||
public PathTranslatingPostProcessor( List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
|
||||
{
|
||||
this.unprefixedPathKeys = unprefixedPathKeys;
|
||||
this.projectDir = projectDir;
|
||||
this.pathTranslator = pathTranslator;
|
||||
}
|
||||
|
||||
public Object execute( String expression, Object value )
|
||||
{
|
||||
if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) )
|
||||
{
|
||||
return pathTranslator.alignToBaseDirectory( String.valueOf( value ), projectDir );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,294 +0,0 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.MapBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
|
||||
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
|
||||
import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper;
|
||||
import org.codehaus.plexus.interpolation.RecursionInterceptor;
|
||||
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
|
||||
import org.codehaus.plexus.interpolation.ValueSource;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Use a regular expression search to find and resolve expressions within the POM.
|
||||
*
|
||||
* @author jdcasey Created on Feb 3, 2005
|
||||
* @version $Id$
|
||||
* @todo Consolidate this logic with the PluginParameterExpressionEvaluator, minus deprecations/bans.
|
||||
*/
|
||||
public class RegexBasedModelInterpolator
|
||||
extends AbstractLogEnabled
|
||||
implements ModelInterpolator
|
||||
{
|
||||
|
||||
private static final List<String> PROJECT_PREFIXES = Arrays.asList( new String[]{"pom.", "project."} );
|
||||
|
||||
private static final List<String> TRANSLATED_PATH_EXPRESSIONS;
|
||||
|
||||
static
|
||||
{
|
||||
List<String> translatedPrefixes = new ArrayList<String>();
|
||||
|
||||
// MNG-1927, MNG-2124, MNG-3355:
|
||||
// If the build section is present and the project directory is non-null, we should make
|
||||
// sure interpolation of the directories below uses translated paths.
|
||||
// Afterward, we'll double back and translate any paths that weren't covered during interpolation via the
|
||||
// code below...
|
||||
translatedPrefixes.add( "build.directory" );
|
||||
translatedPrefixes.add( "build.outputDirectory" );
|
||||
translatedPrefixes.add( "build.testOutputDirectory" );
|
||||
translatedPrefixes.add( "build.sourceDirectory" );
|
||||
translatedPrefixes.add( "build.testSourceDirectory" );
|
||||
|
||||
TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes;
|
||||
}
|
||||
|
||||
private PathTranslator pathTranslator;
|
||||
|
||||
public RegexBasedModelInterpolator()
|
||||
throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
// for testing.
|
||||
protected RegexBasedModelInterpolator( PathTranslator pathTranslator )
|
||||
{
|
||||
this.pathTranslator = pathTranslator;
|
||||
}
|
||||
|
||||
public Model interpolate( Model model, Map<String, ?> context )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
Properties props = new Properties();
|
||||
props.putAll( context );
|
||||
|
||||
return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
|
||||
true );
|
||||
}
|
||||
|
||||
public Model interpolate( Model model, Map<String, ?> context, boolean strict )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
Properties props = new Properties();
|
||||
props.putAll( context );
|
||||
|
||||
return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
|
||||
true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the inbound Model instance to a StringWriter, perform the regex replacement to resolve
|
||||
* POM expressions, then re-parse into the resolved Model instance.
|
||||
* <br/>
|
||||
* <b>NOTE:</b> This will result in a different instance of Model being returned!!!
|
||||
*
|
||||
* @param model The inbound Model instance, to serialize and reference for expression resolution
|
||||
* @param context The other context map to be used during resolution
|
||||
* @param overrideContext The context map which should be used to OVERRIDE
|
||||
* values from everything else. This will come from the CLI
|
||||
* or userProperties in the execution request.
|
||||
* @param projectDir The directory from which the current model's pom was read.
|
||||
* @param strict This parameter is ignored!
|
||||
* @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
|
||||
* @return The resolved instance of the inbound Model. This is a different instance!
|
||||
*/
|
||||
public Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugMessages )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
try
|
||||
{
|
||||
writer.write( sWriter, model );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ModelInterpolationException( "Cannot serialize project model for interpolation.", e );
|
||||
}
|
||||
|
||||
String serializedModel = sWriter.toString();
|
||||
serializedModel = interpolate( serializedModel, model, projectDir, config, debugMessages );
|
||||
|
||||
StringReader sReader = new StringReader( serializedModel );
|
||||
|
||||
MavenXpp3Reader modelReader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = modelReader.read( sReader );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ModelInterpolationException(
|
||||
"Cannot read project model from interpolating filter of serialized version.", e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new ModelInterpolationException(
|
||||
"Cannot read project model from interpolating filter of serialized version.", e );
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates all expressions in the src parameter.
|
||||
* <p/>
|
||||
* The algorithm used for each expression is:
|
||||
* <ul>
|
||||
* <li>If it starts with either "pom." or "project.", the expression is evaluated against the model.</li>
|
||||
* <li>If the value is null, get the value from the context.</li>
|
||||
* <li>If the value is null, but the context contains the expression, don't replace the expression string
|
||||
* with the value, and continue to find other expressions.</li>
|
||||
* <li>If the value is null, get it from the model properties.</li>
|
||||
* <li>
|
||||
*
|
||||
* @param overrideContext
|
||||
* @param debugMessages
|
||||
*/
|
||||
public String interpolate( String src, Model model, final File projectDir, ProjectBuilderConfiguration config,
|
||||
boolean debugMessages )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
Logger logger = getLogger();
|
||||
|
||||
String timestampFormat = DEFAULT_BUILD_TIMESTAMP_FORMAT;
|
||||
|
||||
Properties modelProperties = model.getProperties();
|
||||
if ( modelProperties != null )
|
||||
{
|
||||
timestampFormat = modelProperties.getProperty( BUILD_TIMESTAMP_FORMAT_PROPERTY, timestampFormat );
|
||||
}
|
||||
|
||||
ValueSource modelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
|
||||
ValueSource modelValueSource2 = new ObjectBasedValueSource( model );
|
||||
|
||||
ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource()
|
||||
{
|
||||
public Object getValue( String expression )
|
||||
{
|
||||
if ( projectDir != null && "basedir".equals( expression ) )
|
||||
{
|
||||
return projectDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, PROJECT_PREFIXES, true );
|
||||
|
||||
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
|
||||
|
||||
// NOTE: Order counts here!
|
||||
interpolator.addValueSource( basedirValueSource );
|
||||
interpolator.addValueSource( new BuildTimestampValueSource( config.getBuildStartTime(), timestampFormat ) );
|
||||
interpolator.addValueSource( new MapBasedValueSource( config.getExecutionProperties() ) );
|
||||
interpolator.addValueSource( modelValueSource1 );
|
||||
interpolator.addValueSource(
|
||||
new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
|
||||
interpolator.addValueSource( modelValueSource2 );
|
||||
interpolator.addValueSource( new MapBasedValueSource( config.getUserProperties() ) );
|
||||
|
||||
PathTranslatingPostProcessor pathTranslatingPostProcessor =
|
||||
new PathTranslatingPostProcessor( TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator );
|
||||
|
||||
interpolator.addPostProcessor( pathTranslatingPostProcessor );
|
||||
|
||||
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
|
||||
|
||||
String result = src;
|
||||
try
|
||||
{
|
||||
result = interpolator.interpolate( result, "", recursionInterceptor );
|
||||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
throw new ModelInterpolationException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( debugMessages )
|
||||
{
|
||||
List<?> feedback = interpolator.getFeedback();
|
||||
if ( feedback != null && !feedback.isEmpty() )
|
||||
{
|
||||
logger.debug( "Maven encountered the following problems during initial POM interpolation:" );
|
||||
|
||||
Object last = null;
|
||||
for ( Iterator<?> it = feedback.iterator(); it.hasNext(); )
|
||||
{
|
||||
Object next = it.next();
|
||||
|
||||
if ( next instanceof Throwable )
|
||||
{
|
||||
if ( last == null )
|
||||
{
|
||||
logger.debug( "", ( (Throwable) next ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug( String.valueOf( last ), ( (Throwable) next ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( last != null )
|
||||
{
|
||||
logger.debug( String.valueOf( last ) );
|
||||
}
|
||||
|
||||
last = next;
|
||||
}
|
||||
}
|
||||
|
||||
if ( last != null )
|
||||
{
|
||||
logger.debug( String.valueOf( last ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interpolator.clearFeedback();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -50,20 +50,6 @@ under the License.
|
|||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<!--
|
||||
|
|
||||
|
|
||||
|
|
||||
-->
|
||||
<component>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
<implementation>org.apache.maven.project.interpolation.RegexBasedModelInterpolator</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
<!--
|
||||
|
|
||||
|
@ -118,9 +104,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -55,7 +55,7 @@ under the License.
|
|||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
|
||||
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
|
|
|
@ -1,385 +0,0 @@
|
|||
package org.apache.maven.project.interpolation;
|
||||
|
||||
/*
|
||||
* 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 org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.DistributionManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Organization;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.model.Scm;
|
||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.path.DefaultPathTranslator;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RegexBasedModelInterpolatorTest
|
||||
extends TestCase
|
||||
{
|
||||
private Map context;
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
context = Collections.singletonMap( "basedir", "myBasedir" );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateProjectDotBasedirInDistributionManagement()
|
||||
throws ModelInterpolationException, IOException
|
||||
{
|
||||
Model model = new Model();
|
||||
DistributionManagement dm = new DistributionManagement();
|
||||
DeploymentRepository repo = new DeploymentRepository();
|
||||
|
||||
// from IT0062...
|
||||
repo.setUrl( "http://localhost/${project.basedir}/target/test-repo" );
|
||||
|
||||
dm.setRepository( repo );
|
||||
model.setDistributionManagement( dm );
|
||||
|
||||
String path = "path/to/project";
|
||||
|
||||
File basedir = new File( path ).getAbsoluteFile();
|
||||
|
||||
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model,
|
||||
basedir,
|
||||
config,
|
||||
false );
|
||||
|
||||
assertEquals( "http://localhost/" + basedir.getAbsolutePath() + "/target/test-repo",
|
||||
out.getDistributionManagement().getRepository().getUrl() );
|
||||
}
|
||||
|
||||
public void testShouldNotThrowExceptionOnReferenceToNonExistentValue()
|
||||
throws IOException, ModelInterpolationException
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
Scm scm = new Scm();
|
||||
scm.setConnection( "${test}/somepath" );
|
||||
|
||||
model.setScm( scm );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "${test}/somepath", out.getScm().getConnection() );
|
||||
}
|
||||
|
||||
public void testShouldThrowExceptionOnRecursiveScmConnectionReference()
|
||||
throws IOException
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
Scm scm = new Scm();
|
||||
scm.setConnection( "${project.scm.connection}/somepath" );
|
||||
|
||||
model.setScm( scm );
|
||||
|
||||
try
|
||||
{
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
fail( "The interpolator should not allow self-referencing expressions in POM." );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression()
|
||||
throws IOException, ModelInterpolationException
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
Scm scm = new Scm();
|
||||
scm.setConnection( "${test}/somepath" );
|
||||
|
||||
model.setScm( scm );
|
||||
|
||||
model.addProperty( "test", "test" );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "test/somepath", out.getScm().getConnection() );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateOrganizationNameCorrectly()
|
||||
throws Exception
|
||||
{
|
||||
String orgName = "MyCo";
|
||||
|
||||
Model model = new Model();
|
||||
model.setName( "${pom.organization.name} Tools" );
|
||||
|
||||
Organization org = new Organization();
|
||||
org.setName( orgName );
|
||||
|
||||
model.setOrganization( org );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( orgName + " Tools", out.getName() );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setVersion( "3.8.1" );
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setVersion( "${version}" );
|
||||
|
||||
Dependency dep2 = new Dependency();
|
||||
dep2.setVersion( "${pom.version}" );
|
||||
|
||||
model.addDependency( dep );
|
||||
model.addDependency( dep2 );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "3.8.1", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion() );
|
||||
assertEquals( "3.8.1", ( (Dependency) out.getDependencies().get( 1 ) ).getVersion() );
|
||||
}
|
||||
|
||||
public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setVersion( "3.8.1" );
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setVersion( "${something}" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
/*
|
||||
// This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the
|
||||
// timing of executing the interpolation
|
||||
|
||||
try
|
||||
{
|
||||
new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
fail( "Should have failed to interpolate with invalid reference" );
|
||||
}
|
||||
catch ( ModelInterpolationException expected )
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
*/
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "${something}", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion() );
|
||||
}
|
||||
|
||||
public void testTwoReferences()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setVersion( "3.8.1" );
|
||||
model.setArtifactId( "foo" );
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
dep.setVersion( "${artifactId}-${version}" );
|
||||
|
||||
Dependency dep2 = new Dependency();
|
||||
dep2.setVersion( "${pom.artifactId}-${pom.version}" );
|
||||
|
||||
model.addDependency( dep );
|
||||
model.addDependency( dep2 );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "foo-3.8.1", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion() );
|
||||
assertEquals( "foo-3.8.1", ( (Dependency) out.getDependencies().get( 1 ) ).getVersion() );
|
||||
}
|
||||
|
||||
public void testBasedir()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setVersion( "3.8.1" );
|
||||
model.setArtifactId( "foo" );
|
||||
|
||||
Repository repository = new Repository();
|
||||
|
||||
repository.setUrl( "file://localhost/${basedir}/temp-repo" );
|
||||
|
||||
model.addRepository( repository );
|
||||
|
||||
assertNotNull( context.get( "basedir" ) );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( "file://localhost/myBasedir/temp-repo", ( (Repository) out.getRepositories().get( 0 ) ).getUrl() );
|
||||
}
|
||||
|
||||
public void testExpressionThatEvaluatesToNullReturnsTheLiteralString()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
Properties modelProperties = new Properties();
|
||||
|
||||
modelProperties.setProperty( "outputDirectory", "${DOES_NOT_EXIST}" );
|
||||
|
||||
model.setProperties( modelProperties );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
|
||||
}
|
||||
|
||||
public void testPOMExpressionDoesNotUseSystemProperty()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setVersion( "1.0" );
|
||||
|
||||
Properties modelProperties = new Properties();
|
||||
modelProperties.setProperty( "version", "prop version" );
|
||||
modelProperties.setProperty( "foo.version", "prop foo.version" );
|
||||
modelProperties.setProperty( "pom.version", "prop pom.version" );
|
||||
modelProperties.setProperty( "project.version", "prop project.version" );
|
||||
|
||||
model.setProperties( modelProperties );
|
||||
|
||||
Dependency dep = new Dependency();
|
||||
model.addDependency( dep );
|
||||
|
||||
checkDep( "prop version", "${version}", model );
|
||||
checkDep( "1.0", "${pom.version}", model );
|
||||
checkDep( "1.0", "${project.version}", model );
|
||||
checkDep( "prop foo.version", "${foo.version}", model );
|
||||
}
|
||||
|
||||
private void checkDep( String expectedVersion, String depVersionExpr, Model model )
|
||||
throws Exception
|
||||
{
|
||||
( (Dependency) model.getDependencies().get( 0 ) ).setVersion( depVersionExpr );
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
String result = ( (Dependency) out.getDependencies().get( 0 ) ).getVersion();
|
||||
assertEquals( "Expected '" + expectedVersion + "' for version expression '" + depVersionExpr + "', but was '" + result + "'", expectedVersion, result );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
|
||||
Build build = new Build();
|
||||
build.setSourceDirectory( "correct" );
|
||||
|
||||
Resource res = new Resource();
|
||||
res.setDirectory( "${project.build.sourceDirectory}" );
|
||||
|
||||
build.addResource( res );
|
||||
|
||||
Resource res2 = new Resource();
|
||||
res2.setDirectory( "${pom.build.sourceDirectory}" );
|
||||
|
||||
build.addResource( res2 );
|
||||
|
||||
Resource res3 = new Resource();
|
||||
res3.setDirectory( "${build.sourceDirectory}" );
|
||||
|
||||
build.addResource( res3 );
|
||||
|
||||
model.setBuild( build );
|
||||
|
||||
Model out = new RegexBasedModelInterpolator().interpolate( model, context );
|
||||
|
||||
List outResources = out.getBuild().getResources();
|
||||
Iterator resIt = outResources.iterator();
|
||||
|
||||
assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() );
|
||||
assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() );
|
||||
assertEquals( build.getSourceDirectory(), ( (Resource) resIt.next() ).getDirectory() );
|
||||
}
|
||||
|
||||
public void testShouldInterpolateUnprefixedBasedirExpression()
|
||||
throws ModelInterpolationException, IOException
|
||||
{
|
||||
File basedir = new File( "/test/path" );
|
||||
Model model = new Model();
|
||||
Dependency dep = new Dependency();
|
||||
dep.setSystemPath( "${basedir}/artifact.jar" );
|
||||
|
||||
model.addDependency( dep );
|
||||
|
||||
Model result = new RegexBasedModelInterpolator().interpolate( model, basedir, new DefaultProjectBuilderConfiguration(), true );
|
||||
|
||||
List rDeps = result.getDependencies();
|
||||
assertNotNull( rDeps );
|
||||
assertEquals( 1, rDeps.size() );
|
||||
assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(), new File( ( (Dependency) rDeps.get( 0 ) )
|
||||
.getSystemPath() ).getAbsolutePath() );
|
||||
}
|
||||
|
||||
public void testTwoLevelRecursiveBasedirAlignedExpression()
|
||||
throws Exception
|
||||
{
|
||||
Model model = new Model();
|
||||
Build build = new Build();
|
||||
|
||||
model.setBuild( build );
|
||||
|
||||
build.setDirectory( "${project.basedir}/target" );
|
||||
build.setOutputDirectory( "${project.build.directory}/classes" );
|
||||
|
||||
PathTranslator translator = new DefaultPathTranslator();
|
||||
RegexBasedModelInterpolator interpolator = new RegexBasedModelInterpolator( translator );
|
||||
|
||||
File basedir = new File( System.getProperty( "java.io.tmpdir" ), "base" );
|
||||
|
||||
String value = interpolator.interpolate( "${project.build.outputDirectory}/foo", model, basedir, new DefaultProjectBuilderConfiguration(), true );
|
||||
value = value.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
|
||||
|
||||
String check = new File( basedir, "target/classes/foo" ).getAbsolutePath();
|
||||
check = check.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
|
||||
|
||||
assertEquals( check, value );
|
||||
}
|
||||
|
||||
}
|
|
@ -133,9 +133,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -130,9 +130,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.interpolation.ModelInterpolator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.apache.maven.shared.model;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -34,6 +36,7 @@ public final class InterpolatorProperty
|
|||
*/
|
||||
private final String value;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -112,4 +115,24 @@ public final class InterpolatorProperty
|
|||
return key.hashCode();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Key = " + key + ", Value = " + value + ", Hash = " +
|
||||
this.hashCode();
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> toInterpolatorProperties( Properties properties )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "properties: null" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<Object, Object> e : properties.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty( (String) e.getKey(), (String) e.getValue()) );
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ public final class ModelMarshaller
|
|||
continue;
|
||||
}
|
||||
|
||||
//String val = (mp.getValue() != null) ? "\"" + mp.getValue() + "\"" : null;
|
||||
//String val = (mp.getResolvedValue() != null) ? "\"" + mp.getResolvedValue() + "\"" : null;
|
||||
// System.out.println("new ModelProperty(\"" + mp.getUri() +"\" , " + val +"),");
|
||||
if ( !uri.startsWith( baseUri ) )
|
||||
{
|
||||
|
@ -346,7 +346,7 @@ public final class ModelMarshaller
|
|||
{
|
||||
sb.append( " " ).append(
|
||||
attribute.getUri().substring( attribute.getUri().indexOf( "#property/" ) + 10 ) ).append( "=\"" )
|
||||
.append( attribute.getValue() ).append( "\" " );
|
||||
.append( attribute.getResolvedValue() ).append( "\" " );
|
||||
}
|
||||
}
|
||||
sb.append( ">" );
|
||||
|
|
|
@ -49,7 +49,8 @@ public interface ModelTransformer
|
|||
* @param domainModels list of domain models to transform to a list of model properties. List may not be null.
|
||||
* @return list of model properties
|
||||
*/
|
||||
List<ModelProperty> transformToModelProperties( List<DomainModel> domainModels )
|
||||
List<ModelProperty> transformToModelProperties( List<DomainModel> domainModels,
|
||||
List<InterpolatorProperty> interpolatorProperties)
|
||||
throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ public final class ModelTransformerContext
|
|||
private final static List<InterpolatorProperty> systemInterpolatorProperties =
|
||||
new ArrayList<InterpolatorProperty>();
|
||||
|
||||
private final static List<InterpolatorProperty> environmentInterpolatorProperties =
|
||||
new ArrayList<InterpolatorProperty>();
|
||||
|
||||
static
|
||||
{
|
||||
for ( Map.Entry<Object, Object> e : System.getProperties().entrySet() )
|
||||
|
@ -51,7 +54,7 @@ public final class ModelTransformerContext
|
|||
|
||||
for ( Map.Entry<String, String> e : System.getenv().entrySet() )
|
||||
{
|
||||
systemInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) );
|
||||
environmentInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +75,84 @@ public final class ModelTransformerContext
|
|||
}
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
|
||||
String baseUriForModel,
|
||||
Map<String, String> aliases,
|
||||
boolean includeSystemProperties,
|
||||
boolean includeEnvironmentProperties)
|
||||
{
|
||||
if(modelProperties == null)
|
||||
{
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if(baseUriForModel == null)
|
||||
{
|
||||
throw new IllegalArgumentException( "baseUriForModel: null");
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties
|
||||
= new ArrayList<InterpolatorProperty>( );
|
||||
|
||||
if( includeSystemProperties )
|
||||
{
|
||||
interpolatorProperties.addAll( systemInterpolatorProperties );
|
||||
}
|
||||
|
||||
if( includeEnvironmentProperties )
|
||||
{
|
||||
interpolatorProperties.addAll( environmentInterpolatorProperties );
|
||||
}
|
||||
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel );
|
||||
if ( ip != null )
|
||||
{
|
||||
interpolatorProperties.add( ip );
|
||||
for ( Map.Entry<String, String> a : aliases.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty(
|
||||
ip.getKey().replaceAll( a.getKey(), a.getValue()),
|
||||
ip.getValue().replaceAll( a.getKey(), a.getValue()) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
|
||||
public static void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( !mp.isResolved() )
|
||||
{
|
||||
unresolvedProperties.add( mp );
|
||||
}
|
||||
}
|
||||
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
{
|
||||
for ( ModelProperty mp : unresolvedProperties )
|
||||
{
|
||||
mp.resolveWith(ip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
{
|
||||
for ( ModelProperty mp : unresolvedProperties )
|
||||
{
|
||||
mp.resolveWith(ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transforms the specified model properties using the specified transformers.
|
||||
*
|
||||
|
@ -115,13 +196,12 @@ public final class ModelTransformerContext
|
|||
*/
|
||||
public DomainModel transform(List<DomainModel> domainModels, ModelTransformer fromModelTransformer,
|
||||
ModelTransformer toModelTransformer,
|
||||
Collection<ImportModel> importModels, Collection<InterpolatorProperty> interpolatorProperties)
|
||||
Collection<ImportModel> importModels, List<InterpolatorProperty> interpolatorProperties)
|
||||
throws IOException
|
||||
{
|
||||
List<InterpolatorProperty> properties = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
|
||||
List<ModelProperty> transformedProperties =
|
||||
importModelProperties(importModels, fromModelTransformer.transformToModelProperties( domainModels ));
|
||||
importModelProperties(importModels, fromModelTransformer.transformToModelProperties( domainModels, interpolatorProperties ));
|
||||
|
||||
String baseUriForModel = fromModelTransformer.getBaseUri();
|
||||
List<ModelProperty> modelProperties =
|
||||
|
@ -183,38 +263,9 @@ public final class ModelTransformerContext
|
|||
}
|
||||
}
|
||||
|
||||
//interpolator
|
||||
|
||||
List<ModelProperty> mps = modelDataSource.getModelProperties();
|
||||
|
||||
for ( ModelProperty mp : mps )
|
||||
{
|
||||
InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel );
|
||||
if ( ip != null )
|
||||
{
|
||||
properties.add( ip );
|
||||
}
|
||||
}
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for ( ModelProperty mp : mps )
|
||||
{
|
||||
if ( !mp.isResolved() )
|
||||
{
|
||||
unresolvedProperties.add( mp );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for ( InterpolatorProperty ip : properties )
|
||||
{
|
||||
for ( ModelProperty mp : unresolvedProperties )
|
||||
{
|
||||
mp.resolveWith(ip);
|
||||
System.out.println(mp);
|
||||
System.out.println("-------------------");
|
||||
}
|
||||
}
|
||||
*/
|
||||
//interpolateModelProperties( mps, baseUriForModel );
|
||||
mps = sort( mps, baseUriForModel );
|
||||
|
||||
try
|
||||
|
@ -254,7 +305,7 @@ public final class ModelTransformerContext
|
|||
for(ModelProperty mp: modelProperties) {
|
||||
if(mp.getUri().endsWith("importModel")) {
|
||||
for(ImportModel im : importModels) {
|
||||
if(im.getId().equals(mp.getValue())) {
|
||||
if(im.getId().equals(mp.getResolvedValue())) {
|
||||
properties.addAll(im.getModelProperties());
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +373,7 @@ public final class ModelTransformerContext
|
|||
List<ModelProperty> mps = new ArrayList<ModelProperty>();
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(mp.getValue() != null && mp.getValue().trim().equals("") && isLeafNode( mp, modelProperties) )
|
||||
if(mp.getResolvedValue() != null && mp.getResolvedValue().trim().equals("") && isLeafNode( mp, modelProperties) )
|
||||
{
|
||||
mps.add( new ModelProperty(mp.getUri(), null) );
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ public final class DefaultModelDataSource
|
|||
for ( ModelProperty mp : m )
|
||||
{
|
||||
String x = mp.getUri();
|
||||
if ( x.endsWith( "#property/combine.children" ) && mp.getValue().equals( "append" ) )
|
||||
if ( x.endsWith( "#property/combine.children" ) && mp.getResolvedValue().equals( "append" ) )
|
||||
{
|
||||
combineChildrenUris.add( x.substring( 0, x.length() - 26 ) );
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class ModelMarshallerTest
|
|||
assertEquals( 2, modelProperties.size() );
|
||||
assertEquals( "http://apache.org/maven/project", modelProperties.get( 0 ).getUri() );
|
||||
assertEquals( "http://apache.org/maven/project/version", modelProperties.get( 1 ).getUri() );
|
||||
assertEquals( "1.1", modelProperties.get( 1 ).getValue() );
|
||||
assertEquals( "1.1", modelProperties.get( 1 ).getResolvedValue() );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue