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 org.apache.commons.lang.StringUtils;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.ConfigurationNames;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.repository.RepositoryException;
27 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
28 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
29 import org.apache.maven.archiva.repository.layout.LayoutException;
30 import org.apache.maven.archiva.repository.project.resolvers.NopProjectResolver;
31 import org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolverStack;
32 import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver;
33 import org.codehaus.plexus.logging.AbstractLogEnabled;
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;
39 import java.util.List;
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 extends AbstractLogEnabled
50 implements RegistryListener, Initializable
55 private ArchivaConfiguration archivaConfiguration;
60 private BidirectionalRepositoryLayoutFactory layoutFactory;
63 * @plexus.requirement role-hint="model400"
65 private ProjectModelReader project400Reader;
68 * @plexus.requirement role-hint="model300"
70 private ProjectModelReader project300Reader;
72 private ProjectModelResolverStack currentResolverStack = new ProjectModelResolverStack();
74 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
76 if ( ConfigurationNames.isManagedRepositories( propertyName ) )
82 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
87 public ProjectModelResolverStack getCurrentResolverStack()
89 return currentResolverStack;
92 public void initialize()
93 throws InitializationException
96 archivaConfiguration.addChangeListener( this );
99 private ManagedRepositoryProjectResolver toResolver( ManagedRepositoryConfiguration repo )
100 throws RepositoryException
104 BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repo.getLayout() );
105 ProjectModelReader reader = project400Reader;
107 if ( StringUtils.equals( "legacy", repo.getLayout() ) )
109 reader = project300Reader;
112 ManagedRepositoryProjectResolver resolver = new ManagedRepositoryProjectResolver( repo, reader, layout );
115 catch ( LayoutException e )
117 throw new RepositoryException(
118 "Unable to create RepositoryProjectResolver due to invalid layout spec: " + repo );
122 private void update()
124 synchronized ( currentResolverStack )
126 this.currentResolverStack.clearResolvers();
128 List<ManagedRepositoryConfiguration> list =
129 archivaConfiguration.getConfiguration().getManagedRepositories();
130 for ( ManagedRepositoryConfiguration repo : list )
134 ManagedRepositoryProjectResolver resolver = toResolver( repo );
136 // Add filesystem based resolver.
137 this.currentResolverStack.addProjectModelResolver( resolver );
139 catch ( RepositoryException e )
141 getLogger().warn( e.getMessage(), e );
145 // Add no-op resolver.
146 this.currentResolverStack.addProjectModelResolver( NopProjectResolver.getInstance() );