[MNG-0051] - This test was broken due to an unrelated issue on plugin management inheritance. Fixed it and added some unit tests.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@767266 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-04-21 19:49:19 +00:00
parent 07d018d78d
commit d470d0c812
10 changed files with 399 additions and 95 deletions

View File

@ -74,7 +74,6 @@ public class PluginProcessor
copy( (Plugin) parent, targetPlugin, false );
copyDependencies( new ArrayList<Dependency>(( (Plugin) parent).getDependencies() ), new ArrayList<Dependency>(),
targetPlugin, true );
// copyDependencies( (Plugin) parent, targetPlugin, false );
if(isAdd) t.add( targetPlugin );
}
else
@ -111,6 +110,28 @@ public class PluginProcessor
}
}
}
public void process( Plugin parent, List<Plugin> t, boolean isChildMostSpecialized )
{
if (parent == null) {
return;
}
boolean isAdd = true;
Plugin targetPlugin = find((Plugin) parent, t);
if (targetPlugin == null) {
targetPlugin = new Plugin();
} else {
isAdd = false;
}
copy2((Plugin) parent, targetPlugin, false);
copyDependencies(new ArrayList<Dependency>(((Plugin) parent)
.getDependencies()), new ArrayList<Dependency>(), targetPlugin,
true);
if (isAdd)
t.add(targetPlugin);
}
private static Plugin find(Plugin p1, List<Plugin> plugins)
{
@ -132,9 +153,9 @@ public class PluginProcessor
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() ).append( ":" );
sb.append( (d.getGroupId() != null) ? d.getGroupId() : "org.apache.maven.plugins").append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
}
private static void copyDependencies(List<Dependency> parent, List<Dependency> child, Plugin target, boolean isChild)
@ -146,7 +167,76 @@ public class PluginProcessor
DependenciesProcessor proc = new DependenciesProcessor();
proc.process( parent, child, target.getDependencies(), isChild );
}
/**
* Don't overwrite values
*
* @param source
* @param target
* @param isChild
*/
private static void copy2(Plugin source, Plugin target, boolean isChild)
{
if(!isChild && source.getInherited() != null && !source.getInherited().equalsIgnoreCase( "true" ))
{
return;
}
if(target.getArtifactId() == null)
{
target.setArtifactId( source.getArtifactId() );
}
if(target.getGroupId() == null)
{
target.setGroupId( source.getGroupId() );
}
if(target.getInherited() == null)
{
target.setInherited( source.getInherited() );
}
if(target.getVersion() == null)
{
target.setVersion( source.getVersion() );
}
for( PluginExecution pe : source.getExecutions())
{
PluginExecution idMatch = contains(pe, target.getExecutions());
if(idMatch != null)//Join
{
copyPluginExecution(pe, idMatch, isChild);
}
else
{
PluginExecution targetPe = new PluginExecution();
copyPluginExecution(pe, targetPe, isChild);
target.addExecution( targetPe );
}
}
if(source.getConfiguration() != null)
{
//TODO: Not copying
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
// p2.setConfiguration( configuration ) merge nodes
//Goals
target.setExtensions(source.isExtensions());
}
private static void copy(Plugin source, Plugin target, boolean isChild)
{

View File

@ -22,8 +22,6 @@ package org.apache.maven.model.processors;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
public class PluginsProcessor
@ -56,26 +54,33 @@ public class PluginsProcessor
if ( !c.isEmpty() )
{
List<Plugin> parentDependencies = new ArrayList<Plugin>();
for ( Plugin d1 : c)
for ( Plugin childPlugin : c)
{
for ( Plugin d2 : p)
for ( Plugin parentPlugin : p)
{
if ( match( d1, d2 ) )
if ( match( childPlugin, parentPlugin ) )
{
processor.process( d2, d1, plugins, isChildMostSpecialized );// JOIN
processor.process( parentPlugin, childPlugin, plugins, isChildMostSpecialized );// JOIN
}
else
{
processor.process( null, d1, plugins, isChildMostSpecialized );
parentDependencies.add( d2 );
processor.process( null, childPlugin, plugins, isChildMostSpecialized );
if(!parentDependencies.contains(parentPlugin))
{
parentDependencies.add( parentPlugin );
}
}
}
}
/**
* Process Parents after child to keep plugin order but don't want to overwrite the child values. Use different method
*/
for ( Plugin d2 : parentDependencies )
{
processor.process( d2, null, plugins, isChildMostSpecialized );
processor.process( d2, plugins, isChildMostSpecialized );
}
}
else if( p != null)
{
@ -96,7 +101,7 @@ public class PluginsProcessor
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() ).append( ":" );
sb.append( (d.getGroupId() != null) ? d.getGroupId() : "org.apache.maven.plugins").append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
}

View File

@ -544,7 +544,7 @@ public class DefaultMavenProjectBuilder
{
for ( String s : (List<String>) validationResult.getMessages() )
{
logger.debug( s );
logger.info( s );
}
throw new InvalidProjectModelException( projectId, "Failed to validate POM", pomFile, validationResult );
}

View File

@ -23,7 +23,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -1368,6 +1367,35 @@ public class PomConstructionTest
pom.getValue( "distributionManagement/site/url" ) );
}
public void testPluginManagementInheritance()
throws Exception
{
PomTestWrapper pom = this.buildPom( "plugin-management-inheritance");
assertEquals("0.1-stub-SNAPSHOT", pom.getValue( "build/pluginManagement/plugins[1]/version" ) );
}
public void testProfilePlugins()
throws Exception
{
PomTestWrapper pom = this.buildPom( "profile-plugins", "standard");
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
assertEquals("maven-assembly2-plugin", pom.getValue( "build/plugins[2]/artifactId" ) );
}
public void testPluginInheritanceSimple()
throws Exception
{
PomTestWrapper pom = this.buildPom( "plugin-inheritance-simple/sub");
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
}
public void testPluginManagementDuplicate()
throws Exception
{
PomTestWrapper pom = this.buildPom( "plugin-management-duplicate/sub");
assertEquals( 20, ( (List<?>) pom.getValue( "build/pluginManagement/plugins" ) ).size() );
}
private void assertPathSuffixEquals( String expected, Object actual )
{
String a = actual.toString();
@ -1381,21 +1409,21 @@ public class PomConstructionTest
}
private PomTestWrapper buildPom( String pomPath, Properties properties)
throws Exception
{
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()));
ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
config.setExecutionProperties(properties);
config.setGlobalProfileManager(new DefaultProfileManager(pCtx));
return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) );
}
throws Exception
{
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()));
ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
config.setExecutionProperties(properties);
config.setGlobalProfileManager(new DefaultProfileManager(pCtx));
return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) );
}
private PomTestWrapper buildPom( String pomPath, String... profileIds )
throws Exception

View File

@ -0,0 +1,16 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>gid</groupId>
<artifactId>aid</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-21</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,20 @@
<project>
<parent>
<groupId>gid</groupId>
<artifactId>aid</artifactId>
<version>1.0</version>
</parent>
<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-plugin2</artifactId>
<version>1.0-alpha-21</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,70 +1,37 @@
<?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
<!--
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.
-->
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.mng4053</groupId>
<artifactId>test2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Integration Test :: MNG-4053</name>
<description>
Verify that attributes in plugin configuration elements are not erroneously duplicated to other elements when
plugin management is used.
</description>
<build>
<!-- NOTE: This test used plugin management for the IT plugin -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>config</goal>
</goals>
<configuration>
<propertiesFile>target/config.properties</propertiesFile>
<domParam>
<copy todir="src" overwrite="true">
<fileset dir="target"/>
</copy>
</domParam>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<groupId>gid</groupId>
<artifactId>aid</artifactId>
<version>1.0</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins
</groupId>
<artifactId>maven-it-plugin-configuration
</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,64 @@
<?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>
<parent>
<groupId>gid</groupId>
<artifactId>aid</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4053</groupId>
<artifactId>test2</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,64 @@
<?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.it0052</groupId>
<artifactId>maven-it-it0052</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Maven Integration Test :: it0052</name>
<description>Test that source attachment doesn't take place when -DperformRelease=true is missing.</description>
<!-- NOTE: Use stub versions of the core plugins referenced by the build -->
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>0.1-stub-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,50 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>standard</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly2-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>