]> source.dussan.org Git - archiva.git/commitdiff
avoid using plexus-sisu bridge to get wagon instances: use now spring
authorOlivier Lamy <olamy@apache.org>
Tue, 24 Jan 2012 23:42:53 +0000 (23:42 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 24 Jan 2012 23:42:53 +0000 (23:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1235559 13f79535-47bb-0310-9956-ffa450edef68

17 files changed:
archiva-modules/archiva-base/archiva-converter/pom.xml
archiva-modules/archiva-base/archiva-proxy-common/pom.xml
archiva-modules/archiva-base/archiva-proxy-common/src/main/java/org/apache/archiva/proxy/common/DefaultWagonFactory.java
archiva-modules/archiva-base/archiva-proxy-common/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-proxy-common/src/test/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-proxy/pom.xml
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java
archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/plexus/components.xml [deleted file]
archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-proxy/src/test/resources/spring-context.xml
archiva-modules/archiva-base/archiva-repository-layer/pom.xml
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml
archiva-modules/plugins/maven2-repository/pom.xml
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java

index 6596badab4c8f599e9bf362d10c8a60f6e09de90..18ebf19d19f2db0943289960063f8adc6cd185f1 100644 (file)
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-i18n</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
index 88446fd9d66ae3b299239a171e8c0a5abd72d69a..898bf1ed5c74db11619e68c62caf1fb8a31e45ed 100644 (file)
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-provider-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-file</artifactId>
@@ -79,6 +84,8 @@
               org.apache.archiva.common.plexusbridge;version=${project.version},
               org.apache.commons.lang;version="[2.4,3)",
               org.springframework.stereotype;version="[3,4)",
+              org.springframework.context;version="[3,4)",
+              org.springframework.beans;version="[3,4)",
               org.apache.maven.wagon*,
               org.slf4j;resolution:=optional
             </Import-Package>
index 3f8f311b9fd165d7f9580a9364bade1799636a98..1e9d6cdf4d409d5a3488e4fadfaf20718e0782d7 100755 (executable)
@@ -23,6 +23,8 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.wagon.Wagon;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
@@ -38,12 +40,15 @@ public class DefaultWagonFactory
 
     private PlexusSisuBridge plexusSisuBridge;
 
+    private ApplicationContext applicationContext;
+
     private DebugTransferListener debugTransferListener = new DebugTransferListener();
 
     @Inject
-    public DefaultWagonFactory( PlexusSisuBridge plexusSisuBridge )
+    public DefaultWagonFactory( PlexusSisuBridge plexusSisuBridge, ApplicationContext applicationContext )
     {
         this.plexusSisuBridge = plexusSisuBridge;
+        this.applicationContext = applicationContext;
     }
 
     public Wagon getWagon( String protocol )
@@ -53,12 +58,17 @@ public class DefaultWagonFactory
         {
             // with sisu inject bridge hint is file or http
             // so remove wagon#
-            protocol = StringUtils.remove( protocol, "wagon#" );
-            Wagon wagon = plexusSisuBridge.lookup( Wagon.class, protocol );
+            //protocol = StringUtils.remove( protocol, "wagon#" );
+            // spring beans will be named wagon#protocol (http, https, file )
+            protocol = StringUtils.startsWith( protocol, "wagon#" ) ? protocol : "wagon#" + protocol;
+            //Wagon wagon = plexusSisuBridge.lookup( Wagon.class, protocol );
+
+            Wagon wagon = applicationContext.getBean( protocol, Wagon.class );
             wagon.addTransferListener( debugTransferListener );
             return wagon;
         }
-        catch ( PlexusSisuBridgeException e )
+        //catch ( PlexusSisuBridgeException e )
+        catch ( BeansException e )
         {
             throw new WagonFactoryException( e.getMessage(), e );
         }
index eaf7b4146f0ab89abe8ad3b43f9bf293303c4e99..ef68e5561e05968dd0a00016e3cde32c970e10a7 100644 (file)
@@ -30,5 +30,8 @@
   <context:annotation-config/>
   <context:component-scan base-package="org.apache.archiva.proxy.common"/>
 
+  <bean name="wagon#http" scope="prototype" class="org.apache.maven.wagon.providers.http.HttpWagon"/>
+
+  <bean name="wagon#https" scope="prototype" class="org.apache.maven.wagon.providers.http.HttpWagon"/>
 
 </beans>
\ No newline at end of file
index 011f375fbe61baa754ccaa3e47960da06cfc682d..c19b3e8678ab1def119f144d3d01158fcc03a287 100644 (file)
@@ -27,4 +27,6 @@
            http://www.springframework.org/schema/context/spring-context-3.0.xsd"
        default-lazy-init="true">
 
+  <bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
+
 </beans>
\ No newline at end of file
index c3c231f977f73932e902465e1252d1fac2d90ac7..f695b6364af7fa0ee79fc5753e26036199d327bf 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-plexus-bridge</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-file</artifactId>
index e8be34ea0e40a13187052f4e487e58e74f6d84b6..055d103b7c3bffaa01653c6ed1e06abcc13d9a5f 100644 (file)
@@ -1042,8 +1042,8 @@ public class DefaultRepositoryProxyConnectors
     {
         boolean connected = false;
 
-        final ProxyInfo networkProxy = this.networkProxyMap.get( connector.getProxyId() );
-
+        final ProxyInfo networkProxy =
+            connector.getProxyId() == null ? null : this.networkProxyMap.get( connector.getProxyId() );
 
         if ( log.isDebugEnabled() )
         {
index 14ed55352fa7cb837cb061609a7550037046ad70..2271b1c53adddb920b0c8e9657b4313adf463ca2 100644 (file)
@@ -135,7 +135,7 @@ public abstract class AbstractProxyTestCase
     protected ManagedRepositoryAdmin managedRepositoryAdmin;
 
     @Inject
-    PlexusSisuBridge plexusSisuBridge;
+    protected PlexusSisuBridge plexusSisuBridge;
 
     @Before
     public void setUp()
@@ -208,7 +208,7 @@ public abstract class AbstractProxyTestCase
         wagonMockControl = MockControl.createNiceControl( Wagon.class );
         wagonMock = (Wagon) wagonMockControl.getMock();
 
-        delegate = (WagonDelegate) plexusSisuBridge.lookup( Wagon.class, "test" );
+        delegate = (WagonDelegate) applicationContext.getBean( "wagon#test", Wagon.class );
 
         delegate.setDelegate( wagonMock );
 
@@ -221,7 +221,7 @@ public abstract class AbstractProxyTestCase
     public void shutdown()
         throws Exception
     {
-       removeMavenIndexes();
+        removeMavenIndexes();
     }
 
 
index 6595a3fd56778b0d0d308c40148b08a4c0a05365..341355c526bf3fbbbf13fe71b44245c50a13b19b 100644 (file)
@@ -19,10 +19,6 @@ package org.apache.archiva.proxy;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.wagon.ConnectionException;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
@@ -40,16 +36,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
 /**
  * A dummy wagon implementation
- *
  */
-@Service("wagon#test")
+@Service( "wagon#test" )
 public class WagonDelegate
     implements Wagon
 {
     private Logger log = LoggerFactory.getLogger( WagonDelegate.class );
-    
+
     private Wagon delegate;
 
     private String contentToGet;
@@ -90,7 +91,7 @@ public class WagonDelegate
         return delegate.resourceExists( resourceName );
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public List<String> getFileList( String destinationDirectory )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
@@ -102,15 +103,15 @@ public class WagonDelegate
         return delegate.supportsDirectoryCopy();
     }
 
-     public void setTimeout(int val)
-     {
-         // ignore
-     }
-     public int getTimeout()
-     {
-         return 0;
-     }
+    public void setTimeout( int val )
+    {
+        // ignore
+    }
+
+    public int getTimeout()
+    {
+        return 0;
+    }
 
     public Repository getRepository()
     {
@@ -153,7 +154,7 @@ public class WagonDelegate
         delegate.connect( source, authenticationInfo, proxyInfoProvider );
     }
 
-    @SuppressWarnings("deprecation")
+    @SuppressWarnings( "deprecation" )
     public void openConnection()
         throws ConnectionException, AuthenticationException
     {
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/plexus/components.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/plexus/components.xml
deleted file mode 100644 (file)
index acd2872..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<!--
-  ~ 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.
-  -->
-
-<component-set>
-  <components>
-    <component>
-      <role>org.apache.maven.wagon.Wagon</role>
-      <role-hint>test</role-hint>
-      <implementation>org.apache.archiva.proxy.WagonDelegate</implementation>
-    </component>
-  </components>
-</component-set>
index 011f375fbe61baa754ccaa3e47960da06cfc682d..0e0824920bad4a3da7d49be0132cb82237560340 100644 (file)
@@ -27,4 +27,6 @@
            http://www.springframework.org/schema/context/spring-context-3.0.xsd"
        default-lazy-init="true">
 
+
+
 </beans>
\ No newline at end of file
index e0b433c0397d6a1fa21b0b95fd4cc77f74311c1a..3964a560778675251e058ab94fb8dd0b89a7541b 100755 (executable)
@@ -80,5 +80,7 @@
     <property name="timeToLiveSeconds" value="1800"/>
   </bean>
 
+  <bean name="wagon#test" class="org.apache.archiva.proxy.WagonDelegate" scope="singleton"/>
+  <bean name="wagon#file" scope="prototype" class="org.apache.maven.wagon.providers.file.FileWagon"/>
 
 </beans>
\ No newline at end of file
index dff2fca68c2c71583949acf3ccef121e2695bac8..89b99772c17cdaa681c3ed4dd01aa2759098a6b0 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>maven2-repository</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
index e41caa6bc4560f297811a2d27309da0c1a1be61a..83eeb01c53c7baa30bfa93a4c4ba6b756143129e 100644 (file)
@@ -130,7 +130,6 @@ public class DownloadRemoteIndexTask
             final Wagon wagon = wagonFactory.getWagon( new URL( this.remoteRepository.getUrl() ).getProtocol() );
             setupWagonReadTimeout( wagon );
 
-            // TODO transferListener
             wagon.addTransferListener( new DownloadListener() );
             ProxyInfo proxyInfo = null;
             if ( this.networkProxy != null )
index c10c3b2b89c508954399322c7c963d81c098f9d2..2f59920083363699d6e8f0273c9b6ba323b8518d 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-scanner</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-layer</artifactId>
index b7e9a05a943cf413799d1894ad74a236ddc30995..67f82fbb06cedd7c9a4ec92da8e2215fe6755fa4 100644 (file)
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-provider-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-test</artifactId>
index 6a02f17b4cef58d8c106e67b3055602afab1ff35..f2138237f03ec97fa5d258a750dff36278f3ecb6 100644 (file)
@@ -19,20 +19,15 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
+import org.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
 import org.apache.archiva.proxy.common.WagonFactory;
 import org.apache.archiva.proxy.common.WagonFactoryException;
+import org.apache.archiva.xml.XMLException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.archiva.common.utils.VersionUtil;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
-import org.apache.archiva.xml.XMLException;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.building.FileModelSource;
 import org.apache.maven.model.building.ModelSource;
@@ -50,6 +45,11 @@ import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
 public class RepositoryModelResolver
     implements ModelResolver
 {
@@ -77,9 +77,10 @@ public class RepositoryModelResolver
         this.pathTranslator = pathTranslator;
     }
 
-    public RepositoryModelResolver( File basedir, RepositoryPathTranslator pathTranslator,
-                                    WagonFactory wagonFactory, List<RemoteRepositoryConfiguration> remoteRepositories,
-                                    Map<String, ProxyInfo> networkProxiesMap, ManagedRepositoryConfiguration targetRepository )
+    public RepositoryModelResolver( File basedir, RepositoryPathTranslator pathTranslator, WagonFactory wagonFactory,
+                                    List<RemoteRepositoryConfiguration> remoteRepositories,
+                                    Map<String, ProxyInfo> networkProxiesMap,
+                                    ManagedRepositoryConfiguration targetRepository )
     {
         this( basedir, pathTranslator );
 
@@ -100,24 +101,25 @@ public class RepositoryModelResolver
 
         File model = pathTranslator.toFile( basedir, groupId, artifactId, version, filename );
 
-        if( !model.exists() )
+        if ( !model.exists() )
         {
-            for( RemoteRepositoryConfiguration remoteRepository : remoteRepositories )
+            for ( RemoteRepositoryConfiguration remoteRepository : remoteRepositories )
             {
                 try
                 {
                     boolean success = getModelFromProxy( remoteRepository, groupId, artifactId, version, filename );
-                    if( success && model.exists() )
+                    if ( success && model.exists() )
                     {
-                        log.info( "Model '" + model.getAbsolutePath() + "' successfully retrieved from remote repository '"
-                            + remoteRepository.getId() + "'" );
+                        log.info(
+                            "Model '" + model.getAbsolutePath() + "' successfully retrieved from remote repository '"
+                                + remoteRepository.getId() + "'" );
                         break;
                     }
                 }
-                catch( Exception e )
+                catch ( Exception e )
                 {
                     log.warn( "An exception was caught while attempting to retrieve model '" + model.getAbsolutePath()
-                        + "' from remote repository '" + remoteRepository.getId() + "'.", e );
+                                  + "' from remote repository '" + remoteRepository.getId() + "'.", e );
                     continue;
                 }
             }
@@ -142,7 +144,7 @@ public class RepositoryModelResolver
     // FIXME: we need to do some refactoring, we cannot re-use the proxy components of archiva-proxy in maven2-repository
     // because it's causing a cyclic dependency
     private boolean getModelFromProxy( RemoteRepositoryConfiguration remoteRepository, String groupId,
-                                    String artifactId, String version, String filename )
+                                       String artifactId, String version, String filename )
         throws AuthorizationException, TransferFailedException, ResourceDoesNotExistException, WagonFactoryException,
         XMLException
     {
@@ -177,7 +179,8 @@ public class RepositoryModelResolver
                         // get the metadata first!
                         File tmpMetadataResource = new File( workingDirectory, METADATA_FILENAME );
 
-                        String metadataPath = StringUtils.substringBeforeLast( artifactPath, "/" ) + "/" + METADATA_FILENAME;
+                        String metadataPath =
+                            StringUtils.substringBeforeLast( artifactPath, "/" ) + "/" + METADATA_FILENAME;
 
                         wagon.get( metadataPath, tmpMetadataResource );
 
@@ -190,10 +193,10 @@ public class RepositoryModelResolver
                         String timestampVersion = version;
                         if ( snapshotVersion != null )
                         {
-                            timestampVersion =
-                                timestampVersion.substring( 0, timestampVersion.length() - 8 ); // remove SNAPSHOT from end
-                            timestampVersion =
-                                timestampVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+                            timestampVersion = timestampVersion.substring( 0, timestampVersion.length()
+                                - 8 ); // remove SNAPSHOT from end
+                            timestampVersion = timestampVersion + snapshotVersion.getTimestamp() + "-"
+                                + snapshotVersion.getBuildNumber();
 
                             filename = artifactId + "-" + timestampVersion + ".pom";
 
@@ -209,10 +212,10 @@ public class RepositoryModelResolver
 
                     log.debug( "Downloaded successfully." );
 
-                    tmpSha1 =
-                        transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".sha1" );
-                    tmpMd5 =
-                        transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".md5" );
+                    tmpSha1 = transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory,
+                                                ".sha1" );
+                    tmpMd5 = transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory,
+                                               ".md5" );
                 }
             }
             finally
@@ -267,9 +270,8 @@ public class RepositoryModelResolver
 
         if ( networkProxy != null )
         {
-            String msg =
-                "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort()
-                    + " to connect to remote repository " + remoteRepository.getUrl();
+            String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort()
+                + " to connect to remote repository " + remoteRepository.getUrl();
             if ( networkProxy.getNonProxyHosts() != null )
             {
                 msg += "; excluding hosts: " + networkProxy.getNonProxyHosts();
@@ -289,7 +291,7 @@ public class RepositoryModelResolver
 
         if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
         {
-            log.debug( "Using username " + username + " to connect to remote repository " + remoteRepository.getUrl() );
+            log.debug( "Using username {} to connect to remote repository {}", username, remoteRepository.getUrl() );
             authInfo = new AuthenticationInfo();
             authInfo.setUserName( username );
             authInfo.setPassword( password );
@@ -366,7 +368,8 @@ public class RepositoryModelResolver
             File newLocation = new File( directory, fileToMove.getName() );
             if ( newLocation.exists() && !newLocation.delete() )
             {
-                throw new RuntimeException( "Unable to overwrite existing target file: " + newLocation.getAbsolutePath() );
+                throw new RuntimeException(
+                    "Unable to overwrite existing target file: " + newLocation.getAbsolutePath() );
             }
 
             newLocation.getParentFile().mkdirs();
@@ -383,12 +386,12 @@ public class RepositoryModelResolver
                     if ( newLocation.exists() )
                     {
                         log.error( "Tried to copy file " + fileToMove.getName() + " to " + newLocation.getAbsolutePath()
-                            + " but file with this name already exists." );
+                                       + " but file with this name already exists." );
                     }
                     else
                     {
-                        throw new RuntimeException( "Cannot copy tmp file " + fileToMove.getAbsolutePath()
-                            + " to its final location", e );
+                        throw new RuntimeException(
+                            "Cannot copy tmp file " + fileToMove.getAbsolutePath() + " to its final location", e );
                     }
                 }
                 finally