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.maven.archiva.common.utils.PathUtil;
23 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
24 import org.apache.maven.archiva.converter.RepositoryConversionException;
25 import org.apache.maven.archiva.repository.RepositoryException;
26 import org.apache.maven.archiva.repository.scanner.RepositoryScanner;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
29 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.List;
38 * DefaultLegacyRepositoryConverter
43 public class DefaultLegacyRepositoryConverter
44 implements LegacyRepositoryConverter
49 private ArtifactRepositoryFactory artifactRepositoryFactory;
52 * @plexus.requirement role-hint="default"
54 private ArtifactRepositoryLayout defaultLayout;
57 * @plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
58 * role-hint="artifact-legacy-to-default-converter"
60 private LegacyConverterArtifactConsumer legacyConverterConsumer;
65 private RepositoryScanner repoScanner;
67 public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
68 List fileExclusionPatterns )
69 throws RepositoryConversionException
73 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
75 ManagedRepositoryConfiguration legacyRepository = new ManagedRepositoryConfiguration();
76 legacyRepository.setId( "legacy");
77 legacyRepository.setName( "Legacy Repository" );
78 legacyRepository.setLocation( legacyRepositoryDirectory.getAbsolutePath() );
79 legacyRepository.setLayout( "legacy" );
81 ArtifactRepository repository = artifactRepositoryFactory.createArtifactRepository( "default",
85 legacyConverterConsumer.setExcludes( fileExclusionPatterns );
86 legacyConverterConsumer.setDestinationRepository( repository );
88 List knownConsumers = new ArrayList();
89 knownConsumers.add( legacyConverterConsumer );
91 List invalidConsumers = Collections.EMPTY_LIST;
92 List ignoredContent = new ArrayList();
93 ignoredContent.addAll( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
95 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
96 RepositoryScanner.FRESH_SCAN );
98 catch ( RepositoryException e )
100 throw new RepositoryConversionException( "Error convering legacy repository.", e );