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.repository.AbstractManagedRepository;
24 import org.apache.archiva.repository.ReleaseScheme;
25 import org.apache.archiva.repository.RepositoryCapabilities;
26 import org.apache.archiva.repository.RepositoryType;
27 import org.apache.archiva.repository.StandardCapabilities;
28 import org.apache.archiva.repository.UnsupportedFeatureException;
29 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
30 import org.apache.archiva.repository.features.IndexCreationFeature;
31 import org.apache.archiva.repository.features.RepositoryFeature;
32 import org.apache.archiva.repository.features.StagingRepositoryFeature;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import java.io.IOException;
38 import java.nio.file.Files;
39 import java.nio.file.Path;
40 import java.util.Locale;
41 import java.util.function.Function;
44 * Maven2 managed repository implementation.
46 public class MavenManagedRepository extends AbstractManagedRepository
49 private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
51 public static final String DEFAULT_LAYOUT = "default";
52 public static final String LEGACY_LAYOUT = "legacy";
53 private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
54 private IndexCreationFeature indexCreationFeature;
55 private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
59 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
60 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
61 new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
63 new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
64 StagingRepositoryFeature.class.getName()},
72 public MavenManagedRepository( String id, String name, Path basePath )
74 super( RepositoryType.MAVEN, id, name, basePath);
75 this.indexCreationFeature = new IndexCreationFeature(this, this);
78 public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath )
80 super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
84 public RepositoryCapabilities getCapabilities( )
90 @SuppressWarnings( "unchecked" )
92 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
94 if (ArtifactCleanupFeature.class.equals( clazz ))
96 return (RepositoryFeature<T>) artifactCleanupFeature;
97 } else if (IndexCreationFeature.class.equals(clazz)) {
98 return (RepositoryFeature<T>) indexCreationFeature;
99 } else if (StagingRepositoryFeature.class.equals(clazz)) {
100 return (RepositoryFeature<T>) stagingRepositoryFeature;
102 throw new UnsupportedFeatureException( );
107 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
109 if (ArtifactCleanupFeature.class.equals(clazz) ||
110 IndexCreationFeature.class.equals(clazz) ||
111 StagingRepositoryFeature.class.equals(clazz)) {
118 public boolean hasIndex( )
120 return indexCreationFeature.hasIndex();
124 public void setLocation( URI location )
126 super.setLocation( location );
127 Path newLoc = PathUtil.getPathFromUri( location );
128 if (!Files.exists( newLoc )) {
131 Files.createDirectories( newLoc );
133 catch ( IOException e )
135 log.error("Could not create directory {}",location, e);