Resolving issue: MNG-467 (patch from Kenney Westerhof applied, with minor formatting modifications)

Resolving issue: MNG-503 (another patch from Kenney Westerhof applied)

o Tracked down the potential NPE when using a list of dependencies in the DependencyTask (it needs a Pom in order to create an originating artifact)...creating a dummy Pom instance when the list of dependencies is supplied, since I assume the originatingArtifact is used for tracking/graphing purposes. This new method, called createDummyPom() is in AbstractArtifactTask, so it's available for use in InstallTask and DeployTask if necessary...

Thanks, Kenney!



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191744 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-21 23:25:26 +00:00
parent fd3e9fe9e2
commit 748de75a58
5 changed files with 96 additions and 19 deletions

View File

@ -1,13 +1,46 @@
<project name="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant" default="foo">
<target name="test-pom">
<artifact:pom file="pom.xml" id="my.maven.project"/>
<project name="foo" default="foo" xmlns:artifact="urn:maven-artifact-ant">
<!--
You either need to run the the 'initTaskDefs' task below and
define the artifact namespace like above (choose anything you
like except strings that start with 'antlib:'),
and be sure to supply the path to the maven-artifact-ant jars
<echo>Artifact ID = ${my.maven.project:artifactId}</echo>
OR
<echo>Parent Artifact ID = ${my.maven.project:parent.artifactId}</echo>
just define the artifact namespace as follows:
xmlns:artifact="antlib:org.apache.maven.artifact.ant"
and be sure to add the maven-artifact-ant jars to the ant
classpath (either by setting the CLASSPATH environment variable
before calling ant, or place the jars in the $ANT_HOME/lib directory).
-->
<target name="initTaskDefs">
<!-- don't forget to set the value! -->
<property name="maven.artifact-ant.lib.dir" value="${user.home}/work/opensource/m2/maven-artifact-ant/target/"/>
<path id="maven.classpath">
<pathelement location="${maven.artifact-ant.lib.dir}/maven-artifact-ant-2.0-SNAPSHOT-dep.jar"/>
<pathelement location="${maven.artifact-ant.lib.dir}maven-artifact-ant-2.0-SNAPSHOT.jar"/>
</path>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="urn:maven-artifact-ant"
>
<classpath refid="maven.classpath"/>
</typedef>
</target>
<target name="foo">
<target name="test-pom" depends="initTaskDefs">
<artifact:pom file="pom.xml" id="my.maven.project"/>
<echo>Artifact ID = ${my.maven.project.artifactId}</echo>
<echo>Parent Artifact ID = ${my.maven.project.parent.artifactId}</echo>
</target>
<target name="foo" depends="initTaskDefs">
<artifact:localRepository id="local.repository" location="${basedir}/target/local-repo" layout="default"/>
<artifact:remoteRepository id="deploy.repository" url="file://${basedir}/target/deployment-repo" layout="legacy"/>
@ -51,7 +84,7 @@
</artifact:deploy>
</target>
<target name="test-scm">
<target name="test-scm" depends="initTaskDefs">
<mkdir dir="target" />
<pathconvert targetos="unix" property="repo.path.unix">

View File

@ -27,11 +27,16 @@ import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.maven.model.Model;
import org.apache.maven.profiles.activation.ProfileActivationUtils;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.classworlds.DuplicateRealmException;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -251,14 +256,24 @@ public abstract class AbstractArtifactTask
if ( embedder == null )
{
embedder = new Embedder();
try
{
embedder.start();
ClassWorld classWorld = new ClassWorld();
ClassRealm classRealm = classWorld.newRealm( "plexus.core", getClass().getClassLoader() );
embedder.start( classWorld );
}
catch ( PlexusContainerException e )
{
throw new BuildException( "Unable to start embedder", e );
}
catch ( DuplicateRealmException e )
{
throw new BuildException( "Unable to create embedder ClassRealm", e );
}
getProject().addReference( Embedder.class.getName(), embedder );
}
}
@ -289,6 +304,24 @@ public abstract class AbstractArtifactTask
return pom;
}
protected Pom createDummyPom()
{
Model mavenModel = new Model();
mavenModel.setGroupId( "unspecified" );
mavenModel.setArtifactId( "unspecified" );
mavenModel.setVersion( "0.0" );
mavenModel.setPackaging( "jar" );
MavenProject mavenProject = new MavenProject( mavenModel );
Pom pom = new Pom();
pom.setMavenProject( mavenProject );
return pom;
}
public void addPom( Pom pom )
{
this.pom = pom;

View File

@ -81,6 +81,12 @@ public class DependenciesTask
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
}
}
else
{
// we have to have some sort of Pom object in order to satisfy the requirements for building the
// originating Artifact below...
pom = createDummyPom();
}
Set artifacts = metadataSource.createArtifacts( dependencies, null, null );

View File

@ -92,6 +92,11 @@ public class Pom
return instance;
}
public void setMavenProject( MavenProject mavenProject )
{
getInstance().mavenProject = mavenProject;
}
public File getFile()
{
return getInstance().file;

View File

@ -229,7 +229,7 @@
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.profiless.activation.ProfileActivationCalculator</role>
<role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
</requirement>
</requirements>
</component>
@ -239,8 +239,8 @@
|
-->
<component>
<role>org.apache.maven.profiless.activation.ProfileActivationCalculator</role>
<implementation>org.apache.maven.profiless.activation.ProfileActivationCalculator</implementation>
<role>org.apache.maven.profiles.activation.ProfileActivationCalculator</role>
<implementation>org.apache.maven.profiles.activation.ProfileActivationCalculator</implementation>
</component>
<!--
|
@ -248,9 +248,9 @@
|
-->
<component>
<role>org.apache.maven.profiless.activation.ProfileActivator</role>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>always-on</role-hint>
<implementation>org.apache.maven.profiless.activation.AlwaysOnProfileActivator</implementation>
<implementation>org.apache.maven.profiles.activation.AlwaysOnProfileActivator</implementation>
</component>
<!--
|
@ -258,9 +258,9 @@
|
-->
<component>
<role>org.apache.maven.profiless.activation.ProfileActivator</role>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>jdk-prefix</role-hint>
<implementation>org.apache.maven.profiless.activation.JdkPrefixProfileActivator</implementation>
<implementation>org.apache.maven.profiles.activation.JdkPrefixProfileActivator</implementation>
</component>
<!--
|
@ -268,9 +268,9 @@
|
-->
<component>
<role>org.apache.maven.profiless.activation.ProfileActivator</role>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>system-property</role-hint>
<implementation>org.apache.maven.profiless.activation.SystemPropertyProfileActivator</implementation>
<implementation>org.apache.maven.profiles.activation.SystemPropertyProfileActivator</implementation>
</component>
<!--
|
@ -278,9 +278,9 @@
|
-->
<component>
<role>org.apache.maven.profiless.activation.ProfileActivator</role>
<role>org.apache.maven.profiles.activation.ProfileActivator</role>
<role-hint>explicit-listing</role-hint>
<implementation>org.apache.maven.profiless.activation.ExplicitListingProfileActivator</implementation>
<implementation>org.apache.maven.profiles.activation.ExplicitListingProfileActivator</implementation>
</component>
<!--
|