1 package org.apache.archiva.maven.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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.DefaultFileLockManager;
22 import org.apache.archiva.common.filelock.FileLockManager;
23 import org.apache.archiva.indexer.ArchivaIndexingContext;
24 import org.apache.archiva.maven.repository.content.MavenRepositoryRequestInfo;
25 import org.apache.archiva.repository.ReleaseScheme;
26 import org.apache.archiva.repository.RepositoryCapabilities;
27 import org.apache.archiva.repository.RepositoryRequestInfo;
28 import org.apache.archiva.repository.RepositoryState;
29 import org.apache.archiva.repository.RepositoryType;
30 import org.apache.archiva.repository.StandardCapabilities;
31 import org.apache.archiva.repository.UnsupportedFeatureException;
32 import org.apache.archiva.repository.base.managed.AbstractManagedRepository;
33 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
34 import org.apache.archiva.repository.features.IndexCreationFeature;
35 import org.apache.archiva.repository.features.RepositoryFeature;
36 import org.apache.archiva.repository.features.StagingRepositoryFeature;
37 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import java.io.IOException;
42 import java.nio.file.Path;
43 import java.util.Locale;
46 * Maven2 managed repository implementation.
48 public class MavenManagedRepository extends AbstractManagedRepository
51 private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class );
53 public static final String DEFAULT_LAYOUT = "default";
54 public static final String LEGACY_LAYOUT = "legacy";
55 private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( );
56 private IndexCreationFeature indexCreationFeature;
57 private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
61 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
62 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
63 new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT},
65 new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(),
66 StagingRepositoryFeature.class.getName()},
74 public MavenManagedRepository(String id, String name, FilesystemStorage storage)
77 super( RepositoryType.MAVEN, id, name, storage);
78 this.indexCreationFeature = new IndexCreationFeature(this, this);
79 setLocation(storage.getRoot().getFilePath().toUri());
80 setLastState( RepositoryState.CREATED );
83 public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
85 super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
86 setLocation(storage.getRoot().getFilePath().toUri());
87 setLastState( RepositoryState.CREATED );
91 public RepositoryCapabilities getCapabilities( )
97 @SuppressWarnings( "unchecked" )
99 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
101 if (ArtifactCleanupFeature.class.equals( clazz ))
103 return (RepositoryFeature<T>) artifactCleanupFeature;
104 } else if (IndexCreationFeature.class.equals(clazz)) {
105 return (RepositoryFeature<T>) indexCreationFeature;
106 } else if (StagingRepositoryFeature.class.equals(clazz)) {
107 return (RepositoryFeature<T>) stagingRepositoryFeature;
109 throw new UnsupportedFeatureException( );
114 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
116 if (ArtifactCleanupFeature.class.equals(clazz) ||
117 IndexCreationFeature.class.equals(clazz) ||
118 StagingRepositoryFeature.class.equals(clazz)) {
125 public boolean hasIndex( )
127 return indexCreationFeature.hasIndex();
131 public RepositoryRequestInfo getRequestInfo() {
132 return new MavenRepositoryRequestInfo(this);
135 public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
136 FileLockManager lockManager = new DefaultFileLockManager();
137 FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
138 return new MavenManagedRepository(id, name, storage);
142 public void setIndexingContext(ArchivaIndexingContext context) {
143 super.setIndexingContext(context);