]> source.dussan.org Git - archiva.git/blob
9720bdb53775b9f826006415edebeed2e06ea486
[archiva.git] /
1 package org.apache.maven.archiva.conversion;
2
3 import org.apache.maven.archiva.Archiva;
4 import org.apache.maven.archiva.reporting.ReportingStore;
5 import org.apache.maven.archiva.reporting.ReportGroup;
6 import org.apache.maven.archiva.reporting.ReportingDatabase;
7 import org.apache.maven.archiva.reporting.ReportingStoreException;
8 import org.apache.maven.archiva.converter.RepositoryConverter;
9 import org.apache.maven.archiva.converter.RepositoryConversionException;
10 import org.apache.maven.archiva.discoverer.ArtifactDiscoverer;
11 import org.apache.maven.archiva.discoverer.DiscovererException;
12 import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
13 import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
14 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
15 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
16 import org.apache.maven.artifact.repository.ArtifactRepository;
17 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
18
19 import java.io.File;
20 import java.net.MalformedURLException;
21 import java.util.List;
22
23 /**
24  * @author Jason van Zyl
25  * @plexus.component
26  * @todo turn this into a general conversion component and hide all this crap here.
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,
67                                          File repositoryDirectory,
68                                          List blacklistedPatterns,
69                                          boolean includeSnapshots )
70         throws RepositoryConversionException, DiscovererException
71     {
72         ArtifactRepository legacyRepository;
73
74         ArtifactRepository repository;
75
76         try
77         {
78             legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy",
79                                                                                    legacyRepositoryDirectory.toURI().toURL().toString(),
80                                                                                    legacyLayout, null, null );
81
82             repository = artifactRepositoryFactory.createArtifactRepository( "default",
83                                                                              repositoryDirectory.toURI().toURL().toString(),
84                                                                              defaultLayout, null, null );
85         }
86         catch ( MalformedURLException e )
87         {
88             throw new RepositoryConversionException( "Error convering legacy repository.", e );
89         }
90
91         ArtifactFilter filter =
92             includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter();
93         List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, blacklistedPatterns, filter );
94
95         ReportingDatabase reporter;
96         try
97         {
98             reporter = reportingStore.getReportsFromStore( repository, reportGroup );
99
100             repositoryConverter.convert( legacyArtifacts, repository, reporter );
101
102             reportingStore.storeReports( reporter, repository );
103         }
104         catch ( ReportingStoreException e )
105         {
106             throw new RepositoryConversionException( "Error convering legacy repository.", e );
107         }
108     }
109 }