You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2011/08/09 23:10:57 UTC

svn commit: r1155565 [2/3] - in /maven/maven-3/branches/mirror-group-routing: ./ maven-compat/src/main/java/org/apache/maven/repository/ maven-core/src/main/java/org/apache/maven/artifact/router/mirror/ maven-core/src/main/java/org/apache/maven/executi...

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router.loader;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.router.ArtifactRouter;
+import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.session.ArtifactRouterSession;
+
+public interface ArtifactRouterLoader
+{
+
+    ArtifactRouter load( ArtifactRouterSession session )
+        throws ArtifactRouterException;
+    
+    void save( ArtifactRouter router, ArtifactRouterSession session )
+        throws ArtifactRouterException;
+
+    ArtifactRouter loadDefault();
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router.session;
+
+import java.io.File;
+
+import org.apache.maven.artifact.router.conf.RouterSource;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Server;
+
+public interface ArtifactRouterSession
+{
+
+    public String getDiscoveryStrategy();
+
+    Proxy getProxy( String protocol );
+    
+    Server getServer( String id );
+
+    RouterSource getGroupSource();
+
+    RouterSource getMirrorSource();
+
+    RouterSource getDefaultGroupSource();
+
+    RouterSource getDefaultMirrorSource();
+
+    File getRoutesFile();
+
+    boolean isClear();
+
+    boolean isDisabled();
+
+    boolean isOffline();
+
+    boolean isUpdate();
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java Tue Aug  9 21:10:55 2011
@@ -91,7 +91,7 @@ public class GroupRouteTest
         assertTrue( "Before merge, " + m + " NOT matched!", r.contains( m ) );
         assertFalse( "Before merge, " + a + " matched!", r.contains( a ) );
         
-        r.merge( new GroupPattern( "org.apache.maven.*" ) );
+        r.merge( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven.*" ) ) );
         assertTrue( "After merge, " + m + " NO LONGER matched!", r.contains( m ) );
         assertTrue( "After merge, " + a + " STILL not matched!", r.contains( a ) );
     }
@@ -100,7 +100,7 @@ public class GroupRouteTest
     public void mergeReplacesObsoletePattern()
     {
         GroupRoute r = new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven" ) );
-        r.merge( new GroupPattern( "org.apache.maven.*" ) );
+        r.merge( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven.*" ) ) );
         
         assertEquals( "After merge, obsolete pattern NOT replaced!", 1, r.getGroupPatterns().size() );
     }

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java.orig
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java.orig?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java.orig (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java.orig Tue Aug  9 21:10:55 2011
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 static junit.framework.Assert.*;
+
+import org.apache.maven.artifact.router.GroupPattern;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.junit.Test;
+
+public class GroupRouteTest
+{
+
+    @Test
+    public void containsWithExactMatch()
+    {
+        assertTrue( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven" ) ).contains( new GroupPattern(
+                                                                                                                                    "org.apache.maven" ) ) );
+    }
+
+    @Test
+    public void s_containsWithExactMatch()
+    {
+        assertTrue( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven" ) ).contains( "org.apache.maven" ) );
+    }
+
+    @Test
+    public void containsWithWildcardMatch()
+    {
+        assertTrue( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven.*" ) ).contains( new GroupPattern(
+                                                                                                                                      "org.apache.maven.artifact" ) ) );
+    }
+
+    @Test
+    public void s_containsWithWildcardMatch()
+    {
+        assertTrue( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven.*" ) ).contains( "org.apache.maven.artifact" ) );
+    }
+
+    @Test
+    public void containsWithMatchAmongTwoWildcards()
+    {
+        assertTrue( new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven.plugins.*" ),
+                                    new GroupPattern( "org.codehaus.mojo.*" ) ).contains( new GroupPattern(
+                                                                                                            "org.apache.maven.plugins" ) ) );
+    }
+    
+    @Test
+    public void mergeToIncludeBroaderMatch()
+    {
+        String m = "org.apache.maven";
+        String a = m + ".artifact";
+        
+        GroupRoute r = new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven" ) );
+        assertTrue( "Before merge, " + m + " NOT matched!", r.contains( m ) );
+        assertFalse( "Before merge, " + a + " matched!", r.contains( a ) );
+        
+        r.merge( new GroupPattern( "org.apache.maven.*" ) );
+        assertTrue( "After merge, " + m + " NO LONGER matched!", r.contains( m ) );
+        assertTrue( "After merge, " + a + " STILL not matched!", r.contains( a ) );
+    }
+
+    @Test
+    public void mergeReplacesObsoletePattern()
+    {
+        GroupRoute r = new GroupRoute( "http://maven.apache.org", new GroupPattern( "org.apache.maven" ) );
+        r.merge( new GroupPattern( "org.apache.maven.*" ) );
+        
+        assertEquals( "After merge, obsolete pattern NOT replaced!", 1, r.getGroupPatterns().size() );
+    }
+
+}

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/MirrorRoutingTableTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/MirrorRoutingTableTest.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/MirrorRoutingTableTest.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/MirrorRoutingTableTest.java Tue Aug  9 21:10:55 2011
@@ -20,7 +20,7 @@
 package org.apache.maven.artifact.router;
 
 import org.apache.maven.artifact.router.MirrorRoute;
-import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.internal.DefaultArtifactRouter;
 
 import junit.framework.TestCase;
 
@@ -32,7 +32,7 @@ public class MirrorRoutingTableTest
     {
         String canonical = "http://repo1.maven.org/maven2";
         
-        ArtifactRouter table = new ArtifactRouter();
+        ArtifactRouter table = new DefaultArtifactRouter();
         MirrorRoute route = new MirrorRoute( "test", "http://nowhere.com/mirror", 10, true, canonical );
         table.addMirror( route );
         
@@ -45,7 +45,7 @@ public class MirrorRoutingTableTest
     {
         String canonical = "http://repo1.maven.org/maven3";
         
-        ArtifactRouter table = new ArtifactRouter();
+        ArtifactRouter table = new DefaultArtifactRouter();
         MirrorRoute route = new MirrorRoute( "test", "http://nowhere.com/mirror", 10, true, "http://repo1.maven.org/maven2" );
         table.addMirror( route );
         

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializerTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializerTest.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializerTest.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializerTest.java Tue Aug  9 21:10:55 2011
@@ -39,7 +39,7 @@ package org.apache.maven.artifact.router
  */
 
 import org.apache.maven.artifact.router.MirrorRoute;
-import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.internal.DefaultArtifactRouter;
 import org.apache.maven.artifact.router.io.ArtifactRouteSerializer;
 
 import java.io.StringWriter;
@@ -53,8 +53,8 @@ public class ArtifactRouteSerializerTest
     public void testSerializeOneMirror()
         throws Exception
     {
-        final ArtifactRouter mirrorMap =
-            new ArtifactRouter().addMirror( new MirrorRoute( "central",
+        final DefaultArtifactRouter mirrorMap =
+            new DefaultArtifactRouter().addMirror( new MirrorRoute( "central",
                                                              "http://localhost:8081/nexus", 99, true, "http://repo1.maven.org/maven2" ) );
 
         final StringWriter sw = new StringWriter();
@@ -66,8 +66,8 @@ public class ArtifactRouteSerializerTest
     public void testSerializeToStringOneMirror()
         throws Exception
     {
-        final ArtifactRouter mirrorMap =
-            new ArtifactRouter().addMirror( new MirrorRoute( "central",
+        final DefaultArtifactRouter mirrorMap =
+            new DefaultArtifactRouter().addMirror( new MirrorRoute( "central",
                                                              "http://localhost:8081/nexus", 99, true, "http://repo1.maven.org/maven2" ) );
 
         System.out.println( ArtifactRouteSerializer.serializeToString( mirrorMap ) );
@@ -76,12 +76,12 @@ public class ArtifactRouteSerializerTest
     public void testRoundTripOneMirror()
         throws Exception
     {
-        final ArtifactRouter mirrorMap =
-            new ArtifactRouter().addMirror( new MirrorRoute( "central",
+        final DefaultArtifactRouter mirrorMap =
+            new DefaultArtifactRouter().addMirror( new MirrorRoute( "central",
                                                              "http://localhost:8081/nexus", 99, true, "http://repo1.maven.org/maven2" ) );
 
         final String ser = ArtifactRouteSerializer.serializeToString( mirrorMap );
-        final ArtifactRouter result = ArtifactRouteSerializer.deserialize( ser );
+        final DefaultArtifactRouter result = ArtifactRouteSerializer.deserialize( ser );
 
         assertEquals( mirrorMap, result );
         assertTrue( result.getMirror( "http://repo1.maven.org/maven2" ).isEnabled() );

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/pom.xml?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/pom.xml (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/pom.xml Tue Aug  9 21:10:55 2011
@@ -13,12 +13,24 @@
   
   <dependencies>
     <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-routem-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
     <dependency>
-    	<groupId>org.apache.maven</groupId>
-    	<artifactId>maven-routem-api</artifactId>
+      <groupId>org.sonatype.aether</groupId>
+      <artifactId>aether-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.sonatype.aether</groupId>
+      <artifactId>aether-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.sonatype.aether</groupId>
+      <artifactId>aether-util</artifactId>
     </dependency>
     <dependency>
     	<groupId>org.codehaus.plexus</groupId>

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public final class DefaultArtifactRouter implements ArtifactRouter
+{
+
+    private final List<MirrorRoute> mirrors;
+
+    private final Map<GroupPattern, GroupRoute> groups;
+    
+    private final ArtifactRouteSelector routeSelector;
+
+    public DefaultArtifactRouter( ArtifactRouteSelector routeSelector, Collection<MirrorRoute> mirrors, Collection<GroupRoute> groups )
+    {
+        this.routeSelector = routeSelector;
+        List<MirrorRoute> m = new ArrayList<MirrorRoute>();
+        if ( mirrors != null )
+        {
+            for ( MirrorRoute mirror : mirrors )
+            {
+                if ( !m.contains( mirror ) )
+                {
+                    m.add( mirror );
+                }
+            }
+        }
+        Collections.sort( m );
+
+        this.mirrors = m;
+
+        Map<GroupPattern, GroupRoute> g = new HashMap<GroupPattern, GroupRoute>();
+        if ( groups != null )
+        {
+            for ( GroupRoute route : groups )
+            {
+                for ( GroupPattern pattern : route.getGroupPatterns() )
+                {
+                    g.put( pattern, route );
+                }
+            }
+        }
+        this.groups = g;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#selectSingleMirror(java.lang.String)
+     */
+    public MirrorRoute selectSingleMirror( final String canonicalUrl )
+    {
+        List<MirrorRoute> routes = getAllMirrors( canonicalUrl );
+        if ( routes == null || routes.isEmpty() )
+        {
+            return null;
+        }
+        
+        return routeSelector == null ? routes.get( 0 ) : routeSelector.select( routes );
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#getAllMirrors(java.lang.String)
+     */
+    public synchronized List<MirrorRoute> getAllMirrors( final String canonicalUrl )
+    {
+        List<MirrorRoute> routes = new ArrayList<MirrorRoute>();
+        for ( MirrorRoute mirror : mirrors )
+        {
+            if ( mirror.isEnabled() && mirror.isMirrorOf( canonicalUrl ) )
+            {
+                routes.add( mirror );
+            }
+        }
+
+        Collections.sort( routes );
+
+        return routes;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#getGroup(java.lang.String)
+     */
+    public GroupRoute getGroup( String groupId )
+    {
+        List<GroupPattern> matches = new ArrayList<GroupPattern>();
+        for ( GroupPattern p : this.groups.keySet() )
+        {
+            if ( p.implies( groupId ) )
+            {
+                matches.add( p );
+            }
+        }
+
+        if ( matches.isEmpty() )
+        {
+            return GroupRoute.DEFAULT;
+        }
+        else
+        {
+            Collections.sort( matches );
+            GroupPattern pattern = matches.get( 0 );
+
+            return groups.get( pattern );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#contains(org.apache.maven.artifact.router.MirrorRoute)
+     */
+    public boolean contains( final MirrorRoute o )
+    {
+        return mirrors.contains( o );
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( mirrors == null ) ? 0 : mirrors.hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( final Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+        if ( obj == null )
+        {
+            return false;
+        }
+        if ( getClass() != obj.getClass() )
+        {
+            return false;
+        }
+        final ArtifactRouter other = (ArtifactRouter) obj;
+        if ( mirrors == null )
+        {
+            if ( other.getMirrors() != null )
+            {
+                return false;
+            }
+        }
+        else if ( !mirrors.equals( other.getMirrors() ) )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#getMirrors()
+     */
+    public List<MirrorRoute> getMirrors()
+    {
+        return mirrors;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.artifact.router.ArtifactRouter#containsMirrorOf(java.lang.String)
+     */
+    public boolean containsMirrorOf( final String canonicalUrl )
+    {
+        for ( final MirrorRoute mirror : mirrors )
+        {
+            if ( mirror.isEnabled() && mirror.isMirrorOf( canonicalUrl ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,400 @@
+package org.apache.maven.artifact.router;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.ArtifactRouterCache;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.apache.maven.artifact.router.MirrorRoute;
+import org.apache.maven.artifact.router.RoutingRequestConverter;
+import org.apache.maven.artifact.router.loader.ArtifactRouterLoader;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.metadata.Metadata;
+import org.sonatype.aether.metadata.Metadata.Nature;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.repository.RepositoryPolicy;
+import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
+import org.sonatype.aether.resolution.ArtifactRequest;
+import org.sonatype.aether.resolution.MetadataRequest;
+import org.sonatype.aether.resolution.VersionRangeRequest;
+import org.sonatype.aether.resolution.VersionRequest;
+
+@Component( role = RoutingRequestConverter.class )
+public class DefaultRoutingRequestConverter
+    implements RoutingRequestConverter
+{
+
+    @Requirement
+    private ArtifactRouterLoader routerLoader;
+
+    public void convert( final VersionRangeRequest request, final RepositorySystemSession session )
+    {
+        Artifact artifact = request.getArtifact();
+        List<RemoteRepository> repos = collectRoutingRepos( artifact, session, request.getRepositories() );
+        request.setRepositories( repos );
+    }
+
+    public void convert( VersionRequest request, RepositorySystemSession session )
+    {
+        Artifact artifact = request.getArtifact();
+        List<RemoteRepository> repos = collectRoutingRepos( artifact, session, request.getRepositories() );
+        request.setRepositories( repos );
+    }
+
+    public void convert( ArtifactDescriptorRequest request, RepositorySystemSession session )
+    {
+        Artifact artifact = request.getArtifact();
+        List<RemoteRepository> repos = collectRoutingRepos( artifact, session, request.getRepositories() );
+        request.setRepositories( repos );
+    }
+
+    public void convert( ArtifactRequest request, RepositorySystemSession session )
+    {
+        Artifact artifact = request.getArtifact();
+        List<RemoteRepository> repos = collectRoutingRepos( artifact, session, request.getRepositories() );
+        request.setRepositories( repos );
+    }
+
+    public void convert( Collection<? extends ArtifactRequest> requests, RepositorySystemSession session )
+    {
+        for ( ArtifactRequest request : requests )
+        {
+            Artifact artifact = request.getArtifact();
+            List<RemoteRepository> repos = collectRoutingRepos( artifact, session, request.getRepositories() );
+            request.setRepositories( repos );
+        }
+    }
+
+    public Collection<? extends MetadataRequest> mapMetadataRequests( Collection<? extends MetadataRequest> requests,
+                                                                      RepositorySystemSession session )
+    {
+        Map<MetadataKey, MetadataRequest> metadataMap = new LinkedHashMap<MetadataKey, MetadataRequest>();
+        for ( MetadataRequest mdr : requests )
+        {
+            MetadataKey mdk = new MetadataKey( mdr.getMetadata() );
+
+            if ( !metadataMap.containsKey( mdk ) )
+            {
+                metadataMap.put( mdk, mdr );
+            }
+        }
+
+        List<MetadataRequest> result = new ArrayList<MetadataRequest>();
+        for ( MetadataRequest req : metadataMap.values() )
+        {
+            Metadata md = req.getMetadata();
+
+            List<RemoteRepository> repos = collectRoutingRepos( md, session, req.getRepository() );
+            for ( RemoteRepository repo : repos )
+            {
+                result.add( new MetadataRequest( md, repo, req.getRequestContext() ) );
+            }
+        }
+
+        return result;
+    }
+
+    private List<RemoteRepository> collectRoutingRepos( Metadata md, RepositorySystemSession session,
+                                                        RemoteRepository originalRepo )
+    {
+        Nature nature = md.getNature();
+        boolean includeReleases = nature == Nature.RELEASE || nature == Nature.RELEASE_OR_SNAPSHOT;
+        boolean includeSnapshots = nature == Nature.SNAPSHOT || nature == Nature.RELEASE_OR_SNAPSHOT;
+
+        return collectRoutingRepos( md.getGroupId(), session, Collections.singletonList( originalRepo ),
+                                    includeReleases, includeSnapshots );
+    }
+
+    private List<RemoteRepository> collectRoutingRepos( Artifact artifact, RepositorySystemSession session,
+                                                        List<RemoteRepository> originalRepos )
+    {
+        boolean includeReleases = false;
+        boolean includeSnapshots = false;
+        for ( RemoteRepository repo : originalRepos )
+        {
+            if ( repo.getPolicy( false ).isEnabled() )
+            {
+                includeReleases = true;
+            }
+            else if ( repo.getPolicy( true ).isEnabled() )
+            {
+                includeSnapshots = true;
+            }
+
+            if ( includeSnapshots && includeReleases )
+            {
+                break;
+            }
+        }
+
+        return collectRoutingRepos( artifact.getGroupId(), session, originalRepos, includeSnapshots, includeReleases );
+    }
+
+    private synchronized List<RemoteRepository> collectRoutingRepos( String groupId, RepositorySystemSession session,
+                                                        List<RemoteRepository> originalRepos, boolean includeSnapshots,
+                                                        boolean includeReleases )
+    {
+        ArtifactRouter router = getRouter( session );
+        ArtifactRouterCache cache = getRouterCache( session );
+        GroupRoute group = router.getGroup( groupId );
+
+        RemoteRepository snaps = null;
+        if ( includeSnapshots )
+        {
+            snaps = getGroupRepo( group, true, cache, router );
+        }
+
+        RemoteRepository release = null;
+        if ( includeReleases )
+        {
+            release = getGroupRepo( group, false, cache, router );
+        }
+        
+        List<RemoteRepository> repos = consolidateRepositories( snaps, release, originalRepos );
+        
+        return repos;
+    }
+
+    private List<RemoteRepository> consolidateRepositories( RemoteRepository snaps, RemoteRepository release,
+                                                            List<RemoteRepository> originalRepos )
+    {
+        // Consolidate created repos with supplied repos
+        // - map urls represented by created group repos
+        //   * include direct url
+        //   * include mirrored repos
+        //   * separate between snaps mirrors and release mirrors
+        // - iterate supplied repos
+        //   * if url mirrored by created snapshot repo, eliminate from results
+        //     > if releases also allowed in this repo, enable releases in created snapshot repo
+        //   * if url mirrored by created release repo, eliminate from results
+        //     > if snapshots also allowed in this repo, enable snapshots in created release repo
+
+        Set<String> releaseMirrors = new HashSet<String>();
+        releaseMirrors.add( release.getUrl() );
+        if ( release.getMirroredRepositories() != null )
+        {
+            for ( RemoteRepository repo : release.getMirroredRepositories() )
+            {
+                releaseMirrors.add( repo.getUrl() );
+            }
+        }
+        
+        List<RemoteRepository> results = new ArrayList<RemoteRepository>();
+        Set<String> captured = new HashSet<String>();
+        
+        results.add( release );
+        captured.add( release.getUrl() );
+
+        Set<String> snapsMirrors = new HashSet<String>();
+        if ( snaps != release )
+        {
+            snapsMirrors.add( snaps.getUrl() );
+            if ( snaps.getMirroredRepositories() != null )
+            {
+                for ( RemoteRepository repo : snaps.getMirroredRepositories() )
+                {
+                    snapsMirrors.add( repo.getUrl() );
+                }
+            }
+            
+            results.add( snaps );
+            captured.add( snaps.getUrl() );
+        }
+
+        for ( RemoteRepository repo : originalRepos )
+        {
+            if ( releaseMirrors.contains( repo.getUrl() ) )
+            {
+                RepositoryPolicy snapshotPolicy = repo.getPolicy( true );
+                RepositoryPolicy relSnapshotPolicy = release.getPolicy( true );
+                
+                if ( relSnapshotPolicy != null && !relSnapshotPolicy.isEnabled() && snapshotPolicy != null
+                    && snapshotPolicy.isEnabled() )
+                {
+                    relSnapshotPolicy.setEnabled( true );
+                }
+            }
+            else if ( snapsMirrors.contains( repo.getUrl() ) )
+            {
+                RepositoryPolicy releasePolicy = repo.getPolicy( false );
+                RepositoryPolicy snapReleasePolicy = snaps.getPolicy( false );
+                
+                if ( snapReleasePolicy != null && !snapReleasePolicy.isEnabled() && releasePolicy != null
+                    && releasePolicy.isEnabled() )
+                {
+                    snapReleasePolicy.setEnabled( true );
+                }
+            }
+            else if ( !captured.contains( repo.getUrl() ) )
+            {
+                results.add( repo );
+                captured.add( repo.getUrl() );
+            }
+        }
+        
+        return results;
+    }
+
+    private RemoteRepository getGroupRepo( GroupRoute group, boolean snapshots, ArtifactRouterCache cache, ArtifactRouter router )
+    {
+        RemoteRepository repo = cache.getGroupRepository( group, snapshots );
+        if ( repo == null )
+        {
+            MirrorRoute mirror =
+                router.selectSingleMirror( snapshots ? group.getCanonicalSnapshotsUrl()
+                                : group.getCanonicalReleasesUrl() );
+
+            repo = new RemoteRepository();
+
+            repo.setRepositoryManager( false );
+            repo.setId( mirror.getId() );
+            repo.setUrl( mirror.getRouteUrl() );
+
+            // FIXME: repository policy should probably come from globals, NOT from server-specified mirror config!
+            repo.setPolicy( snapshots, mirror.toRepositoryPolicy() );
+            
+            Set<String> mirrorOfUrls = mirror.getMirrorOfUrls();
+            if ( mirrorOfUrls != null )
+            {
+                List<RemoteRepository> mirrorOf = new ArrayList<RemoteRepository>( mirrorOfUrls.size() );
+                for ( String url : mirrorOfUrls )
+                {
+                    RemoteRepository r = new RemoteRepository();
+                    r.setUrl( url );
+                    mirrorOf.add( r );
+                }
+                
+                repo.setMirroredRepositories( mirrorOf );
+            }
+            
+            cache.setGroupRepository( group, snapshots, repo );
+        }
+
+        return repo;
+    }
+
+    private synchronized ArtifactRouterCache getRouterCache( RepositorySystemSession session )
+    {
+        ArtifactRouterCache cache = (ArtifactRouterCache) session.getData().get( ArtifactRouterCache.SESSION_KEY );
+        if ( cache == null )
+        {
+            cache = new ArtifactRouterCache();
+            session.getData().set( ArtifactRouterCache.SESSION_KEY, cache );
+        }
+
+        return cache;
+    }
+
+    private synchronized ArtifactRouter getRouter( RepositorySystemSession session )
+    {
+        ArtifactRouter router = (ArtifactRouter) session.getData().get( ArtifactRouter.SESSION_KEY );
+        if ( router == null )
+        {
+            router = routerLoader.loadDefault();
+            session.getData().set( ArtifactRouter.SESSION_KEY, router );
+        }
+
+        return router;
+    }
+
+    // private static final class MetadataKey
+    // {
+    // private final String gid;
+    //
+    // private final String url;
+    //
+    // MetadataKey( Metadata metadata, RemoteRepository repo )
+    // {
+    // this.gid = metadata.getGroupId();
+    // this.url = repo.getUrl();
+    // }
+    //
+    // @Override
+    // public int hashCode()
+    // {
+    // final int prime = 31;
+    // int result = 1;
+    // result = prime * result + ( ( gid == null ) ? 0 : gid.hashCode() );
+    // result = prime * result + ( ( url == null ) ? 0 : url.hashCode() );
+    // return result;
+    // }
+    //
+    // @Override
+    // public boolean equals( Object obj )
+    // {
+    // if ( this == obj )
+    // return true;
+    // if ( obj == null )
+    // return false;
+    // if ( getClass() != obj.getClass() )
+    // return false;
+    // MetadataKey other = (MetadataKey) obj;
+    // if ( gid == null )
+    // {
+    // if ( other.gid != null )
+    // return false;
+    // }
+    // else if ( !gid.equals( other.gid ) )
+    // return false;
+    // if ( url == null )
+    // {
+    // if ( other.url != null )
+    // return false;
+    // }
+    // else if ( !url.equals( other.url ) )
+    // return false;
+    // return true;
+    // }
+    // }
+    //
+    private static final class MetadataKey
+    {
+        private final Metadata md;
+
+        MetadataKey( Metadata md )
+        {
+            this.md = md;
+        }
+
+        public int hashCode()
+        {
+            final int prime = 13;
+            int result = 1;
+            result = prime * result + md.getGroupId().hashCode();
+            result = prime * result + md.getArtifactId().hashCode();
+            result = prime * result + md.getVersion().hashCode();
+            result = prime * result + md.getType().hashCode();
+            result = prime * result + md.getNature().hashCode();
+            return result;
+        }
+
+        public boolean equals( Object other )
+        {
+            if ( other == this )
+            {
+                return true;
+            }
+
+            if ( !( other instanceof MetadataKey ) )
+            {
+                return false;
+            }
+
+            MetadataKey om = (MetadataKey) other;
+            return md.getGroupId().equals( om.md.getGroupId() ) && md.getArtifactId().equals( om.md.getArtifactId() )
+                && md.getVersion().equals( om.md.getVersion() ) && md.getType().equals( om.md.getType() )
+                && md.getNature() == om.md.getNature();
+        }
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,20 @@
+package org.apache.maven.artifact.router;
+
+import java.util.Collection;
+
+import org.apache.maven.artifact.router.ArtifactRouteSelector;
+import org.apache.maven.artifact.router.MirrorRoute;
+import org.codehaus.plexus.component.annotations.Component;
+
+@Component( role=ArtifactRouteSelector.class, hint="weighted-random" )
+public class WeightedRandomRouteSelector
+    implements ArtifactRouteSelector
+{
+
+    public MirrorRoute select( Collection<MirrorRoute> routes )
+    {
+        // FIXME: Implement this!
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,246 @@
+package org.apache.maven.artifact.router.aether;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.router.RoutingRequestConverter;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.SyncContext;
+import org.sonatype.aether.collection.CollectRequest;
+import org.sonatype.aether.collection.CollectResult;
+import org.sonatype.aether.collection.DependencyCollectionException;
+import org.sonatype.aether.deployment.DeployRequest;
+import org.sonatype.aether.deployment.DeployResult;
+import org.sonatype.aether.deployment.DeploymentException;
+import org.sonatype.aether.graph.DependencyFilter;
+import org.sonatype.aether.graph.DependencyNode;
+import org.sonatype.aether.graph.DependencyVisitor;
+import org.sonatype.aether.installation.InstallRequest;
+import org.sonatype.aether.installation.InstallResult;
+import org.sonatype.aether.installation.InstallationException;
+import org.sonatype.aether.repository.LocalRepository;
+import org.sonatype.aether.repository.LocalRepositoryManager;
+import org.sonatype.aether.resolution.ArtifactDescriptorException;
+import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
+import org.sonatype.aether.resolution.ArtifactDescriptorResult;
+import org.sonatype.aether.resolution.ArtifactRequest;
+import org.sonatype.aether.resolution.ArtifactResolutionException;
+import org.sonatype.aether.resolution.ArtifactResult;
+import org.sonatype.aether.resolution.DependencyRequest;
+import org.sonatype.aether.resolution.DependencyResolutionException;
+import org.sonatype.aether.resolution.DependencyResult;
+import org.sonatype.aether.resolution.MetadataRequest;
+import org.sonatype.aether.resolution.MetadataResult;
+import org.sonatype.aether.resolution.VersionRangeRequest;
+import org.sonatype.aether.resolution.VersionRangeResolutionException;
+import org.sonatype.aether.resolution.VersionRangeResult;
+import org.sonatype.aether.resolution.VersionRequest;
+import org.sonatype.aether.resolution.VersionResolutionException;
+import org.sonatype.aether.resolution.VersionResult;
+import org.sonatype.aether.util.graph.FilteringDependencyVisitor;
+
+@Component( role = RepositorySystem.class, hint = "default" )
+public class RouteMRepositorySystem
+    implements RepositorySystem
+{
+
+    @Requirement( hint = "aether-default" )
+    private RepositorySystem delegate;
+
+    @Requirement
+    private RoutingRequestConverter routeConverter;
+
+    public CollectResult collectDependencies( RepositorySystemSession session, CollectRequest request )
+        throws DependencyCollectionException
+    {
+        return delegate.collectDependencies( session, request );
+    }
+
+    public InstallResult install( RepositorySystemSession session, InstallRequest request )
+        throws InstallationException
+    {
+        return delegate.install( session, request );
+    }
+
+    public DeployResult deploy( RepositorySystemSession session, DeployRequest request )
+        throws DeploymentException
+    {
+        return delegate.deploy( session, request );
+    }
+
+    public LocalRepositoryManager newLocalRepositoryManager( LocalRepository localRepository )
+    {
+        return delegate.newLocalRepositoryManager( localRepository );
+    }
+
+    public SyncContext newSyncContext( RepositorySystemSession session, boolean shared )
+    {
+        return delegate.newSyncContext( session, shared );
+    }
+
+    public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request )
+        throws VersionRangeResolutionException
+    {
+        routeConverter.convert( request, session );
+
+        return delegate.resolveVersionRange( session, request );
+    }
+
+    public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request )
+        throws VersionResolutionException
+    {
+        routeConverter.convert( request, session );
+
+        return delegate.resolveVersion( session, request );
+    }
+
+    public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session,
+                                                            ArtifactDescriptorRequest request )
+        throws ArtifactDescriptorException
+    {
+        routeConverter.convert( request, session );
+
+        return delegate.readArtifactDescriptor( session, request );
+    }
+
+    public ArtifactResult resolveArtifact( RepositorySystemSession session, ArtifactRequest request )
+        throws ArtifactResolutionException
+    {
+        routeConverter.convert( request, session );
+
+        return delegate.resolveArtifact( session, request );
+    }
+
+    public List<ArtifactResult> resolveArtifacts( RepositorySystemSession session,
+                                                  Collection<? extends ArtifactRequest> requests )
+        throws ArtifactResolutionException
+    {
+        routeConverter.convert( requests, session );
+
+        return delegate.resolveArtifacts( session, requests );
+    }
+
+    public DependencyResult resolveDependencies( RepositorySystemSession session, DependencyRequest request )
+        throws DependencyResolutionException
+    {
+        DependencyResult result = new DependencyResult( request );
+        
+        DependencyNode root;
+        CollectRequest collectRequest = request.getCollectRequest();
+        if ( collectRequest != null )
+        {
+            CollectResult collectResult;
+            try
+            {
+                collectResult = collectDependencies( session, request.getCollectRequest() );
+            }
+            catch ( DependencyCollectionException e )
+            {
+                result.setCollectExceptions( e.getResult().getExceptions() );
+                throw new DependencyResolutionException( result, e );
+            }
+            
+            root = collectResult.getRoot();
+        }
+        else
+        {
+            root = request.getRoot();
+        }
+        
+        result.setRoot( root );
+        
+        List<ArtifactResult> artifactResults;
+        try
+        {
+            artifactResults = resolveDependencies( session, root, request.getFilter() );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new DependencyResolutionException( result, e );
+        }
+        
+        result.setArtifactResults( artifactResults );
+        return result;
+    }
+
+    public List<ArtifactResult> resolveDependencies( RepositorySystemSession session, DependencyNode node,
+                                                     DependencyFilter filter )
+        throws ArtifactResolutionException
+    {
+        Set<ArtifactRequest> requests = new LinkedHashSet<ArtifactRequest>();
+        Collection<DependencyNode> dependencies = traverse( node, filter );
+        for ( DependencyNode dn : dependencies )
+        {
+            requests.add( new ArtifactRequest( dn ) );
+        }
+        
+        return resolveArtifacts( session, requests );
+    }
+
+    public List<ArtifactResult> resolveDependencies( RepositorySystemSession session, CollectRequest request,
+                                                     DependencyFilter filter )
+        throws DependencyCollectionException, ArtifactResolutionException
+    {
+        DependencyRequest req = new DependencyRequest( request, filter );
+        DependencyResult res;
+        try
+        {
+            res = resolveDependencies( session, req );
+        }
+        catch ( DependencyResolutionException e )
+        {
+            Throwable cause = e.getCause();
+            
+            //NOTE: From our implementation above, only these two are possible!
+            if ( cause instanceof ArtifactResolutionException )
+            {
+                throw (ArtifactResolutionException) cause;
+            }
+            else
+            {
+                throw (DependencyCollectionException ) cause;
+            }
+        }
+        
+        return res.getArtifactResults();
+    }
+
+    public List<MetadataResult> resolveMetadata( RepositorySystemSession session,
+                                                 Collection<? extends MetadataRequest> requests )
+    {
+        Collection<? extends MetadataRequest> mappedRequests = routeConverter.mapMetadataRequests( requests, session );
+        
+        return delegate.resolveMetadata( session, mappedRequests );
+    }
+    
+    private Set<DependencyNode> traverse( DependencyNode root, DependencyFilter filter )
+    {
+        FlatteningVisitor visitor = new FlatteningVisitor();
+        root.accept( new FilteringDependencyVisitor( visitor, filter ) ); 
+        
+        return visitor.nodes;
+    }
+
+    private static final class FlatteningVisitor implements DependencyVisitor
+    {
+        Set<DependencyNode> nodes = new LinkedHashSet<DependencyNode>();
+
+        public boolean visitEnter( DependencyNode node )
+        {
+            nodes.add( node );
+            return true;
+        }
+
+        public boolean visitLeave( DependencyNode node )
+        {
+            return true;
+        }
+        
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router.conf;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Set;
+
+public final class DefaultArtifactRouterConfiguration
+    implements ArtifactRouterConfiguration
+{
+
+    private final File routesFile;
+
+    private final boolean disabled;
+
+    private final String discoveryStrategy;
+
+    private final String selectionStrategy;
+
+    private final Set<ArtifactRouterOption> routerOptions;
+
+    private final RouterSource groupSource;
+
+    private final RouterSource mirrorSource;
+
+    public DefaultArtifactRouterConfiguration( File routesFile, RouterSource groupSource, RouterSource mirrorSource,
+                                               String discoveryStrategy, String selectionStrategy, boolean disabled,
+                                               Set<ArtifactRouterOption> options )
+    {
+        this.routesFile = routesFile;
+        this.groupSource = groupSource;
+        this.mirrorSource = mirrorSource;
+        this.discoveryStrategy = discoveryStrategy;
+        this.selectionStrategy = selectionStrategy;
+        this.disabled = disabled;
+
+        if ( options == null || options.isEmpty() )
+        {
+            routerOptions = Collections.unmodifiableSet( Collections.singleton( ArtifactRouterOption.update ) );
+        }
+        else
+        {
+            routerOptions = Collections.unmodifiableSet( options );
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getGroupSource()
+     */
+    public RouterSource getGroupSource()
+    {
+        return groupSource;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getMirrorSource()
+     */
+    public RouterSource getMirrorSource()
+    {
+        return mirrorSource;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#isDisabled()
+     */
+    public boolean isDisabled()
+    {
+        return disabled;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getDiscoveryStrategy()
+     */
+    public String getDiscoveryStrategy()
+    {
+        return discoveryStrategy;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getSelectionStrategy()
+     */
+    public String getSelectionStrategy()
+    {
+        return selectionStrategy;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getRoutesFile()
+     */
+    public File getRoutesFile()
+    {
+        return routesFile;
+    }
+
+    // public ArtifactRouterConfiguration setOffline( boolean offline )
+    // {
+    // return setOption( ArtifactRouterOption.offline, offline );
+    // }
+    //
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#isOffline()
+     */
+    public boolean isOffline()
+    {
+        return this.routerOptions.contains( ArtifactRouterOption.offline );
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#isClear()
+     */
+    public boolean isClear()
+    {
+        return routerOptions.contains( ArtifactRouterOption.clear );
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#isUpdate()
+     */
+    public boolean isUpdate()
+    {
+        return routerOptions.contains( ArtifactRouterOption.update );
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getDefaultGroupSource()
+     */
+    public RouterSource getDefaultGroupSource()
+    {
+        return CANONICAL_GROUP_SOURCE;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration#getDefaultMirrorSource()
+     */
+    public RouterSource getDefaultMirrorSource()
+    {
+        return CANONICAL_MIRROR_SOURCE;
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java Tue Aug  9 21:10:55 2011
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.artifact.router.conf;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 static org.codehaus.plexus.util.IOUtil.close;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.codehaus.plexus.logging.Logger;
+
+public class FileRouterConfigLoader
+    implements ArtifactRouterConfigLoader
+{
+
+    private static final String KEY_ROUTES_FILE = "routing-tables-file";
+    
+    private static final String KEY_MIRROR_SOURCE = "mirror-source";
+
+    private static final String KEY_GROUP_SOURCE = "group-source";
+
+    private static final String KEY_DISABLED = "disabled";
+
+    private static final String KEY_DISCOVERY_STRATEGY = "discovery-strategy";
+
+    private static final String KEY_SELECTION_STRATEGY = "selection-strategy";
+    
+    private static final String ROUTES_FILE = "artifact-routes.json";
+
+    private static final String CONFIG_FILENAME = "router.properties";
+
+    public static final String DEFAULT_SOURCE_ID = "central.router";
+
+    private Logger logger;
+
+    private File confDir;
+
+    public FileRouterConfigLoader( File confDir, Logger logger )
+    {
+        this.confDir = confDir;
+        this.logger = logger;
+    }
+
+    public ArtifactRouterConfiguration build()
+        throws ArtifactRouterConfigurationException
+    {
+        RouterConfigBuilder builder = new RouterConfigBuilder();
+        File routerConfig = new File( confDir, CONFIG_FILENAME );
+
+        if ( logger.isDebugEnabled() )
+        {
+            logger.debug( "Loading mirror configuration from file: " + routerConfig );
+        }
+
+        File routesFile = null;
+        
+        if ( routerConfig.canRead() )
+        {
+            InputStream stream = null;
+            try
+            {
+                stream = new FileInputStream( routerConfig );
+                final Properties p = new Properties();
+                p.load( stream );
+
+                String path = p.getProperty( KEY_ROUTES_FILE );
+                if ( path != null )
+                {
+                    routesFile = new File( path );
+                }
+
+                builder.withEnabled( !Boolean.parseBoolean( p.getProperty( KEY_DISABLED, "false" ) ) );
+
+                String strat = p.getProperty( KEY_DISCOVERY_STRATEGY );
+                if ( strat != null )
+                {
+                    builder.withDiscoveryStrategy( strat );
+                }
+
+                strat = p.getProperty( KEY_SELECTION_STRATEGY );
+                if ( strat != null )
+                {
+                    builder.withDiscoveryStrategy( strat );
+                }
+
+                RouterSource src = loadRouterSource( p, KEY_MIRROR_SOURCE );
+                if ( src != null )
+                {
+                    builder.withMirrorSource( src );
+                }
+                
+                src = loadRouterSource( p, KEY_GROUP_SOURCE );
+                if ( src != null )
+                {
+                    builder.withGroupSource( src );
+                }
+            }
+            catch ( final IOException e )
+            {
+                throw new ArtifactRouterConfigurationException( "Failed to read router config properties from: '"
+                    + routerConfig + "'.\nReason: " + e.getMessage(), e );
+            }
+            finally
+            {
+                close( stream );
+            }
+        }
+        else
+        {
+            if ( logger.isDebugEnabled() )
+            {
+                logger.debug( "Cannot read router configuration from: " + routerConfig
+                                + ". Using defaults." );
+            }
+        }
+        
+        if ( routesFile == null )
+        {
+            routesFile = new File( confDir, ROUTES_FILE );
+        }
+        
+        builder.withRoutesFile( routesFile );
+        
+        return builder.build();
+    }
+
+    private RouterSource loadRouterSource( Properties p, String keyMirrorSource )
+        throws MalformedURLException
+    {
+        String url = p.getProperty( KEY_MIRROR_SOURCE );
+        String id = DEFAULT_SOURCE_ID;
+        
+        if ( url != null )
+        {
+            URL u = new URL( url );
+            if ( u.getUserInfo() != null )
+            {
+                id = u.getUserInfo();
+                
+                StringBuilder sb = new StringBuilder( u.getProtocol() ).append( "://" ).append( u.getHost() );
+                if ( u.getPort() > 0 )
+                {
+                    sb.append( ":" ).append( u.getPort() );
+                }
+
+                if ( u.getFile() != null )
+                {
+                    sb.append( u.getFile() );
+                }
+
+                url = sb.toString();
+            }
+        }
+        
+        return new RouterSource( id, url );
+    }
+
+}

Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java Tue Aug  9 21:10:55 2011
@@ -1,47 +1,114 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
 package org.apache.maven.artifact.router.conf;
 
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 static org.apache.maven.artifact.router.conf.ArtifactRouterOption.*;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
 
-public interface RouterConfigBuilder
+public class RouterConfigBuilder
 {
 
+    private File routesFile;
+
+    private RouterSource groupSource;
+
+    private RouterSource mirrorSource;
+
+    private String discoveryStrategy = ArtifactRouterConfiguration.NO_DISCOVERY_STRATEGIES;
+
+    private String selectionStrategy = ArtifactRouterConfiguration.WEIGHTED_RANDOM_STRATEGY;
+
+    private boolean disabled = false;
+
+    private Set<ArtifactRouterOption> options = new HashSet<ArtifactRouterOption>();
+
     ArtifactRouterConfiguration build()
-        throws ArtifactRouterConfigurationException;
+    {
+        return new DefaultArtifactRouterConfiguration( routesFile, groupSource, mirrorSource, discoveryStrategy,
+                                                       selectionStrategy, disabled, options );
+    }
+
+    RouterConfigBuilder withRoutesFile( File routesFile )
+    {
+        this.routesFile = routesFile;
+        return this;
+    }
+
+    RouterConfigBuilder withGroupSource( RouterSource groupSource )
+    {
+        this.groupSource = groupSource;
+        return this;
+    }
+
+    RouterConfigBuilder withMirrorSource( RouterSource mirrorSource )
+    {
+        this.mirrorSource = mirrorSource;
+        return this;
+    }
+
+    RouterConfigBuilder withGroupSource( String id, String url )
+    {
+        this.groupSource = new RouterSource( id, url );
+        return this;
+    }
+
+    RouterConfigBuilder withMirrorSource( String id, String url )
+    {
+        this.mirrorSource = new RouterSource( id, url );
+        return this;
+    }
+
+    RouterConfigBuilder withDiscoveryStrategy( String discoveryStrategy )
+    {
+        this.discoveryStrategy = discoveryStrategy;
+        return this;
+    }
+    
+    RouterConfigBuilder withSelectionStrategy( String selectionStrategy )
+    {
+        this.selectionStrategy = selectionStrategy;
+        return this;
+    }
+    
+    RouterConfigBuilder disabled()
+    {
+        this.disabled = true;
+        return this;
+    }
+    
+    RouterConfigBuilder withEnabled( boolean enabled )
+    {
+        this.disabled = !enabled;
+        return this;
+    }
+    
+    RouterConfigBuilder withOffline( boolean enable )
+    {
+        return withOption( offline, enable );
+    }
+    
+    RouterConfigBuilder withClear( boolean enable )
+    {
+        return withOption( clear, enable );
+    }
+
+    RouterConfigBuilder withUpdate( boolean enable )
+    {
+        return withOption( update, enable );
+    }
+
+    RouterConfigBuilder withOption( ArtifactRouterOption option, boolean enable )
+    {
+        if ( enable )
+        {
+            options.add( option );
+        }
+        else
+        {
+            options.remove( option );
+        }
+        
+        return this;
+    }
 
 }

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterReader.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterReader.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterReader.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterReader.java Tue Aug  9 21:10:55 2011
@@ -19,13 +19,23 @@
 
 package org.apache.maven.artifact.router.loader;
 
+import java.util.Collection;
+
 import org.apache.maven.artifact.router.ArtifactRouter;
 import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.apache.maven.artifact.router.MirrorRoute;
 import org.apache.maven.artifact.router.conf.RouterSource;
 import org.apache.maven.artifact.router.session.ArtifactRouterSession;
 
 public interface ArtifactRouterReader
 {
+    
+    Collection<GroupRoute> loadGroupRoutes( RouterSource source, ArtifactRouterSession session )
+        throws ArtifactRouterException;
+
+    Collection<MirrorRoute> loadMirrorRoutes( RouterSource source, ArtifactRouterSession session )
+                    throws ArtifactRouterException;
 
     ArtifactRouter loadRouter( RouterSource source, ArtifactRouterSession session )
         throws ArtifactRouterException;

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultArtifactRouterReader.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultArtifactRouterReader.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultArtifactRouterReader.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultArtifactRouterReader.java Tue Aug  9 21:10:55 2011
@@ -22,15 +22,6 @@ package org.apache.maven.artifact.router
 import static org.codehaus.plexus.util.IOUtil.close;
 import static org.codehaus.plexus.util.StringUtils.isNotBlank;
 
-import org.apache.maven.artifact.router.ArtifactRouter;
-import org.apache.maven.artifact.router.ArtifactRouterException;
-import org.apache.maven.artifact.router.conf.RouterSource;
-import org.apache.maven.artifact.router.io.ArtifactRouteSerializer;
-import org.apache.maven.artifact.router.session.ArtifactRouterSession;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.codehaus.plexus.component.annotations.Component;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -41,9 +32,21 @@ import java.net.PasswordAuthentication;
 import java.net.Proxy.Type;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Collection;
 import java.util.StringTokenizer;
 import java.util.zip.GZIPInputStream;
 
+import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.apache.maven.artifact.router.MirrorRoute;
+import org.apache.maven.artifact.router.conf.RouterSource;
+import org.apache.maven.artifact.router.io.ArtifactRouteSerializer;
+import org.apache.maven.artifact.router.session.ArtifactRouterSession;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Server;
+import org.codehaus.plexus.component.annotations.Component;
+
 @Component( role = ArtifactRouterReader.class )
 public class DefaultArtifactRouterReader
     implements ArtifactRouterReader
@@ -58,6 +61,54 @@ public class DefaultArtifactRouterReader
     public ArtifactRouter loadRouter( RouterSource source, ArtifactRouterSession session )
         throws ArtifactRouterException
     {
+        InputStream in = null;
+        try
+        {
+            in = getRouteSourceContent( source, session );
+
+            return in == null ? null : ArtifactRouteSerializer.deserialize( new InputStreamReader( in ) );
+        }
+        finally
+        {
+            close( in );
+        }
+    }
+
+    public Collection<GroupRoute> loadGroupRoutes( RouterSource source, ArtifactRouterSession session )
+        throws ArtifactRouterException
+    {
+        InputStream in = null;
+        try
+        {
+            in = getRouteSourceContent( source, session );
+
+            return in == null ? null : ArtifactRouteSerializer.deserializeGroups( new InputStreamReader( in ) );
+        }
+        finally
+        {
+            close( in );
+        }
+    }
+
+    public Collection<MirrorRoute> loadMirrorRoutes( RouterSource source, ArtifactRouterSession session )
+        throws ArtifactRouterException
+    {
+        InputStream in = null;
+        try
+        {
+            in = getRouteSourceContent( source, session );
+
+            return in == null ? null : ArtifactRouteSerializer.deserializeMirrors( new InputStreamReader( in ) );
+        }
+        finally
+        {
+            close( in );
+        }
+    }
+
+    private InputStream getRouteSourceContent( RouterSource source, ArtifactRouterSession session )
+        throws ArtifactRouterException
+    {
         RouterAuthenticator authenticator = new RouterAuthenticator( source, session );
         Authenticator.setDefault( authenticator );
 
@@ -73,7 +124,6 @@ public class DefaultArtifactRouterReader
 
         Proxy proxy = authenticator.getProxy( url.getProtocol(), url.getHost() );
 
-        ArtifactRouter router = null;
         InputStream in = null;
         try
         {
@@ -85,7 +135,7 @@ public class DefaultArtifactRouterReader
             else
             {
                 Type type = proxy.getProtocol().toLowerCase().startsWith( "socks" ) ? Type.SOCKS : Type.HTTP;
-                
+
                 java.net.Proxy connProxy =
                     new java.net.Proxy( type, new InetSocketAddress( proxy.getHost(), proxy.getPort() ) );
 
@@ -102,19 +152,13 @@ public class DefaultArtifactRouterReader
             {
                 in = new GZIPInputStream( in );
             }
-
-            router = ArtifactRouteSerializer.deserialize( new InputStreamReader( in ) );
         }
         catch ( IOException e )
         {
             throw new ArtifactRouterException( "Cannot load artifact routes from: " + source, e );
         }
-        finally
-        {
-            close( in );
-        }
 
-        return router;
+        return in;
     }
 
     // private Proxy setProxy( Proxy proxy )

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java Tue Aug  9 21:10:55 2011
@@ -48,6 +48,8 @@ import java.util.Map;
 
 import org.apache.maven.artifact.router.ArtifactRouter;
 import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.DefaultArtifactRouter;
+import org.apache.maven.artifact.router.WeightedRandomRouteSelector;
 import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
 import org.apache.maven.artifact.router.conf.RouterSource;
 import org.apache.maven.artifact.router.io.ArtifactRouteSerializer;
@@ -77,7 +79,9 @@ public class DefaultRouterLoader
     {
         if ( session == null || session.isDisabled() )
         {
-            return new ArtifactRouter();
+            // FIXME
+            throw new UnsupportedOperationException();
+//            return new DefaultArtifactRouter( new WeightedRandomRouteSelector(), null, null );
         }
         
         return loadRoutes( session );
@@ -147,7 +151,9 @@ public class DefaultRouterLoader
             }
         }
         
-        return new ArtifactRouter();
+        // FIXME
+        throw new UnsupportedOperationException();
+//        return new DefaultArtifactRouter();
     }
 
     protected ArtifactRouter loadRoutes( final ArtifactRouterSession session )
@@ -157,8 +163,10 @@ public class DefaultRouterLoader
         
         if ( session.isClear() )
         {
-            routes = new ArtifactRouter();
+            // FIXME
+//            routes = new DefaultArtifactRouter();
             save( routes, session );
+            throw new UnsupportedOperationException();
         }
         else
         {
@@ -177,7 +185,7 @@ public class DefaultRouterLoader
                     ArtifactRouter r = routerReader.loadRouter( src, session );
                     if ( r != null )
                     {
-                        routes.merge( r );
+                        routes = merge( routes, r );
                     }
                 }
                 else if ( discoveryStrategy != null
@@ -197,7 +205,7 @@ public class DefaultRouterLoader
                         ArtifactRouter result = strategy.findRouter( session );
                         if ( result != null )
                         {
-                            routes.merge( result );
+                            routes = merge( routes, result );
                         }
                     }
                 }
@@ -207,7 +215,7 @@ public class DefaultRouterLoader
                     ArtifactRouter r = routerReader.loadRouter( src, session );
                     if ( r != null )
                     {
-                        routes.merge( r );
+                        routes = merge( routes, r );
                     }
                 }
             }
@@ -222,12 +230,20 @@ public class DefaultRouterLoader
 
         if ( routes == null )
         {
-            routes = new ArtifactRouter();
+            // FIXME
+            throw new UnsupportedOperationException();
+//            routes = new DefaultArtifactRouter();
         }
 
         return routes;
     }
 
+    private ArtifactRouter merge( ArtifactRouter routes, ArtifactRouter r )
+    {
+        // FIXME
+        throw new UnsupportedOperationException();
+    }
+
     private ArtifactRouterDiscoveryStrategy getDiscoveryStrategy( final String key )
     {
         ArtifactRouterDiscoveryStrategy strat = strategies.get( key );
@@ -244,4 +260,10 @@ public class DefaultRouterLoader
         return strat;
     }
 
+    public DefaultArtifactRouter loadDefault()
+    {
+        // FIXME Implement this!
+        throw new UnsupportedOperationException( "TODO: Implement me!" );
+    }
+
 }

Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/ArtifactRouterDiscoveryStrategy.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/ArtifactRouterDiscoveryStrategy.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/ArtifactRouterDiscoveryStrategy.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/ArtifactRouterDiscoveryStrategy.java Tue Aug  9 21:10:55 2011
@@ -19,33 +19,20 @@
 
 package org.apache.maven.artifact.router.loader.discovery;
 
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.util.Collection;
 
-import org.apache.maven.artifact.router.ArtifactRouter;
 import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.apache.maven.artifact.router.MirrorRoute;
 import org.apache.maven.artifact.router.session.ArtifactRouterSession;
 
 public interface ArtifactRouterDiscoveryStrategy
 {
 
-    ArtifactRouter findRouter( final ArtifactRouterSession session )
+    Collection<GroupRoute> findGroupRoutes( final ArtifactRouterSession session )
+        throws ArtifactRouterException;
+
+    Collection<MirrorRoute> findMirrorRoutes( final ArtifactRouterSession session )
         throws ArtifactRouterException;
 
 }