1 package org.apache.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 com.cronutils.model.CronType;
23 import com.cronutils.model.definition.CronDefinition;
24 import com.cronutils.model.definition.CronDefinitionBuilder;
25 import com.cronutils.parser.CronParser;
26 import org.apache.archiva.repository.features.RepositoryFeature;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Locale;
39 * Implementation of a repository with the necessary fields for a bare repository.
40 * No features are provided. Capabilities and features must be implemented by concrete classes.
43 public abstract class AbstractRepository implements EditableRepository
46 private final RepositoryType type;
47 private final String id;
48 private Map<Locale, String> names = new HashMap<>( );
49 private Map<Locale, String> descriptions = new HashMap<>( );
51 private Locale primaryLocale = new Locale("en_US");
53 private Set<URI> failoverLocations = new HashSet<>( );
54 private Set<URI> uFailoverLocations = Collections.unmodifiableSet( failoverLocations );
55 private boolean scanned = true;
56 String schedulingDefinition = "0 0 02 * *";
57 private boolean index;
58 private URI indexPath;
59 private String layout;
60 private Set<ReleaseScheme> activeReleaseSchemes = new HashSet<>( );
61 private Set<ReleaseScheme> uActiveReleaseSchemes = Collections.unmodifiableSet( activeReleaseSchemes );
62 public static final CronDefinition CRON_DEFINITION = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
64 public AbstractRepository(RepositoryType type, String id, String name) {
66 this.names.put( primaryLocale, name);
70 public AbstractRepository(Locale primaryLocale, RepositoryType type, String id, String name) {
71 setPrimaryLocale( primaryLocale );
73 this.names.put( primaryLocale, name);
77 protected void setPrimaryLocale(Locale locale) {
78 this.primaryLocale = locale;
82 public String getId( )
88 public String getName( )
90 return getName( primaryLocale );
94 public String getName( Locale locale )
96 return names.get(locale);
100 public String getDescription( )
102 return getDescription( primaryLocale );
106 public String getDescription( Locale locale )
108 return descriptions.get(primaryLocale);
112 public RepositoryType getType( )
118 public URI getLocation( )
124 public Set<URI> getFailoverLocations( )
126 return uFailoverLocations;
130 public boolean isScanned( )
136 public String getSchedulingDefinition( )
138 return schedulingDefinition;
142 public boolean hasIndex( )
148 public URI getIndexPath( )
154 public String getLayout( )
160 public Set<ReleaseScheme> getActiveReleaseSchemes( )
162 return uActiveReleaseSchemes;
166 public abstract RepositoryCapabilities getCapabilities( );
169 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
171 throw new UnsupportedFeatureException( "Feature "+clazz+" not supported" );
175 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
181 public Locale getPrimaryLocale( )
183 return primaryLocale;
187 public void setName( Locale locale, String name )
189 names.put(locale, name);
193 public void setDescription( Locale locale, String description )
195 descriptions.put(locale, description);
199 public void setLocation( URI location )
201 this.location = location;
205 public void addFailoverLocation( URI location )
207 this.failoverLocations.add(location);
211 public void removeFailoverLocation( URI location )
213 this.failoverLocations.remove( location );
217 public void clearFailoverLocations( )
219 this.failoverLocations.clear();
223 public void setScanned( boolean scanned )
225 this.scanned = scanned;
229 public void setIndex( boolean hasIndex )
231 this.index = hasIndex;
235 public void setIndexPath( URI indexPath )
237 this.indexPath = indexPath;
241 public void setLayout( String layout )
243 this.layout = layout;
247 public void addActiveReleaseScheme( ReleaseScheme scheme )
249 this.activeReleaseSchemes.add(scheme);
253 public void removeActiveReleaseScheme( ReleaseScheme scheme )
255 this.activeReleaseSchemes.remove(scheme);
259 public void clearActiveReleaseSchemes( )
261 this.activeReleaseSchemes.clear();
265 public void setSchedulingDefinition(String cronExpression) {
266 CronParser parser = new CronParser(CRON_DEFINITION);
267 parser.parse(cronExpression).validate();
268 this.schedulingDefinition = cronExpression;