PR: MPARTIFACT-51
correct POM rewriting for dependency properties, add test also add other missing dependencies, required in Maven 1.1 git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@190044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
b858a1ad69
commit
4b3393de62
6 files changed
+307
-116
No files matched your search
+27
-1
@@ -18,7 +18,8 @@
|
||||
*/
|
||||
-->
|
||||
|
||||
<project>
|
||||
<project xmlns="http://maven.apache.org/POM/3.0.0" xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<extend>../plugin-parent/project.xml</extend>
|
||||
<pomVersion>3</pomVersion>
|
||||
<id>maven-artifact-plugin</id>
|
||||
@@ -89,6 +90,21 @@
|
||||
<artifactId>commons-digester</artifactId>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
@@ -165,4 +181,14 @@
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
|
||||
<unitTest>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/test/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</unitTest>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,176 @@
|
||||
package org.apache.maven.artifact;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.Project;
|
||||
import org.apache.maven.MavenException;
|
||||
import org.apache.maven.MavenUtils;
|
||||
import org.apache.maven.jelly.MavenJellyContext;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.commons.betwixt.io.BeanWriter;
|
||||
import org.apache.commons.betwixt.XMLIntrospector;
|
||||
import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
|
||||
import org.apache.oro.text.perl.Perl5Util;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Rewrite a full model for publishing. Inheritence and expression will have been resolved.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PomRewriter
|
||||
{
|
||||
public static File getRewrittenPom( Project project )
|
||||
throws MavenException
|
||||
{
|
||||
Model model = getRewrittenModel( project );
|
||||
|
||||
FileWriter w = null;
|
||||
try
|
||||
{
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
File f = File.createTempFile( "maven-artifact-plugin.", null );
|
||||
f.deleteOnExit();
|
||||
w = new FileWriter( f );
|
||||
writer.write( w, model );
|
||||
|
||||
return f;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MavenException( "Error getting the project as a string", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( w );
|
||||
}
|
||||
}
|
||||
|
||||
static Model getRewrittenModel( Project project )
|
||||
throws MavenException
|
||||
{
|
||||
Model model;
|
||||
try
|
||||
{
|
||||
// Very gross, but in Maven 1.0 we can't get access, and we don't want initialize() called
|
||||
// A future version should use use project.getModel() and serialize that
|
||||
Method m = MavenUtils.class.getDeclaredMethod( "getNonJellyProject",
|
||||
new Class[]{File.class, MavenJellyContext.class,
|
||||
boolean.class} );
|
||||
m.setAccessible( true );
|
||||
Project p = (Project) m.invoke( null,
|
||||
new Object[]{project.getFile(), project.getContext(), Boolean.TRUE} );
|
||||
m.setAccessible( false );
|
||||
m = MavenUtils.class.getDeclaredMethod( "getJellyProject", new Class[]{Project.class} );
|
||||
m.setAccessible( true );
|
||||
p = (Project) m.invoke( null, new Object[]{p} );
|
||||
m.setAccessible( false );
|
||||
|
||||
// now sanitize
|
||||
p.setContext( null );
|
||||
p.setParent( null );
|
||||
p.setArtifacts( null );
|
||||
p.setDependencyVerifier( null );
|
||||
p.setExtend( null );
|
||||
|
||||
Map depProperties = new HashMap();
|
||||
for ( Iterator i = p.getDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
org.apache.maven.project.Dependency d = (org.apache.maven.project.Dependency) i.next();
|
||||
if ( d.getProperties() != null && !d.getProperties().isEmpty() )
|
||||
{
|
||||
depProperties.put( d.getId(), d.getProperties() );
|
||||
d.setProperties( null );
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayOutputStream projectStream = new ByteArrayOutputStream();
|
||||
|
||||
BeanWriter beanWriter = new BeanWriter( projectStream );
|
||||
beanWriter.setXMLIntrospector( createXMLIntrospector() );
|
||||
|
||||
beanWriter.enablePrettyPrint();
|
||||
beanWriter.setWriteIDs( false );
|
||||
beanWriter.write( p );
|
||||
|
||||
String asString = projectStream.toString( System.getProperty( "file.encoding" ) );
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
model = reader.read( new StringReader( asString ) );
|
||||
model.setId( null );
|
||||
|
||||
for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
if ( depProperties.containsKey( d.getId() ) )
|
||||
{
|
||||
d.getProperties().putAll( (Properties) depProperties.get( d.getId() ) );
|
||||
}
|
||||
|
||||
d.setId( null );
|
||||
|
||||
if ( d.getUrl() != null && d.getUrl().length() == 0 )
|
||||
{
|
||||
d.setUrl( null );
|
||||
}
|
||||
|
||||
if ( d.getType() != null && d.getType().length() == 0 )
|
||||
{
|
||||
d.setType( null );
|
||||
}
|
||||
|
||||
if ( d.getJar() != null && d.getJar().length() == 0 )
|
||||
{
|
||||
d.setJar( null );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MavenException( "Error getting the project as a string", e );
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
private static XMLIntrospector createXMLIntrospector()
|
||||
{
|
||||
XMLIntrospector introspector = new XMLIntrospector();
|
||||
|
||||
introspector.setAttributesForPrimitives( false );
|
||||
introspector.setElementNameMapper( new DecapitalizeNameMapper() );
|
||||
|
||||
return introspector;
|
||||
}
|
||||
}
|
||||
+16
-115
@@ -1,20 +1,19 @@
|
||||
package org.apache.maven.artifact.deployer;
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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 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
|
||||
* 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.
|
||||
* ====================================================================
|
||||
* 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.commons.betwixt.XMLIntrospector;
|
||||
@@ -26,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.maven.MavenConstants;
|
||||
import org.apache.maven.MavenException;
|
||||
import org.apache.maven.MavenUtils;
|
||||
import org.apache.maven.artifact.PomRewriter;
|
||||
import org.apache.maven.jelly.MavenJellyContext;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Model;
|
||||
@@ -118,7 +118,7 @@ public class DefaultArtifactDeployer
|
||||
File file;
|
||||
if ( POM_TYPE.equals( type ) )
|
||||
{
|
||||
file = getRewrittenPom( project );
|
||||
file = PomRewriter.getRewrittenPom( project );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -128,111 +128,12 @@ public class DefaultArtifactDeployer
|
||||
// do not deploy POM twice
|
||||
if ( !POM_TYPE.equals( type ) )
|
||||
{
|
||||
doDeploy( getRewrittenPom( project ), project, POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
|
||||
doDeploy( PomRewriter.getRewrittenPom( project ), project, POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
|
||||
}
|
||||
|
||||
doDeploy( file, project, handler, version, type );
|
||||
}
|
||||
|
||||
private static File getRewrittenPom( Project project )
|
||||
throws MavenException
|
||||
{
|
||||
Model model;
|
||||
try
|
||||
{
|
||||
// Very gross, but in Maven 1.0 we can't get access, and we don't want initialize() called
|
||||
// A future version should use use project.getModel() and serialize that
|
||||
Method m = MavenUtils.class.getDeclaredMethod( "getNonJellyProject",
|
||||
new Class[]{File.class, MavenJellyContext.class,
|
||||
boolean.class} );
|
||||
m.setAccessible( true );
|
||||
Project p = (Project) m.invoke( null,
|
||||
new Object[]{project.getFile(), project.getContext(), Boolean.TRUE} );
|
||||
m.setAccessible( false );
|
||||
m = MavenUtils.class.getDeclaredMethod( "getJellyProject", new Class[]{Project.class} );
|
||||
m.setAccessible( true );
|
||||
p = (Project) m.invoke( null, new Object[]{p} );
|
||||
m.setAccessible( false );
|
||||
|
||||
// now sanitize
|
||||
p.setContext( null );
|
||||
p.setParent( null );
|
||||
p.setArtifacts( null );
|
||||
p.setDependencyVerifier( null );
|
||||
p.setExtend( null );
|
||||
|
||||
ByteArrayOutputStream projectStream = new ByteArrayOutputStream();
|
||||
|
||||
BeanWriter beanWriter = new BeanWriter( projectStream );
|
||||
beanWriter.setXMLIntrospector( createXMLIntrospector() );
|
||||
|
||||
beanWriter.enablePrettyPrint();
|
||||
beanWriter.setWriteIDs( false );
|
||||
beanWriter.write( p );
|
||||
|
||||
String asString = projectStream.toString( System.getProperty( "file.encoding" ) );
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
model = reader.read( new StringReader( asString ) );
|
||||
model.setId( null );
|
||||
|
||||
for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
d.setId( null );
|
||||
|
||||
if ( d.getUrl() != null && d.getUrl().length() == 0 )
|
||||
{
|
||||
d.setUrl( null );
|
||||
}
|
||||
|
||||
if ( d.getType() != null && d.getType().length() == 0 )
|
||||
{
|
||||
d.setType( null );
|
||||
}
|
||||
|
||||
if ( d.getJar() != null && d.getJar().length() == 0 )
|
||||
{
|
||||
d.setJar( null );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MavenException( "Error getting the project as a string", e );
|
||||
}
|
||||
|
||||
FileWriter w = null;
|
||||
try
|
||||
{
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
File f = File.createTempFile( "maven-artifact-plugin.", null );
|
||||
f.deleteOnExit();
|
||||
w = new FileWriter( f );
|
||||
writer.write( w, model );
|
||||
|
||||
return f;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MavenException( "Error getting the project as a string", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( w );
|
||||
}
|
||||
}
|
||||
|
||||
private static XMLIntrospector createXMLIntrospector()
|
||||
{
|
||||
XMLIntrospector introspector = new XMLIntrospector();
|
||||
|
||||
introspector.setAttributesForPrimitives( false );
|
||||
introspector.setElementNameMapper( new DecapitalizeNameMapper() );
|
||||
|
||||
return introspector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArtifactDeployer#install(String, String, Project, ArtifactTypeHandler)
|
||||
*/
|
||||
@@ -258,7 +159,7 @@ public class DefaultArtifactDeployer
|
||||
File file;
|
||||
if ( POM_TYPE.equals( type ) )
|
||||
{
|
||||
file = getRewrittenPom( project );
|
||||
file = PomRewriter.getRewrittenPom( project );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -270,7 +171,7 @@ public class DefaultArtifactDeployer
|
||||
// do not install twice
|
||||
if ( !POM_TYPE.equals( type ) )
|
||||
{
|
||||
doInstall( getRewrittenPom( project ), POM_TYPE, project, version, POM_ARTIFACT_TYPE_HANDLER );
|
||||
doInstall( PomRewriter.getRewrittenPom( project ), POM_TYPE, project, version, POM_ARTIFACT_TYPE_HANDLER );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.apache.maven.artifact;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.apache.maven.project.Project;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.MavenException;
|
||||
import org.apache.maven.MavenUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Test the POM rewriter.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PomRewriterTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPropertiesRewriting()
|
||||
throws MavenException
|
||||
{
|
||||
Project project = getProject( "pom-with-properties.xml" );
|
||||
|
||||
Model model = PomRewriter.getRewrittenModel( project );
|
||||
|
||||
Dependency dep = (Dependency) model.getDependencies().get( 0 );
|
||||
assertEquals( "check property war.bundle", "true", dep.getProperty( "war.bundle" ) );
|
||||
assertEquals( "check num properties", 1, dep.getProperties().size() );
|
||||
|
||||
dep = (Dependency) model.getDependencies().get( 1 );
|
||||
assertEquals( "check property gump.project", "jakarta-taglibs-standard", dep.getProperty( "gump.project" ) );
|
||||
assertEquals( "check property gump.id", "jstl", dep.getProperty( "gump.id" ) );
|
||||
assertEquals( "check num properties", 2, dep.getProperties().size() );
|
||||
}
|
||||
|
||||
private static Project getProject( String resourceName )
|
||||
throws MavenException
|
||||
{
|
||||
// TODO: use a resource if MavenUtils supported it
|
||||
return MavenUtils.getProject( new File( System.getProperty( "basedir"), "src/test/resources/" + resourceName ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<project xmlns="http://maven.apache.org/POM/3.0.0" xsi:schemaLocation="http://maven.apache.org/POM/3.0.0 http://maven.apache.org/maven-v3_0_0.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<pomVersion>3</pomVersion>
|
||||
<artifactId>artifactId</artifactId>
|
||||
<groupId>groupId</groupId>
|
||||
<currentVersion>1.0-SNAPSHOT</currentVersion>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>a1</artifactId>
|
||||
<groupId>g1</groupId>
|
||||
<version>v1</version>
|
||||
<properties>
|
||||
<war.bundle>true</war.bundle>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jstl</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<url>http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/intro.html</url>
|
||||
<properties>
|
||||
<gump.project>jakarta-taglibs-standard</gump.project>
|
||||
<gump.id>jstl</gump.id>
|
||||
</properties>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -26,6 +26,7 @@
|
||||
</properties>
|
||||
<body>
|
||||
<release version="1.5.2-SNAPSHOT" date="in SVN">
|
||||
<action dev="brett" type="fix" issue="MPARTIFACT-51">Correct the translation of dependency properties on deployment of the POM</action>
|
||||
<action dev="brett" type="fix" issue="MPARTIFACT-52">Upgrade Wagon SSH External provider to correct issues</action>
|
||||
</release>
|
||||
<release version="1.5.1" date="2005-06-05">
|
||||
|
||||
Reference in new issue
Block a user