1 package org.apache.maven.archiva.repository.project;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.List;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.ConfigurationNames;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
29 import org.apache.maven.archiva.repository.RepositoryContentFactory;
30 import org.apache.maven.archiva.repository.RepositoryException;
31 import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver;
32 import org.apache.maven.archiva.repository.project.resolvers.NopProjectResolver;
33 import org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolverStack;
34 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
35 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
36 import org.codehaus.plexus.registry.Registry;
37 import org.codehaus.plexus.registry.RegistryListener;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Factory for ProjectModelResolver objects
44 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
46 * @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelResolverFactory"
48 public class ProjectModelResolverFactory
49 implements RegistryListener, Initializable
51 private Logger log = LoggerFactory.getLogger( ProjectModelResolverFactory.class );
56 private ArchivaConfiguration archivaConfiguration;
61 private RepositoryContentFactory repositoryFactory;
64 * @plexus.requirement role-hint="model400"
66 private ProjectModelReader project400Reader;
69 * @plexus.requirement role-hint="model300"
71 private ProjectModelReader project300Reader;
73 private ProjectModelResolverStack currentResolverStack = new ProjectModelResolverStack();
75 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
77 if ( ConfigurationNames.isManagedRepositories( propertyName ) )
83 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
88 public ProjectModelResolverStack getCurrentResolverStack()
90 return currentResolverStack;
93 public void initialize()
94 throws InitializationException
97 archivaConfiguration.addChangeListener( this );
100 private ManagedRepositoryProjectResolver toResolver( ManagedRepositoryConfiguration repo )
101 throws RepositoryException
103 ManagedRepositoryContent repoContent = repositoryFactory.getManagedRepositoryContent( repo.getId() );
104 ProjectModelReader reader = project400Reader;
106 if ( StringUtils.equals( "legacy", repo.getLayout() ) )
108 reader = project300Reader;
111 return new ManagedRepositoryProjectResolver( repoContent, reader );
114 private void update()
116 synchronized ( currentResolverStack )
118 this.currentResolverStack.clearResolvers();
120 List<ManagedRepositoryConfiguration> list =
121 archivaConfiguration.getConfiguration().getManagedRepositories();
122 for ( ManagedRepositoryConfiguration repo : list )
126 ManagedRepositoryProjectResolver resolver = toResolver( repo );
128 // Add filesystem based resolver.
129 this.currentResolverStack.addProjectModelResolver( resolver );
131 catch ( RepositoryException e )
133 log.warn( e.getMessage(), e );
137 // Add no-op resolver.
138 this.currentResolverStack.addProjectModelResolver( NopProjectResolver.getInstance() );