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.RepositoryType; 027import org.apache.archiva.repository.StandardCapabilities; 028import org.apache.archiva.repository.storage.FilesystemStorage; 029import org.apache.archiva.repository.storage.RepositoryStorage; 030import org.apache.archiva.repository.features.IndexCreationFeature; 031import org.apache.archiva.repository.features.RemoteIndexFeature; 032import org.slf4j.Logger; 033import org.slf4j.LoggerFactory; 034 035import java.io.IOException; 036import java.nio.file.Path; 037import java.util.Locale; 038 039/** 040 * 041 * Just a helper class, mainly used for unit tests. 042 * 043 * 044 */ 045public class BasicRemoteRepository extends AbstractRemoteRepository 046 047{ 048 Logger log = LoggerFactory.getLogger(BasicRemoteRepository.class); 049 050 RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature(); 051 IndexCreationFeature indexCreationFeature = new IndexCreationFeature(true); 052 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 RemoteIndexFeature.class.toString(), 058 IndexCreationFeature.class.toString() 059 }, true, true, true, true, true ); 060 061 public BasicRemoteRepository( String id, String name, RepositoryStorage storage) 062 { 063 super( RepositoryType.MAVEN, id, name, storage); 064 initFeatures(); 065 } 066 067 public BasicRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage ) 068 { 069 super( primaryLocale, type, id, name, storage ); 070 initFeatures(); 071 } 072 073 private void initFeatures() { 074 addFeature( remoteIndexFeature ); 075 addFeature( indexCreationFeature ); 076 } 077 078 @Override 079 public boolean hasIndex( ) 080 { 081 return true; 082 } 083 084 @Override 085 public RepositoryCapabilities getCapabilities( ) 086 { 087 return CAPABILITIES; 088 } 089 090 091 public static BasicRemoteRepository newFilesystemInstance(String id, String name, Path basePath) throws IOException { 092 FileLockManager lockManager = new DefaultFileLockManager(); 093 FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); 094 return new BasicRemoteRepository(id, name, storage); 095 } 096}