This project has retired. For details please refer to its Attic page.
DefaultLegacyRepositoryConverter xref
View Javadoc
1   package org.apache.archiva.converter.legacy;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.admin.model.beans.ManagedRepository;
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.consumers.InvalidRepositoryContentConsumer;
27  import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
28  import org.apache.archiva.converter.RepositoryConversionException;
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.layout.ArtifactRepositoryLayout;
34  import org.springframework.stereotype.Service;
35  
36  import javax.inject.Inject;
37  import javax.inject.Named;
38  import java.io.File;
39  import java.util.ArrayList;
40  import java.util.Arrays;
41  import java.util.Collections;
42  import java.util.List;
43  
44  /**
45   * DefaultLegacyRepositoryConverter
46   *
47   *
48   */
49  @Service( "legacyRepositoryConverter#default" )
50  public class DefaultLegacyRepositoryConverter
51      implements LegacyRepositoryConverter
52  {
53      /**
54       *
55       */
56      private ArtifactRepositoryFactory artifactRepositoryFactory;
57  
58      /**
59       *
60       */
61      private ArtifactRepositoryLayout defaultLayout;
62  
63      /**
64       *
65       */
66      @Inject
67      @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
68      private LegacyConverterArtifactConsumer legacyConverterConsumer;
69  
70      /**
71       *
72       */
73      @Inject
74      private RepositoryScanner repoScanner;
75  
76      @Inject
77      public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
78          throws PlexusSisuBridgeException
79      {
80          artifactRepositoryFactory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
81          defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
82      }
83  
84      @Override
85      public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
86                                           List<String> fileExclusionPatterns )
87          throws RepositoryConversionException
88      {
89          try
90          {
91              String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
92  
93              ManagedRepository legacyRepository = new ManagedRepository();
94              legacyRepository.setId( "legacy" );
95              legacyRepository.setName( "Legacy Repository" );
96              legacyRepository.setLocation( legacyRepositoryDirectory.getAbsolutePath() );
97              legacyRepository.setLayout( "legacy" );
98  
99              ArtifactRepository repository =
100                 artifactRepositoryFactory.createArtifactRepository( "default", defaultRepositoryUrl, defaultLayout,
101                                                                     null, null );
102             legacyConverterConsumer.setExcludes( fileExclusionPatterns );
103             legacyConverterConsumer.setDestinationRepository( repository );
104 
105             List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>( 1 );
106             knownConsumers.add( legacyConverterConsumer );
107 
108             List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
109             List<String> ignoredContent = new ArrayList<String>( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
110 
111             repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
112                               RepositoryScanner.FRESH_SCAN );
113         }
114         catch ( RepositoryScannerException e )
115         {
116             throw new RepositoryConversionException( "Error convering legacy repository.", e );
117         }
118     }
119 }