This project has retired. For details please refer to its
Attic page.
DefaultLegacyRepositoryConverter xref
1 package org.apache.archiva.converter.legacy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.base.BasicManagedRepository;
31 import org.apache.archiva.repository.storage.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.MavenArtifactRepository;
37 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
38 import org.springframework.stereotype.Service;
39
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import java.io.IOException;
43 import java.nio.file.Path;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.Collections;
47 import java.util.List;
48
49
50
51
52
53
54 @Service( "legacyRepositoryConverter#default" )
55 public class DefaultLegacyRepositoryConverter
56 implements LegacyRepositoryConverter
57 {
58
59
60
61
62
63
64
65
66 private ArtifactRepositoryLayout defaultLayout;
67
68 @Inject
69 FileTypes fileTypes;
70
71
72
73
74 @Inject
75 @Named( value = "knownRepositoryContentConsumer#artifact-legacy-to-default-converter" )
76 private LegacyConverterArtifactConsumer legacyConverterConsumer;
77
78
79
80
81 @Inject
82 private RepositoryScanner repoScanner;
83
84 @Inject
85 public DefaultLegacyRepositoryConverter( PlexusSisuBridge plexusSisuBridge )
86 throws PlexusSisuBridgeException
87 {
88
89 defaultLayout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
90 }
91
92 @Override
93 public void convertLegacyRepository( Path legacyRepositoryDirectory, Path repositoryDirectory,
94 List<String> fileExclusionPatterns )
95 throws RepositoryConversionException
96 {
97 try
98 {
99 String defaultRepositoryUrl = PathUtil.toUrl( repositoryDirectory );
100
101 BasicManagedRepository legacyRepository = BasicManagedRepository.newFilesystemInstance( "legacy", "Legacy Repository", repositoryDirectory);
102 legacyRepository.setLocation( legacyRepositoryDirectory.toAbsolutePath().toUri() );
103 legacyRepository.setLayout( "legacy" );
104 DefaultFileLockManager lockManager = new DefaultFileLockManager();
105 FilesystemStorage storage = new FilesystemStorage(legacyRepositoryDirectory, lockManager);
106 legacyRepository.setContent(new ManagedDefaultRepositoryContent(legacyRepository, fileTypes, lockManager));
107
108 ArtifactRepository repository =
109 new MavenArtifactRepository("default", defaultRepositoryUrl, defaultLayout, null, null);
110
111 legacyConverterConsumer.setExcludes( fileExclusionPatterns );
112 legacyConverterConsumer.setDestinationRepository( repository );
113
114 List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<>( 1 );
115 knownConsumers.add( legacyConverterConsumer );
116
117 List<InvalidRepositoryContentConsumer> invalidConsumers = Collections.emptyList();
118 List<String> ignoredContent = new ArrayList<String>( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
119
120 repoScanner.scan( legacyRepository, knownConsumers, invalidConsumers, ignoredContent,
121 RepositoryScanner.FRESH_SCAN );
122 }
123 catch (RepositoryScannerException | IOException e )
124 {
125 throw new RepositoryConversionException( "Error convering legacy repository.", e );
126 }
127 }
128 }