You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/05 08:24:08 UTC

svn commit: r168282 - /maven/components/trunk/maven-mboot2/src/main/java /maven/components/trunk/maven-mboot2/src/main/java/download /maven/components/trunk/maven-mboot2/src/main/java/model /maven/components/trunk/maven-settings

Author: brett
Date: Wed May  4 23:24:07 2005
New Revision: 168282

URL: http://svn.apache.org/viewcvs?rev=168282&view=rev
Log:
PR: MNG-145
add mirror notation to settings, introduce to bootstrap

Modified:
    maven/components/trunk/maven-mboot2/src/main/java/MBoot.java
    maven/components/trunk/maven-mboot2/src/main/java/download/ArtifactDownloader.java
    maven/components/trunk/maven-mboot2/src/main/java/model/ModelReader.java
    maven/components/trunk/maven-mboot2/src/main/java/model/Repository.java
    maven/components/trunk/maven-settings/settings.mdo

Modified: maven/components/trunk/maven-mboot2/src/main/java/MBoot.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-mboot2/src/main/java/MBoot.java?rev=168282&r1=168281&r2=168282&view=diff
==============================================================================
--- maven/components/trunk/maven-mboot2/src/main/java/MBoot.java (original)
+++ maven/components/trunk/maven-mboot2/src/main/java/MBoot.java Wed May  4 23:24:07 2005
@@ -242,16 +242,44 @@
             online = false;
         }
 
-        Repository localRepository = new Repository( mavenRepoLocal, Repository.LAYOUT_DEFAULT );
+        Repository localRepository = new Repository( "local", mavenRepoLocal, Repository.LAYOUT_DEFAULT );
 
         if ( online )
         {
-            downloader = new ArtifactDownloader( localRepository, Collections.EMPTY_LIST );
+            downloader = new ArtifactDownloader( localRepository );
             if ( userModelReader.getActiveProxy() != null )
             {
                 Proxy proxy = userModelReader.getActiveProxy();
                 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" );
@@ -948,6 +976,8 @@
     class SettingsReader
         extends AbstractReader
     {
+        private List mirrors = new ArrayList();
+
         private List profiles = new ArrayList();
 
         private Profile currentProfile = null;
@@ -962,6 +992,8 @@
 
         private Proxy activeProxy = null;
 
+        private Mirror currentMirror;
+
         public Profile getActiveProfile()
         {
             return activeProfile;
@@ -1018,7 +1050,7 @@
                 }
                 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 )
@@ -1054,6 +1086,41 @@
                     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 ) )
             {
                 if ( profiles.size() == 1 )
@@ -1103,6 +1170,10 @@
             {
                 currentProxy = new Proxy();
             }
+            else if ( "mirror".equals( rawName ) )
+            {
+                currentMirror = new Mirror();
+            }
         }
 
         public void reset()
@@ -1111,8 +1182,15 @@
             this.activeProfile = null;
             this.activeProxy = null;
             this.currentProfile = null;
+            this.currentMirror = null;
             this.profiles.clear();
             this.proxies.clear();
+            this.mirrors.clear();
+        }
+
+        public List getMirrors()
+        {
+            return mirrors;
         }
     }
 
@@ -1143,7 +1221,7 @@
         }
     }
 
-    public class Proxy
+    public static class Proxy
     {
         private boolean active;
 
@@ -1206,4 +1284,42 @@
         }
     }
 
+    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;
+        }
+    }
 }

Modified: maven/components/trunk/maven-mboot2/src/main/java/download/ArtifactDownloader.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-mboot2/src/main/java/download/ArtifactDownloader.java?rev=168282&r1=168281&r2=168282&view=diff
==============================================================================
--- maven/components/trunk/maven-mboot2/src/main/java/download/ArtifactDownloader.java (original)
+++ maven/components/trunk/maven-mboot2/src/main/java/download/ArtifactDownloader.java Wed May  4 23:24:07 2005
@@ -9,19 +9,15 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
-import java.util.HashMap;
 import java.util.Map;
 
 public class ArtifactDownloader
 {
     public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
 
-    private List remoteRepos;
-
     private boolean useTimestamp = true;
 
     private boolean ignoreErrors = false;
@@ -40,11 +36,11 @@
 
     private Map downloadedArtifacts = new HashMap();
 
-    public ArtifactDownloader( Repository localRepository, List remoteRepositories )
+    private List remoteRepositories;
+
+    public ArtifactDownloader( Repository localRepository )
         throws Exception
     {
-        setRemoteRepos( remoteRepositories );
-
         if ( localRepository == null )
         {
             System.err.println( "local repository not specified" );
@@ -53,9 +49,6 @@
         }
 
         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 )
@@ -115,28 +108,11 @@
         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 )
     {
         boolean fileFound = false;
 
-        for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
+        for ( Iterator i = getRemoteRepositories().iterator(); i.hasNext(); )
         {
             Repository remoteRepo = (Repository) i.next();
 
@@ -177,7 +153,8 @@
                 {
                     File file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
                                                                  dep.getVersion(), dep.getType(),
-                                                                 dep.getArtifactId() + "-" + dep.getResolvedVersion() + ".pom" );
+                                                                 dep.getArtifactId() + "-" + dep.getResolvedVersion() +
+                                                                 ".pom" );
 
                     file.getParentFile().mkdirs();
 
@@ -250,19 +227,6 @@
         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 )
     {
         System.out.println( message );
@@ -271,5 +235,26 @@
     public Repository getLocalRepository()
     {
         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;
     }
 }

Modified: maven/components/trunk/maven-mboot2/src/main/java/model/ModelReader.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-mboot2/src/main/java/model/ModelReader.java?rev=168282&r1=168281&r2=168282&view=diff
==============================================================================
--- maven/components/trunk/maven-mboot2/src/main/java/model/ModelReader.java (original)
+++ maven/components/trunk/maven-mboot2/src/main/java/model/ModelReader.java Wed May  4 23:24:07 2005
@@ -312,7 +312,11 @@
         }
         else if ( insideRepository )
         {
-            if ( rawName.equals( "url" ) )
+            if ( rawName.equals( "id" ) )
+            {
+                currentRepository.setId( getBodyText() );
+            }
+            else if ( rawName.equals( "url" ) )
             {
                 currentRepository.setBasedir( getBodyText() );
             }

Modified: maven/components/trunk/maven-mboot2/src/main/java/model/Repository.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-mboot2/src/main/java/model/Repository.java?rev=168282&r1=168281&r2=168282&view=diff
==============================================================================
--- maven/components/trunk/maven-mboot2/src/main/java/model/Repository.java (original)
+++ maven/components/trunk/maven-mboot2/src/main/java/model/Repository.java Wed May  4 23:24:07 2005
@@ -34,12 +34,15 @@
 
     private String layout;
 
+    private String id;
+
     public Repository()
     {
     }
 
-    public Repository( String basedir, String layout )
+    public Repository( String id, String basedir, String layout )
     {
+        this.id = id;
         this.basedir = basedir;
         this.layout = layout;
     }
@@ -135,4 +138,18 @@
         this.layout = layout;
     }
 
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    public String getLayout()
+    {
+        return layout;
+    }
 }

Modified: maven/components/trunk/maven-settings/settings.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/settings.mdo?rev=168282&r1=168281&r2=168282&view=diff
==============================================================================
--- maven/components/trunk/maven-settings/settings.mdo (original)
+++ maven/components/trunk/maven-settings/settings.mdo Wed May  4 23:24:07 2005
@@ -62,6 +62,17 @@
           </association>
         </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>
           <name>profiles</name>
           <version>1.0.0</version>
           <description><![CDATA[
@@ -348,5 +359,61 @@
         </field>
       </fields>
     </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>
-</model>
\ No newline at end of file
+</model>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org