1 package org.apache.archiva.repository.base.managed;
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
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.configuration.Configuration;
21 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
22 import org.apache.archiva.repository.ManagedRepository;
23 import org.apache.archiva.repository.Repository;
24 import org.apache.archiva.repository.RepositoryException;
25 import org.apache.archiva.repository.RepositoryHandler;
26 import org.apache.archiva.repository.RepositoryType;
27 import org.apache.archiva.repository.base.AbstractRepositoryHandler;
28 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
29 import org.apache.archiva.repository.base.ConfigurationHandler;
30 import org.apache.archiva.repository.features.StagingRepositoryFeature;
31 import org.apache.archiva.repository.validation.CheckedResult;
32 import org.apache.archiva.repository.validation.RepositoryChecker;
33 import org.apache.archiva.repository.validation.RepositoryValidator;
34 import org.apache.archiva.repository.validation.ValidationResponse;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import java.util.Collection;
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.HashSet;
42 import java.util.List;
45 import java.util.stream.Collectors;
48 * Handler implementation for managed repositories.
50 * @author Martin Stockhammer <martin_s@apache.org>
52 public class ManagedRepositoryHandler
53 extends AbstractRepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration>
54 implements RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration>
56 private static final Logger log = LoggerFactory.getLogger( ManagedRepositoryHandler.class );
57 private final ConfigurationHandler configurationHandler;
58 private final ArchivaRepositoryRegistry repositoryRegistry;
59 private final RepositoryValidator<ManagedRepository> validator;
60 private Map<String, ManagedRepository> managedRepositories = new HashMap<>( );
61 private Map<String, ManagedRepository> uManagedRepositories = Collections.unmodifiableMap( managedRepositories );
64 public ManagedRepositoryHandler( ArchivaRepositoryRegistry repositoryRegistry,
65 ConfigurationHandler configurationHandler,
66 List<RepositoryValidator<? extends Repository>> repositoryValidatorList )
68 this.configurationHandler = configurationHandler;
69 this.repositoryRegistry = repositoryRegistry;
70 this.validator = getCombinedValidatdor( ManagedRepository.class, repositoryValidatorList );
74 public void initializeFromConfig( )
76 this.managedRepositories.clear( );
77 this.managedRepositories.putAll( newInstancesFromConfig( ) );
78 for ( ManagedRepository managedRepository : this.managedRepositories.values( ) )
80 activateRepository( managedRepository );
86 public void activateRepository( ManagedRepository repository )
92 public Map<String, ManagedRepository> newInstancesFromConfig( )
96 Set<String> configRepoIds = new HashSet<>( );
97 List<ManagedRepositoryConfiguration> managedRepoConfigs =
98 configurationHandler.getBaseConfiguration( ).getManagedRepositories( );
100 if ( managedRepoConfigs == null )
102 return managedRepositories;
105 for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
107 ManagedRepository repo = put( repoConfig, null );
108 configRepoIds.add( repoConfig.getId( ) );
109 if ( repo.supportsFeature( StagingRepositoryFeature.class ) )
111 StagingRepositoryFeature stagF = repo.getFeature( StagingRepositoryFeature.class ).get( );
112 if ( stagF.getStagingRepository( ) != null )
114 configRepoIds.add( stagF.getStagingRepository( ).getId( ) );
118 List<String> toRemove = managedRepositories.keySet( ).stream( ).filter( id -> !configRepoIds.contains( id ) ).collect( Collectors.toList( ) );
119 for ( String id : toRemove )
121 ManagedRepository removed = managedRepositories.remove( id );
125 catch ( Throwable e )
127 log.error( "Could not initialize repositories from config: {}", e.getMessage( ), e );
128 return managedRepositories;
130 return managedRepositories;
134 public ManagedRepository newInstance( RepositoryType type, String id ) throws RepositoryException
140 public ManagedRepository newInstance( ManagedRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
146 public ManagedRepository put( ManagedRepository repository ) throws RepositoryException
152 public ManagedRepository put( ManagedRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
158 public ManagedRepository put( ManagedRepositoryConfiguration repositoryConfiguration, Configuration configuration ) throws RepositoryException
164 public <D> CheckedResult<ManagedRepository, D> putWithCheck( ManagedRepositoryConfiguration repositoryConfiguration, RepositoryChecker<ManagedRepository, D> checker ) throws RepositoryException
170 public void remove( String id ) throws RepositoryException
176 public void remove( String id, Configuration configuration ) throws RepositoryException
182 public ManagedRepository get( String id )
188 public ManagedRepository clone( ManagedRepository repo ) throws RepositoryException
194 public void updateReferences( ManagedRepository repo, ManagedRepositoryConfiguration repositoryConfiguration ) throws RepositoryException
200 public Collection<ManagedRepository> getAll( )
206 public RepositoryValidator<ManagedRepository> getValidator( )
212 public ValidationResponse<ManagedRepository> validateRepository( ManagedRepository repository )
218 public ValidationResponse<ManagedRepository> validateRepositoryForUpdate( ManagedRepository repository )
224 public boolean hasRepository( String id )