1 package org.apache.archiva.repository.maven;
3 import org.apache.archiva.common.filelock.DefaultFileLockManager;
4 import org.apache.archiva.common.filelock.FileLockManager;
5 import org.apache.archiva.repository.ReleaseScheme;
6 import org.apache.archiva.repository.RemoteRepository;
7 import org.apache.archiva.repository.RepositoryCapabilities;
8 import org.apache.archiva.repository.RepositoryState;
9 import org.apache.archiva.repository.RepositoryType;
10 import org.apache.archiva.repository.StandardCapabilities;
11 import org.apache.archiva.repository.UnsupportedFeatureException;
12 import org.apache.archiva.repository.base.remote.AbstractRemoteRepository;
13 import org.apache.archiva.repository.features.IndexCreationFeature;
14 import org.apache.archiva.repository.features.RemoteIndexFeature;
15 import org.apache.archiva.repository.features.RepositoryFeature;
16 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.io.IOException;
21 import java.nio.file.Path;
22 import java.util.Locale;
25 * Licensed to the Apache Software Foundation (ASF) under one
26 * or more contributor license agreements. See the NOTICE file
27 * distributed with this work for additional information
28 * regarding copyright ownership. The ASF licenses this file
29 * to you under the Apache License, Version 2.0 (the
30 * "License"); you may not use this file except in compliance
31 * with the License. You may obtain a copy of the License at
33 * http://www.apache.org/licenses/LICENSE-2.0
35 * Unless required by applicable law or agreed to in writing,
36 * software distributed under the License is distributed on an
37 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
38 * KIND, either express or implied. See the License for the
39 * specific language governing permissions and limitations
44 * Maven2 remote repository implementation
46 public class MavenRemoteRepository extends AbstractRemoteRepository
47 implements RemoteRepository
50 Logger log = LoggerFactory.getLogger(MavenRemoteRepository.class);
52 final private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
53 final private IndexCreationFeature indexCreationFeature;
55 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
56 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
57 new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT},
59 new String[] {RemoteIndexFeature.class.getName(), IndexCreationFeature.class.getName()},
67 public MavenRemoteRepository(String id, String name, FilesystemStorage storage)
69 super( RepositoryType.MAVEN, id, name, storage );
70 this.indexCreationFeature = new IndexCreationFeature(this, this);
71 setLastState( RepositoryState.CREATED );
74 public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
76 super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
77 this.indexCreationFeature = new IndexCreationFeature(this, this);
78 setLastState( RepositoryState.CREATED );
82 public boolean hasIndex( )
84 return remoteIndexFeature.hasIndex();
88 public RepositoryCapabilities getCapabilities( )
93 @SuppressWarnings( "unchecked" )
95 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
97 if (RemoteIndexFeature.class.equals( clazz )) {
98 return (RepositoryFeature<T>) remoteIndexFeature;
99 } else if (IndexCreationFeature.class.equals(clazz)) {
100 return (RepositoryFeature<T>) indexCreationFeature;
102 throw new UnsupportedFeatureException( );
107 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
109 if ( RemoteIndexFeature.class.equals(clazz) || IndexCreationFeature.class.equals(clazz)) {
117 public String toString() {
118 return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString();
121 public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
122 FileLockManager lockManager = new DefaultFileLockManager();
123 FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
124 return new MavenRemoteRepository(id, name, storage);