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 [1/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...
Author: jdcasey
Date: Tue Aug 9 21:10:55 2011
New Revision: 1155565
URL: http://svn.apache.org/viewvc?rev=1155565&view=rev
Log:
Filling out the loading of router data, including booting up the loader session, etc. in the maven cli.
Added:
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouteSelector.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouterCache.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java.orig
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java.orig
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/RoutingRequestConverter.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigLoader.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java.orig
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java.orig
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultArtifactRouter.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/DefaultRoutingRequestConverter.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/WeightedRandomRouteSelector.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/aether/RouteMRepositorySystem.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultArtifactRouterConfiguration.java (with props)
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigLoader.java (with props)
Removed:
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigBuilder.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/session/ArtifactRouterSession.java
Modified:
maven/maven-3/branches/mirror-group-routing/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java
maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/artifact/router/mirror/RoutingMirrorSelector.java
maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
maven/maven-3/branches/mirror-group-routing/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/pom.xml
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouter.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/MirrorRoute.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/GroupRouteTest.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/MirrorRoutingTableTest.java
maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/test/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializerTest.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/pom.xml
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterReader.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultArtifactRouterReader.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/ArtifactRouterDiscoveryStrategy.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/discovery/DNSDiscoveryStrategy.java
maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/session/DefaultArtifactRouterSession.java
maven/maven-3/branches/mirror-group-routing/pom.xml
maven/maven-3/branches/mirror-group-routing/pom.xml.orig
Modified: maven/maven-3/branches/mirror-group-routing/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java Tue Aug 9 21:10:55 2011
@@ -76,7 +76,7 @@ public class DefaultMirrorSelector
final String repoUrl = repository.getUrl();
ArtifactRouter router = legacySupport.getSession().getArtifactRouter();
- final MirrorRoute rMirror = router.getMirror( repoUrl );
+ final MirrorRoute rMirror = router.selectSingleMirror( repoUrl );
if ( rMirror != null )
{
Modified: maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/artifact/router/mirror/RoutingMirrorSelector.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/artifact/router/mirror/RoutingMirrorSelector.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/artifact/router/mirror/RoutingMirrorSelector.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/artifact/router/mirror/RoutingMirrorSelector.java Tue Aug 9 21:10:55 2011
@@ -19,8 +19,8 @@ package org.apache.maven.artifact.router
* under the License.
*/
-import org.apache.maven.artifact.router.MirrorRoute;
import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.MirrorRoute;
import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.repository.MirrorSelector;
import org.sonatype.aether.repository.RemoteRepository;
@@ -66,7 +66,7 @@ public class RoutingMirrorSelector
{
final String repoUrl = repository.getUrl();
- final MirrorRoute route = router.getMirror( repoUrl );
+ final MirrorRoute route = router.selectSingleMirror( repoUrl );
if ( route != null )
{
Modified: maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java Tue Aug 9 21:10:55 2011
@@ -20,8 +20,8 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.router.ArtifactRouter;
import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
+import org.apache.maven.artifact.router.internal.DefaultArtifactRouter;
import org.apache.maven.model.Profile;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
@@ -1080,21 +1080,16 @@ public class DefaultMavenExecutionReques
return this;
}
- private ArtifactRouter artifactRouter;
+ private DefaultArtifactRouter artifactRouter;
private ArtifactRouterConfiguration artifactRouterConfig;
- public synchronized ArtifactRouter getArtifactRouter()
+ public synchronized DefaultArtifactRouter getArtifactRouter()
{
- if ( artifactRouter == null )
- {
- artifactRouter = new ArtifactRouter();
- }
-
return artifactRouter;
}
- public MavenExecutionRequest setArtifactRouter( final ArtifactRouter artifactRouter )
+ public MavenExecutionRequest setArtifactRouter( final DefaultArtifactRouter artifactRouter )
{
this.artifactRouter = artifactRouter;
return this;
Modified: maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java Tue Aug 9 21:10:55 2011
@@ -26,7 +26,7 @@ import java.util.Set;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
+import org.apache.maven.artifact.router.conf.DefaultArtifactRouterConfiguration;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
@@ -276,7 +276,7 @@ public class DefaultMavenExecutionReques
{
if ( request.getArtifactRouter() == null && request.getArtifactRouterConfiguration() == null )
{
- request.setArtifactRouterConfiguration( new ArtifactRouterConfiguration() );
+ request.setArtifactRouterConfiguration( new DefaultArtifactRouterConfiguration() );
}
}
Modified: maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java Tue Aug 9 21:10:55 2011
@@ -26,8 +26,8 @@ import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.router.ArtifactRouter;
import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
+import org.apache.maven.artifact.router.internal.DefaultArtifactRouter;
import org.apache.maven.artifact.router.session.ArtifactRouterSession;
import org.apache.maven.model.Profile;
import org.apache.maven.project.ProjectBuildingRequest;
@@ -286,9 +286,9 @@ public interface MavenExecutionRequest
ProjectBuildingRequest getProjectBuildingRequest();
- ArtifactRouter getArtifactRouter();
+ DefaultArtifactRouter getArtifactRouter();
- MavenExecutionRequest setArtifactRouter( ArtifactRouter router );
+ MavenExecutionRequest setArtifactRouter( DefaultArtifactRouter router );
MavenExecutionRequest setArtifactRouterConfiguration( ArtifactRouterConfiguration routerConfig );
Modified: maven/maven-3/branches/mirror-group-routing/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java Tue Aug 9 21:10:55 2011
@@ -37,9 +37,9 @@ import org.apache.maven.BuildAbort;
import org.apache.maven.InternalErrorException;
import org.apache.maven.Maven;
import org.apache.maven.artifact.router.ArtifactRouterException;
-import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
+import org.apache.maven.artifact.router.conf.DefaultArtifactRouterConfiguration;
import org.apache.maven.artifact.router.conf.ArtifactRouterOption;
-import org.apache.maven.artifact.router.conf.FileRouterConfigBuilder;
+import org.apache.maven.artifact.router.conf.FileRouterConfigLoader;
import org.apache.maven.artifact.router.loader.ArtifactRouterLoader;
import org.apache.maven.artifact.router.session.ArtifactRouterSession;
import org.apache.maven.artifact.router.session.DefaultArtifactRouterSession;
@@ -937,8 +937,8 @@ public class MavenCli
userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
}
- ArtifactRouterConfiguration routerConfig =
- new FileRouterConfigBuilder( DEFAULT_USER_EXT_CONF_DIR, logger ).build();
+ DefaultArtifactRouterConfiguration routerConfig =
+ new FileRouterConfigLoader( DEFAULT_USER_EXT_CONF_DIR, logger ).build();
if ( commandLine.hasOption( CLIManager.ROUTER_OPTIONS ) )
{
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/pom.xml?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/pom.xml (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/pom.xml Tue Aug 9 21:10:55 2011
@@ -33,5 +33,17 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-annotations</artifactId>
+ </dependency>
</dependencies>
</project>
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouteSelector.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/ArtifactRouteSelector.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouteSelector.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouteSelector.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,10 @@
+package org.apache.maven.artifact.router;
+
+import java.util.Collection;
+
+public interface ArtifactRouteSelector
+{
+
+ MirrorRoute select( Collection<MirrorRoute> routes );
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouteSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouter.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/ArtifactRouter.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouter.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouter.java Tue Aug 9 21:10:55 2011
@@ -1,355 +1,22 @@
-/*
- * 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;
-import java.util.Random;
-public final class ArtifactRouter
+public interface ArtifactRouter
{
public static final String SESSION_KEY = ArtifactRouter.class.getName();
- private List<MirrorRoute> mirrors = new ArrayList<MirrorRoute>();
-
- private Map<GroupPattern, GroupRoute> groups = new HashMap<GroupPattern, GroupRoute>();
-
- private final transient Random random = new Random();
-
- private transient Map<String, int[]> mirrorIndexGrabBags = new HashMap<String, int[]>();
-
- private Map<String, MirrorRoute> selectedMirrors = new HashMap<String, MirrorRoute>();
-
- public synchronized ArtifactRouter clearSelections()
- {
- selectedMirrors.clear();
- return this;
- }
-
- public synchronized ArtifactRouter merge( ArtifactRouter other )
- {
- addMirrors( other.mirrors );
- addGroups( other.groups.values() );
-
- for ( Map.Entry<String, MirrorRoute> entry : other.selectedMirrors.entrySet() )
- {
- String url = entry.getKey();
-
- if ( !selectedMirrors.containsKey( url ) )
- {
- selectedMirrors.put( url, entry.getValue() );
- }
- }
-
- return this;
- }
-
- public synchronized ArtifactRouter addMirrors( final Collection<MirrorRoute> mirrors )
- {
- if ( mirrors != null )
- {
- for ( MirrorRoute route : mirrors )
- {
- addMirror( route );
- }
- }
-
- return this;
- }
-
- public synchronized ArtifactRouter addMirror( final MirrorRoute mirror )
- {
- if ( mirror == null )
- {
- return this;
- }
-
- if ( !mirrors.contains( mirror ) )
- {
- mirrors.add( mirror );
- for ( String url : mirror.getMirrorOfUrls() )
- {
- mirrorIndexGrabBags.remove( url );
- selectedMirrors.remove( url );
- }
- }
-
- return this;
- }
-
- public synchronized MirrorRoute getMirror( final String canonicalUrl )
- {
- MirrorRoute route = selectedMirrors.get( canonicalUrl );
- if ( route == null )
- {
- route = getWeightedRandomMirror( canonicalUrl );
- selectedMirrors.put( canonicalUrl, route );
- }
-
- return route;
- }
-
- public synchronized ArtifactRouter addGroups( final Collection<GroupRoute> groups )
- {
- if ( groups != null )
- {
- for ( GroupRoute route : groups )
- {
- addGroup( route );
- }
- }
-
- return this;
- }
-
- public synchronized ArtifactRouter addGroup( final GroupRoute group )
- {
- if ( group == null )
- {
- return this;
- }
-
- GroupRoute toInsert = group;
-
- List<GroupRoute> routes = new ArrayList<GroupRoute>( groups.values() );
- int idx = routes.indexOf( group );
- if ( idx > -1 )
- {
- GroupRoute existing = routes.get( idx );
- for ( GroupPattern p : existing.getGroupPatterns() )
- {
- groups.remove( p );
- }
-
- existing.merge( group.getGroupPatterns() );
- toInsert = existing;
- }
-
- for ( GroupPattern p : toInsert.getGroupPatterns() )
- {
- groups.put( p, toInsert );
- }
-
- return this;
- }
-
- 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 );
- }
- }
-
- // private MirrorRoute getHighestPriorityMirror( final String canonicalUrl )
- // {
- // if ( mirrors.isEmpty() )
- // {
- // return null;
- // }
- //
- // final List<MirrorRoute> available = new ArrayList<MirrorRoute>( mirrors );
- //
- // // sort by weight.
- // Collections.sort( available );
- //
- // for ( final MirrorRoute mirror : available )
- // {
- // // return the highest-priority ENABLED mirror.
- // if ( mirror.isEnabled() && canonicalUrl.equals( mirror.getUrl() ) )
- // {
- // return mirror;
- // }
- // }
- //
- // return null;
- // }
-
- private MirrorRoute getWeightedRandomMirror( final String canonicalUrl )
- {
- if ( mirrors.isEmpty() )
- {
- return null;
- }
-
- int[] indexGrabBag = null;
- synchronized ( canonicalUrl )
- {
- indexGrabBag = mirrorIndexGrabBags.get( canonicalUrl );
- if ( indexGrabBag == null )
- {
- final List<Integer> gb = new ArrayList<Integer>();
- for ( int idx = 0; idx < mirrors.size(); idx++ )
- {
- final MirrorRoute mirror = mirrors.get( idx );
- if ( !mirror.isEnabled() || !mirror.isMirrorOf( canonicalUrl ) )
- {
- // only select from enabled mirrors that actually mirror the given canonical repository URL.
- continue;
- }
-
- if ( mirror.getWeight() < 1 )
- {
- // make sure this mirror has at least one chance of being picked.
- gb.add( idx );
- }
- else
- {
- // if weight == 9, give this mirror 9 chances of being picked randomly.
- for ( int i = 0; i < mirror.getWeight(); i++ )
- {
- gb.add( idx );
- }
- }
- }
-
- indexGrabBag = new int[gb.size()];
- for ( int i = 0; i < indexGrabBag.length; i++ )
- {
- indexGrabBag[i] = gb.get( i );
- }
-
- mirrorIndexGrabBags.put( canonicalUrl, indexGrabBag );
- }
- }
-
- if ( indexGrabBag.length == 0 )
- {
- return null;
- }
-
- // generate a random number that will correspond to an index stored in the index grab bag.
- int idx = Math.abs( random.nextInt() ) % indexGrabBag.length;
-
- // use that random number to select the index of the mirror in the mirrors list.
- idx = indexGrabBag[idx];
-
- // lookup the mirror instance associated with the index from the grab bag.
- return mirrors.get( idx );
- }
-
- 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;
- }
+ MirrorRoute selectSingleMirror( final String canonicalUrl );
- @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.mirrors != null )
- {
- return false;
- }
- }
- else if ( !mirrors.equals( other.mirrors ) )
- {
- return false;
- }
- return true;
- }
+ List<MirrorRoute> getAllMirrors( final String canonicalUrl );
- public List<MirrorRoute> getMirrors()
- {
- return mirrors;
- }
+ GroupRoute getGroup( String groupId );
- void setMirrors( final List<MirrorRoute> mirrors )
- {
- this.mirrors = mirrors;
- }
+ boolean contains( final MirrorRoute o );
- public boolean containsMirrorOf( final String canonicalUrl )
- {
- for ( final MirrorRoute mirror : mirrors )
- {
- if ( mirror.isEnabled() && mirror.isMirrorOf( canonicalUrl ) )
- {
- return true;
- }
- }
+ List<MirrorRoute> getMirrors();
- return false;
- }
+ boolean containsMirrorOf( final String canonicalUrl );
-}
+}
\ No newline at end of file
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouterCache.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/ArtifactRouterCache.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouterCache.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouterCache.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,75 @@
+package org.apache.maven.artifact.router;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.sonatype.aether.repository.RemoteRepository;
+
+public class ArtifactRouterCache
+{
+
+ public static final String SESSION_KEY = ArtifactRouterCache.class.getName();
+
+ private final Map<GroupCacheKey, RemoteRepository> groupRepositories =
+ new WeakHashMap<GroupCacheKey, RemoteRepository>();
+
+ public RemoteRepository getGroupRepository( GroupRoute groupRoute, boolean snapshot )
+ {
+ return groupRepositories.get( new GroupCacheKey( groupRoute, snapshot ) );
+ }
+
+ public void setGroupRepository( GroupRoute groupRoute, boolean snapshot,
+ RemoteRepository repo )
+ {
+ groupRepositories.put( new GroupCacheKey( groupRoute, snapshot ), repo );
+ }
+
+ public void clear()
+ {
+ groupRepositories.clear();
+ }
+
+ private static final class GroupCacheKey
+ {
+ private final GroupRoute route;
+ private final boolean snapshot;
+
+ GroupCacheKey( GroupRoute route, boolean snapshot )
+ {
+ this.route = route;
+ this.snapshot = snapshot;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( snapshot ? 1231 : 1237 );
+ result = prime * result + ( ( route == null ) ? 0 : route.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;
+ GroupCacheKey other = (GroupCacheKey) obj;
+ if ( snapshot != other.snapshot )
+ return false;
+ if ( route == null )
+ {
+ if ( other.route != null )
+ return false;
+ }
+ else if ( !route.equals( other.route ) )
+ return false;
+ return true;
+ }
+ }
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/ArtifactRouterCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.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/GroupPattern.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java Tue Aug 9 21:10:55 2011
@@ -163,7 +163,7 @@ public final class GroupPattern
{
final int prime = 31;
int result = 1;
- result = prime * result + ( ( basePattern == null ) ? 0 : basePattern.hashCode() );
+ result = prime * result + ( ( basePattern == null ) ? 0 : basePattern.hashCode() ) + ( wildcard ? 1 : 0 );
return result;
}
@@ -184,7 +184,8 @@ public final class GroupPattern
}
else if ( !basePattern.equals( other.basePattern ) )
return false;
- return true;
+
+ return wildcard == other.wildcard;
}
public String getBasePattern()
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java.orig
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java.orig?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java.orig (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupPattern.java.orig Tue Aug 9 21:10:55 2011
@@ -0,0 +1,213 @@
+/*
+ * 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.
+ */
+
+public final class GroupPattern
+ implements Comparable<GroupPattern>
+{
+
+ private static final String GROUP_SEPARATOR = "[\\/.]";
+
+ private final String pattern;
+
+ private transient final String[] parts;
+
+ private transient final boolean wildcard;
+
+ private transient final String basePattern;
+
+ public GroupPattern( String pattern )
+ {
+ this.pattern = pattern;
+ if ( pattern.endsWith("*") )
+ {
+ wildcard = true;
+ pattern = pattern.substring( 0, pattern.length() - 1 );
+ if ( pattern.endsWith(".") )
+ {
+ pattern = pattern.substring( 0, pattern.length() - 1 );
+ }
+ }
+ else
+ {
+ wildcard = false;
+ }
+
+ this.basePattern = pattern;
+ parts = pattern.split( GROUP_SEPARATOR );
+
+ if ( parts.length < 1 || parts[0] == "" )
+ {
+ throw new IllegalArgumentException( "Invalid groupId pattern: '" + this.pattern + "'." );
+ }
+ }
+
+ public boolean implies( GroupPattern pattern )
+ {
+ return implies( pattern.parts ) && ( wildcard || !pattern.wildcard );
+ }
+
+ public boolean implies( String pattern )
+ {
+ return implies( pattern.split( GROUP_SEPARATOR ) );
+ }
+
+ private boolean implies( String[] patternParts )
+ {
+ if ( parts.length > patternParts.length )
+ {
+ return false;
+ }
+
+ for ( int i = 0; i < parts.length; i++ )
+ {
+ if ( !parts[i].equals( patternParts[i]) )
+ {
+ return false;
+ }
+ }
+
+ if ( wildcard || parts.length == patternParts.length )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean moreGeneralThan( final GroupPattern other )
+ {
+ if ( this.implies( other ) && !other.implies( this ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean lessGeneralThan( final GroupPattern other )
+ {
+ if ( other.implies( this ) && !this.implies( other ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public int compareTo( GroupPattern other )
+ {
+ if ( other.basePattern.equals( basePattern ) )
+ {
+ if ( wildcard == other.wildcard )
+ {
+ return 0;
+ }
+ else if ( wildcard )
+ {
+ return 1;
+ }
+
+ return -1;
+ }
+ else if ( basePattern.startsWith( other.basePattern ) )
+ {
+ return -1;
+ }
+ else if ( other.basePattern.startsWith( basePattern ) )
+ {
+ return 1;
+ }
+
+ return basePattern.compareTo( other.basePattern );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( basePattern == null ) ? 0 : basePattern.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;
+ GroupPattern other = (GroupPattern) obj;
+ if ( basePattern == null )
+ {
+ if ( other.basePattern != null )
+ return false;
+ }
+ else if ( !basePattern.equals( other.basePattern ) )
+ return false;
+ return true;
+ }
+
+ public String getBasePattern()
+ {
+ return basePattern;
+ }
+
+ public boolean isWildcard()
+ {
+ return wildcard;
+ }
+
+ public String getPattern()
+ {
+ return pattern;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append( "GroupPattern [" ).append( pattern ).append( "]" );
+ return builder.toString();
+ }
+
+}
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.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/GroupRoute.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java Tue Aug 9 21:10:55 2011
@@ -49,56 +49,98 @@ public final class GroupRoute
public static final GroupRoute DEFAULT = new GroupRoute( "http://repo1.maven.org/maven2", new GroupPattern( "*" ) );
- private final String canonicalUrl;
+ private final String canonicalReleasesUrl;
- private final List<GroupPattern> groupPatterns = new ArrayList<GroupPattern>();
+ private String canonicalSnapshotsUrl;
- public GroupRoute( String canonicalUrl, Collection<GroupPattern> groupPatterns )
+ private List<GroupPattern> groupPatterns = new ArrayList<GroupPattern>();
+
+ public GroupRoute( String canonicalReleasesUrl, Collection<GroupPattern> groupPatterns )
{
- this.canonicalUrl = canonicalUrl;
- merge( groupPatterns );
+ this( canonicalReleasesUrl, null, groupPatterns );
}
- public GroupRoute( String canonicalUrl, GroupPattern...groupPatterns )
+ public GroupRoute( String canonicalReleasesUrl, GroupPattern...groupPatterns )
{
- this.canonicalUrl = canonicalUrl;
- merge( groupPatterns );
+ this( canonicalReleasesUrl, null, groupPatterns );
}
- public boolean merge( GroupPattern...groupPatterns )
+ public GroupRoute( String canonicalReleasesUrl, String canonicalSnapshotsUrl, Collection<GroupPattern> groupPatterns )
{
- return merge( Arrays.asList( groupPatterns ) );
+ this.canonicalReleasesUrl = canonicalReleasesUrl;
+ this.canonicalSnapshotsUrl = canonicalSnapshotsUrl;
+ this.groupPatterns = consolidate( this.groupPatterns, groupPatterns );
}
- public synchronized boolean merge( Collection<GroupPattern> groupPatterns )
+ public GroupRoute( String canonicalReleasesUrl, String canonicalSnapshotsUrl, GroupPattern...groupPatterns )
+ {
+ this.canonicalReleasesUrl = canonicalReleasesUrl;
+ this.canonicalSnapshotsUrl = canonicalSnapshotsUrl;
+ this.groupPatterns.clear();
+ this.groupPatterns = consolidate( this.groupPatterns, Arrays.asList( groupPatterns ) );
+ }
+
+ public synchronized boolean merge( GroupRoute otherRoute )
{
boolean changed = false;
- if ( groupPatterns != null && !groupPatterns.isEmpty() )
+ if ( this.canonicalSnapshotsUrl == null && patternsAreEqual( otherRoute ) )
{
- List<GroupPattern> all = new ArrayList<GroupPattern>( this.groupPatterns );
- all.addAll( groupPatterns );
- Collections.sort( all );
- Collections.reverse( all );
-
- this.groupPatterns.clear();
-
- GroupPattern last = all.remove( 0 );
- for ( GroupPattern p : all )
- {
- if ( !last.implies( p ) )
- {
- this.groupPatterns.add( last );
- last = p;
- }
- }
-
- this.groupPatterns.add( last );
+ this.canonicalSnapshotsUrl = otherRoute.getCanonicalSnapshotsUrl();
}
+ this.groupPatterns = consolidate( this.groupPatterns, otherRoute.getGroupPatterns() );
+
return changed;
}
+ private boolean patternsAreEqual( GroupRoute otherRoute )
+ {
+ List<GroupPattern> otherPatterns = otherRoute.getGroupPatterns();
+ if ( groupPatterns.size() != otherPatterns.size() )
+ return false;
+
+ for( int i = 0; i< groupPatterns.size(); i++ )
+ {
+ if ( !groupPatterns.get( i ).equals( otherPatterns.get( i ) ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private synchronized List<GroupPattern> consolidate( List<GroupPattern> myPatterns,
+ Collection<GroupPattern> otherPatterns )
+ {
+ if ( otherPatterns == null || otherPatterns.isEmpty() )
+ {
+ return myPatterns;
+ }
+
+ List<GroupPattern> result = new ArrayList<GroupPattern>();
+
+ List<GroupPattern> all = new ArrayList<GroupPattern>( myPatterns );
+ all.addAll( otherPatterns );
+ Collections.sort( all );
+ Collections.reverse( all );
+
+ GroupPattern last = all.remove( 0 );
+ for ( GroupPattern p : all )
+ {
+ if ( !last.implies( p ) )
+ {
+ result.add( last );
+ last = p;
+ }
+ }
+
+ result.add( last );
+
+ return result;
+ }
+
public boolean contains( GroupPattern pattern )
{
for ( GroupPattern p : groupPatterns )
@@ -125,12 +167,17 @@ public final class GroupRoute
return false;
}
- public String getCanonicalUrl()
+ public String getCanonicalReleasesUrl()
+ {
+ return canonicalReleasesUrl;
+ }
+
+ public String getCanonicalSnapshotsUrl()
{
- return canonicalUrl;
+ return canonicalSnapshotsUrl;
}
- public Collection<GroupPattern> getGroupPatterns()
+ public List<GroupPattern> getGroupPatterns()
{
return groupPatterns;
}
@@ -140,7 +187,7 @@ public final class GroupRoute
{
final int prime = 31;
int result = 1;
- result = prime * result + ( ( canonicalUrl == null ) ? 0 : canonicalUrl.hashCode() );
+ result = prime * result + ( ( canonicalReleasesUrl == null ) ? 0 : canonicalReleasesUrl.hashCode() );
return result;
}
@@ -154,12 +201,12 @@ public final class GroupRoute
if ( getClass() != obj.getClass() )
return false;
GroupRoute other = (GroupRoute) obj;
- if ( canonicalUrl == null )
+ if ( canonicalReleasesUrl == null )
{
- if ( other.canonicalUrl != null )
+ if ( other.canonicalReleasesUrl != null )
return false;
}
- else if ( !canonicalUrl.equals( other.canonicalUrl ) )
+ else if ( !canonicalReleasesUrl.equals( other.canonicalReleasesUrl ) )
return false;
return true;
}
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java.orig
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java.orig?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java.orig (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/GroupRoute.java.orig Tue Aug 9 21:10:55 2011
@@ -0,0 +1,167 @@
+/*
+ * 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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public final class GroupRoute
+{
+
+ public static final GroupRoute DEFAULT = new GroupRoute( "http://repo1.maven.org/maven2", new GroupPattern( "*" ) );
+
+ private final String canonicalUrl;
+
+ private final List<GroupPattern> groupPatterns = new ArrayList<GroupPattern>();
+
+ public GroupRoute( String canonicalUrl, Collection<GroupPattern> groupPatterns )
+ {
+ this.canonicalUrl = canonicalUrl;
+ merge( groupPatterns );
+ }
+
+ public GroupRoute( String canonicalUrl, GroupPattern...groupPatterns )
+ {
+ this.canonicalUrl = canonicalUrl;
+ merge( groupPatterns );
+ }
+
+ public boolean merge( GroupPattern...groupPatterns )
+ {
+ return merge( Arrays.asList( groupPatterns ) );
+ }
+
+ public synchronized boolean merge( Collection<GroupPattern> groupPatterns )
+ {
+ boolean changed = false;
+
+ if ( groupPatterns != null && !groupPatterns.isEmpty() )
+ {
+ List<GroupPattern> all = new ArrayList<GroupPattern>( this.groupPatterns );
+ all.addAll( groupPatterns );
+ Collections.sort( all );
+ Collections.reverse( all );
+
+ this.groupPatterns.clear();
+
+ GroupPattern last = all.remove( 0 );
+ for ( GroupPattern p : all )
+ {
+ if ( !last.implies( p ) )
+ {
+ this.groupPatterns.add( last );
+ last = p;
+ }
+ }
+
+ this.groupPatterns.add( last );
+ }
+
+ return changed;
+ }
+
+ public boolean contains( GroupPattern pattern )
+ {
+ for ( GroupPattern p : groupPatterns )
+ {
+ if ( p.implies( pattern ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean contains( String pattern )
+ {
+ for ( GroupPattern p : groupPatterns )
+ {
+ if ( p.implies( pattern ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public String getCanonicalUrl()
+ {
+ return canonicalUrl;
+ }
+
+ public Collection<GroupPattern> getGroupPatterns()
+ {
+ return groupPatterns;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( canonicalUrl == null ) ? 0 : canonicalUrl.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;
+ GroupRoute other = (GroupRoute) obj;
+ if ( canonicalUrl == null )
+ {
+ if ( other.canonicalUrl != null )
+ return false;
+ }
+ else if ( !canonicalUrl.equals( other.canonicalUrl ) )
+ return false;
+ return true;
+ }
+
+}
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/MirrorRoute.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/MirrorRoute.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/MirrorRoute.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/MirrorRoute.java Tue Aug 9 21:10:55 2011
@@ -58,7 +58,7 @@ public final class MirrorRoute
private final int weight;
private final boolean enabled;
-
+
private final Set<String> mirrorOfUrls;
// NOTE: ONLY used during deserialization!
@@ -71,8 +71,8 @@ public final class MirrorRoute
enabled = false;
}
- public MirrorRoute( final String id, final String routeUrl, final int weight,
- final boolean enabled, final String... mirrorOfUrls )
+ public MirrorRoute( final String id, final String routeUrl,
+ final int weight, final boolean enabled, final String... mirrorOfUrls )
{
if ( mirrorOfUrls.length < 1 )
{
@@ -86,8 +86,8 @@ public final class MirrorRoute
this.enabled = enabled;
}
- public MirrorRoute( final String id, final String routeUrl, final int weight,
- final boolean enabled, final Collection<String> mirrorOfUrls )
+ public MirrorRoute( final String id, final String routeUrl,
+ final int weight, final boolean enabled, final Collection<String> mirrorOfUrls )
{
if ( mirrorOfUrls.size() < 1 )
{
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/RoutingRequestConverter.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/RoutingRequestConverter.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/RoutingRequestConverter.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/RoutingRequestConverter.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,28 @@
+package org.apache.maven.artifact.router;
+
+import java.util.Collection;
+
+import org.sonatype.aether.RepositorySystemSession;
+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;
+
+public interface RoutingRequestConverter
+{
+
+ void convert( final VersionRangeRequest request, final RepositorySystemSession session );
+
+ void convert( VersionRequest request, RepositorySystemSession session );
+
+ void convert( ArtifactDescriptorRequest request, RepositorySystemSession session );
+
+ void convert( ArtifactRequest request, RepositorySystemSession session );
+
+ void convert( Collection<? extends ArtifactRequest> requests, RepositorySystemSession session );
+
+ Collection<? extends MetadataRequest> mapMetadataRequests( Collection<? extends MetadataRequest> requests,
+ RepositorySystemSession session );
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/RoutingRequestConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigLoader.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/conf/ArtifactRouterConfigLoader.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigLoader.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigLoader.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+public interface ArtifactRouterConfigLoader
+{
+
+ ArtifactRouterConfiguration build()
+ throws ArtifactRouterConfigurationException;
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.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/conf/ArtifactRouterConfiguration.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,40 @@
+package org.apache.maven.artifact.router.conf;
+
+import java.io.File;
+
+public interface ArtifactRouterConfiguration
+{
+
+ public static final RouterSource CANONICAL_GROUP_SOURCE =
+ new RouterSource( "default", "http://repository.apache.org/router/groups.json" );
+
+ public static final RouterSource CANONICAL_MIRROR_SOURCE =
+ new RouterSource( "default", "http://repository.apache.org/router/mirrors.json" );
+
+ public static final String NO_DISCOVERY_STRATEGIES = "none";
+
+ public static final String WEIGHTED_RANDOM_STRATEGY = "weighted-random";
+
+ RouterSource getGroupSource();
+
+ RouterSource getMirrorSource();
+
+ boolean isDisabled();
+
+ String getDiscoveryStrategy();
+
+ String getSelectionStrategy();
+
+ File getRoutesFile();
+
+ boolean isOffline();
+
+ boolean isClear();
+
+ boolean isUpdate();
+
+ RouterSource getDefaultGroupSource();
+
+ RouterSource getDefaultMirrorSource();
+
+}
\ No newline at end of file
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.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/conf/ArtifactRouterConfigurationException.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.maven.artifact.router.ArtifactRouterException;
+
+/*
+ * 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.
+ */
+
+public class ArtifactRouterConfigurationException
+ extends ArtifactRouterException
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public ArtifactRouterConfigurationException( final String message, final Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ArtifactRouterConfigurationException( final String message )
+ {
+ super( message );
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.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/conf/ArtifactRouterOption.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public enum ArtifactRouterOption
+{
+
+ update( "Update routes" ),
+ offline( "Offline. Use only stored routes." ),
+ clear( "Clear stored routes." ),
+ unset( "Unset defaults." );
+
+ private String description;
+
+ private ArtifactRouterOption( String description )
+ {
+ this.description = description;
+ }
+
+ public static String list( String separator )
+ {
+ StringBuilder sb = new StringBuilder();
+ for ( ArtifactRouterOption opt : values() )
+ {
+ sb.append( separator ).append( opt.name().toLowerCase() ).append( " - " ).append( opt.description );
+ }
+
+ return sb.toString();
+ }
+
+ public static Set<ArtifactRouterOption> parse( String... values )
+ {
+ Set<ArtifactRouterOption> options = new HashSet<ArtifactRouterOption>();
+
+ Map<String, ArtifactRouterOption> allOptions = new HashMap<String, ArtifactRouterOption>();
+ for ( ArtifactRouterOption value : values() )
+ {
+ allOptions.put( value.name(), value );
+ }
+
+ all: for ( String value : values )
+ {
+ String[] parts = value.split( "[|,]" );
+ for ( String part : parts )
+ {
+ ArtifactRouterOption opt = allOptions.remove( part.toLowerCase().trim() );
+ if ( opt != null )
+ {
+ options.add( opt );
+ }
+
+ if ( allOptions.isEmpty() )
+ {
+ break all;
+ }
+ }
+ }
+
+ return options;
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterOption.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.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/conf/RouterSource.java?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.java Tue Aug 9 21:10:55 2011
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+public class RouterSource
+{
+
+ private final String url;
+
+ private final String id;
+
+ public RouterSource( String id, String url )
+ {
+ this.id = id;
+ this.url = url;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+
+ public String toString()
+ {
+ return "RouterSource[" + id + "@" + getUrl() + "]";
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/conf/RouterSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.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/io/ArtifactRouteSerializer.java?rev=1155565&r1=1155564&r2=1155565&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java (original)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java Tue Aug 9 21:10:55 2011
@@ -42,6 +42,7 @@ import org.apache.maven.artifact.router.
import org.apache.maven.artifact.router.GroupPattern;
import org.apache.maven.artifact.router.GroupRoute;
import org.apache.maven.artifact.router.MirrorRoute;
+import org.apache.maven.artifact.router.ArtifactRouter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java.orig
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java.orig?rev=1155565&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java.orig (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-api/src/main/java/org/apache/maven/artifact/router/io/ArtifactRouteSerializer.java.orig Tue Aug 9 21:10:55 2011
@@ -0,0 +1,357 @@
+/*
+ * 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.io;
+
+/*
+ * 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.GroupPattern;
+import org.apache.maven.artifact.router.GroupRoute;
+import org.apache.maven.artifact.router.MirrorRoute;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.InstanceCreator;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import com.google.gson.reflect.TypeToken;
+
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class ArtifactRouteSerializer
+{
+
+ // NOTE: Gson is supposed to be threadsafe, so all this static stuff should be fine.
+ private static Gson gson;
+
+ public static void serializeMirrors( final Set<MirrorRoute> mirrors, final Writer writer )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ getGson().toJson( mirrors, writer );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write mirrors to router format.", e );
+ }
+ }
+
+ public static String serializeMirrorsToString( final Set<MirrorRoute> mirrors )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().toJson( mirrors );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write mirrors to router format.", e );
+ }
+ }
+
+ public static Set<MirrorRoute> deserializeMirrors( final Reader reader )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( reader, RepositoryMirrorSetCreator.getType() );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read mirrors from router format.", e );
+ }
+ }
+
+ public static Set<MirrorRoute> deserializeMirrors( final String source )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( source, RepositoryMirrorSetCreator.getType() );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read mirrors from router format.", e );
+ }
+ }
+
+ public static void serializeGroups( final Set<GroupRoute> groups, final Writer writer )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ getGson().toJson( groups, writer );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write groups to router format.", e );
+ }
+ }
+
+ public static String serializeGroupsToString( final Set<GroupRoute> groups )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().toJson( groups );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write groups to router format.", e );
+ }
+ }
+
+ public static Set<GroupRoute> deserializeGroups( final Reader reader )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( reader, GroupRouteSetCreator.getType() );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read groups from router format.", e );
+ }
+ }
+
+ public static Set<GroupRoute> deserializeGroups( final String source )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( source, GroupRouteSetCreator.getType() );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read groups from router format.", e );
+ }
+ }
+
+ public static void serialize( final ArtifactRouter tables, final Writer writer )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ getGson().toJson( tables, writer );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write routing tables.", e );
+ }
+ }
+
+ public static String serializeToString( final ArtifactRouter tables )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().toJson( tables );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot write routing tables.", e );
+ }
+ }
+
+ public static ArtifactRouter deserialize( final Reader reader )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( reader, ArtifactRouter.class );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read routing tables.", e );
+ }
+ }
+
+ public static ArtifactRouter deserialize( final String source )
+ throws ArtifactRouterModelException
+ {
+ try
+ {
+ return getGson().fromJson( source, ArtifactRouter.class );
+ }
+ catch ( final JsonParseException e )
+ {
+ throw new ArtifactRouterModelException( "Cannot read routing tables.", e );
+ }
+ }
+
+ private static Gson getGson()
+ {
+ if ( gson == null )
+ {
+ final GsonBuilder builder = new GsonBuilder();
+ builder.disableHtmlEscaping().disableInnerClassSerialization().setPrettyPrinting();
+ builder.registerTypeAdapter( RepositoryMirrorSetCreator.getType(), new RepositoryMirrorSetCreator() );
+ builder.registerTypeAdapter( RepositoryMirrorListCreator.getType(), new RepositoryMirrorListCreator() );
+ builder.registerTypeAdapter( GroupRouteMapCreator.getType(), new GroupRouteMapCreator() );
+ builder.registerTypeAdapter( GroupRouteSetCreator.getType(), new GroupRouteSetCreator() );
+ builder.registerTypeAdapter( GroupPattern.class, new GroupPatternSerializer() );
+
+ gson = builder.create();
+ }
+
+ return gson;
+ }
+
+ public static final class GroupRouteMapCreator
+ implements InstanceCreator<Map<GroupPattern, GroupRoute>>
+ {
+
+ public Map<GroupPattern, GroupRoute> createInstance( Type type )
+ {
+ return new HashMap<GroupPattern, GroupRoute>();
+ }
+
+ public static Type getType()
+ {
+ return new TypeToken<Map<GroupPattern, GroupRoute>>()
+ {
+ }.getType();
+ }
+
+ }
+
+ public static final class GroupRouteSetCreator
+ implements InstanceCreator<Set<GroupRoute>>
+ {
+
+ public Set<GroupRoute> createInstance( Type type )
+ {
+ return new HashSet<GroupRoute>();
+ }
+
+ public static Type getType()
+ {
+ return new TypeToken<Set<GroupRoute>>()
+ {
+ }.getType();
+ }
+
+ }
+
+ public static final class GroupPatternListCreator
+ implements InstanceCreator<List<GroupPattern>>
+ {
+
+ public List<GroupPattern> createInstance( Type type )
+ {
+ return new ArrayList<GroupPattern>();
+ }
+
+ public static Type getType()
+ {
+ return new TypeToken<List<GroupPattern>>()
+ {
+ }.getType();
+ }
+
+ }
+
+ public static final class RepositoryMirrorListCreator
+ implements InstanceCreator<List<MirrorRoute>>
+ {
+
+ public List<MirrorRoute> createInstance( final Type type )
+ {
+ return new ArrayList<MirrorRoute>();
+ }
+
+ public static Type getType()
+ {
+ return new TypeToken<List<MirrorRoute>>()
+ {
+ }.getType();
+ }
+
+ }
+
+ public static final class RepositoryMirrorSetCreator
+ implements InstanceCreator<Set<MirrorRoute>>
+ {
+
+ public Set<MirrorRoute> createInstance( final Type type )
+ {
+ return new LinkedHashSet<MirrorRoute>();
+ }
+
+ public static Type getType()
+ {
+ return new TypeToken<Set<MirrorRoute>>()
+ {
+ }.getType();
+ }
+
+ }
+
+ public static final class GroupPatternSerializer
+ implements JsonSerializer<GroupPattern>, JsonDeserializer<GroupPattern>
+ {
+
+ public GroupPattern deserialize( JsonElement json, Type typeOfT, JsonDeserializationContext context )
+ throws JsonParseException
+ {
+ String pattern = json.getAsString();
+ return new GroupPattern( pattern );
+ }
+
+ public JsonElement serialize( GroupPattern src, Type typeOfSrc, JsonSerializationContext context )
+ {
+ return new JsonPrimitive( src.getPattern() );
+ }
+
+ }
+
+}