mirror of https://github.com/apache/maven.git
[MNG-4053] [regression] XML attributes in plugin configuration get duplicated to other elements in combination with plugin management
o Added UT git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@747943 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a965b55cf4
commit
dc43d5412f
|
@ -812,19 +812,6 @@ public class PomConstructionTest
|
|||
assertTrue( pom.getValue( "build/filters[7]" ).toString().endsWith( "parent-d.properties" ) );
|
||||
}
|
||||
|
||||
/** MNG-4027
|
||||
public void testProjectInjectedDependencies()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "profile-injected-dependencies" );
|
||||
assertEquals( 4, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
|
||||
assertEquals( "a", pom.getValue( "dependencies[1]/artifactId" ) );
|
||||
assertEquals( "c", pom.getValue( "dependencies[2]/artifactId" ) );
|
||||
assertEquals( "b", pom.getValue( "dependencies[3]/artifactId" ) );
|
||||
assertEquals( "d", pom.getValue( "dependencies[4]/artifactId" ) );
|
||||
}
|
||||
//*/
|
||||
|
||||
/** MNG-4027
|
||||
public void testProfileInjectedDependencies()
|
||||
throws Exception
|
||||
|
@ -853,7 +840,6 @@ public class PomConstructionTest
|
|||
}
|
||||
//*/
|
||||
|
||||
|
||||
/** MNG-4040 */
|
||||
public void testProfileModuleInheritance()
|
||||
throws Exception
|
||||
|
@ -862,6 +848,42 @@ public class PomConstructionTest
|
|||
assertEquals(0, ( (List<?>) pom.getValue( "modules" ) ).size());
|
||||
|
||||
}
|
||||
|
||||
public void testPluginConfigurationUsingAttributesWithoutPluginManagement()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "plugin-config-attributes/wo-plugin-mngt" );
|
||||
assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
|
||||
assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
|
||||
assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
|
||||
}
|
||||
|
||||
/** FIXME: MNG-4053
|
||||
public void testPluginConfigurationUsingAttributesWithPluginManagement()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "plugin-config-attributes/w-plugin-mngt" );
|
||||
assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
|
||||
assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
|
||||
assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
|
||||
}
|
||||
|
||||
public void testPluginConfigurationUsingAttributesWithPluginManagementAndProfile()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPomFromMavenProject( "plugin-config-attributes/w-profile", "maven-core-it" );
|
||||
assertEquals( "src", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@todir" ) );
|
||||
assertEquals( "true", pom.getValue( "build/plugins[1]/configuration/domParam/copy/@overwrite" ) );
|
||||
assertEquals( "target", pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@dir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@todir" ) );
|
||||
assertEquals( null, pom.getValue( "build/plugins[1]/configuration/domParam/copy/fileset/@overwrite" ) );
|
||||
}
|
||||
//*/
|
||||
|
||||
private void assertPathWithNormalizedFileSeparators( Object value )
|
||||
{
|
||||
assertEquals( new File( value.toString() ).getPath(), value.toString() );
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.jxpath.JXPathContext;
|
||||
import org.apache.commons.jxpath.JXPathNotFoundException;
|
||||
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
|
@ -202,7 +203,14 @@ public class PomTestWrapper
|
|||
|
||||
public Object getValue( String expression )
|
||||
{
|
||||
return context.getValue( expression );
|
||||
try
|
||||
{
|
||||
return context.getValue( expression );
|
||||
}
|
||||
catch ( JXPathNotFoundException e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean xPathExpressionEqualsValue( String expression, String value )
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package org.apache.maven.project.harness;
|
||||
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.jxpath.ri.QName;
|
||||
import org.apache.commons.jxpath.ri.model.NodeIterator;
|
||||
import org.apache.commons.jxpath.ri.model.NodePointer;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
/**
|
||||
* An attribute iterator for JXPath to support <code>Xpp3Dom</code>.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
* @version $Id$
|
||||
*/
|
||||
class Xpp3DomAttributeIterator
|
||||
implements NodeIterator
|
||||
{
|
||||
|
||||
private NodePointer parent;
|
||||
|
||||
private Xpp3Dom node;
|
||||
|
||||
private List<Map.Entry<String, String>> attributes;
|
||||
|
||||
private Map.Entry<String, String> attribute;
|
||||
|
||||
private int position;
|
||||
|
||||
public Xpp3DomAttributeIterator( NodePointer parent, QName qname )
|
||||
{
|
||||
this.parent = parent;
|
||||
this.node = (Xpp3Dom) parent.getNode();
|
||||
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
for ( String name : this.node.getAttributeNames() )
|
||||
{
|
||||
if ( name.equals( qname.getName() ) || "*".equals( qname.getName() ) )
|
||||
{
|
||||
String value = this.node.getAttribute( name );
|
||||
map.put( name, value );
|
||||
}
|
||||
}
|
||||
this.attributes = new ArrayList<Map.Entry<String, String>>( map.entrySet() );
|
||||
}
|
||||
|
||||
public NodePointer getNodePointer()
|
||||
{
|
||||
if ( position == 0 )
|
||||
{
|
||||
setPosition( 1 );
|
||||
}
|
||||
return ( attribute == null ) ? null : new Xpp3DomAttributePointer( parent, attribute );
|
||||
}
|
||||
|
||||
public int getPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean setPosition( int position )
|
||||
{
|
||||
this.position = position;
|
||||
attribute = ( position > 0 && position <= attributes.size() ) ? attributes.get( position - 1 ) : null;
|
||||
return attribute != null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package org.apache.maven.project.harness;
|
||||
|
||||
/*
|
||||
* 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 java.util.Map;
|
||||
|
||||
import org.apache.commons.jxpath.ri.QName;
|
||||
import org.apache.commons.jxpath.ri.model.NodePointer;
|
||||
|
||||
/**
|
||||
* An attribute pointer for JXPath to support <code>Xpp3Dom</code>.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
class Xpp3DomAttributePointer
|
||||
extends NodePointer
|
||||
{
|
||||
|
||||
private Map.Entry<String, String> attrib;
|
||||
|
||||
public Xpp3DomAttributePointer( NodePointer parent, Map.Entry<String, String> attrib )
|
||||
{
|
||||
super( parent );
|
||||
this.attrib = attrib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2 )
|
||||
{
|
||||
// should never happen because attributes have no children
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return attrib.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBaseValue()
|
||||
{
|
||||
return attrib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getImmediateNode()
|
||||
{
|
||||
return attrib;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getName()
|
||||
{
|
||||
return new QName( null, attrib.getKey() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActual()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollection()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue( Object value )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
|
@ -146,4 +146,11 @@ class Xpp3DomNodePointer
|
|||
{
|
||||
return new Xpp3DomNodeIterator( this, test, reverse, startWith );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeIterator attributeIterator( QName qname )
|
||||
{
|
||||
return new Xpp3DomAttributeIterator( this, qname );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?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.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>
|
||||
<configuration>
|
||||
<propertiesFile>target/config.properties</propertiesFile>
|
||||
<domParam>
|
||||
<copy todir="src" overwrite="true">
|
||||
<fileset dir="target"/>
|
||||
</copy>
|
||||
</domParam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,74 @@
|
|||
<?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.mng4053</groupId>
|
||||
<artifactId>test3</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 and a profile are 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>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<!-- NOTE: This test injects the plugin configuration via a profile -->
|
||||
<id>maven-core-it</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-configuration</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<propertiesFile>target/config.properties</propertiesFile>
|
||||
<domParam>
|
||||
<copy todir="src" overwrite="true">
|
||||
<fileset dir="target"/>
|
||||
</copy>
|
||||
</domParam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,53 @@
|
|||
<?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.mng4053</groupId>
|
||||
<artifactId>test1</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
|
||||
no plugin management is used.
|
||||
</description>
|
||||
|
||||
<build>
|
||||
<!-- NOTE: This test does not use plugin management for the IT plugin -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.its.plugins</groupId>
|
||||
<artifactId>maven-it-plugin-configuration</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<propertiesFile>target/config.properties</propertiesFile>
|
||||
<domParam>
|
||||
<copy todir="src" overwrite="true">
|
||||
<fileset dir="target"/>
|
||||
</copy>
|
||||
</domParam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Loading…
Reference in New Issue