PR: MNG-145

add mirror notation to settings, introduce to bootstrap

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168282 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-05 06:24:07 +00:00
parent 6dca9007eb
commit 678919ad40
5 changed files with 239 additions and 50 deletions

View File

@ -242,16 +242,44 @@ public class MBoot
online = false; online = false;
} }
Repository localRepository = new Repository( mavenRepoLocal, Repository.LAYOUT_DEFAULT ); Repository localRepository = new Repository( "local", mavenRepoLocal, Repository.LAYOUT_DEFAULT );
if ( online ) if ( online )
{ {
downloader = new ArtifactDownloader( localRepository, Collections.EMPTY_LIST ); downloader = new ArtifactDownloader( localRepository );
if ( userModelReader.getActiveProxy() != null ) if ( userModelReader.getActiveProxy() != null )
{ {
Proxy proxy = userModelReader.getActiveProxy(); Proxy proxy = userModelReader.getActiveProxy();
downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() ); downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() );
} }
List remoteRepos = downloader.getRemoteRepositories();
List newRemoteRepos = new ArrayList();
for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
{
Repository repo = (Repository) i.next();
boolean foundMirror = false;
for ( Iterator j = userModelReader.getMirrors().iterator(); j.hasNext() && !foundMirror; )
{
Mirror m = (Mirror) j.next();
if ( m.getMirrorOf().equals( repo.getId() ) )
{
newRemoteRepos.add( new Repository( m.getId(), m.getUrl(), repo.getLayout() ) );
foundMirror = true;
}
}
if ( !foundMirror )
{
newRemoteRepos.add( repo );
}
}
downloader.setRemoteRepositories( newRemoteRepos );
System.out.println( "Using the following for your local repository: " + localRepository );
System.out.println( "Using the following for your remote repository: " + newRemoteRepos );
} }
String basedir = System.getProperty( "user.dir" ); String basedir = System.getProperty( "user.dir" );
@ -948,6 +976,8 @@ public class MBoot
class SettingsReader class SettingsReader
extends AbstractReader extends AbstractReader
{ {
private List mirrors = new ArrayList();
private List profiles = new ArrayList(); private List profiles = new ArrayList();
private Profile currentProfile = null; private Profile currentProfile = null;
@ -962,6 +992,8 @@ public class MBoot
private Proxy activeProxy = null; private Proxy activeProxy = null;
private Mirror currentMirror;
public Profile getActiveProfile() public Profile getActiveProfile()
{ {
return activeProfile; return activeProfile;
@ -1018,7 +1050,7 @@ public class MBoot
} }
else else
{ {
throw new SAXException( "Invalid proxy entry. Missing one or more " + "fields: {host, port}." ); throw new SAXException( "Invalid proxy entry. Missing one or more fields: {host, port}." );
} }
} }
else if ( currentProxy != null ) else if ( currentProxy != null )
@ -1054,6 +1086,41 @@ public class MBoot
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" ); throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
} }
} }
else if ( "mirror".equals( rawName ) )
{
if ( notEmpty( currentMirror.getId() ) && notEmpty( currentMirror.getMirrorOf() ) &&
notEmpty( currentMirror.getUrl() ) )
{
mirrors.add( currentMirror );
currentMirror = null;
}
else
{
throw new SAXException( "Invalid mirror entry. Missing one or more fields: {id, mirrorOf, url}." );
}
}
else if ( currentMirror != null )
{
if ( "id".equals( rawName ) )
{
currentMirror.setId( currentBody.toString().trim() );
}
else if ( "mirrorOf".equals( rawName ) )
{
currentMirror.setMirrorOf( currentBody.toString().trim() );
}
else if ( "url".equals( rawName ) )
{
currentMirror.setUrl( currentBody.toString().trim() );
}
else if ( "name".equals( rawName ) )
{
}
else
{
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
}
}
else if ( "settings".equals( rawName ) ) else if ( "settings".equals( rawName ) )
{ {
if ( profiles.size() == 1 ) if ( profiles.size() == 1 )
@ -1103,6 +1170,10 @@ public class MBoot
{ {
currentProxy = new Proxy(); currentProxy = new Proxy();
} }
else if ( "mirror".equals( rawName ) )
{
currentMirror = new Mirror();
}
} }
public void reset() public void reset()
@ -1111,8 +1182,15 @@ public class MBoot
this.activeProfile = null; this.activeProfile = null;
this.activeProxy = null; this.activeProxy = null;
this.currentProfile = null; this.currentProfile = null;
this.currentMirror = null;
this.profiles.clear(); this.profiles.clear();
this.proxies.clear(); this.proxies.clear();
this.mirrors.clear();
}
public List getMirrors()
{
return mirrors;
} }
} }
@ -1143,7 +1221,7 @@ public class MBoot
} }
} }
public class Proxy public static class Proxy
{ {
private boolean active; private boolean active;
@ -1206,4 +1284,42 @@ public class MBoot
} }
} }
public static class Mirror
{
private String id;
private String mirrorOf;
private String url;
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public void setMirrorOf( String mirrorOf )
{
this.mirrorOf = mirrorOf;
}
public void setUrl( String url )
{
this.url = url;
}
public String getMirrorOf()
{
return mirrorOf;
}
public String getUrl()
{
return url;
}
}
} }

View File

@ -9,19 +9,15 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ArtifactDownloader public class ArtifactDownloader
{ {
public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT"; public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
private List remoteRepos;
private boolean useTimestamp = true; private boolean useTimestamp = true;
private boolean ignoreErrors = false; private boolean ignoreErrors = false;
@ -40,11 +36,11 @@ public class ArtifactDownloader
private Map downloadedArtifacts = new HashMap(); private Map downloadedArtifacts = new HashMap();
public ArtifactDownloader( Repository localRepository, List remoteRepositories ) private List remoteRepositories;
public ArtifactDownloader( Repository localRepository )
throws Exception throws Exception
{ {
setRemoteRepos( remoteRepositories );
if ( localRepository == null ) if ( localRepository == null )
{ {
System.err.println( "local repository not specified" ); System.err.println( "local repository not specified" );
@ -53,9 +49,6 @@ public class ArtifactDownloader
} }
this.localRepository = localRepository; this.localRepository = localRepository;
System.out.println( "Using the following for your local repository: " + localRepository );
System.out.println( "Using the following for your remote repositories: " + remoteRepos );
} }
public void setProxy( String host, String port, String userName, String password ) public void setProxy( String host, String port, String userName, String password )
@ -115,28 +108,11 @@ public class ArtifactDownloader
return dep.getVersion().indexOf( SNAPSHOT_SIGNATURE ) >= 0; return dep.getVersion().indexOf( SNAPSHOT_SIGNATURE ) >= 0;
} }
private void setRemoteRepos( List repositories )
{
remoteRepos = new ArrayList();
if ( repositories != null )
{
remoteRepos.addAll( repositories );
}
if ( repositories.isEmpty() )
{
// TODO: use super POM?
Repository repository = new Repository( REPO_URL, Repository.LAYOUT_DEFAULT );
remoteRepos.add( repository );
}
}
private boolean getRemoteArtifact( Dependency dep, File destinationFile ) private boolean getRemoteArtifact( Dependency dep, File destinationFile )
{ {
boolean fileFound = false; boolean fileFound = false;
for ( Iterator i = remoteRepos.iterator(); i.hasNext(); ) for ( Iterator i = getRemoteRepositories().iterator(); i.hasNext(); )
{ {
Repository remoteRepo = (Repository) i.next(); Repository remoteRepo = (Repository) i.next();
@ -177,7 +153,8 @@ public class ArtifactDownloader
{ {
File file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(), File file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), dep.getVersion(), dep.getType(),
dep.getArtifactId() + "-" + dep.getResolvedVersion() + ".pom" ); dep.getArtifactId() + "-" + dep.getResolvedVersion() +
".pom" );
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
@ -250,19 +227,6 @@ public class ArtifactDownloader
return filename.substring( 0, index ) + s; return filename.substring( 0, index ) + s;
} }
private String replace( String text, String repl, String with )
{
StringBuffer buf = new StringBuffer( text.length() );
int start = 0, end = 0;
while ( ( end = text.indexOf( repl, start ) ) != -1 )
{
buf.append( text.substring( start, end ) ).append( with );
start = end + repl.length();
}
buf.append( text.substring( start ) );
return buf.toString();
}
private void log( String message ) private void log( String message )
{ {
System.out.println( message ); System.out.println( message );
@ -272,4 +236,25 @@ public class ArtifactDownloader
{ {
return localRepository; return localRepository;
} }
public List getRemoteRepositories()
{
if ( remoteRepositories == null )
{
remoteRepositories = new ArrayList();
}
if ( remoteRepositories.isEmpty() )
{
// TODO: use super POM?
remoteRepositories.add( new Repository( "central", REPO_URL, Repository.LAYOUT_DEFAULT ) );
}
return remoteRepositories;
}
public void setRemoteRepositories( List remoteRepositories )
{
this.remoteRepositories = remoteRepositories;
}
} }

View File

@ -312,7 +312,11 @@ public class ModelReader
} }
else if ( insideRepository ) else if ( insideRepository )
{ {
if ( rawName.equals( "url" ) ) if ( rawName.equals( "id" ) )
{
currentRepository.setId( getBodyText() );
}
else if ( rawName.equals( "url" ) )
{ {
currentRepository.setBasedir( getBodyText() ); currentRepository.setBasedir( getBodyText() );
} }

View File

@ -34,12 +34,15 @@ public class Repository
private String layout; private String layout;
private String id;
public Repository() public Repository()
{ {
} }
public Repository( String basedir, String layout ) public Repository( String id, String basedir, String layout )
{ {
this.id = id;
this.basedir = basedir; this.basedir = basedir;
this.layout = layout; this.layout = layout;
} }
@ -135,4 +138,18 @@ public class Repository
this.layout = layout; this.layout = layout;
} }
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public String getLayout()
{
return layout;
}
} }

View File

@ -61,6 +61,17 @@
<multiplicity>*</multiplicity> <multiplicity>*</multiplicity>
</association> </association>
</field> </field>
<field>
<name>mirrors</name>
<version>1.0.0</version>
<description>
Configuration of download mirrors for repositories.
</description>
<association>
<type>Mirror</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field> <field>
<name>profiles</name> <name>profiles</name>
<version>1.0.0</version> <version>1.0.0</version>
@ -348,5 +359,61 @@
</field> </field>
</fields> </fields>
</class> </class>
<class>
<name>Mirror</name>
<version>1.0.0</version>
<description>
A download mirror for a given repository.
</description>
<fields>
<field>
<name>id</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description>
The server ID of this mirror. This must -not- be the same as that of the repository you are mirroring.
</description>
</field>
<field>
<name>mirrorOf</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description>
The server ID of the repository being mirrored, eg "central".
</description>
</field>
<field>
<name>name</name>
<required>false</required>
<version>1.0.0</version>
<type>String</type>
<description>
The optional name that describes the mirror.
</description>
</field>
<field>
<name>url</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description>
The URL of the mirror repository.
</description>
</field>
<!--
<field>
<name>allowOriginal</name>
<version>1.0.0</version>
<type>boolean</type>
<defaultValue>true</defaultValue>
<description>
Whether to allow the user of the original as a fallback if an artifact is not found on the mirror.
</description>
</field>
-->
</fields>
</class>
</classes> </classes>
</model> </model>