]> source.dussan.org Git - archiva.git/blob
d40e8315777ca7c2acd05f2ade66fc7b2508b56a
[archiva.git] /
1 package org.apache.maven.archiva.conversion;
2
3 import org.apache.maven.archiva.converter.RepositoryConversionException;
4 import org.apache.maven.archiva.converter.RepositoryConverter;
5 import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
6 import org.apache.maven.archiva.discoverer.DiscovererException;
7 import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
8 import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
9 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
10 import org.apache.maven.archiva.reporting.group.ReportGroup;
11 import org.apache.maven.archiva.reporting.store.ReportingStore;
12 import org.apache.maven.archiva.reporting.store.ReportingStoreException;
13 import org.apache.maven.artifact.repository.ArtifactRepository;
14 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
15 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
16 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
17
18 import java.io.File;
19 import java.net.MalformedURLException;
20 import java.util.List;
21
22 /**
23  * @author Jason van Zyl
24  * @plexus.component
25  * @todo turn this into a general conversion component and hide all this crap here.
26  * @todo it should be possible to move this to the converter module without causing it to gain additional dependencies
27  */
28 public class DefaultLegacyRepositoryConverter
29     implements LegacyRepositoryConverter
30 {
31     /**
32      * @plexus.requirement role-hint="legacy"
33      */
34     private ArtifactDiscoverer artifactDiscoverer;
35
36     /**
37      * @plexus.requirement role-hint="legacy"
38      */
39     private ArtifactRepositoryLayout legacyLayout;
40
41     /**
42      * @plexus.requirement role-hint="default"
43      */
44     private ArtifactRepositoryLayout defaultLayout;
45
46     /**
47      * @plexus.requirement
48      */
49     private ArtifactRepositoryFactory artifactRepositoryFactory;
50
51     /**
52      * @plexus.requirement
53      */
54     private RepositoryConverter repositoryConverter;
55
56     /**
57      * @plexus.requirement
58      */
59     private ReportingStore reportingStore;
60
61     /**
62      * @plexus.requirement role-hint="health"
63      */
64     private ReportGroup reportGroup;
65
66     public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
67                                          List blacklistedPatterns, boolean includeSnapshots )
68         throws RepositoryConversionException, DiscovererException
69     {
70         ArtifactRepository legacyRepository;
71
72         ArtifactRepository repository;
73
74         try
75         {
76             legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy",
77                                                                                    legacyRepositoryDirectory.toURI().toURL().toString(),
78                                                                                    legacyLayout, null, null );
79
80             repository = artifactRepositoryFactory.createArtifactRepository( "default",
81                                                                              repositoryDirectory.toURI().toURL().toString(),
82                                                                              defaultLayout, null, null );
83         }
84         catch ( MalformedURLException e )
85         {
86             throw new RepositoryConversionException( "Error convering legacy repository.", e );
87         }
88
89         ArtifactFilter filter =
90             includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter();
91         List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, blacklistedPatterns, filter );
92
93         ReportingDatabase reporter;
94         try
95         {
96             reporter = reportingStore.getReportsFromStore( repository, reportGroup );
97
98             repositoryConverter.convert( legacyArtifacts, repository, reporter );
99
100             reportingStore.storeReports( reporter, repository );
101         }
102         catch ( ReportingStoreException e )
103         {
104             throw new RepositoryConversionException( "Error convering legacy repository.", e );
105         }
106     }
107 }