This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository.maven2;
002
003import org.apache.archiva.common.filelock.DefaultFileLockManager;
004import org.apache.archiva.common.filelock.FileLockManager;
005import org.apache.archiva.repository.base.AbstractRemoteRepository;
006import org.apache.archiva.repository.ReleaseScheme;
007import org.apache.archiva.repository.RemoteRepository;
008import org.apache.archiva.repository.RepositoryCapabilities;
009import org.apache.archiva.repository.RepositoryType;
010import org.apache.archiva.repository.StandardCapabilities;
011import org.apache.archiva.repository.UnsupportedFeatureException;
012import org.apache.archiva.repository.storage.FilesystemStorage;
013import org.apache.archiva.repository.features.IndexCreationFeature;
014import org.apache.archiva.repository.features.RemoteIndexFeature;
015import org.apache.archiva.repository.features.RepositoryFeature;
016import org.slf4j.Logger;
017import org.slf4j.LoggerFactory;
018
019import java.io.IOException;
020import java.nio.file.Path;
021import java.util.Locale;
022
023/*
024 * Licensed to the Apache Software Foundation (ASF) under one
025 * or more contributor license agreements.  See the NOTICE file
026 * distributed with this work for additional information
027 * regarding copyright ownership.  The ASF licenses this file
028 * to you under the Apache License, Version 2.0 (the
029 * "License"); you may not use this file except in compliance
030 * with the License.  You may obtain a copy of the License at
031 *
032 *  http://www.apache.org/licenses/LICENSE-2.0
033 *
034 * Unless required by applicable law or agreed to in writing,
035 * software distributed under the License is distributed on an
036 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
037 * KIND, either express or implied.  See the License for the
038 * specific language governing permissions and limitations
039 * under the License.
040 */
041
042/**
043 * Maven2 remote repository implementation
044 */
045public class MavenRemoteRepository extends AbstractRemoteRepository
046    implements RemoteRepository
047{
048
049    Logger log = LoggerFactory.getLogger(MavenRemoteRepository.class);
050
051    final private RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
052    final private IndexCreationFeature indexCreationFeature;
053
054    private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
055        new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
056        new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT},
057        new String[] {},
058        new String[] {RemoteIndexFeature.class.getName(), IndexCreationFeature.class.getName()},
059        true,
060        true,
061        true,
062        true,
063        false
064    );
065
066    public MavenRemoteRepository(String id, String name, FilesystemStorage storage)
067    {
068        super( RepositoryType.MAVEN, id, name, storage );
069        this.indexCreationFeature = new IndexCreationFeature(this, this);
070
071    }
072
073    public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
074    {
075        super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
076        this.indexCreationFeature = new IndexCreationFeature(this, this);
077    }
078
079    @Override
080    public boolean hasIndex( )
081    {
082        return remoteIndexFeature.hasIndex();
083    }
084
085    @Override
086    public RepositoryCapabilities getCapabilities( )
087    {
088        return CAPABILITIES;
089    }
090
091    @SuppressWarnings( "unchecked" )
092    @Override
093    public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
094    {
095        if (RemoteIndexFeature.class.equals( clazz )) {
096            return (RepositoryFeature<T>) remoteIndexFeature;
097        } else if (IndexCreationFeature.class.equals(clazz)) {
098            return (RepositoryFeature<T>) indexCreationFeature;
099        } else {
100            throw new UnsupportedFeatureException(  );
101        }
102    }
103
104    @Override
105    public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
106    {
107        if ( RemoteIndexFeature.class.equals(clazz) || IndexCreationFeature.class.equals(clazz)) {
108            return true;
109        } else {
110            return false;
111        }
112    }
113
114    @Override
115    public String toString() {
116        return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString();
117    }
118
119    public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
120        FileLockManager lockManager = new DefaultFileLockManager();
121        FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
122        return new MavenRemoteRepository(id, name, storage);
123    }
124}