moved to its own tree

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@506345 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-02-12 07:29:48 +00:00
parent 2cc41c5e6c
commit 971b2dee8a
19 changed files with 0 additions and 2381 deletions

View File

@ -1,112 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2005-2006 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.
-->
<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/maven-v4_0_0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-artifact-ant</artifactId>
<name>Maven Tasks for Ant</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<descriptor>src/main/assembly/dep.xml</descriptor>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-error-diagnostics</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +0,0 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.test</groupId>
<artifactId>sample-build-test</artifactId>
<version>2.0-beta-4-SNAPSHOT</version>
</project>

View File

@ -1,218 +0,0 @@
<project name="foo" default="foo" xmlns:artifact="urn:maven-artifact-ant">
<!--
<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.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
OR
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 update the version! -->
<path id="maven.classpath">
<pathelement location="target/maven-artifact-ant-2.1-SNAPSHOT-dep.jar" />
</path>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
<classpath refid="maven.classpath"/>
</typedef>
<artifact:localRepository id="local.repository" location="${basedir}/target/local-repo" layout="default"/>
<artifact:remoteRepository id="deploy.repository" url="file://localhost/${basedir}/target/deployment-repo" layout="legacy"/>
<artifact:pom file="pom.xml" id="maven.project"/>
</target>
<target name="test-no-deps" depends="initTaskDefs">
<artifact:dependencies filesetId="runtime.fileset">
</artifact:dependencies>
<copy todir="target/test-no-deps" verbose="true">
<fileset refid="runtime.fileset"/>
</copy>
</target>
<target name="test-bad-dep" depends="initTaskDefs">
<artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset">
<dependency groupId="foo" artifactId="foo" version="1.0-alpha-2"/>
</artifact:dependencies>
</target>
<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="test-legacy-pom" depends="initTaskDefs">
<artifact:dependencies>
<dependency groupId="geronimo-spec" artifactId="geronimo-spec-javamail" version="1.3.1-rc5" />
<localRepository location="${basedir}/target/local-repo-legacy" />
<remoteRepository url="http://repo1.maven.org/maven" layout="legacy" id="central" />
</artifact:dependencies>
</target>
<target name="foo" depends="initTaskDefs">
<artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4">
<exclusion groupId="junit" artifactId="junit"/>
</dependency>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
<dependency groupId="org.apache.maven" artifactId="maven-core-it-support-old-location" version="1.1"/>
<localRepository refid="local.repository"/>
<remoteRepository url="http://snapshots.maven.codehaus.org/maven2">
<snapshots enabled="true"/>
<releases enabled="false"/>
</remoteRepository>
</artifact:dependencies>
<copy todir="target/files">
<fileset refid="dependency.fileset"/>
</copy>
<artifact:dependencies filesetId="my.dependency.fileset" verbose="true">
<pom refid="maven.project"/>
</artifact:dependencies>
<copy todir="target/my-dependencies">
<fileset refid="my.dependency.fileset"/>
</copy>
<artifact:dependencies filesetId="my.compile.dependency.fileset" useScope="compile">
<pom refid="maven.project"/>
</artifact:dependencies>
<copy todir="target/my-compile-dependencies">
<fileset refid="my.compile.dependency.fileset"/>
</copy>
<copy todir="target/my-compile-dependencies/WEB-INF/lib">
<fileset refid="my.compile.dependency.fileset"/>
<mapper type="flatten" />
</copy>
<antcall target="test-deploy" />
<antcall target="test-legacy-pom" />
</target>
<target name="test-deploy-spaces" depends="initTaskDefs">
<artifact:install-provider artifactId="wagon-ssh" version="1.0-alpha-5"/>
<echo file="target/test file.txt">dummy</echo>
<artifact:deploy file="target/test file.txt">
<remoteRepository url="scp://localhost/tmp/deployment-repo" />
<pom refid="maven.project"/>
</artifact:deploy>
</target>
<target name="test-deploy" depends="initTaskDefs">
<property name="outJar" value="${maven.project.build.directory}/${maven.project.build.finalName}.jar"/>
<artifact:install file="${outJar}">
<pom refid="maven.project"/>
</artifact:install>
<echo>Note: only works on snapshots!</echo>
<artifact:deploy file="${outJar}">
<remoteSnapshotRepository refid="deploy.repository"/>
<pom refid="maven.project"/>
</artifact:deploy>
<artifact:install-provider artifactId="wagon-ssh" version="1.0-alpha-5"/>
<artifact:deploy file="${outJar}">
<remoteRepository url="scp://localhost/tmp/deployment-repo">
<authentication username="brett" privateKey="${user.home}/.ssh/id_dsa"/>
</remoteRepository>
<pom refid="maven.project"/>
</artifact:deploy>
</target>
<target name="test-scm" depends="initTaskDefs">
<echo>Testing SCM Wagon</echo>
<mkdir dir="target"/>
<pathconvert targetos="unix" property="repo.path.unix">
<map from="c:" to=""/>
<path>
<pathelement location="${basedir}/target/deployment-repo-scm"/>
</path>
</pathconvert>
<property name="scm.url" value="file://${repo.path.unix}"/>
<delete dir="${repo.path.unix}"/>
<exec executable="svnadmin" failonerror="true">
<arg line="create ${repo.path.unix}"/>
</exec>
<artifact:localRepository id="local.repository" location="${basedir}/target/local-repo" layout="default"/>
<artifact:remoteRepository id="deploy.repository" url="scm:svn:${scm.url}" layout="default"/>
<artifact:dependencies pathId="dependency.classpath">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4"/>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
<exec executable="svn" dir="${basedir}/target/local-repo" failonerror="true">
<arg line="import -m 'import' ${scm.url}"/>
</exec>
<delete dir="${basedir}/target/local-repo-scm"/>
<!-- Could the SCM provider initialise this? -->
<exec executable="svn" dir="${basedir}/target" failonerror="true">
<arg line="co ${scm.url} -N local-repo-scm"/>
</exec>
<artifact:localRepository id="local.repository.scm" location="${basedir}/target/local-repo-scm" layout="default"/>
<artifact:dependencies pathId="dependency.classpath.scm">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4"/>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
<localRepository refid="local.repository.scm"/>
<remoteRepository refid="deploy.repository"/>
</artifact:dependencies>
<property name="outJar" value="${maven.project.build.directory}/${maven.project.build.finalName}.jar"/>
<artifact:deploy file="${outJar}">
<localRepository refid="local.repository.scm"/>
<remoteRepository refid="deploy.repository"/>
<pom refid="maven.project"/>
</artifact:deploy>
</target>
<target name="test-invalid-pom-ref" depends="initTaskDefs">
<artifact:dependencies>
<pom refid="invalid-ref" />
</artifact:dependencies>
</target>
<target name="test-no-dist-mgmt" depends="initTaskDefs">
<artifact:deploy file="sample-build-test.pom">
<pom file="sample-build-test.pom" />
<remoteRepository refid="deploy.repository" />
</artifact:deploy>
</target>
</project>

View File

@ -1,20 +0,0 @@
<assembly>
<!-- TODO: a jarjar format would be better -->
<id>dep</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>ant:ant</exclude>
<!-- TODO: remove when all references are moved to the new group -->
<exclude>plexus:plexus-utils</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

View File

@ -1,463 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
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.usability.diagnostics.ErrorDiagnostics;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* Base class for artifact tasks.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public abstract class AbstractArtifactTask
extends Task
{
private Settings settings;
private PlexusContainer container;
private Pom pom;
private String pomRefId;
private LocalRepository localRepository;
protected ArtifactRepository createLocalArtifactRepository()
{
if ( localRepository == null )
{
localRepository = getDefaultLocalRepository();
}
ArtifactRepositoryLayout repositoryLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, localRepository.getLayout() );
return new DefaultArtifactRepository( "local", "file://" + localRepository.getLocation(), repositoryLayout );
}
protected ArtifactRepository createRemoteArtifactRepository( RemoteRepository repository )
{
ArtifactRepositoryLayout repositoryLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, repository.getLayout() );
WagonManager manager = (WagonManager) lookup( WagonManager.ROLE );
Authentication authentication = repository.getAuthentication();
if ( authentication != null )
{
manager.addAuthenticationInfo( repository.getId(), authentication.getUserName(), authentication.getPassword(),
authentication.getPrivateKey(), authentication.getPassphrase() );
}
Proxy proxy = repository.getProxy();
if ( proxy != null )
{
manager.addProxy( proxy.getType(), proxy.getHost(), proxy.getPort(), proxy.getUserName(),
proxy.getPassword(), proxy.getNonProxyHosts() );
}
ArtifactRepositoryFactory repositoryFactory = null;
ArtifactRepository artifactRepository;
try
{
repositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repository.getSnapshots() );
ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repository.getReleases() );
artifactRepository = repositoryFactory.createArtifactRepository( repository.getId(), repository.getUrl(),
repositoryLayout, snapshots, releases );
}
finally
{
try
{
getContainer().release( repositoryFactory );
}
catch ( ComponentLifecycleException e )
{
// TODO: Warn the user, or not?
}
}
return artifactRepository;
}
private static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy )
{
boolean enabled = true;
String updatePolicy = null;
String checksumPolicy = null;
if ( policy != null )
{
enabled = policy.isEnabled();
if ( policy.getUpdatePolicy() != null )
{
updatePolicy = policy.getUpdatePolicy();
}
if ( policy.getChecksumPolicy() != null )
{
checksumPolicy = policy.getChecksumPolicy();
}
}
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
}
protected LocalRepository getDefaultLocalRepository()
{
Settings settings = getSettings();
LocalRepository localRepository = new LocalRepository();
localRepository.setId( "local" );
localRepository.setLocation( new File( settings.getLocalRepository() ) );
return localRepository;
}
protected synchronized Settings getSettings()
{
if ( settings == null )
{
settings = new Settings();
File settingsFile = new File( System.getProperty( "user.home" ), ".ant/settings.xml" );
if ( !settingsFile.exists() )
{
settingsFile = new File( System.getProperty( "user.home" ), ".m2/settings.xml" );
}
if ( settingsFile.exists() )
{
FileReader reader = null;
try
{
reader = new FileReader( settingsFile );
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
settings = modelReader.read( reader );
}
catch ( IOException e )
{
log( "Error reading settings file '" + settingsFile + "' - ignoring. Error was: " + e.getMessage(),
Project.MSG_WARN );
}
catch ( XmlPullParserException e )
{
log( "Error parsing settings file '" + settingsFile + "' - ignoring. Error was: " + e.getMessage(),
Project.MSG_WARN );
}
finally
{
IOUtil.close( reader );
}
}
if ( StringUtils.isEmpty( settings.getLocalRepository() ) )
{
String location = new File( System.getProperty( "user.home" ), ".m2/repository" ).getAbsolutePath();
settings.setLocalRepository( location );
}
}
return settings;
}
protected RemoteRepository createAntRemoteRepository( org.apache.maven.model.Repository pomRepository )
{
RemoteRepository r = createAntRemoteRepositoryBase( pomRepository );
if ( pomRepository.getSnapshots() != null )
{
r.addSnapshots( convertRepositoryPolicy( pomRepository.getSnapshots() ) );
}
if ( pomRepository.getReleases() != null )
{
r.addReleases( convertRepositoryPolicy( pomRepository.getReleases() ) );
}
return r;
}
protected RemoteRepository createAntRemoteRepositoryBase( org.apache.maven.model.RepositoryBase pomRepository )
{
// TODO: actually, we need to not funnel this through the ant repository - we should pump settings into wagon
// manager at the start like m2 does, and then match up by repository id
// As is, this could potentially cause a problem with 2 remote repositories with different authentication info
RemoteRepository r = new RemoteRepository();
r.setId( pomRepository.getId() );
r.setUrl( pomRepository.getUrl() );
r.setLayout( pomRepository.getLayout() );
Server server = getSettings().getServer( pomRepository.getId() );
if ( server != null )
{
r.addAuthentication( new Authentication( server ) );
}
org.apache.maven.settings.Proxy proxy = getSettings().getActiveProxy();
if ( proxy != null )
{
r.addProxy( new Proxy( proxy ) );
}
Mirror mirror = getSettings().getMirrorOf( pomRepository.getId() );
if ( mirror != null )
{
r.setUrl( mirror.getUrl() );
}
return r;
}
protected Object lookup( String role )
{
try
{
return getContainer().lookup( role );
}
catch ( ComponentLookupException e )
{
throw new BuildException( "Unable to find component: " + role, e );
}
}
protected Object lookup( String role, String roleHint )
{
try
{
return getContainer().lookup( role, roleHint );
}
catch ( ComponentLookupException e )
{
throw new BuildException( "Unable to find component: " + role + "[" + roleHint + "]", e );
}
}
protected static RemoteRepository getDefaultRemoteRepository()
{
// TODO: could we utilise the super POM for this?
RemoteRepository remoteRepository = new RemoteRepository();
remoteRepository.setId( "central" );
remoteRepository.setUrl( "http://repo1.maven.org/maven2" );
RepositoryPolicy snapshots = new RepositoryPolicy();
snapshots.setEnabled( false );
remoteRepository.addSnapshots( snapshots );
return remoteRepository;
}
protected synchronized PlexusContainer getContainer()
{
if ( container == null )
{
container = (PlexusContainer) getProject().getReference( PlexusContainer.class.getName() );
if ( container == null )
{
try
{
ClassWorld classWorld = new ClassWorld();
classWorld.newRealm( "plexus.core", getClass().getClassLoader() );
container = new DefaultPlexusContainer( null, null, 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( PlexusContainer.class.getName(),container );
}
}
return container;
}
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;
}
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 diagnoseError( Throwable error )
{
try
{
ErrorDiagnostics diagnostics = (ErrorDiagnostics) container.lookup( ErrorDiagnostics.ROLE );
StringBuffer message = new StringBuffer();
message.append( "An error has occurred while processing the Maven artifact tasks.\n" );
message.append( " Diagnosis:\n\n" );
message.append( diagnostics.diagnose( error ) );
message.append( "\n\n" );
log( message.toString(), Project.MSG_INFO );
}
catch ( ComponentLookupException e )
{
log( "Failed to retrieve error diagnoser.", Project.MSG_DEBUG );
}
}
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;
}
public void setProfiles( String profiles )
{
if ( profiles != null )
{
// TODO: not sure this is the best way to do this...
// System.setProperty( ProfileActivationUtils.ACTIVE_PROFILE_IDS, profiles );
}
}
protected Artifact createArtifact( Pom pom )
{
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
pom.getPackaging() );
}
private static RepositoryPolicy convertRepositoryPolicy( org.apache.maven.model.RepositoryPolicy pomRepoPolicy )
{
RepositoryPolicy policy = new RepositoryPolicy();
policy.setEnabled( pomRepoPolicy.isEnabled() );
policy.setUpdatePolicy( pomRepoPolicy.getUpdatePolicy() );
return policy;
}
/**
* @noinspection RefusedBequest
*/
public void execute()
{
try
{
doExecute();
}
catch ( BuildException e )
{
diagnoseError( e );
throw e;
}
}
protected abstract void doExecute();
}

View File

@ -1,67 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.wagon.events.TransferEvent;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
/**
* Log wagon events in the ant tasks
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class AntDownloadMonitor
extends ProjectComponent
implements TransferListener
{
public void debug( String s )
{
log( s, Project.MSG_DEBUG );
}
public void transferCompleted( TransferEvent event )
{
}
public void transferError( TransferEvent event )
{
log( event.getException().getMessage(), Project.MSG_ERR );
}
public void transferInitiated( TransferEvent event )
{
String message = event.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
log( message + ": " + event.getResource().getName() );
}
public void transferProgress( TransferEvent event, byte[] bytes, int i )
{
}
public void transferStarted( TransferEvent event )
{
long contentLength = event.getResource().getContentLength();
if ( contentLength > 0 )
{
log( "Transferring " + ( contentLength / 1024 ) + "K" );
}
}
}

View File

@ -1,109 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.resolver.ResolutionListener;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.tools.ant.Project;
/**
* Show resolution information in Ant.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class AntResolutionListener
implements ResolutionListener
{
private String indent = "";
private final Project project;
public AntResolutionListener( Project project )
{
this.project = project;
}
public void testArtifact( Artifact node )
{
}
public void startProcessChildren( Artifact artifact )
{
indent += " ";
}
public void endProcessChildren( Artifact artifact )
{
indent = indent.substring( 2 );
}
public void includeArtifact( Artifact artifact )
{
project.log( indent + artifact + " (selected)" );
}
public void omitForNearer( Artifact omitted, Artifact kept )
{
project.log( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
}
public void omitForCycle( Artifact omitted )
{
project.log( indent + omitted + " (removed - causes a cycle in the graph)" );
}
public void updateScope( Artifact artifact, String scope )
{
project.log( indent + artifact + " (setting scope to: " + scope + ")" );
}
public void updateScopeCurrentPom( Artifact artifact, String scope )
{
project.log( indent + artifact + " (not setting scope to: " + scope + "; local scope " + artifact.getScope() +
" wins)" );
}
public void selectVersionFromRange( Artifact artifact )
{
project.log( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: " +
artifact.getVersionRange() + ")" );
}
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
{
project.log( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: " +
replacement.getVersionRange() + " to: " + newRange + " )" );
}
public void manageArtifact( Artifact artifact, Artifact replacement )
{
String msg = indent + artifact;
msg += " (";
if ( replacement.getVersion() != null )
{
msg += "applying version: " + replacement.getVersion() + ";";
}
if ( replacement.getScope() != null )
{
msg += "applying scope: " + replacement.getScope();
}
msg += ")";
project.log( msg );
}
}

View File

@ -1,43 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.wagon.authentication.AuthenticationInfo;
import org.apache.maven.settings.Server;
/**
* Ant Wrapper for wagon authentication.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class Authentication
extends AuthenticationInfo
{
public Authentication()
{
super();
}
public Authentication( Server server )
{
setUserName( server.getUsername() );
setPassword( server.getPassword() );
setPassphrase( server.getPassphrase() );
setPrivateKey( server.getPrivateKey() );
}
}

View File

@ -1,295 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Dependencies task, using maven-artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class DependenciesTask
extends AbstractArtifactTask
{
private List dependencies = new ArrayList();
private List remoteRepositories = new ArrayList();
private String pathId;
private String filesetId;
private String useScope;
private String type;
private boolean verbose;
protected void doExecute()
{
ArtifactRepository localRepo = createLocalArtifactRepository();
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
List dependencies = this.dependencies;
Pom pom = buildPom( projectBuilder, localRepo );
if ( pom != null )
{
if ( !dependencies.isEmpty() )
{
throw new BuildException( "You cannot specify both dependencies and a pom in the dependencies task" );
}
dependencies = pom.getDependencies();
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
{
Repository pomRepository = (Repository) i.next();
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();
}
if ( dependencies.isEmpty() )
{
log( "There were no dependencies specified", Project.MSG_WARN );
}
log( "Resolving dependencies...", Project.MSG_VERBOSE );
WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
wagonManager.setDownloadMonitor( new AntDownloadMonitor() );
ArtifactResolutionResult result;
Set artifacts;
try
{
artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
Artifact pomArtifact = artifactFactory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom
.getVersion(), pom.getPackaging() );
List listeners = Collections.EMPTY_LIST;
if ( verbose )
{
listeners = Collections.singletonList( new AntResolutionListener( getProject() ) );
}
List remoteRepositories = getRemoteRepositories();
RemoteRepository remoteRepository = getDefaultRemoteRepository();
remoteRepositories.add( remoteRepository );
List remoteArtifactRepositories = createRemoteArtifactRepositories( remoteRepositories );
// TODO: managed dependencies
Map managedDependencies = Collections.EMPTY_MAP;
ArtifactFilter filter = null;
if ( useScope != null )
{
filter = new ScopeArtifactFilter( useScope );
}
if ( type != null )
{
TypeArtifactFilter typeArtifactFilter = new TypeArtifactFilter( type );
if ( filter != null )
{
AndArtifactFilter andFilter = new AndArtifactFilter();
andFilter.add( filter );
andFilter.add( typeArtifactFilter );
filter = andFilter;
}
else
{
filter = typeArtifactFilter;
}
}
result = resolver.resolveTransitively( artifacts, pomArtifact, managedDependencies, localRepo,
remoteArtifactRepositories, metadataSource, filter, listeners );
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new BuildException( "Dependency not found: " + e.getMessage(), e );
}
catch ( InvalidDependencyVersionException e )
{
throw new BuildException( e.getMessage(), e );
}
if ( pathId != null && getProject().getReference( pathId ) != null )
{
throw new BuildException( "Reference ID " + pathId + " already exists" );
}
if ( filesetId != null && getProject().getReference( filesetId ) != null )
{
throw new BuildException( "Reference ID " + filesetId + " already exists" );
}
FileList fileList = new FileList();
fileList.setDir( getLocalRepository().getLocation() );
FileSet fileSet = new FileSet();
fileSet.setDir( fileList.getDir( getProject() ) );
if ( result.getArtifacts().isEmpty() )
{
fileSet.createExclude().setName( "**/**" );
}
else
{
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact artifact = (Artifact) i.next();
String filename = localRepo.pathOf( artifact );
FileList.FileName file = new FileList.FileName();
file.setName( filename );
fileList.addConfiguredFile( file );
fileSet.createInclude().setName( filename );
}
}
if ( pathId != null )
{
Path path = new Path( getProject() );
path.addFilelist( fileList );
getProject().addReference( pathId, path );
}
if ( filesetId != null )
{
getProject().addReference( filesetId, fileSet );
}
}
private List createRemoteArtifactRepositories( List remoteRepositories )
{
List list = new ArrayList();
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
list.add( createRemoteArtifactRepository( (RemoteRepository) i.next() ) );
}
return list;
}
public List getRemoteRepositories()
{
return remoteRepositories;
}
public void addRemoteRepository( RemoteRepository remoteRepository )
{
remoteRepositories.add( remoteRepository );
}
public List getDependencies()
{
return dependencies;
}
public void addDependency( Dependency dependency )
{
dependencies.add( dependency );
}
public String getPathId()
{
return pathId;
}
public void setPathId( String pathId )
{
this.pathId = pathId;
}
public String getFilesetId()
{
return filesetId;
}
public void setFilesetId( String filesetId )
{
this.filesetId = filesetId;
}
public void setVerbose( boolean verbose )
{
this.verbose = verbose;
}
public void setUseScope( String useScope )
{
this.useScope = useScope;
}
public void setType( String type )
{
this.type = type;
}
}

View File

@ -1,150 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.tools.ant.BuildException;
import java.io.File;
/**
* Deploy task, using maven-artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class DeployTask
extends AbstractArtifactTask
{
private RemoteRepository remoteRepository;
private RemoteRepository remoteSnapshotRepository;
private File file;
protected void doExecute()
{
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" );
}
Artifact artifact = createArtifact( pom );
DistributionManagement distributionManagement = pom.getDistributionManagement();
if ( remoteSnapshotRepository == null && remoteRepository == null )
{
if ( distributionManagement != null )
{
if ( distributionManagement.getSnapshotRepository() != null )
{
remoteSnapshotRepository = createAntRemoteRepositoryBase( distributionManagement
.getSnapshotRepository() );
}
if ( distributionManagement.getRepository() != null )
{
remoteRepository = createAntRemoteRepositoryBase( distributionManagement.getRepository() );
}
}
}
if ( remoteSnapshotRepository == null )
{
remoteSnapshotRepository = remoteRepository;
}
ArtifactRepository deploymentRepository;
if ( artifact.isSnapshot() && remoteSnapshotRepository != null )
{
deploymentRepository = createRemoteArtifactRepository( remoteSnapshotRepository );
}
else if ( remoteRepository != null )
{
deploymentRepository = createRemoteArtifactRepository( remoteRepository );
}
else
{
throw new BuildException(
"A distributionManagement element or remoteRepository element is required to deploy" );
}
// Deploy the POM
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
if ( !isPomArtifact )
{
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
artifact.addMetadata( metadata );
}
log( "Deploying to " + deploymentRepository.getUrl() );
ArtifactDeployer deployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
try
{
if ( !isPomArtifact )
{
deployer.deploy( file, artifact, deploymentRepository, localRepo );
}
else
{
deployer.deploy( pom.getFile(), artifact, deploymentRepository, localRepo );
}
}
catch ( ArtifactDeploymentException e )
{
throw new BuildException(
"Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
}
}
public RemoteRepository getRemoteRepository()
{
return remoteRepository;
}
public void addRemoteSnapshotRepository( RemoteRepository remoteSnapshotRepository )
{
this.remoteSnapshotRepository = remoteSnapshotRepository;
}
public void addRemoteRepository( RemoteRepository remoteRepository )
{
this.remoteRepository = remoteRepository;
}
public File getFile()
{
return file;
}
public void setFile( File file )
{
this.file = file;
}
}

View File

@ -1,86 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.tools.ant.BuildException;
import java.io.File;
/**
* Install task, using maven-artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo should be able to incorporate into the install mojo?
*/
public class InstallTask
extends AbstractArtifactTask
{
private File file;
protected void doExecute()
{
ArtifactRepository localRepo = createLocalArtifactRepository();
MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
Pom pom = buildPom( builder, localRepo );
Artifact artifact = createArtifact( pom );
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
if ( !isPomArtifact )
{
ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
artifact.addMetadata( metadata );
}
ArtifactInstaller installer = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
try
{
if ( !isPomArtifact )
{
installer.install( file, artifact, localRepo );
}
else
{
installer.install( pom.getFile(), artifact, localRepo );
}
}
catch ( ArtifactInstallationException e )
{
throw new BuildException(
"Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
}
}
public File getFile()
{
return file;
}
public void setFile( File file )
{
this.file = file;
}
}

View File

@ -1,131 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.tools.ant.BuildException;
import org.codehaus.plexus.PlexusContainerException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Ant Wrapper for wagon provider installation.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class InstallWagonProviderTask
extends AbstractArtifactTask
{
private String artifactId;
private String version;
private static final String WAGON_GROUP_ID = "org.apache.maven.wagon";
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
public void doExecute()
throws BuildException
{
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
ArtifactRepository artifactRepository = createRemoteArtifactRepository( getDefaultRemoteRepository() );
List remoteRepositories = Collections.singletonList( artifactRepository );
VersionRange versionRange;
try
{
versionRange = VersionRange.createFromVersionSpec( version );
}
catch ( InvalidVersionSpecificationException e )
{
throw new BuildException( "Unable to get extension '" +
ArtifactUtils.versionlessKey( WAGON_GROUP_ID, artifactId ) + "' because version '" + version +
" is invalid: " + e.getMessage(), e );
}
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
Artifact providerArtifact = factory.createExtensionArtifact( WAGON_GROUP_ID, artifactId, versionRange );
ArtifactResolutionResult result;
try
{
result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
createArtifact( createDummyPom() ), createLocalArtifactRepository(),
remoteRepositories, metadataSource, null );
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Error downloading wagon provider from the remote repository: " + e.getMessage(),
e );
}
catch ( ArtifactNotFoundException e )
{
throw new BuildException( "Unable to locate wagon provider in remote repository: " + e.getMessage(), e );
}
log( "Installing provider: " + providerArtifact );
try
{
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
getContainer().addJarResource( a.getFile() );
}
}
catch ( PlexusContainerException e )
{
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
}
}
}

View File

@ -1,41 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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 java.io.File;
/**
* Local repository type.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class LocalRepository
extends Repository
{
private File location;
public File getLocation()
{
return ( (LocalRepository) getInstance() ).location;
}
public void setLocation( File location )
{
this.location = location;
}
}

View File

@ -1,346 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.PropertyHelper;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
import java.io.File;
/**
* A POM typedef.
*
* Also an Ant Task that registers a handler called POMPropertyHelper
* that intercepts all calls to property value resolution and replies instead
* of Ant to properties that start with the id of the pom.
*
* Example:
* ${maven.project.artifactId}
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a>
* @version $Id$
*/
public class Pom
extends AbstractArtifactTask
{
private String refid;
private String antId;
private MavenProject mavenProject;
private File file;
/**
* The property interceptor.
*/
private final POMPropertyHelper helper = new POMPropertyHelper();
public String getRefid()
{
return refid;
}
public void setRefid( String refid )
{
this.refid = refid;
}
public void setId( String id )
{
this.antId = id;
}
protected Pom getInstance()
{
Pom instance = this;
if ( refid != null )
{
instance = (Pom) getProject().getReference( refid );
if ( instance == null )
{
throw new BuildException( "Invalid reference: '" + refid + "'" );
}
}
return instance;
}
public void setMavenProject( MavenProject mavenProject )
{
getInstance().mavenProject = mavenProject;
}
public File getFile()
{
return getInstance().file;
}
public void setFile( File file )
{
this.file = file;
}
void initialise( MavenProjectBuilder builder, ArtifactRepository localRepository )
{
if ( mavenProject != null )
{
log( "POM is already initialized for: " + mavenProject.getId(), Project.MSG_DEBUG );
return;
}
// TODO: should this be in execute() too? Would that work when it is used as a type?
if ( file != null )
{
try
{
// TODO: should the profiles be constructed and passed in here? From Ant, or perhaps settings?
mavenProject = builder.build( file, localRepository, null );
}
catch ( ProjectBuildingException e )
{
throw new BuildException( "Unable to build project: " + file, e );
}
}
else if ( refid != null )
{
getInstance().initialise( builder, localRepository );
}
}
protected MavenProject getMavenProject()
{
return getInstance().mavenProject;
}
public String getArtifactId()
{
return getMavenProject().getArtifactId();
} //-- String getArtifactId()
public Build getBuild()
{
return getMavenProject().getBuild();
} //-- Build getBuild()
public CiManagement getCiManagement()
{
return getMavenProject().getCiManagement();
} //-- CiManagement getCiManagement()
public java.util.List getContributors()
{
return getMavenProject().getContributors();
} //-- java.util.List getContributors()
public java.util.List getDependencies()
{
return getMavenProject().getDependencies();
} //-- java.util.List getDependencies()
public DependencyManagement getDependencyManagement()
{
return getMavenProject().getDependencyManagement();
} //-- DependencyManagement getDependencyManagement()
public String getDescription()
{
return getMavenProject().getDescription();
} //-- String getDescription()
public java.util.List getDevelopers()
{
return getMavenProject().getDevelopers();
} //-- java.util.List getDevelopers()
public DistributionManagement getDistributionManagement()
{
return getMavenProject().getDistributionManagement();
} //-- DistributionManagement getDistributionManagement()
public String getGroupId()
{
return getMavenProject().getGroupId();
} //-- String getGroupId()
public String getInceptionYear()
{
return getMavenProject().getInceptionYear();
} //-- String getInceptionYear()
public IssueManagement getIssueManagement()
{
return getMavenProject().getIssueManagement();
} //-- IssueManagement getIssueManagement()
public java.util.List getLicenses()
{
return getMavenProject().getLicenses();
} //-- java.util.List getLicenses()
public java.util.List getMailingLists()
{
return getMavenProject().getMailingLists();
} //-- java.util.List getMailingLists()
public String getModelVersion()
{
return getMavenProject().getModelVersion();
} //-- String getModelVersion()
public java.util.List getModules()
{
return getMavenProject().getModules();
} //-- java.util.List getModules()
public String getName()
{
return getMavenProject().getName();
} //-- String getName()
public Organization getOrganization()
{
return getMavenProject().getOrganization();
} //-- Organization getOrganization()
public String getPackaging()
{
return getMavenProject().getPackaging();
} //-- String getPackaging()
public java.util.List getPluginRepositories()
{
return getMavenProject().getPluginRepositories();
} //-- java.util.List getPluginRepositories()
public Reporting getReporting()
{
return getMavenProject().getReporting();
} //-- Reports getReports()
public java.util.List getRepositories()
{
return getMavenProject().getRepositories();
} //-- java.util.List getRepositories()
public Scm getScm()
{
return getMavenProject().getScm();
} //-- Scm getScm()
public String getUrl()
{
return getMavenProject().getUrl();
} //-- String getUrl()
public String getVersion()
{
return getMavenProject().getVersion();
} //-- String getVersion()
public String getId()
{
return getMavenProject().getId();
}
/**
* Registers POMPropertyHelper as a property interceptor
*/
protected void doExecute()
{
ArtifactRepository localRepo = createLocalArtifactRepository();
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
initialise( projectBuilder, localRepo );
Project project = getProject();
// Add a reference to this task/type
project.addReference( antId, this );
// Register the property interceptor
PropertyHelper phelper = PropertyHelper.getPropertyHelper( project );
helper.setNext( phelper.getNext() );
helper.setProject( project );
phelper.setNext( helper );
}
/**
* The property interceptor that handles the calls for "pom." properties
*/
private class POMPropertyHelper
extends PropertyHelper
{
/**
* The method that gets called by Ant with every request of property
*/
public Object getPropertyHook( String ns, String name, boolean user )
{
String prefix = antId + ".";
if ( !name.startsWith( prefix ) )
{
// pass on to next interceptor
return super.getPropertyHook( ns, name, user );
}
try
{
// else handle the property resolution
String expression = name.substring( prefix.length() );
return getPOMValue( "project." + expression );
}
catch ( Exception ex )
{
ex.printStackTrace();
return null;
}
}
private Object getPOMValue( String expression )
{
Object value = null;
try
{
value = ReflectionValueExtractor.evaluate( expression, getMavenProject() );
}
catch ( Exception e )
{
throw new BuildException( "Error extracting expression from POM", e );
}
return value;
}
}
}

View File

@ -1,44 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.wagon.proxy.ProxyInfo;
/**
* Ant Wrapper for wagon proxy.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class Proxy
extends ProxyInfo
{
public Proxy()
{
super();
}
public Proxy( org.apache.maven.settings.Proxy proxy )
{
setHost( proxy.getHost() );
setPort( proxy.getPort() );
setNonProxyHosts( proxy.getNonProxyHosts() );
setUserName( proxy.getUsername() );
setPassword( proxy.getPassword() );
setType( proxy.getProtocol() );
}
}

View File

@ -1,88 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.
*/
/**
* Remote repository type.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class RemoteRepository
extends Repository
{
private String url;
private Authentication authentication;
private Proxy proxy;
private RepositoryPolicy snapshots;
private RepositoryPolicy releases;
public String getUrl()
{
return ( (RemoteRepository) getInstance() ).url;
}
public void setUrl( String url )
{
this.url = url;
}
public Authentication getAuthentication()
{
return authentication;
}
public void addAuthentication( Authentication authentication )
{
this.authentication = authentication;
}
public void addProxy( Proxy proxy )
{
this.proxy = proxy;
}
public Proxy getProxy()
{
return ( (RemoteRepository) getInstance() ).proxy;
}
public RepositoryPolicy getSnapshots()
{
return ( (RemoteRepository) getInstance() ).snapshots;
}
public void addSnapshots( RepositoryPolicy snapshots )
{
this.snapshots = snapshots;
}
public RepositoryPolicy getReleases()
{
return ( (RemoteRepository) getInstance() ).releases;
}
public void addReleases( RepositoryPolicy releases )
{
this.releases = releases;
}
}

View File

@ -1,80 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
/**
* Base class for a repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public abstract class Repository
extends ProjectComponent
{
private String id;
private String refid;
private String layout = "default";
public String getId()
{
if ( getInstance().id == null )
{
getInstance().setId( "remote" );
}
return getInstance().id;
}
public void setId( String id )
{
this.id = id;
}
public String getRefid()
{
return refid;
}
public void setRefid( String refid )
{
this.refid = refid;
}
protected Repository getInstance()
{
Repository instance = this;
if ( refid != null )
{
instance = (Repository) getProject().getReference( refid );
}
return instance;
}
public String getLayout()
{
return getInstance().layout;
}
public void setLayout( String layout )
{
this.layout = layout;
}
}

View File

@ -1,65 +0,0 @@
package org.apache.maven.artifact.ant;
/*
* 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.tools.ant.ProjectComponent;
/**
* Base class for a repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class RepositoryPolicy
extends ProjectComponent
{
private String updatePolicy;
private String checksumPolicy;
private boolean enabled = true;
public String getUpdatePolicy()
{
return updatePolicy;
}
public void setUpdatePolicy( String updatePolicy )
{
this.updatePolicy = updatePolicy;
}
public boolean isEnabled()
{
return enabled;
}
public void setEnabled( boolean enabled )
{
this.enabled = enabled;
}
public String getChecksumPolicy()
{
return checksumPolicy;
}
public void setChecksumPolicy( String checksumPolicy )
{
this.checksumPolicy = checksumPolicy;
}
}

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<antlib>
<!-- Tasks -->
<taskdef name="dependencies" classname="org.apache.maven.artifact.ant.DependenciesTask"/>
<taskdef name="install" classname="org.apache.maven.artifact.ant.InstallTask"/>
<taskdef name="deploy" classname="org.apache.maven.artifact.ant.DeployTask"/>
<taskdef name="install-provider" classname="org.apache.maven.artifact.ant.InstallWagonProviderTask"/>
<!-- Types -->
<typedef name="localRepository" classname="org.apache.maven.artifact.ant.LocalRepository"/>
<typedef name="remoteRepository" classname="org.apache.maven.artifact.ant.RemoteRepository"/>
<typedef name="authentication" classname="org.apache.maven.artifact.ant.Authentication"/>
<typedef name="proxy" classname="org.apache.maven.artifact.ant.Proxy"/>
<!-- Tasks that are also types -->
<taskdef name="pom" classname="org.apache.maven.artifact.ant.Pom"/>
</antlib>