1 package org.apache.archiva.configuration;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.model.AuditInformation;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.model.beans.NetworkProxy;
26 import org.apache.archiva.admin.model.beans.ProxyConnector;
27 import org.apache.archiva.admin.model.beans.RemoteRepository;
28 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
29 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
30 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
31 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorOrderComparator;
32 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
33 import org.apache.commons.lang.StringUtils;
34 import org.apache.maven.index.context.IndexingContext;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.HashMap;
42 import java.util.Iterator;
43 import java.util.List;
47 * @author Olivier Lamy
50 public class MockRepoAdmin
51 implements RemoteRepositoryAdmin, ManagedRepositoryAdmin, ProxyConnectorAdmin, NetworkProxyAdmin
54 @Named( value = "archivaConfiguration#test" )
55 private ArchivaConfiguration archivaConfiguration;
57 public List<RemoteRepository> getRemoteRepositories()
58 throws RepositoryAdminException
60 List<RemoteRepository> remoteRepositories =
61 new ArrayList<RemoteRepository>( archivaConfiguration.getConfiguration().getRemoteRepositories().size() );
62 for ( RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories() )
64 RemoteRepository remoteRepository =
65 new RemoteRepository( repositoryConfiguration.getId(), repositoryConfiguration.getName(),
66 repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
67 repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
68 repositoryConfiguration.getTimeout() );
69 remoteRepository.setDownloadRemoteIndex( repositoryConfiguration.isDownloadRemoteIndex() );
70 remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() );
71 remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() );
72 remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() );
73 remoteRepository.setRemoteDownloadNetworkProxyId(
74 repositoryConfiguration.getRemoteDownloadNetworkProxyId() );
75 remoteRepository.setRemoteDownloadTimeout( repositoryConfiguration.getRemoteDownloadTimeout() );
76 remoteRepository.setDownloadRemoteIndexOnStartup(
77 repositoryConfiguration.isDownloadRemoteIndexOnStartup() );
78 remoteRepositories.add( remoteRepository );
80 return remoteRepositories;
83 public RemoteRepository getRemoteRepository( String repositoryId )
84 throws RepositoryAdminException
86 for ( RemoteRepository remoteRepository : getRemoteRepositories() )
88 if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
90 return remoteRepository;
96 public Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
97 throws RepositoryAdminException
99 return null; //To change body of implemented methods use File | Settings | File Templates.
102 public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
103 throws RepositoryAdminException
105 return null; //To change body of implemented methods use File | Settings | File Templates.
108 public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
109 throws RepositoryAdminException
111 return null; //To change body of implemented methods use File | Settings | File Templates.
114 public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
115 throws RepositoryAdminException
117 return null; //To change body of implemented methods use File | Settings | File Templates.
120 public IndexingContext createIndexContext( RemoteRepository repository )
121 throws RepositoryAdminException
123 return null; //To change body of implemented methods use File | Settings | File Templates.
126 public List<ManagedRepository> getManagedRepositories()
127 throws RepositoryAdminException
129 return null; //To change body of implemented methods use File | Settings | File Templates.
132 public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
133 throws RepositoryAdminException
135 return null; //To change body of implemented methods use File | Settings | File Templates.
138 public ManagedRepository getManagedRepository( String repositoryId )
139 throws RepositoryAdminException
141 for ( ManagedRepositoryConfiguration repoConfig : archivaConfiguration.getConfiguration().getManagedRepositories() )
143 if ( StringUtils.equals( repositoryId, repoConfig.getId() ) )
145 return new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
146 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
147 repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
148 repoConfig.getIndexDir(), repoConfig.isScanned(),
149 repoConfig.getDaysOlder(), repoConfig.getRetentionCount(),
150 repoConfig.isDeleteReleasedSnapshots(), false );
156 public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
157 boolean deleteContent )
158 throws RepositoryAdminException
160 return null; //To change body of implemented methods use File | Settings | File Templates.
163 public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
164 AuditInformation auditInformation )
165 throws RepositoryAdminException
167 return null; //To change body of implemented methods use File | Settings | File Templates.
170 public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
171 AuditInformation auditInformation, boolean resetStats )
172 throws RepositoryAdminException
174 return null; //To change body of implemented methods use File | Settings | File Templates.
177 public IndexingContext createIndexContext( ManagedRepository repository )
178 throws RepositoryAdminException
180 return null; //To change body of implemented methods use File | Settings | File Templates.
183 public List<ProxyConnector> getProxyConnectors()
184 throws RepositoryAdminException
186 List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
187 archivaConfiguration.getConfiguration().getProxyConnectors();
188 List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>( proxyConnectorConfigurations.size() );
189 for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations )
191 proxyConnectors.add( getProxyConnector( configuration ) );
193 Collections.sort( proxyConnectors, ProxyConnectorOrderComparator.getInstance() );
194 return proxyConnectors;
197 public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
198 throws RepositoryAdminException
200 return null; //To change body of implemented methods use File | Settings | File Templates.
203 public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
204 throws RepositoryAdminException
206 return null; //To change body of implemented methods use File | Settings | File Templates.
209 public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
210 throws RepositoryAdminException
212 return null; //To change body of implemented methods use File | Settings | File Templates.
215 public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
216 throws RepositoryAdminException
218 return null; //To change body of implemented methods use File | Settings | File Templates.
221 public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
222 throws RepositoryAdminException
224 Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>();
226 Iterator<ProxyConnector> it = getProxyConnectors().iterator();
227 while ( it.hasNext() )
229 ProxyConnector proxyConfig = it.next();
230 String key = proxyConfig.getSourceRepoId();
232 List<ProxyConnector> connectors = proxyConnectorMap.get( key );
233 if ( connectors == null )
235 connectors = new ArrayList<ProxyConnector>( 1 );
236 proxyConnectorMap.put( key, connectors );
239 connectors.add( proxyConfig );
241 Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() );
244 return proxyConnectorMap;
247 public List<NetworkProxy> getNetworkProxies()
248 throws RepositoryAdminException
250 return null; //To change body of implemented methods use File | Settings | File Templates.
253 public NetworkProxy getNetworkProxy( String networkProxyId )
254 throws RepositoryAdminException
256 return null; //To change body of implemented methods use File | Settings | File Templates.
259 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
260 throws RepositoryAdminException
262 //To change body of implemented methods use File | Settings | File Templates.
265 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
266 throws RepositoryAdminException
268 //To change body of implemented methods use File | Settings | File Templates.
271 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
272 throws RepositoryAdminException
274 //To change body of implemented methods use File | Settings | File Templates.
277 protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration )
279 return proxyConnectorConfiguration == null
281 : new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class );