From df43187e32aa8a3aea7d7000dc4743799f4cd027 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Thu, 17 Nov 2005 16:46:16 +0000 Subject: [PATCH] PR: MNG-1466 Submitted By: Garrett Conaty Reviewed By: John Casey Applied patch, with small changes to the default repository id's to match those in Maven proper. "default-local" -> "local", and "default-remote" -> "central". This patch adds ID handling to repositories in the maven ant tasks. It should enable definition of multiple remote repositories in an Ant script. Thanks, Garrett and Konstantin, for the work! git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@345281 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/ant/AbstractArtifactTask.java | 7 +++++-- .../maven/artifact/ant/RemoteRepository.java | 6 +++--- .../apache/maven/artifact/ant/Repository.java | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java index 59eb4c3f48..fbdbdd888e 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java @@ -91,7 +91,7 @@ public abstract class AbstractArtifactTask Authentication authentication = repository.getAuthentication(); if ( authentication != null ) { - manager.addAuthenticationInfo( "remote", authentication.getUserName(), authentication.getPassword(), + manager.addAuthenticationInfo( repository.getId(), authentication.getUserName(), authentication.getPassword(), authentication.getPrivateKey(), authentication.getPassphrase() ); } @@ -113,7 +113,7 @@ public abstract class AbstractArtifactTask ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repository.getSnapshots() ); ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repository.getReleases() ); - artifactRepository = repositoryFactory.createArtifactRepository( "remote", repository.getUrl(), + artifactRepository = repositoryFactory.createArtifactRepository( repository.getId(), repository.getUrl(), repositoryLayout, snapshots, releases ); } finally @@ -157,6 +157,7 @@ public abstract class AbstractArtifactTask { Settings settings = getSettings(); LocalRepository localRepository = new LocalRepository(); + localRepository.setId( "local" ); localRepository.setLocation( new File( settings.getLocalRepository() ) ); return localRepository; } @@ -232,6 +233,7 @@ public abstract class AbstractArtifactTask // 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() ); @@ -283,6 +285,7 @@ public abstract class AbstractArtifactTask { // 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 ); diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java index db3974cd1e..3ab77f6dbd 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java @@ -62,12 +62,12 @@ public class RemoteRepository public Proxy getProxy() { - return proxy; + return ( (RemoteRepository) getInstance() ).proxy; } public RepositoryPolicy getSnapshots() { - return snapshots; + return ( (RemoteRepository) getInstance() ).snapshots; } public void addSnapshots( RepositoryPolicy snapshots ) @@ -77,7 +77,7 @@ public class RemoteRepository public RepositoryPolicy getReleases() { - return releases; + return ( (RemoteRepository) getInstance() ).releases; } public void addReleases( RepositoryPolicy releases ) diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/Repository.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/Repository.java index 177ef0fe70..2de3b4864a 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/Repository.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/Repository.java @@ -16,6 +16,7 @@ package org.apache.maven.artifact.ant; * limitations under the License. */ +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.ProjectComponent; /** @@ -27,10 +28,27 @@ import org.apache.tools.ant.ProjectComponent; public abstract class Repository extends ProjectComponent { + private String id; + private String refid; private String layout = "default"; + public String getId() + { + System.out.println("Repository.getId() == " + getInstance().id); + if (getInstance().id == null) + { + throw new BuildException("id must be specified for a repository definition"); + } + return getInstance().id; + } + + public void setId( String id ) + { + this.id = id; + } + public String getRefid() { return refid;