1 package org.apache.archiva.repository.maven2;
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.archiva.common.utils.PathUtil;
23 import org.apache.archiva.indexer.ArchivaIndexingContext;
24 import org.apache.archiva.repository.AbstractManagedRepository;
25 import org.apache.archiva.repository.ReleaseScheme;
26 import org.apache.archiva.repository.RepositoryCapabilities;
27 import org.apache.archiva.repository.RepositoryType;
28 import org.apache.archiva.repository.StandardCapabilities;
29 import org.apache.archiva.repository.UnsupportedFeatureException;
30 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
31 import org.apache.archiva.repository.features.IndexCreationFeature;
32 import org.apache.archiva.repository.features.RepositoryFeature;
33 import org.apache.archiva.repository.features.StagingRepositoryFeature;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import java.io.IOException;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import java.util.Collections;
43 import java.util.HashSet;
44 import java.util.Locale;
48 * Maven2 managed repository implementation.
50 public class MavenManagedRepository extends AbstractManagedRepository
53 private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
55 public static final String DEFAULT_LAYOUT = "default";
56 public static final String LEGACY_LAYOUT = "legacy";
57 private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
58 private IndexCreationFeature indexCreationFeature;
59 private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
63 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
64 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
65 new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
67 new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
68 StagingRepositoryFeature.class.getName()},
76 public MavenManagedRepository( String id, String name, Path basePath )
78 super( RepositoryType.MAVEN, id, name, basePath);
79 this.indexCreationFeature = new IndexCreationFeature(id, this);
82 public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath )
84 super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
88 public RepositoryCapabilities getCapabilities( )
94 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
96 if (ArtifactCleanupFeature.class.equals( clazz ))
98 return (RepositoryFeature<T>) artifactCleanupFeature;
99 } else if (IndexCreationFeature.class.equals(clazz)) {
100 return (RepositoryFeature<T>) indexCreationFeature;
101 } else if (StagingRepositoryFeature.class.equals(clazz)) {
102 return (RepositoryFeature<T>) stagingRepositoryFeature;
104 throw new UnsupportedFeatureException( );
109 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
111 if (ArtifactCleanupFeature.class.equals(clazz) ||
112 IndexCreationFeature.class.equals(clazz) ||
113 StagingRepositoryFeature.class.equals(clazz)) {
120 public boolean hasIndex( )
122 return indexCreationFeature.hasIndex();
126 public void setLocation( URI location )
128 super.setLocation( location );
129 Path newLoc = PathUtil.getPathFromUri( location );
130 if (!Files.exists( newLoc )) {
133 Files.createDirectories( newLoc );
135 catch ( IOException e )
137 log.error("Could not create directory {}",location, e);