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.*;
24 import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo;
25 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
26 import org.apache.archiva.repository.features.IndexCreationFeature;
27 import org.apache.archiva.repository.features.RepositoryFeature;
28 import org.apache.archiva.repository.features.StagingRepositoryFeature;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.io.IOException;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.util.Locale;
37 import java.util.function.Function;
40 * Maven2 managed repository implementation.
42 public class MavenManagedRepository extends AbstractManagedRepository
45 private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
47 public static final String DEFAULT_LAYOUT = "default";
48 public static final String LEGACY_LAYOUT = "legacy";
49 private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
50 private IndexCreationFeature indexCreationFeature;
51 private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
55 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
56 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
57 new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
59 new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
60 StagingRepositoryFeature.class.getName()},
68 public MavenManagedRepository( String id, String name, Path basePath )
70 super( RepositoryType.MAVEN, id, name, basePath);
71 this.indexCreationFeature = new IndexCreationFeature(this, this);
74 public MavenManagedRepository( Locale primaryLocale, String id, String name, Path basePath )
76 super( primaryLocale, RepositoryType.MAVEN, id, name, basePath );
80 public RepositoryCapabilities getCapabilities( )
86 @SuppressWarnings( "unchecked" )
88 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
90 if (ArtifactCleanupFeature.class.equals( clazz ))
92 return (RepositoryFeature<T>) artifactCleanupFeature;
93 } else if (IndexCreationFeature.class.equals(clazz)) {
94 return (RepositoryFeature<T>) indexCreationFeature;
95 } else if (StagingRepositoryFeature.class.equals(clazz)) {
96 return (RepositoryFeature<T>) stagingRepositoryFeature;
98 throw new UnsupportedFeatureException( );
103 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
105 if (ArtifactCleanupFeature.class.equals(clazz) ||
106 IndexCreationFeature.class.equals(clazz) ||
107 StagingRepositoryFeature.class.equals(clazz)) {
114 public boolean hasIndex( )
116 return indexCreationFeature.hasIndex();
120 public void setLocation( URI location )
122 super.setLocation( location );
123 Path newLoc = PathUtil.getPathFromUri( location );
124 if (!Files.exists( newLoc )) {
127 Files.createDirectories( newLoc );
129 catch ( IOException e )
131 log.error("Could not create directory {}",location, e);
137 public RepositoryRequestInfo getRequestInfo() {
138 return new MavenRepositoryRequestInfo(this);