]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1473] remove use of plexus-spring
authorOlivier Lamy <olamy@apache.org>
Wed, 1 Jun 2011 13:48:32 +0000 (13:48 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 1 Jun 2011 13:48:32 +0000 (13:48 +0000)
fix module metadata-store-file

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1130154 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileRepositorySessionFactory.java
archiva-modules/plugins/metadata-store-file/src/main/resources/META-INF/spring-context.xml [new file with mode: 0755]
archiva-modules/plugins/metadata-store-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java

index df353fa19a2a634783b8c575fc5c0916cd7e5642..bd75b57201a9ef465e8c9167c05f89c4f340ebcf 100644 (file)
@@ -67,7 +67,7 @@ public class FileMetadataRepository
 
     private final ArchivaConfiguration configuration;
 
-    private static final Logger log = LoggerFactory.getLogger( FileMetadataRepository.class );
+    private Logger log = LoggerFactory.getLogger( FileMetadataRepository.class );
 
     private static final String PROJECT_METADATA_KEY = "project-metadata";
 
@@ -118,7 +118,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO!
-            e.printStackTrace();
+            log.error( e.getMessage(), e );
         }
     }
 
@@ -222,7 +222,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.error( e.getMessage(), e );
         }
     }
 
@@ -279,7 +279,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.error( e.getMessage(), e );
         }
     }
 
@@ -296,7 +296,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO!
-            e.printStackTrace();
+            log.error( e.getMessage(), e );
         }
     }
 
@@ -342,7 +342,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.error( e.getMessage(), e );
             return null;
         }
         MetadataFacet metadataFacet = null;
@@ -375,7 +375,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO!
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.error( e.getMessage(), e );
         }
     }
 
@@ -746,7 +746,7 @@ public class FileMetadataRepository
         catch ( IOException e )
         {
             // TODO
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            log.error( e.getMessage(), e );
         }
         return new Properties();
     }
@@ -933,7 +933,7 @@ public class FileMetadataRepository
                     MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
                     if ( factory == null )
                     {
-                        log.error( "Attempted to load unknown project version metadata facet: " + facetId );
+                        log.error( "Attempted to load unknown project version metadata facet: {}", facetId );
                     }
                     else
                     {
index 4301fc0257a3af688227f78e160bade69509bf9d..9b3ea500ed73d02406610714ea05054b14a61b6c 100644 (file)
@@ -24,13 +24,21 @@ import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
- * @plexus.component role="org.apache.archiva.metadata.repository.RepositorySessionFactory" role-hint="file"
+ * plexus.component role="org.apache.archiva.metadata.repository.RepositorySessionFactory" role-hint="file"
  */
+@Service( "repositorySessionFactory#file" )
 public class FileRepositorySessionFactory
     implements RepositorySessionFactory
 {
@@ -40,15 +48,38 @@ public class FileRepositorySessionFactory
     private Map<String, MetadataFacetFactory> metadataFacetFactories;
 
     /**
-     * @plexus.requirement
+     * plexus.requirement
      */
+    @Inject
+    @Named( value = "archivaConfiguration#default" )
     private ArchivaConfiguration configuration;
 
     /**
-     * @plexus.requirement
+     * plexus.requirement
      */
+    @Inject
     private MetadataResolver metadataResolver;
 
+    @Inject
+    private ApplicationContext applicationContext;
+
+    @PostConstruct
+    public void initialize()
+    {
+        Map<String, MetadataFacetFactory> tmpMetadataFacetFactories =
+            applicationContext.getBeansOfType( MetadataFacetFactory.class );
+        // olamy with spring the "id" is now "metadataFacetFactory#hint"
+        // whereas was only hint with plexus so let remove  metadataFacetFactory#
+        metadataFacetFactories = new HashMap<String, MetadataFacetFactory>( tmpMetadataFacetFactories.size() );
+
+        for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() )
+        {
+            metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() );
+        }
+
+
+    }
+
     public RepositorySession createSession()
     {
         MetadataRepository metadataRepository = new FileMetadataRepository( metadataFacetFactories, configuration );
diff --git a/archiva-modules/plugins/metadata-store-file/src/main/resources/META-INF/spring-context.xml b/archiva-modules/plugins/metadata-store-file/src/main/resources/META-INF/spring-context.xml
new file mode 100755 (executable)
index 0000000..c5f30ba
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.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.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+       default-lazy-init="true">
+
+  <context:annotation-config/>
+  <context:component-scan base-package="org.apache.archiva.metadata.repository.file"/>
+
+</beans>
\ No newline at end of file
index 3922ec0ea30de778ce326567b56e486b25c9c7c1..05693af3257cef5b049e8fb64ff976814da5c3e2 100644 (file)
@@ -41,9 +41,11 @@ public class FileMetadataRepositoryTest
     {
         super.setUp();
 
-        File directory = getTestFile( "target/test-repositories" );
-        FileUtils.deleteDirectory( directory );
-
+        File directory = new File( "target/test-repositories" );
+        if (directory.exists())
+        {
+            FileUtils.deleteDirectory( directory );
+        }
         ArchivaConfiguration config = createTestConfiguration( directory );
         Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();