001package org.apache.archiva.converter.legacy; 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.plexusbridge.PlexusSisuBridge; 024import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; 025import org.apache.archiva.common.utils.PathUtil; 026import org.apache.archiva.configuration.FileTypes; 027import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; 028import org.apache.archiva.consumers.KnownRepositoryContentConsumer; 029import org.apache.archiva.converter.RepositoryConversionException; 030import org.apache.archiva.repository.base.BasicManagedRepository; 031import org.apache.archiva.repository.storage.FilesystemStorage; 032import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent; 033import org.apache.archiva.repository.scanner.RepositoryScanner; 034import org.apache.archiva.repository.scanner.RepositoryScannerException; 035import org.apache.maven.artifact.repository.ArtifactRepository; 036import org.apache.maven.artifact.repository.MavenArtifactRepository; 037import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; 038import org.springframework.stereotype.Service; 039 040import javax.inject.Inject; 041import javax.inject.Named; 042import java.io.IOException; 043import java.nio.file.Path; 044import java.util.ArrayList; 045import java.util.Arrays; 046import java.util.Collections; 047import java.util.List; 048 049/** 050 * DefaultLegacyRepositoryConverter 051 * 052 * 053 */ 054@Service( "legacyRepositoryConverter#default" ) 055public class DefaultLegacyRepositoryConverter 056 implements LegacyRepositoryConverter 057{ 058 /** 059 * 060 */ 061 // private ArtifactRepositoryFactory artifactRepositoryFactory; 062 063 /** 064 * 065 */ 066 private ArtifactRepositoryLayout defaultLayout; 067 068 @Inject 069 FileTypes fileTypes; 070 071 /** 072 * 073 */ 074 @Inject 075 @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" ) 076 private LegacyConverterArtifactConsumer legacyConverterConsumer; 077 078 /** 079 * 080 */ 081 @Inject 082 private RepositoryScanner repoScanner; 083 084 @Inject 085 public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge ) 086 throws PlexusSisuBridgeException 087 { 088 // artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class ); 089 defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" ); 090 } 091 092 @Override 093 public void convertLegacyRepository( Path legacyRepositoryDirectory, Path repositoryDirectory, 094 List<String> fileExclusionPatterns ) 095 throws RepositoryConversionException 096 { 097 try 098 { 099 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory ); 100 101 BasicManagedRepository legacyRepository = BasicManagedRepository.newFilesystemInstance( "legacy", "Legacy Repository", repositoryDirectory); 102 legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() ); 103 legacyRepository.setLayout( "legacy" ); 104 DefaultFileLockManager lockManager = new DefaultFileLockManager(); 105 FilesystemStorage storage = new FilesystemStorage(legacyRepositoryDirectory, lockManager); 106 legacyRepository.setContent(new ManagedDefaultRepositoryContent(legacyRepository, fileTypes, lockManager)); 107 108 ArtifactRepository repository = 109 new MavenArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null); 110 111 legacyConverterConsumer.setExcludes( fileExclusionPatterns ); 112 legacyConverterConsumer.setDestinationRepository( repository ); 113 114 List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>( 1 ); 115 knownConsumers.add( legacyConverterConsumer ); 116 117 List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList(); 118 List<String> ignoredContent = new ArrayList<String>( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) ); 119 120 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent, 121 RepositoryScanner.FRESH_SCAN ); 122 } 123 catch (RepositoryScannerException | IOException e ) 124 { 125 throw new RepositoryConversionException( "Error convering legacy repository.", e ); 126 } 127 } 128}