[MRM-1473] remove use of plexus-spring

fix module metadata-store-file



git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1130154 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-01 13:48:32 +00:00
parent 09292c0037
commit 76386bfcb1
4 changed files with 81 additions and 15 deletions

View File

@ -67,7 +67,7 @@ public class FileMetadataRepository
private final ArchivaConfiguration configuration; 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"; private static final String PROJECT_METADATA_KEY = "project-metadata";
@ -118,7 +118,7 @@ public class FileMetadataRepository
catch ( IOException e ) catch ( IOException e )
{ {
// TODO! // TODO!
e.printStackTrace(); log.error( e.getMessage(), e );
} }
} }
@ -222,7 +222,7 @@ public class FileMetadataRepository
catch ( IOException e ) catch ( IOException e )
{ {
// TODO // 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 ) catch ( IOException e )
{ {
// TODO // 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 ) catch ( IOException e )
{ {
// TODO! // TODO!
e.printStackTrace(); log.error( e.getMessage(), e );
} }
} }
@ -342,7 +342,7 @@ public class FileMetadataRepository
catch ( IOException e ) catch ( IOException e )
{ {
// TODO // TODO
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. log.error( e.getMessage(), e );
return null; return null;
} }
MetadataFacet metadataFacet = null; MetadataFacet metadataFacet = null;
@ -375,7 +375,7 @@ public class FileMetadataRepository
catch ( IOException e ) catch ( IOException e )
{ {
// TODO! // 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 ) catch ( IOException e )
{ {
// TODO // TODO
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. log.error( e.getMessage(), e );
} }
return new Properties(); return new Properties();
} }
@ -933,7 +933,7 @@ public class FileMetadataRepository
MetadataFacetFactory factory = metadataFacetFactories.get( facetId ); MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
if ( factory == null ) 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 else
{ {

View 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.MetadataResolver;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; 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; 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 public class FileRepositorySessionFactory
implements RepositorySessionFactory implements RepositorySessionFactory
{ {
@ -40,15 +48,38 @@ public class FileRepositorySessionFactory
private Map<String, MetadataFacetFactory> metadataFacetFactories; private Map<String, MetadataFacetFactory> metadataFacetFactories;
/** /**
* @plexus.requirement * plexus.requirement
*/ */
@Inject
@Named( value = "archivaConfiguration#default" )
private ArchivaConfiguration configuration; private ArchivaConfiguration configuration;
/** /**
* @plexus.requirement * plexus.requirement
*/ */
@Inject
private MetadataResolver metadataResolver; 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() public RepositorySession createSession()
{ {
MetadataRepository metadataRepository = new FileMetadataRepository( metadataFacetFactories, configuration ); MetadataRepository metadataRepository = new FileMetadataRepository( metadataFacetFactories, configuration );

View File

@ -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>

View File

@ -41,9 +41,11 @@ public class FileMetadataRepositoryTest
{ {
super.setUp(); super.setUp();
File directory = getTestFile( "target/test-repositories" ); File directory = new File( "target/test-repositories" );
if (directory.exists())
{
FileUtils.deleteDirectory( directory ); FileUtils.deleteDirectory( directory );
}
ArchivaConfiguration config = createTestConfiguration( directory ); ArchivaConfiguration config = createTestConfiguration( directory );
Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories(); Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();