mirror of https://github.com/apache/maven.git
o Created UT from MNG-3821
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@728654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
edb695cff5
commit
3ce9917532
|
@ -14,20 +14,33 @@ import org.codehaus.plexus.PlexusTestCase;
|
||||||
public class PomConstructionTest
|
public class PomConstructionTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private static String BASE_POM_DIR = "src/test/resources-project-builder";
|
private static String BASE_POM_DIR = "src/test/resources-project-builder";
|
||||||
|
|
||||||
private ProjectBuilder projectBuilder;
|
private ProjectBuilder projectBuilder;
|
||||||
|
|
||||||
private MavenTools mavenTools;
|
private MavenTools mavenTools;
|
||||||
|
|
||||||
|
private PomArtifactResolver pomArtifactResolver;
|
||||||
|
|
||||||
private File testDirectory;
|
private File testDirectory;
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
testDirectory = new File( getBasedir(), BASE_POM_DIR );
|
testDirectory = new File( getBasedir(), BASE_POM_DIR );
|
||||||
projectBuilder = lookup( ProjectBuilder.class );
|
projectBuilder = lookup( ProjectBuilder.class );
|
||||||
mavenTools = lookup( MavenTools.class );
|
mavenTools = lookup( MavenTools.class );
|
||||||
|
pomArtifactResolver = new PomArtifactResolver()
|
||||||
|
{
|
||||||
|
|
||||||
|
public void resolve( Artifact artifact )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "Parent POM should be locally reachable " + artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some better conventions for the test poms needs to be created and each of these tests
|
// Some better conventions for the test poms needs to be created and each of these tests
|
||||||
|
@ -45,7 +58,7 @@ public class PomConstructionTest
|
||||||
assertEquals( 3, model.getLineageCount() );
|
assertEquals( 3, model.getLineageCount() );
|
||||||
PomTestWrapper pom = new PomTestWrapper( model );
|
PomTestWrapper pom = new PomTestWrapper( model );
|
||||||
assertModelEquals( pom, "maven-dependency-plugin", "build/plugins[4]/artifactId" );
|
assertModelEquals( pom, "maven-dependency-plugin", "build/plugins[4]/artifactId" );
|
||||||
List executions = (List) pom.getValue( "build/plugins[4]/executions" );
|
List<?> executions = (List<?>) pom.getValue( "build/plugins[4]/executions" );
|
||||||
assertEquals( 7, executions.size() );
|
assertEquals( 7, executions.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,16 +81,42 @@ public class PomConstructionTest
|
||||||
PomArtifactResolver resolver = artifactResolver( "single-test-poms" );
|
PomArtifactResolver resolver = artifactResolver( "single-test-poms" );
|
||||||
PomClassicDomainModel model = projectBuilder.buildModel( pomFile, null, resolver );
|
PomClassicDomainModel model = projectBuilder.buildModel( pomFile, null, resolver );
|
||||||
PomTestWrapper pom = new PomTestWrapper( model );
|
PomTestWrapper pom = new PomTestWrapper( model );
|
||||||
List dependencies = (List) pom.getValue( "build/plugins[1]/dependencies" );
|
List<?> dependencies = (List<?>) pom.getValue( "build/plugins[1]/dependencies" );
|
||||||
assertEquals( 1, dependencies.size() );
|
assertEquals( 1, dependencies.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME: cf. MNG-3821
|
||||||
|
public void testErroneousJoiningOfDifferentPluginsWithEqualExecutionIds()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
PomTestWrapper pom = buildPom( "equal-plugin-exec-ids" );
|
||||||
|
assertEquals( "maven-it-plugin-a", pom.getValue( "build/plugins[1]/artifactId" ) );
|
||||||
|
assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
|
||||||
|
assertEquals( "maven-it-plugin-b", pom.getValue( "build/plugins[2]/artifactId" ) );
|
||||||
|
assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
|
||||||
|
assertEquals( "maven-it-plugin-a", pom.getValue( "reporting/plugins[1]/artifactId" ) );
|
||||||
|
assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
|
||||||
|
assertEquals( "maven-it-plugin-b", pom.getValue( "reporting/plugins[2]/artifactId" ) );
|
||||||
|
assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private PomArtifactResolver artifactResolver( String basedir )
|
private PomArtifactResolver artifactResolver( String basedir )
|
||||||
{
|
{
|
||||||
PomArtifactResolver resolver = new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
|
return new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
|
||||||
return resolver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PomTestWrapper buildPom( String pomPath )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
File pomFile = new File( testDirectory, pomPath );
|
||||||
|
if ( pomFile.isDirectory() )
|
||||||
|
{
|
||||||
|
pomFile = new File( pomFile, "pom.xml" );
|
||||||
|
}
|
||||||
|
return new PomTestWrapper( projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression )
|
protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression )
|
||||||
{
|
{
|
||||||
assertEquals( expected, pom.getValue( expression ) );
|
assertEquals( expected, pom.getValue( expression ) );
|
||||||
|
@ -89,7 +128,7 @@ public class PomConstructionTest
|
||||||
implements PomArtifactResolver
|
implements PomArtifactResolver
|
||||||
{
|
{
|
||||||
private Map<String,File> artifacts = new HashMap<String,File>();
|
private Map<String,File> artifacts = new HashMap<String,File>();
|
||||||
|
|
||||||
private File basedir;
|
private File basedir;
|
||||||
|
|
||||||
public FileBasedPomArtifactResolver( File basedir )
|
public FileBasedPomArtifactResolver( File basedir )
|
||||||
|
|
|
@ -43,7 +43,12 @@ public class PomTestWrapper {
|
||||||
this.domainModel = new PomClassicDomainModel(model);
|
this.domainModel = new PomClassicDomainModel(model);
|
||||||
context = JXPathContext.newContext(domainModel.getModel());
|
context = JXPathContext.newContext(domainModel.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PomClassicDomainModel getDomainModel()
|
||||||
|
{
|
||||||
|
return this.domainModel;
|
||||||
|
}
|
||||||
|
|
||||||
public String getValueOfProjectUri(String projectUri, boolean withResolvedValue) throws IOException {
|
public String getValueOfProjectUri(String projectUri, boolean withResolvedValue) throws IOException {
|
||||||
if(projectUri.contains("#collection") || projectUri.contains("#set")) {
|
if(projectUri.contains("#collection") || projectUri.contains("#set")) {
|
||||||
throw new IllegalArgumentException("projectUri: contains a collection or set");
|
throw new IllegalArgumentException("projectUri: contains a collection or set");
|
||||||
|
@ -65,7 +70,7 @@ public class PomTestWrapper {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Iterator getIteratorForXPathExpression(String expression) {
|
public Iterator<?> getIteratorForXPathExpression(String expression) {
|
||||||
return context.iterate(expression);
|
return context.iterate(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.apache.maven.its.mng3821</groupId>
|
||||||
|
<artifactId>test</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>Maven Integration Test :: MNG-3821</name>
|
||||||
|
<description>
|
||||||
|
Verify that using the same id for executions/reportsets of different plugins doesn't blow up the project builder.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.plugins</groupId>
|
||||||
|
<artifactId>maven-it-plugin-a</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>the-one-and-only-id</id>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.plugins</groupId>
|
||||||
|
<artifactId>maven-it-plugin-b</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>the-one-and-only-id</id>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.plugins</groupId>
|
||||||
|
<artifactId>maven-it-plugin-a</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<reportSets>
|
||||||
|
<reportSet>
|
||||||
|
<id>the-one-and-only-id</id>
|
||||||
|
</reportSet>
|
||||||
|
</reportSets>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.its.plugins</groupId>
|
||||||
|
<artifactId>maven-it-plugin-b</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<reportSets>
|
||||||
|
<reportSet>
|
||||||
|
<id>the-one-and-only-id</id>
|
||||||
|
</reportSet>
|
||||||
|
</reportSets>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
Loading…
Reference in New Issue