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/05/24 05:31:42 UTC
svn commit: r1126851 [2/2] - in
/maven/maven-3/branches/mirror-group-routing: ./
maven-compat/src/main/java/org/apache/maven/repository/ maven-core/
maven-core/src/main/java/org/apache/maven/
maven-core/src/main/java/org/apache/maven/execution/ maven-c...
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/ArtifactRouterException.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/ArtifactRouterException.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/ArtifactRouterException.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/ArtifactRouterException.java Tue May 24 03:31:40 2011
@@ -0,0 +1,38 @@
+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 class ArtifactRouterException
+ extends Exception
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public ArtifactRouterException( final String message, final Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public ArtifactRouterException( final String message )
+ {
+ super( message );
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/ArtifactRouterException.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/ArtifactRouterConfiguration.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/ArtifactRouterConfiguration.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfiguration.java Tue May 24 03:31:40 2011
@@ -0,0 +1,124 @@
+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 org.apache.http.auth.UsernamePasswordCredentials;
+
+import java.io.File;
+
+public final class ArtifactRouterConfiguration
+{
+
+ private static final String CANONICAL_MIRRORS_URL = "http://repository.apache.org/router/mirrors.json";
+
+ private static final String CANONICAL_GROUPS_URL = "http://repository.apache.org/router/groups.json";
+
+ public static final String ALL_DISCOVERY_STRATEGIES = "all";
+
+ public static final String NO_DISCOVERY_STRATEGIES = "none";
+
+ private File selectedRoutesFile;
+
+ private String routerMirrorsUrl;
+
+ private UsernamePasswordCredentials routerCredentials;
+
+ private boolean disabled = false;
+
+ private String[] discoveryStrategies = { ALL_DISCOVERY_STRATEGIES };
+
+ private String routerGroupsUrl;
+
+ public ArtifactRouterConfiguration setRouterCredentials( final String user, final String password )
+ {
+ routerCredentials = new UsernamePasswordCredentials( user, password );
+ return this;
+ }
+
+ public UsernamePasswordCredentials getRouterCredentials()
+ {
+ return routerCredentials;
+ }
+
+ public ArtifactRouterConfiguration setRouterMirrorsUrl( final String routerMirrorsUrl )
+ {
+ this.routerMirrorsUrl = routerMirrorsUrl;
+ return this;
+ }
+
+ public String getRouterMirrorsUrl()
+ {
+ return routerMirrorsUrl;
+ }
+
+ public void setRouterGroupsUrl( String routerGroupsUrl )
+ {
+ this.routerGroupsUrl = routerGroupsUrl;
+ }
+
+ public String getRouterGroupsUrl()
+ {
+ return routerGroupsUrl;
+ }
+
+ public boolean isDisabled()
+ {
+ return disabled;
+ }
+
+ public ArtifactRouterConfiguration setDisabled( final boolean disabled )
+ {
+ this.disabled = disabled;
+ return this;
+ }
+
+ public String getCanonicalMirrorsUrl()
+ {
+ return CANONICAL_MIRRORS_URL;
+ }
+
+ public String getCanonicalGroupsUrl()
+ {
+ return CANONICAL_GROUPS_URL;
+ }
+
+ public String[] getDiscoveryStrategies()
+ {
+ return discoveryStrategies == null ? new String[0] : discoveryStrategies;
+ }
+
+ public ArtifactRouterConfiguration setDiscoveryStrategies( final String... strategies )
+ {
+ discoveryStrategies = strategies;
+ return this;
+ }
+
+ public File getSelectedRoutesFile()
+ {
+ return selectedRoutesFile;
+ }
+
+ public ArtifactRouterConfiguration setSelectedRoutesFile( File selectedRoutesFile )
+ {
+ this.selectedRoutesFile = selectedRoutesFile;
+ return this;
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/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-impl/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-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/ArtifactRouterConfigurationException.java Tue May 24 03:31:40 2011
@@ -0,0 +1,38 @@
+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 class ArtifactRouterConfigurationException
+ extends Exception
+{
+
+ 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-impl/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-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultRouterConfigBuilder.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/DefaultRouterConfigBuilder.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultRouterConfigBuilder.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultRouterConfigBuilder.java Tue May 24 03:31:40 2011
@@ -0,0 +1,115 @@
+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 static org.codehaus.plexus.util.StringUtils.isNotBlank;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+
+import javax.inject.Named;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+//@Component( role = RouterConfigBuilder.class )
+@Named( "default" )
+public class DefaultRouterConfigBuilder
+ implements RouterConfigBuilder
+{
+
+ private static final String KEY_ROUTER_MIRRORS_URL = "router-mirrors-url";
+
+ private static final String KEY_ROUTER_GROUPS_URL = "router-groups-url";
+
+ private static final String KEY_ROUTER_USER = "router-user";
+
+ private static final String KEY_ROUTER_PASSWORD = "router-password";
+
+ private static final String KEY_DISABLED = "disabled";
+
+ private static final String KEY_DISCOVERY_STRATEGIES = "discovery-strategies";
+
+ @Requirement
+ private Logger logger;
+
+ public ArtifactRouterConfiguration build( final RouterConfigSource source )
+ throws ArtifactRouterConfigurationException
+ {
+ final ArtifactRouterConfiguration config = new ArtifactRouterConfiguration();
+
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Loading mirror configuration from file: " + source.getSource() );
+ }
+
+ if ( source.canRead() )
+ {
+ InputStream stream = null;
+ try
+ {
+ stream = source.getInputStream();
+ final Properties p = new Properties();
+ p.load( stream );
+
+ config.setRouterMirrorsUrl( p.getProperty( KEY_ROUTER_MIRRORS_URL ) );
+ config.setRouterGroupsUrl( p.getProperty( KEY_ROUTER_GROUPS_URL ) );
+ config.setDisabled( Boolean.parseBoolean( p.getProperty( KEY_DISABLED, "false" ) ) );
+
+ final String user = p.getProperty( KEY_ROUTER_USER );
+ final String pass = p.getProperty( KEY_ROUTER_PASSWORD );
+
+ final String[] strat =
+ p.getProperty( KEY_DISCOVERY_STRATEGIES, ArtifactRouterConfiguration.ALL_DISCOVERY_STRATEGIES )
+ .split( "\\s*,\\s*" );
+
+ config.setDiscoveryStrategies( strat );
+
+ if ( isNotBlank( user ) && isNotBlank( pass ) )
+ {
+ config.setRouterCredentials( user, pass );
+ }
+ }
+ catch ( final IOException e )
+ {
+ throw new ArtifactRouterConfigurationException( "Failed to read router config properties from: '"
+ + source.getSource() + "'.", e );
+ }
+ finally
+ {
+ close( stream );
+ }
+ }
+ else
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Cannot read router configuration from: " + source.getSource()
+ + ". Using defaults." );
+ }
+ }
+
+ return config;
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/DefaultRouterConfigBuilder.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/FileRouterConfigSource.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/FileRouterConfigSource.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigSource.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigSource.java Tue May 24 03:31:40 2011
@@ -0,0 +1,63 @@
+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 java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class FileRouterConfigSource
+ implements RouterConfigSource
+{
+
+ private static final String CONFIG_FILENAME = "router.properties";
+
+ private File configFile;
+
+ public FileRouterConfigSource( final File src )
+ {
+ if ( src != null && src.isDirectory() )
+ {
+ configFile = new File( src, CONFIG_FILENAME );
+ }
+ else
+ {
+ configFile = src;
+ }
+ }
+
+ public Object getSource()
+ {
+ return configFile;
+ }
+
+ public boolean canRead()
+ {
+ return configFile != null && configFile.exists() && configFile.canRead() && !configFile.isDirectory();
+ }
+
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return new FileInputStream( configFile );
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/FileRouterConfigSource.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/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=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.java Tue May 24 03:31:40 2011
@@ -0,0 +1,28 @@
+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 RouterConfigBuilder
+{
+
+ ArtifactRouterConfiguration build( final RouterConfigSource source )
+ throws ArtifactRouterConfigurationException;
+
+}
\ No newline at end of file
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigBuilder.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/RouterConfigSource.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/RouterConfigSource.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigSource.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigSource.java Tue May 24 03:31:40 2011
@@ -0,0 +1,35 @@
+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 java.io.IOException;
+import java.io.InputStream;
+
+public interface RouterConfigSource
+{
+
+ Object getSource();
+
+ boolean canRead();
+
+ InputStream getInputStream()
+ throws IOException;
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/conf/RouterConfigSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/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/discovery/ArtifactRouterDiscoveryStrategy.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/ArtifactRouterDiscoveryStrategy.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/ArtifactRouterDiscoveryStrategy.java Tue May 24 03:31:40 2011
@@ -0,0 +1,30 @@
+package org.apache.maven.artifact.router.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 org.apache.maven.artifact.router.ArtifactRouterException;
+
+public interface ArtifactRouterDiscoveryStrategy
+{
+
+ String findRouter()
+ throws ArtifactRouterException;
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/ArtifactRouterDiscoveryStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/DNSDiscoveryStrategy.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/discovery/DNSDiscoveryStrategy.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/DNSDiscoveryStrategy.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/DNSDiscoveryStrategy.java Tue May 24 03:31:40 2011
@@ -0,0 +1,107 @@
+package org.apache.maven.artifact.router.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 org.apache.maven.artifact.router.ArtifactRouterException;
+import org.codehaus.plexus.component.annotations.Component;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+@Component( role = ArtifactRouterDiscoveryStrategy.class, hint = "dns" )
+final class DNSDiscoveryStrategy
+ implements ArtifactRouterDiscoveryStrategy
+{
+
+ public String findRouter()
+ throws ArtifactRouterException
+ {
+ final Map<String, String> env = new HashMap<String, String>();
+ env.put( "java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory" );
+
+ DirContext jndiContext;
+ try
+ {
+ jndiContext = new InitialDirContext( new Hashtable<String, String>( env ) );
+ }
+ catch ( final NamingException e )
+ {
+ throw new ArtifactRouterException( "Failed to initialize JNDI context for mirror-router DNS lookups: "
+ + e.getMessage(), e );
+ }
+
+ InetAddress[] addresses;
+ try
+ {
+ final InetAddress lh = InetAddress.getLocalHost();
+ addresses = InetAddress.getAllByName( lh.getHostName() );
+ }
+ catch ( final UnknownHostException e )
+ {
+ throw new ArtifactRouterException( "Failed to retrieve local hostnames for mirror router: " + e.getMessage(),
+ e );
+ }
+
+ for ( final InetAddress addr : addresses )
+ {
+ final String hostname = addr.getCanonicalHostName();
+
+ final int idx = hostname.indexOf( '.' );
+ if ( idx > -1 )
+ {
+ final String domain = hostname.substring( idx + 1 );
+ final Attributes attrs;
+ try
+ {
+ attrs = jndiContext.getAttributes( "_maven." + domain, new String[] { "TXT" } );
+ }
+ catch ( final NamingException e )
+ {
+ continue;
+ }
+
+ String txtRecord = null;
+ try
+ {
+ txtRecord = (String) attrs.get( "TXT" ).get();
+ }
+ catch ( final NamingException e )
+ {
+ }
+
+ if ( txtRecord != null )
+ {
+ return txtRecord;
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/discovery/DNSDiscoveryStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/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-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java?rev=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/ArtifactRouterLoader.java Tue May 24 03:31:40 2011
@@ -0,0 +1,35 @@
+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.conf.ArtifactRouterConfiguration;
+
+public interface ArtifactRouterLoader
+{
+
+ ArtifactRouter load( ArtifactRouterConfiguration config )
+ throws ArtifactRouterException;
+
+ void saveSelectedMirrors( ArtifactRouter router, ArtifactRouterConfiguration config )
+ throws ArtifactRouterException;
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/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-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=1126851&view=auto
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java (added)
+++ maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java Tue May 24 03:31:40 2011
@@ -0,0 +1,404 @@
+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 static org.codehaus.plexus.util.IOUtil.close;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.maven.artifact.router.MirrorRoute;
+import org.apache.maven.artifact.router.ArtifactRouteSerializer;
+import org.apache.maven.artifact.router.ArtifactRouterModelException;
+import org.apache.maven.artifact.router.ArtifactRoutingTables;
+import org.apache.maven.artifact.router.ArtifactRouter;
+import org.apache.maven.artifact.router.ArtifactRouterException;
+import org.apache.maven.artifact.router.conf.ArtifactRouterConfiguration;
+import org.apache.maven.artifact.router.discovery.ArtifactRouterDiscoveryStrategy;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.IOUtil;
+
+import javax.inject.Named;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+//@Component( role = ArtifactRouterLoader.class )
+@Named( "default" )
+public class DefaultRouterLoader
+ implements ArtifactRouterLoader
+{
+
+ @Requirement( role = ArtifactRouterDiscoveryStrategy.class )
+ private Map<String, ArtifactRouterDiscoveryStrategy> strategies;
+
+ @Requirement
+ private Logger logger;
+
+ public ArtifactRouter load( final ArtifactRouterConfiguration config )
+ throws ArtifactRouterException
+ {
+ if ( config == null )
+ {
+ return new ArtifactRouter();
+ }
+
+ ArtifactRoutingTables routingTable = loadRoutingTable( config );
+ Map<String, MirrorRoute> selectedRoutes = loadSelectedRoutes( config );
+
+ return new ArtifactRouter( routingTable, selectedRoutes );
+ }
+
+ public void saveSelectedMirrors( final ArtifactRouter router, final ArtifactRouterConfiguration config )
+ throws ArtifactRouterException
+ {
+ if ( config == null )
+ {
+ return;
+ }
+
+ Map<String, MirrorRoute> selectedRoutes = router.getSelectedRoutes();
+ File selectedRoutesFile = config.getSelectedRoutesFile();
+ if ( selectedRoutesFile != null )
+ {
+ FileWriter writer = null;
+ try
+ {
+ File dir = selectedRoutesFile.getParentFile();
+ if ( dir != null && !dir.exists() )
+ {
+ dir.mkdirs();
+ }
+
+ writer = new FileWriter( selectedRoutesFile );
+ ArtifactRouteSerializer.serializeLoose( new LinkedHashSet<MirrorRoute>( selectedRoutes.values() ), writer );
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactRouterException( "Cannot write selected mirrors to: " + selectedRoutesFile, e );
+ }
+ catch ( ArtifactRouterModelException e )
+ {
+ throw new ArtifactRouterException( "Cannot write selected mirrors to: " + selectedRoutesFile, e );
+ }
+ finally
+ {
+ close( writer );
+ }
+ }
+ }
+
+ protected Map<String, MirrorRoute> loadSelectedRoutes( ArtifactRouterConfiguration config )
+ throws ArtifactRouterException
+ {
+ File selectedRoutesFile = config.getSelectedRoutesFile();
+ if ( selectedRoutesFile != null && selectedRoutesFile.exists() && selectedRoutesFile.canRead() )
+ {
+ FileReader reader = null;
+ try
+ {
+ reader = new FileReader( selectedRoutesFile );
+ Set<MirrorRoute> routes = ArtifactRouteSerializer.deserializeLoose( reader );
+
+ Map<String, MirrorRoute> result = new LinkedHashMap<String, MirrorRoute>();
+ for ( MirrorRoute route : routes )
+ {
+ for ( String mirrorOf : route.getMirrorOfUrls() )
+ {
+ result.put( mirrorOf, route );
+ }
+ }
+
+ return result;
+ }
+ catch ( IOException e )
+ {
+ throw new ArtifactRouterException( "Cannot read selected mirrors from: " + selectedRoutesFile, e );
+ }
+ catch ( ArtifactRouterModelException e )
+ {
+ throw new ArtifactRouterException( "Cannot read selected mirrors from: " + selectedRoutesFile, e );
+ }
+ finally
+ {
+ close( reader );
+ }
+ }
+
+ return Collections.emptyMap();
+ }
+
+ protected ArtifactRoutingTables loadRoutingTable( final ArtifactRouterConfiguration config )
+ throws ArtifactRouterException
+ {
+ ArtifactRoutingTables routingTable = null;
+
+ if ( !config.isDisabled() )
+ {
+ final DefaultHttpClient client = new DefaultHttpClient();
+ if ( config.getRouterCredentials() != null )
+ {
+ client.setCredentialsProvider( new CredentialsProvider()
+ {
+ public void setCredentials( final AuthScope authscope, final Credentials credentials )
+ {
+ }
+
+ public synchronized Credentials getCredentials( final AuthScope authscope )
+ {
+ final UsernamePasswordCredentials creds = config.getRouterCredentials();
+ return creds;
+ }
+
+ public void clear()
+ {
+ }
+ } );
+ }
+
+ try
+ {
+ if ( config.getRouterMirrorsUrl() != null )
+ {
+ routingTable = getMirrorMapping( config.getRouterMirrorsUrl(), config, client );
+ }
+ else
+ {
+ final String[] discoStrategies = config.getDiscoveryStrategies();
+ final List<ArtifactRouterDiscoveryStrategy> strats = new ArrayList<ArtifactRouterDiscoveryStrategy>();
+ if ( discoStrategies.length == 1 )
+ {
+ final String key = discoStrategies[0];
+ if ( ArtifactRouterConfiguration.NO_DISCOVERY_STRATEGIES.equalsIgnoreCase( key ) )
+ {
+ // NOP
+ }
+ else if ( ArtifactRouterConfiguration.ALL_DISCOVERY_STRATEGIES.equalsIgnoreCase( key ) )
+ {
+ strats.addAll( strategies.values() );
+ }
+ else
+ {
+ final ArtifactRouterDiscoveryStrategy strat = getDiscoveryStrategy( key );
+ if ( strat != null )
+ {
+ strats.add( strat );
+ }
+ }
+ }
+ else
+ {
+ for ( final String key : discoStrategies )
+ {
+ final ArtifactRouterDiscoveryStrategy strat = getDiscoveryStrategy( key );
+ if ( strat != null )
+ {
+ strats.add( strat );
+ }
+ }
+ }
+
+ String routerUrl = null;
+ for ( final ArtifactRouterDiscoveryStrategy strategy : strats )
+ {
+ routerUrl = strategy.findRouter();
+ if ( routerUrl != null && routerUrl.trim().length() > 0 )
+ {
+ routingTable = getMirrorMapping( routerUrl, config, client );
+ if ( routingTable != null )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ final String centralRouterUrl = config.getCanonicalMirrorsUrl();
+ if ( routingTable == null && centralRouterUrl != null && centralRouterUrl.trim().length() > 0 )
+ {
+ routingTable = getMirrorMapping( centralRouterUrl, config, client );
+ }
+ }
+ catch ( final ArtifactRouterException e )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.error( "Failed to auto-detect mirrors: " + e.getMessage(), e );
+ }
+ }
+ }
+
+ if ( routingTable == null )
+ {
+ routingTable = new ArtifactRoutingTables();
+ }
+
+ return routingTable;
+ }
+
+ private ArtifactRouterDiscoveryStrategy getDiscoveryStrategy( final String key )
+ {
+ ArtifactRouterDiscoveryStrategy strat = strategies.get( key );
+ if ( strat == null )
+ {
+ strat = strategies.get( key.toLowerCase() );
+ }
+
+ if ( strat == null )
+ {
+ logger.warn( "Cannot find RouterDiscoveryStrategy with hint: '" + key + "'" );
+ }
+
+ return strat;
+ }
+
+ private ArtifactRoutingTables getMirrorMapping( final String routerUrl, final ArtifactRouterConfiguration config,
+ final HttpClient client )
+ {
+ if ( config.isDisabled() )
+ {
+ return new ArtifactRoutingTables();
+ }
+
+ if ( routerUrl != null && routerUrl.trim().length() > 0 )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Grabbing mirror mappings from: " + routerUrl.toString() );
+ }
+ System.out.println( "Grabbing mirror mappings from: " + routerUrl );
+
+ final HttpGet get = new HttpGet( routerUrl );
+ get.addHeader( "Accept", "application/json;q=0.9,*/*;q=0.8" );
+
+ try
+ {
+ return client.execute( get, new ResponseHandler<ArtifactRoutingTables>()
+ {
+ public ArtifactRoutingTables handleResponse( final HttpResponse response )
+ throws /* ClientProtocolException, */IOException
+ {
+ final int statusCode = response.getStatusLine().getStatusCode();
+ if ( statusCode == 200 )
+ {
+ InputStream stream = null;
+ try
+ {
+ stream = response.getEntity().getContent();
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtil.copy( stream, baos );
+
+ String content = null;
+ final Header contentType = response.getFirstHeader( "Content-Type" );
+ if ( contentType != null )
+ {
+ final HeaderElement[] contentTypeElts = contentType.getElements();
+
+ if ( contentTypeElts != null )
+ {
+ for ( final HeaderElement elt : contentTypeElts )
+ {
+ final NameValuePair nv = elt.getParameterByName( "charset" );
+ if ( nv != null )
+ {
+ content = new String( baos.toByteArray(), nv.getValue() );
+ }
+ }
+ }
+ }
+
+ if ( content == null )
+ {
+ content = new String( baos.toByteArray() );
+ }
+
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Response code/message: '" + response.getStatusLine().getStatusCode()
+ + " " + response.getStatusLine().getReasonPhrase() + "'\nContent is:\n\n"
+ + content );
+ }
+
+ return ArtifactRouteSerializer.deserialize( content );
+ }
+ catch ( final ArtifactRouterModelException e )
+ {
+ logger.error( "Failed to retrieve mirror mapping from: " + routerUrl, e );
+ }
+ finally
+ {
+ close( stream );
+ }
+ }
+ else if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Response: " + response.getStatusLine().getStatusCode() + " "
+ + response.getStatusLine().getReasonPhrase() );
+ }
+
+ return null;
+ }
+ } );
+ }
+ catch ( final ClientProtocolException e )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Failed to read proxied repositories from: '" + routerUrl + "'. Reason: "
+ + e.getMessage(), e );
+ }
+ }
+ catch ( final IOException e )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Failed to read proxied repositories from: '" + routerUrl + "'. Reason: "
+ + e.getMessage(), e );
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: maven/maven-3/branches/mirror-group-routing/maven-routem-impl/src/main/java/org/apache/maven/artifact/router/loader/DefaultRouterLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/maven-3/branches/mirror-group-routing/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/pom.xml?rev=1126851&r1=1126850&r2=1126851&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/pom.xml (original)
+++ maven/maven-3/branches/mirror-group-routing/pom.xml Tue May 24 03:31:40 2011
@@ -37,7 +37,7 @@
<classWorldsVersion>2.4</classWorldsVersion>
<commonsCliVersion>1.2</commonsCliVersion>
<easyMockVersion>1.2_Java1.3</easyMockVersion>
- <junitVersion>3.8.2</junitVersion>
+ <junitVersion>4.8.2</junitVersion>
<plexusVersion>1.5.5</plexusVersion>
<plexusInterpolationVersion>1.14</plexusInterpolationVersion>
<plexusUtilsVersion>2.0.6</plexusUtilsVersion>
@@ -141,6 +141,7 @@
<module>maven-embedder</module>
<module>maven-compat</module>
<module>maven-routem-api</module>
+ <module>maven-routem-impl</module>
</modules>
<scm>
@@ -176,6 +177,11 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
+ <artifactId>maven-routem-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${project.version}</version>
</dependency>
Modified: maven/maven-3/branches/mirror-group-routing/pom.xml.orig
URL: http://svn.apache.org/viewvc/maven/maven-3/branches/mirror-group-routing/pom.xml.orig?rev=1126851&r1=1126850&r2=1126851&view=diff
==============================================================================
--- maven/maven-3/branches/mirror-group-routing/pom.xml.orig (original)
+++ maven/maven-3/branches/mirror-group-routing/pom.xml.orig Tue May 24 03:31:40 2011
@@ -140,7 +140,7 @@
<module>maven-model-builder</module>
<module>maven-embedder</module>
<module>maven-compat</module>
- <module>maven-auto-mirror-model</module>
+ <module>maven-routem-api</module>
</modules>
<scm>
@@ -171,7 +171,7 @@
<!--bootstrap-start-comment-->
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-auto-mirror-model</artifactId>
+ <artifactId>maven-routem-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -345,7 +345,7 @@
<version>${jxpathVersion}</version>
</dependency>
- <!-- START: Used in auto-mirror handling -->
+ <!-- START: Used in Route-M auto-mirror handling -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>