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
41 @Service( "repositoryContentFactory#default" )
42 public class RepositoryContentFactory
43 implements RegistryListener
49 private ArchivaConfiguration archivaConfiguration;
52 private ApplicationContext applicationContext;
54 private final Map<String, ManagedRepositoryContent> managedContentMap;
56 private final Map<String, RemoteRepositoryContent> remoteContentMap;
59 public RepositoryContentFactory()
61 managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>();
62 remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>();
66 * Get the ManagedRepositoryContent object for the repository Id specified.
68 * @param repoId the repository id to fetch.
69 * @return the ManagedRepositoryContent object associated with the repository id.
70 * @throws RepositoryNotFoundException if the repository id does not exist within the configuration.
71 * @throws RepositoryException the repository content object cannot be loaded due to configuration issue.
73 public ManagedRepositoryContent getManagedRepositoryContent( String repoId )
74 throws RepositoryNotFoundException, RepositoryException
76 ManagedRepositoryContent repo = managedContentMap.get( repoId );
83 ManagedRepositoryConfiguration repoConfig =
84 archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
85 if ( repoConfig == null )
87 throw new RepositoryNotFoundException( "Unable to find managed repository configuration for id:" + repoId );
90 repo = applicationContext.getBean( "managedRepositoryContent#" + repoConfig.getLayout(),
91 ManagedRepositoryContent.class );
92 repo.setRepository( repoConfig );
93 managedContentMap.put( repoId, repo );
98 public RemoteRepositoryContent getRemoteRepositoryContent( String repoId )
99 throws RepositoryNotFoundException, RepositoryException
101 RemoteRepositoryContent repo = remoteContentMap.get( repoId );
108 RemoteRepositoryConfiguration repoConfig =
109 archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId );
110 if ( repoConfig == null )
112 throw new RepositoryNotFoundException( "Unable to find remote repository configuration for id:" + repoId );
115 repo = applicationContext.getBean( "remoteRepositoryContent#" + repoConfig.getLayout(),
116 RemoteRepositoryContent.class );
117 repo.setRepository( repoConfig );
118 remoteContentMap.put( repoId, repo );
124 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
126 if ( ConfigurationNames.isManagedRepositories( propertyName ) || ConfigurationNames.isRemoteRepositories(
133 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
139 public void initialize()
141 archivaConfiguration.addChangeListener( this );
144 private void initMaps()
146 // olamy we use concurent so no need of synchronize
147 //synchronized ( managedContentMap )
149 managedContentMap.clear();
152 //synchronized ( remoteContentMap )
154 remoteContentMap.clear();
158 public ArchivaConfiguration getArchivaConfiguration()
160 return archivaConfiguration;
163 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
165 this.archivaConfiguration = archivaConfiguration;