mirror of https://github.com/apache/maven.git
PR: MNG-435
add a <artifact:setProperty property|ref="..." expression="project.*" pomRefId="..." /> tag for exposing the pom as variables git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4c030598a
commit
a27bf46440
|
@ -1,4 +1,4 @@
|
|||
<model>
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
|
@ -74,4 +74,4 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</model>
|
||||
</project>
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
<project name="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant" default="foo">
|
||||
<target name="foo">
|
||||
<!--
|
||||
TODO...
|
||||
- read .m2/settings.xml
|
||||
-->
|
||||
<target name="test-pom">
|
||||
<artifact:pom file="pom.xml" id="my.maven.project"/>
|
||||
|
||||
<artifact:setProperty property="my.artifactid" expression="project.artifactId" pomRefId="my.maven.project" />
|
||||
<echo>Artifact ID = ${my.artifactid}</echo>
|
||||
|
||||
<artifact:setProperty property="my.parent.artifactid" expression="project.parent.artifactId" pomRefId="my.maven.project" />
|
||||
<echo>Artifact ID = ${my.parent.artifactid}</echo>
|
||||
</target>
|
||||
|
||||
<target name="foo">
|
||||
<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"/>
|
||||
|
|
|
@ -19,10 +19,11 @@ package org.apache.maven.artifact.ant;
|
|||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Server;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
@ -46,19 +47,30 @@ import java.io.IOException;
|
|||
public abstract class AbstractArtifactTask
|
||||
extends Task
|
||||
{
|
||||
private Embedder embedder;
|
||||
|
||||
private Settings settings;
|
||||
|
||||
protected ArtifactRepository createLocalArtifactRepository( LocalRepository repository )
|
||||
private Embedder embedder;
|
||||
|
||||
private Pom pom;
|
||||
|
||||
private String pomRefId;
|
||||
|
||||
private LocalRepository localRepository;
|
||||
|
||||
protected ArtifactRepository createLocalArtifactRepository()
|
||||
{
|
||||
if ( localRepository == null )
|
||||
{
|
||||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||
repository.getLayout() );
|
||||
localRepository.getLayout() );
|
||||
|
||||
CustomWagonManager manager = (CustomWagonManager) lookup( WagonManager.ROLE );
|
||||
manager.setLocalRepository( repository.getLocation() );
|
||||
manager.setLocalRepository( localRepository.getLocation() );
|
||||
|
||||
return new ArtifactRepository( "local", "file://" + repository.getLocation(), repositoryLayout );
|
||||
return new ArtifactRepository( "local", "file://" + localRepository.getLocation(), repositoryLayout );
|
||||
}
|
||||
|
||||
protected ArtifactRepository createRemoteArtifactRepository( RemoteRepository repository )
|
||||
|
@ -95,53 +107,6 @@ public abstract class AbstractArtifactTask
|
|||
return artifactRepository;
|
||||
}
|
||||
|
||||
protected Object lookup( String role )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getEmbedder().lookup( role );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new BuildException( "Unable to find component: " + role, e );
|
||||
}
|
||||
}
|
||||
|
||||
private Object lookup( String role, String roleHint )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getEmbedder().lookup( role, roleHint );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new BuildException( "Unable to find component: " + role + "[" + roleHint + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized Embedder getEmbedder()
|
||||
{
|
||||
if ( embedder == null )
|
||||
{
|
||||
embedder = (Embedder) getProject().getReference( Embedder.class.getName() );
|
||||
|
||||
if ( embedder == null )
|
||||
{
|
||||
embedder = new Embedder();
|
||||
try
|
||||
{
|
||||
embedder.start();
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new BuildException( "Unable to start embedder", e );
|
||||
}
|
||||
getProject().addReference( Embedder.class.getName(), embedder );
|
||||
}
|
||||
}
|
||||
return embedder;
|
||||
}
|
||||
|
||||
protected LocalRepository getDefaultLocalRepository()
|
||||
{
|
||||
Settings settings = getSettings();
|
||||
|
@ -226,4 +191,100 @@ public abstract class AbstractArtifactTask
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
protected Object lookup( String role )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getEmbedder().lookup( role );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new BuildException( "Unable to find component: " + role, e );
|
||||
}
|
||||
}
|
||||
|
||||
protected Object lookup( String role, String roleHint )
|
||||
{
|
||||
try
|
||||
{
|
||||
return getEmbedder().lookup( role, roleHint );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new BuildException( "Unable to find component: " + role + "[" + roleHint + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized Embedder getEmbedder()
|
||||
{
|
||||
if ( embedder == null )
|
||||
{
|
||||
embedder = (Embedder) getProject().getReference( Embedder.class.getName() );
|
||||
|
||||
if ( embedder == null )
|
||||
{
|
||||
embedder = new Embedder();
|
||||
try
|
||||
{
|
||||
embedder.start();
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
throw new BuildException( "Unable to start embedder", e );
|
||||
}
|
||||
getProject().addReference( Embedder.class.getName(), embedder );
|
||||
}
|
||||
}
|
||||
return embedder;
|
||||
}
|
||||
|
||||
public Pom buildPom( MavenProjectBuilder projectBuilder, ArtifactRepository localArtifactRepository )
|
||||
{
|
||||
if ( pomRefId != null && pom != null )
|
||||
{
|
||||
throw new BuildException( "You cannot specify both a POM element and a pomrefid element" );
|
||||
}
|
||||
|
||||
Pom pom = this.pom;
|
||||
if ( pomRefId != null )
|
||||
{
|
||||
pom = (Pom) getProject().getReference( pomRefId );
|
||||
if ( pom == null )
|
||||
{
|
||||
throw new BuildException( "Reference '" + pomRefId + "' was not found." );
|
||||
}
|
||||
}
|
||||
|
||||
if ( pom != null )
|
||||
{
|
||||
pom.initialise( projectBuilder, localArtifactRepository );
|
||||
}
|
||||
return pom;
|
||||
}
|
||||
|
||||
public void addPom( Pom pom )
|
||||
{
|
||||
this.pom = pom;
|
||||
}
|
||||
|
||||
public String getPomRefId()
|
||||
{
|
||||
return pomRefId;
|
||||
}
|
||||
|
||||
public void setPomRefId( String pomRefId )
|
||||
{
|
||||
this.pomRefId = pomRefId;
|
||||
}
|
||||
|
||||
public LocalRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void addLocalRepository( LocalRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,24 +47,15 @@ public class DependenciesTask
|
|||
{
|
||||
private List dependencies = new ArrayList();
|
||||
|
||||
private LocalRepository localRepository;
|
||||
|
||||
private List remoteRepositories = new ArrayList();
|
||||
|
||||
private String pathId;
|
||||
|
||||
private String filesetId;
|
||||
|
||||
private Pom pom;
|
||||
|
||||
public void execute()
|
||||
{
|
||||
if ( localRepository == null )
|
||||
{
|
||||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
|
@ -72,6 +63,7 @@ public class DependenciesTask
|
|||
|
||||
List dependencies = this.dependencies;
|
||||
|
||||
Pom pom = buildPom( projectBuilder, localRepo );
|
||||
if ( pom != null )
|
||||
{
|
||||
if ( !dependencies.isEmpty() )
|
||||
|
@ -79,8 +71,6 @@ public class DependenciesTask
|
|||
throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
|
||||
}
|
||||
|
||||
pom.initialise( projectBuilder, localRepo );
|
||||
|
||||
dependencies = pom.getDependencies();
|
||||
|
||||
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
|
||||
|
@ -120,7 +110,7 @@ public class DependenciesTask
|
|||
}
|
||||
|
||||
FileList fileList = new FileList();
|
||||
fileList.setDir( localRepository.getLocation() );
|
||||
fileList.setDir( getLocalRepository().getLocation() );
|
||||
|
||||
FileSet fileSet = new FileSet();
|
||||
fileSet.setDir( fileList.getDir( getProject() ) );
|
||||
|
@ -196,16 +186,6 @@ public class DependenciesTask
|
|||
dependencies.add( dependency );
|
||||
}
|
||||
|
||||
public LocalRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void addLocalRepository( LocalRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
|
||||
public String getPathId()
|
||||
{
|
||||
return pathId;
|
||||
|
@ -225,14 +205,4 @@ public class DependenciesTask
|
|||
{
|
||||
this.filesetId = filesetId;
|
||||
}
|
||||
|
||||
public Pom getPom()
|
||||
{
|
||||
return pom;
|
||||
}
|
||||
|
||||
public void addPom( Pom pom )
|
||||
{
|
||||
this.pom = pom;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,29 +37,22 @@ import java.io.File;
|
|||
public class DeployTask
|
||||
extends AbstractArtifactTask
|
||||
{
|
||||
private Pom pom;
|
||||
|
||||
private LocalRepository localRepository;
|
||||
|
||||
private RemoteRepository remoteRepository;
|
||||
|
||||
private File file;
|
||||
|
||||
public void execute()
|
||||
{
|
||||
if ( localRepository == null )
|
||||
{
|
||||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
|
||||
if ( pom == null )
|
||||
{
|
||||
throw new BuildException( "A POM element is required to deploy to the repository" );
|
||||
}
|
||||
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
pom.initialise( (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ), localRepo );
|
||||
|
||||
if ( remoteRepository == null )
|
||||
{
|
||||
if ( pom.getDistributionManagement() == null || pom.getDistributionManagement().getRepository() == null )
|
||||
|
@ -102,26 +95,6 @@ public class DeployTask
|
|||
}
|
||||
}
|
||||
|
||||
public Pom getPom()
|
||||
{
|
||||
return pom;
|
||||
}
|
||||
|
||||
public void addPom( Pom pom )
|
||||
{
|
||||
this.pom = pom;
|
||||
}
|
||||
|
||||
public LocalRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void addLocalRepository( LocalRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
|
||||
public RemoteRepository getRemoteRepository()
|
||||
{
|
||||
return remoteRepository;
|
||||
|
|
|
@ -38,21 +38,14 @@ import java.io.File;
|
|||
public class InstallTask
|
||||
extends AbstractArtifactTask
|
||||
{
|
||||
private Pom pom;
|
||||
|
||||
private LocalRepository localRepository;
|
||||
|
||||
private File file;
|
||||
|
||||
public void execute()
|
||||
{
|
||||
if ( localRepository == null )
|
||||
{
|
||||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
pom.initialise( (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ), localRepo );
|
||||
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
Pom pom = buildPom( builder, localRepo );
|
||||
|
||||
Artifact artifact = new DefaultArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
|
||||
pom.getPackaging() );
|
||||
|
@ -82,27 +75,7 @@ public class InstallTask
|
|||
throw new BuildException( "Error installing artifact", e );
|
||||
}
|
||||
}
|
||||
|
||||
public Pom getPom()
|
||||
{
|
||||
return pom;
|
||||
}
|
||||
|
||||
public void addPom( Pom pom )
|
||||
{
|
||||
this.pom = pom;
|
||||
}
|
||||
|
||||
public LocalRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void addLocalRepository( LocalRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
|
||||
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
|
|
|
@ -102,7 +102,7 @@ public class Pom
|
|||
}
|
||||
}
|
||||
|
||||
private MavenProject getMavenProject()
|
||||
protected MavenProject getMavenProject()
|
||||
{
|
||||
return getInstance().mavenProject;
|
||||
}
|
||||
|
@ -202,12 +202,10 @@ public class Pom
|
|||
return getMavenProject().getPackaging();
|
||||
} //-- String getPackaging()
|
||||
|
||||
/* TODO: requires newer maven-core
|
||||
public java.util.List getPluginRepositories()
|
||||
{
|
||||
return getModel().getPluginRepositories();
|
||||
return getMavenProject().getPluginRepositories();
|
||||
} //-- java.util.List getPluginRepositories()
|
||||
*/
|
||||
|
||||
public Reports getReports()
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<typedef name="dependencies" classname="org.apache.maven.artifact.ant.DependenciesTask"/>
|
||||
<typedef name="install" classname="org.apache.maven.artifact.ant.InstallTask"/>
|
||||
<typedef name="deploy" classname="org.apache.maven.artifact.ant.DeployTask"/>
|
||||
<typedef name="setProperty" classname="org.apache.maven.artifact.ant.SetPropertyTask"/>
|
||||
|
||||
<!-- Types -->
|
||||
<typedef name="localRepository" classname="org.apache.maven.artifact.ant.LocalRepository"/>
|
||||
|
|
Loading…
Reference in New Issue