1 package org.apache.archiva.converter.legacy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.common.filelock.DefaultFileLockManager;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
25 import org.apache.archiva.common.utils.PathUtil;
26 import org.apache.archiva.configuration.FileTypes;
27 import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
28 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
29 import org.apache.archiva.converter.RepositoryConversionException;
30 import org.apache.archiva.repository.BasicManagedRepository;
31 import org.apache.archiva.repository.content.FilesystemStorage;
32 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
33 import org.apache.archiva.repository.scanner.RepositoryScanner;
34 import org.apache.archiva.repository.scanner.RepositoryScannerException;
35 import org.apache.maven.artifact.repository.ArtifactRepository;
36 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
37 import org.apache.maven.artifact.repository.MavenArtifactRepository;
38 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
39 import org.springframework.stereotype.Service;
41 import javax.inject.Inject;
42 import javax.inject.Named;
43 import java.io.IOException;
44 import java.nio.file.Path;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Collections;
48 import java.util.List;
51 * DefaultLegacyRepositoryConverter
55 @Service( "legacyRepositoryConverter#default" )
56 public class DefaultLegacyRepositoryConverter
57 implements LegacyRepositoryConverter
62 // private ArtifactRepositoryFactory artifactRepositoryFactory;
67 private ArtifactRepositoryLayout defaultLayout;
76 @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
77 private LegacyConverterArtifactConsumer legacyConverterConsumer;
83 private RepositoryScanner repoScanner;
86 public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
87 throws PlexusSisuBridgeException
89 // artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
90 defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
94 public void convertLegacyRepository( Path legacyRepositoryDirectory, Path repositoryDirectory,
95 List<String> fileExclusionPatterns )
96 throws RepositoryConversionException
100 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
102 BasicManagedRepository legacyRepository = BasicManagedRepository.newFilesystemInstance( "legacy", "Legacy Repository", repositoryDirectory.getParent());
103 legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() );
104 legacyRepository.setLayout( "legacy" );
105 DefaultFileLockManager lockManager = new DefaultFileLockManager();
106 FilesystemStorage storage = new FilesystemStorage(legacyRepositoryDirectory, lockManager);
107 legacyRepository.setContent(new ManagedDefaultRepositoryContent(legacyRepository, fileTypes, lockManager));
109 ArtifactRepository repository =
110 new MavenArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
112 legacyConverterConsumer.setExcludes( fileExclusionPatterns );
113 legacyConverterConsumer.setDestinationRepository( repository );
115 List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>( 1 );
116 knownConsumers.add( legacyConverterConsumer );
118 List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
119 List<String> ignoredContent = new ArrayList<String>( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
121 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
122 RepositoryScanner.FRESH_SCAN );
124 catch (RepositoryScannerException | IOException e )
126 throw new RepositoryConversionException( "Error convering legacy repository.", e );