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.plexusbridge.PlexusSisuBridge;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
24 import org.apache.archiva.common.utils.PathUtil;
25 import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
26 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
27 import org.apache.archiva.converter.RepositoryConversionException;
28 import org.apache.archiva.repository.BasicManagedRepository;
29 import org.apache.archiva.repository.scanner.RepositoryScanner;
30 import org.apache.archiva.repository.scanner.RepositoryScannerException;
31 import org.apache.maven.artifact.repository.ArtifactRepository;
32 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
33 import org.apache.maven.artifact.repository.MavenArtifactRepository;
34 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.nio.file.Path;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collections;
43 import java.util.List;
46 * DefaultLegacyRepositoryConverter
50 @Service( "legacyRepositoryConverter#default" )
51 public class DefaultLegacyRepositoryConverter
52 implements LegacyRepositoryConverter
57 // private ArtifactRepositoryFactory artifactRepositoryFactory;
62 private ArtifactRepositoryLayout defaultLayout;
68 @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
69 private LegacyConverterArtifactConsumer legacyConverterConsumer;
75 private RepositoryScanner repoScanner;
78 public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
79 throws PlexusSisuBridgeException
81 // artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
82 defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
86 public void convertLegacyRepository( Path legacyRepositoryDirectory, Path repositoryDirectory,
87 List<String> fileExclusionPatterns )
88 throws RepositoryConversionException
92 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
94 BasicManagedRepository legacyRepository = new BasicManagedRepository( "legacy", "Legacy Repository", repositoryDirectory.getParent());
95 legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() );
96 legacyRepository.setLayout( "legacy" );
98 ArtifactRepository repository =
99 new MavenArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
101 legacyConverterConsumer.setExcludes( fileExclusionPatterns );
102 legacyConverterConsumer.setDestinationRepository( repository );
104 List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>( 1 );
105 knownConsumers.add( legacyConverterConsumer );
107 List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
108 List<String> ignoredContent = new ArrayList<String>( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
110 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
111 RepositoryScanner.FRESH_SCAN );
113 catch ( RepositoryScannerException e )
115 throw new RepositoryConversionException( "Error convering legacy repository.", e );