001package org.apache.archiva.repository.maven2; 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.indexer.ArchivaIndexingContext; 025import org.apache.archiva.repository.*; 026import org.apache.archiva.repository.base.AbstractManagedRepository; 027import org.apache.archiva.repository.storage.FilesystemStorage; 028import org.apache.archiva.repository.content.maven2.MavenRepositoryRequestInfo; 029import org.apache.archiva.repository.features.ArtifactCleanupFeature; 030import org.apache.archiva.repository.features.IndexCreationFeature; 031import org.apache.archiva.repository.features.RepositoryFeature; 032import org.apache.archiva.repository.features.StagingRepositoryFeature; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036import java.io.IOException; 037import java.nio.file.Path; 038import java.util.Locale; 039 040/** 041 * Maven2 managed repository implementation. 042 */ 043public class MavenManagedRepository extends AbstractManagedRepository 044{ 045 046 private static final Logger log = LoggerFactory.getLogger( MavenManagedRepository.class ); 047 048 public static final String DEFAULT_LAYOUT = "default"; 049 public static final String LEGACY_LAYOUT = "legacy"; 050 private ArtifactCleanupFeature artifactCleanupFeature = new ArtifactCleanupFeature( ); 051 private IndexCreationFeature indexCreationFeature; 052 private StagingRepositoryFeature stagingRepositoryFeature = new StagingRepositoryFeature( ); 053 054 055 056 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities( 057 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT }, 058 new String[] { DEFAULT_LAYOUT, LEGACY_LAYOUT}, 059 new String[] {}, 060 new String[] {ArtifactCleanupFeature.class.getName(), IndexCreationFeature.class.getName(), 061 StagingRepositoryFeature.class.getName()}, 062 true, 063 true, 064 true, 065 true, 066 false 067 ); 068 069 public MavenManagedRepository(String id, String name, FilesystemStorage storage) 070 { 071 072 super( RepositoryType.MAVEN, id, name, storage); 073 this.indexCreationFeature = new IndexCreationFeature(this, this); 074 setLocation(storage.getAsset("").getFilePath().toUri()); 075 } 076 077 public MavenManagedRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage ) 078 { 079 super( primaryLocale, RepositoryType.MAVEN, id, name, storage ); 080 setLocation(storage.getAsset("").getFilePath().toUri()); 081 } 082 083 @Override 084 public RepositoryCapabilities getCapabilities( ) 085 { 086 return CAPABILITIES; 087 } 088 089 090 @SuppressWarnings( "unchecked" ) 091 @Override 092 public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException 093 { 094 if (ArtifactCleanupFeature.class.equals( clazz )) 095 { 096 return (RepositoryFeature<T>) artifactCleanupFeature; 097 } else if (IndexCreationFeature.class.equals(clazz)) { 098 return (RepositoryFeature<T>) indexCreationFeature; 099 } else if (StagingRepositoryFeature.class.equals(clazz)) { 100 return (RepositoryFeature<T>) stagingRepositoryFeature; 101 } else { 102 throw new UnsupportedFeatureException( ); 103 } 104 } 105 106 @Override 107 public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz ) 108 { 109 if (ArtifactCleanupFeature.class.equals(clazz) || 110 IndexCreationFeature.class.equals(clazz) || 111 StagingRepositoryFeature.class.equals(clazz)) { 112 return true; 113 } 114 return false; 115 } 116 117 @Override 118 public boolean hasIndex( ) 119 { 120 return indexCreationFeature.hasIndex(); 121 } 122 123 @Override 124 public RepositoryRequestInfo getRequestInfo() { 125 return new MavenRepositoryRequestInfo(this); 126 } 127 128 public static MavenManagedRepository newLocalInstance(String id, String name, Path basePath) throws IOException { 129 FileLockManager lockManager = new DefaultFileLockManager(); 130 FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager); 131 return new MavenManagedRepository(id, name, storage); 132 } 133 134 @Override 135 public void setIndexingContext(ArchivaIndexingContext context) { 136 super.setIndexingContext(context); 137 } 138 139}