1 package org.apache.maven.archiva.repository;
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.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.ConfigurationNames;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
26 import org.codehaus.plexus.registry.Registry;
27 import org.codehaus.plexus.registry.RegistryListener;
28 import org.springframework.context.ApplicationContext;
29 import org.springframework.stereotype.Service;
31 import javax.annotation.PostConstruct;
32 import javax.inject.Inject;
34 import java.util.concurrent.ConcurrentHashMap;
37 * RepositoryContentRequest
42 * role="org.apache.maven.archiva.repository.RepositoryContentFactory"
44 @Service( "repositoryContentFactory#default" )
45 public class RepositoryContentFactory
46 implements RegistryListener
52 private ArchivaConfiguration archivaConfiguration;
55 private ApplicationContext applicationContext;
57 private final Map<String, ManagedRepositoryContent> managedContentMap;
59 private final Map<String, RemoteRepositoryContent> remoteContentMap;
62 public RepositoryContentFactory()
64 managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>();
65 remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>();
69 * Get the ManagedRepositoryContent object for the repository Id specified.
71 * @param repoId the repository id to fetch.
72 * @return the ManagedRepositoryContent object associated with the repository id.
73 * @throws RepositoryNotFoundException if the repository id does not exist within the configuration.
74 * @throws RepositoryException the repository content object cannot be loaded due to configuration issue.
76 public ManagedRepositoryContent getManagedRepositoryContent( String repoId )
77 throws RepositoryNotFoundException, RepositoryException
79 ManagedRepositoryContent repo = managedContentMap.get( repoId );
86 ManagedRepositoryConfiguration repoConfig =
87 archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
88 if ( repoConfig == null )
90 throw new RepositoryNotFoundException( "Unable to find managed repository configuration for id:" + repoId );
93 repo = applicationContext.getBean( "managedRepositoryContent#" + repoConfig.getLayout(),
94 ManagedRepositoryContent.class );
95 repo.setRepository( repoConfig );
96 managedContentMap.put( repoId, repo );
101 public RemoteRepositoryContent getRemoteRepositoryContent( String repoId )
102 throws RepositoryNotFoundException, RepositoryException
104 RemoteRepositoryContent repo = remoteContentMap.get( repoId );
111 RemoteRepositoryConfiguration repoConfig =
112 archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId );
113 if ( repoConfig == null )
115 throw new RepositoryNotFoundException( "Unable to find remote repository configuration for id:" + repoId );
118 repo = applicationContext.getBean( "remoteRepositoryContent#" + repoConfig.getLayout(),
119 RemoteRepositoryContent.class );
120 repo.setRepository( repoConfig );
121 remoteContentMap.put( repoId, repo );
127 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
129 if ( ConfigurationNames.isManagedRepositories( propertyName ) || ConfigurationNames.isRemoteRepositories(
136 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
142 public void initialize()
144 archivaConfiguration.addChangeListener( this );
147 private void initMaps()
149 // olamy we use concurent so no need of synchronize
150 //synchronized ( managedContentMap )
152 managedContentMap.clear();
155 //synchronized ( remoteContentMap )
157 remoteContentMap.clear();
161 public ArchivaConfiguration getArchivaConfiguration()
163 return archivaConfiguration;
166 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
168 this.archivaConfiguration = archivaConfiguration;