This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository.base;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.common.filelock.DefaultFileLockManager;
023import org.apache.archiva.common.filelock.FileLockManager;
024import org.apache.archiva.repository.ReleaseScheme;
025import org.apache.archiva.repository.RepositoryCapabilities;
026import org.apache.archiva.repository.RepositoryRequestInfo;
027import org.apache.archiva.repository.RepositoryType;
028import org.apache.archiva.repository.StandardCapabilities;
029import org.apache.archiva.repository.storage.FilesystemStorage;
030import org.apache.archiva.repository.storage.RepositoryStorage;
031import org.apache.archiva.repository.features.ArtifactCleanupFeature;
032import org.apache.archiva.repository.features.IndexCreationFeature;
033import org.apache.archiva.repository.features.StagingRepositoryFeature;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037import java.io.IOException;
038import java.nio.file.Path;
039import java.util.Locale;
040
041/**
042 *
043 * Just a helper class, mainly used for unit tests.
044 *
045 *
046 */
047public class BasicManagedRepository extends AbstractManagedRepository
048
049{
050    Logger log = LoggerFactory.getLogger(BasicManagedRepository.class);
051    ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature(  );
052    StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( );
053
054    static final StandardCapabilities CAPABILITIES = new StandardCapabilities( new ReleaseScheme[] {
055        ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT
056    }, new String[] {"default"}, new String[0], new String[] {
057        ArtifactCleanupFeature.class.toString(), IndexCreationFeature.class.toString(),
058        StagingRepositoryFeature.class.toString()
059    }, true, true, true, true, true  );
060
061    public BasicManagedRepository( String id, String name, RepositoryStorage repositoryStorage )
062    {
063        super( RepositoryType.MAVEN, id, name, repositoryStorage );
064        initFeatures();
065    }
066
067    public BasicManagedRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage repositoryStorage )
068    {
069        super( primaryLocale, type, id, name, repositoryStorage);
070        initFeatures();
071    }
072
073    private void initFeatures() {
074        IndexCreationFeature indexCreationFeature = new IndexCreationFeature(this, this);
075        addFeature( artifactCleanupFeature );
076        addFeature( indexCreationFeature );
077        addFeature( stagingRepositoryFeature );
078    }
079
080    @Override
081    public boolean hasIndex( )
082    {
083        return true;
084    }
085
086    @Override
087    public RepositoryCapabilities getCapabilities( )
088    {
089        return CAPABILITIES;
090    }
091
092
093    @Override
094    public RepositoryRequestInfo getRequestInfo() {
095        return null;
096    }
097
098    /**
099     * Creates a filesystem based repository instance. The path is built by basePath/repository-id
100     *
101     * @param id The repository id
102     * @param name The name of the repository
103     * @param repositoryPath The path to the repository
104     * @return The repository instance
105     * @throws IOException
106     */
107    public static BasicManagedRepository newFilesystemInstance(String id, String name, Path repositoryPath) throws IOException {
108        FileLockManager lockManager = new DefaultFileLockManager();
109        FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
110        return new BasicManagedRepository(id, name, storage);
111    }
112
113}