1 package org.apache.maven.archiva.conversion;
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;
19 import java.net.MalformedURLException;
20 import java.util.List;
23 * @author Jason van Zyl
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
28 public class DefaultLegacyRepositoryConverter
29 implements LegacyRepositoryConverter
32 * @plexus.requirement role-hint="legacy"
34 private ArtifactDiscoverer artifactDiscoverer;
37 * @plexus.requirement role-hint="legacy"
39 private ArtifactRepositoryLayout legacyLayout;
42 * @plexus.requirement role-hint="default"
44 private ArtifactRepositoryLayout defaultLayout;
49 private ArtifactRepositoryFactory artifactRepositoryFactory;
54 private RepositoryConverter repositoryConverter;
59 private ReportingStore reportingStore;
62 * @plexus.requirement role-hint="health"
64 private ReportGroup reportGroup;
66 public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory,
67 List blacklistedPatterns, boolean includeSnapshots )
68 throws RepositoryConversionException, DiscovererException
70 ArtifactRepository legacyRepository;
72 ArtifactRepository repository;
76 legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy",
77 legacyRepositoryDirectory.toURI().toURL().toString(),
78 legacyLayout, null, null );
80 repository = artifactRepositoryFactory.createArtifactRepository( "default",
81 repositoryDirectory.toURI().toURL().toString(),
82 defaultLayout, null, null );
84 catch ( MalformedURLException e )
86 throw new RepositoryConversionException( "Error convering legacy repository.", e );
89 ArtifactFilter filter =
90 includeSnapshots ? new AcceptAllArtifactFilter() : (ArtifactFilter) new SnapshotArtifactFilter();
91 List legacyArtifacts = artifactDiscoverer.discoverArtifacts( legacyRepository, blacklistedPatterns, filter );
93 ReportingDatabase reporter;
96 reporter = reportingStore.getReportsFromStore( repository, reportGroup );
98 repositoryConverter.convert( legacyArtifacts, repository, reporter );
100 reportingStore.storeReports( reporter, repository );
102 catch ( ReportingStoreException e )
104 throw new RepositoryConversionException( "Error convering legacy repository.", e );