Tests for MNG-1943 - interpolation in parent pom and MNG-3567 - pluginManagement inherited. Added additional methods to maven embedder for querying of plugin configs.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@740395 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-02-03 19:50:11 +00:00
parent d1124333ad
commit adfb3ddeb9
15 changed files with 260 additions and 15 deletions

View File

@ -59,6 +59,10 @@
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</dependency>
</dependencies>
<build>
<resources>

View File

@ -91,6 +91,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
@ -258,6 +259,24 @@ public class MavenEmbedder
}
}
public Object getPluginConfigurationAsDom(String pluginId, String mojoId, Model model) throws Exception
{
try {
return mixer.mixPluginAndReturnConfigAsDom(pluginRepository.findPluginById(pluginId, mojoId), model);
} catch (PlexusConfigurationException e) {
throw new IOException(e.getMessage());
}
}
public Object getPluginConfigurationAsDom(String pluginId, String mojoId, Model model, String xpathExpression) throws Exception
{
try {
return mixer.mixPluginAndReturnConfigAsDom(pluginRepository.findPluginById(pluginId, mojoId), model, xpathExpression);
} catch (PlexusConfigurationException e) {
throw new IOException(e.getMessage());
}
}
// ----------------------------------------------------------------------
// Settings
// ----------------------------------------------------------------------

View File

@ -71,8 +71,6 @@ under the License.
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -120,6 +120,16 @@ public class DefaultMavenProjectBuilder
public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config )
throws ProjectBuildingException
{
if(projectDescriptor == null)
{
throw new IllegalArgumentException("projectDescriptor: null");
}
if(config == null)
{
throw new IllegalArgumentException("config: null");
}
List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>( );
artifactRepositories.addAll( mavenTools.buildArtifactRepositories( projectBuilder.getSuperModel() ) );
if(config.getRemoteRepositories() != null)
@ -398,7 +408,8 @@ public class DefaultMavenProjectBuilder
null,
interpolatorProperties,
resolver,
config );
config,
this);
}
catch ( IOException e )
{

View File

@ -194,12 +194,41 @@ public class MavenProject
public MavenProject( Model model )
{
if(model == null)
{
throw new IllegalArgumentException("model: null");
}
setModel( model );
}
/**
* Constructor
*
* @param model - may not be null
* @param artifactFactory - may not be null
* @param mavenTools - may not be null
* @param mavenProjectBuilder
* @param projectBuilderConfiguration
* @throws InvalidRepositoryException
*/
public MavenProject( Model model, ArtifactFactory artifactFactory, MavenTools mavenTools, MavenProjectBuilder mavenProjectBuilder, ProjectBuilderConfiguration projectBuilderConfiguration )
throws InvalidRepositoryException
{
if(model == null)
{
throw new IllegalArgumentException("model: null");
}
if(artifactFactory == null)
{
throw new IllegalArgumentException("artifactFactory: null");
}
if(mavenTools == null)
{
throw new IllegalArgumentException("mavenTools: null");
}
setModel( model );
this.mavenProjectBuilder = mavenProjectBuilder;
this.projectBuilderConfiguration = projectBuilderConfiguration;
@ -330,7 +359,17 @@ public class MavenProject
public MavenProject getParent()
{
if ( parent == null )
{ /*
if(mavenProjectBuilder == null)
{
throw new IllegalArgumentException("mavenProjectBuilder: null");
}
if(projectBuilderConfiguration == null)
{
throw new IllegalArgumentException("projectBuilderConfiguration: null");
}
*/
if ( parentFile != null )
{
try

View File

@ -4,6 +4,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Model;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
@ -14,4 +15,10 @@ public interface Mixer
Model mixPlugin(Plugin plugin, Model model) throws IOException;
PlexusConfiguration mixPluginAndReturnConfig(Plugin plugin, Model model) throws IOException;
Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model) throws IOException,
XmlPullParserException;
Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model, String xpathExpression) throws IOException,
XmlPullParserException;
}

View File

@ -27,6 +27,7 @@ import java.util.List;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.model.InterpolatorProperty;
/**
@ -54,7 +55,8 @@ public interface ProjectBuilder
List<Model> mixins,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver,
ProjectBuilderConfiguration projectBuilderConfiguration )
ProjectBuilderConfiguration projectBuilderConfiguration,
MavenProjectBuilder mavenProjectBuilder)
throws IOException;
Model getSuperModel();

View File

@ -22,6 +22,7 @@ package org.apache.maven.project.builder.impl;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -37,7 +38,9 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.*;
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import org.codehaus.plexus.component.annotations.Component;
@ -46,9 +49,12 @@ import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.commons.jxpath.JXPathContext;
/**
* Default implementation of the project builder.
@ -170,7 +176,8 @@ public class DefaultProjectBuilder
List<Model> mixins,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver,
ProjectBuilderConfiguration projectBuilderConfiguration )
ProjectBuilderConfiguration projectBuilderConfiguration,
MavenProjectBuilder mavenProjectBuilder)
throws IOException
{
PomClassicDomainModel domainModel = buildModel( pom,
@ -183,7 +190,7 @@ public class DefaultProjectBuilder
MavenProject mavenProject = new MavenProject( domainModel.getModel(),
artifactFactory,
mavenTools,
null,
mavenProjectBuilder,
projectBuilderConfiguration );
mavenProject.setParentFile( domainModel.getParentFile() );
@ -385,12 +392,35 @@ public class DefaultProjectBuilder
null,
listeners ) );
return transformedDomainModel.getModel();
// List<ModelProperty> pluginProperties = ModelMarshaller.marshallXmlToModelProperties(
// (new PluginMixin(plugin)).getInputStream(), ProjectUri.Build.Plugins.xUri, null);
}
public PlexusConfiguration mixPluginAndReturnConfig(Plugin plugin, Model model) throws IOException
{
List<ModelProperty> mps = mixPluginAndReturnConfigAsProperties(plugin, model);
return !mps.isEmpty() ?
new XmlPlexusConfiguration(ModelMarshaller.unmarshalModelPropertiesToXml(mps, ProjectUri.Build.Plugins.Plugin.xUri)) : null;
}
public Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model) throws IOException, XmlPullParserException
{
List<ModelProperty> mps = mixPluginAndReturnConfigAsProperties(plugin, model);
return !mps.isEmpty() ? Xpp3DomBuilder.build(
new StringReader(ModelMarshaller.unmarshalModelPropertiesToXml(mps, ProjectUri.Build.Plugins.Plugin.xUri) ) ) : null;
}
public Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model, String xpathExpression) throws IOException,
XmlPullParserException
{
Object dom = mixPluginAndReturnConfigAsDom(plugin, model);
if(dom == null)
{
return null;
}
return JXPathContext.newContext( dom ).getValue(xpathExpression);
}
private List<ModelProperty> mixPluginAndReturnConfigAsProperties(Plugin plugin, Model model) throws IOException
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
domainModels.add( new PluginMixin(plugin) );
@ -420,11 +450,11 @@ public class DefaultProjectBuilder
config.add(mp);
}
}
return new XmlPlexusConfiguration(ModelMarshaller.unmarshalModelPropertiesToXml(config, ProjectUri.Build.Plugins.Plugin.xUri));
return config;
}
}
return null;
return new ArrayList<ModelProperty>();
}
private static boolean matchesIdOfPlugin(ModelContainer mc, Plugin plugin)

View File

@ -31,7 +31,12 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
@ -49,6 +54,8 @@ public class PomConstructionTest
private ProjectBuilder projectBuilder;
private MavenProjectBuilder mavenProjectBuilder;
private Mixer mixer;
private MavenTools mavenTools;
@ -64,6 +71,7 @@ public class PomConstructionTest
{
testDirectory = new File( getBasedir(), BASE_POM_DIR );
testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR );
mavenProjectBuilder = lookup( MavenProjectBuilder.class );
projectBuilder = lookup( ProjectBuilder.class );
mixer = (Mixer) projectBuilder;
mavenTools = lookup( MavenTools.class );
@ -137,6 +145,24 @@ public class PomConstructionTest
}
*/
/* MNG-3567*/
public void testParentInterpolation()
throws Exception
{
PomTestWrapper pom = buildPomFromMavenProject( "parent-interpolation/sub" );
pom = new PomTestWrapper(pom.getMavenProject().getParent());
assertEquals( "1.3.0-SNAPSHOT", pom.getValue( "build/plugins[1]/version" ) );
}
/* MNG-3567*/
public void testPluginManagementInherited()
throws Exception
{
PomTestWrapper pom = buildPom( "pluginmanagement-inherited/sub" );
assertEquals( "1.0-alpha-21", pom.getValue( "build/plugins[1]/version" ) );
}
public void testPluginOrder()
throws Exception
{
@ -760,6 +786,20 @@ public class PomConstructionTest
return new PomTestWrapper( pomFile, projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
}
private PomTestWrapper buildPomFromMavenProject( String pomPath )
throws IOException
{
File pomFile = new File( testDirectory , pomPath );
if ( pomFile.isDirectory() )
{
pomFile = new File( pomFile, "pom.xml" );
}
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
config.setLocalRepository(new DefaultArtifactRepository("default", "", new DefaultRepositoryLayout()));
return new PomTestWrapper( pomFile, projectBuilder.buildFromLocalPath( pomFile, null, null, pomArtifactResolver,
config, mavenProjectBuilder ) );
}
private Model buildMixin( String mixinPath )
throws IOException, XmlPullParserException
{

View File

@ -30,6 +30,7 @@ import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
import org.apache.maven.model.Model;
import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.model.ModelProperty;
public class PomTestWrapper
@ -41,6 +42,8 @@ public class PomTestWrapper
private JXPathContext context;
private MavenProject mavenProject;
static
{
JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() );
@ -64,6 +67,29 @@ public class PomTestWrapper
context = JXPathContext.newContext( domainModel.getModel() );
}
public PomTestWrapper( File pomFile, MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{
throw new IllegalArgumentException( "mavenProject: null" );
}
this.mavenProject = mavenProject;
this.pomFile = pomFile;
context = JXPathContext.newContext( mavenProject.getModel() );
}
public PomTestWrapper( MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{
throw new IllegalArgumentException( "mavenProject: null" );
}
this.mavenProject = mavenProject;
context = JXPathContext.newContext( mavenProject.getModel() );
}
public PomTestWrapper( File file )
throws IOException
{
@ -88,6 +114,11 @@ public class PomTestWrapper
context = JXPathContext.newContext( domainModel.getModel() );
}
public MavenProject getMavenProject()
{
return mavenProject;
}
public PomClassicDomainModel getDomainModel()
{
return this.domainModel;

View File

@ -0,0 +1,15 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus</artifactId>
<version>1.3.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>${project.version}</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,9 @@
<project>
<parent>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus</artifactId>
<version>1.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>a</artifactId>
</project>

View File

@ -0,0 +1,17 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus</artifactId>
<version>1.3.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-21</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,17 @@
<project>
<parent>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus</artifactId>
<version>1.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>a</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -59,6 +59,7 @@ under the License.
<mercuryMp3Version>1.0-alpha-1</mercuryMp3Version>
<woodstoxVersion>3.2.6</woodstoxVersion>
<modelloVersion>1.0-alpha-22</modelloVersion>
<jxpathVersion>1.3</jxpathVersion>
</properties>
<issueManagement>
<system>jira</system>
@ -400,6 +401,11 @@ under the License.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>${jxpathVersion}</version>
</dependency>
<!-- Mercury -->
<dependency>