1 package org.apache.maven.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.repository.scanner.RepositoryScanner;
25 import org.apache.archiva.repository.scanner.RepositoryScannerException;
26 import org.apache.maven.archiva.common.utils.PathUtil;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
29 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
30 import org.apache.maven.archiva.converter.RepositoryConversionException;
31 import org.apache.maven.artifact.repository.ArtifactRepository;
32 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
33 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
34 import org.springframework.stereotype.Service;
36 import javax.inject.Inject;
37 import javax.inject.Named;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collections;
42 import java.util.List;
45 * DefaultLegacyRepositoryConverter
50 @Service( "legacyRepositoryConverter#default" )
51 public class DefaultLegacyRepositoryConverter
52 implements LegacyRepositoryConverter
57 private ArtifactRepositoryFactory artifactRepositoryFactory;
60 * plexus.requirement role-hint="default"
62 private ArtifactRepositoryLayout defaultLayout;
65 * plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
66 * role-hint="artifact-legacy-to-default-converter"
69 @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
70 private LegacyConverterArtifactConsumer legacyConverterConsumer;
76 private RepositoryScanner repoScanner;
79 public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
80 throws PlexusSisuBridgeException
82 artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
83 defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
86 public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
87 List<String> fileExclusionPatterns )
88 throws RepositoryConversionException
92 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
94 ManagedRepositoryConfiguration legacyRepository = new ManagedRepositoryConfiguration();
95 legacyRepository.setId( "legacy" );
96 legacyRepository.setName( "Legacy Repository" );
97 legacyRepository.setLocation( legacyRepositoryDirectory.getAbsolutePath() );
98 legacyRepository.setLayout( "legacy" );
100 ArtifactRepository repository =
101 artifactRepositoryFactory.createArtifactRepository( "default", defaultRepositoryUrl, defaultLayout,
103 legacyConverterConsumer.setExcludes( fileExclusionPatterns );
104 legacyConverterConsumer.setDestinationRepository( repository );
106 List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
107 knownConsumers.add( legacyConverterConsumer );
109 List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
110 List<String> ignoredContent = new ArrayList<String>();
111 ignoredContent.addAll( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
113 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
114 RepositoryScanner.FRESH_SCAN );
116 catch ( RepositoryScannerException e )
118 throw new RepositoryConversionException( "Error convering legacy repository.", e );