jdcasey 2005/04/07 14:26:21
Modified: sandbox/repoclean/src/main/resources/META-INF/plexus components.xml sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean RepositoryCleaner.java Added: sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/index ArtifactIndexer.java Log: Added the ability to generate an index file under .index.txt for the repository as we convert it. Revision Changes Path 1.1 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/index/ArtifactIndexer.java Index: ArtifactIndexer.java =================================================================== package org.apache.maven.tools.repoclean.index; import org.apache.maven.artifact.Artifact; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.IOUtil; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author jdcasey */ public class ArtifactIndexer extends AbstractLogEnabled { public static final String ROLE = ArtifactIndexer.class.getName(); public void writeAritfactIndex( List artifacts, File targetRepositoryBase ) { List sortedArtifacts = new ArrayList( artifacts ); Collections.sort( sortedArtifacts, new ArtifactIdComparator() ); File indexFile = new File( targetRepositoryBase, ".index.txt" ); FileWriter indexWriter = null; try { indexWriter = new FileWriter( indexFile ); for ( Iterator it = sortedArtifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); indexWriter.write( artifact.getId() + "\n" ); } } catch ( IOException e ) { getLogger().error( "Error writing artifact index file.", e ); } finally { IOUtil.close( indexWriter ); } } private static final class ArtifactIdComparator implements Comparator { public int compare( Object first, Object second ) { Artifact firstArtifact = (Artifact) first; Artifact secondArtifact = (Artifact) second; return firstArtifact.getConflictId().compareTo( secondArtifact.getConflictId() ); } } } 1.7 +12 -0 maven-components/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml Index: components.xml =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- components.xml 7 Apr 2005 16:37:18 -0000 1.6 +++ components.xml 7 Apr 2005 21:26:21 -0000 1.7 @@ -103,6 +103,9 @@ <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier</role> </requirement> <requirement> + <role>org.apache.maven.tools.repoclean.index.ArtifactIndexer</role> + </requirement> + <requirement> <role>org.codehaus.plexus.mailsender.MailSender</role> </requirement> </requirements> @@ -112,6 +115,15 @@ | | --> + <component> + <role>org.apache.maven.tools.repoclean.index.ArtifactIndexer</role> + <implementation>org.apache.maven.tools.repoclean.index.ArtifactIndexer</implementation> + </component> + <!-- + | + | + | + --> <component> <role>org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer</role> <role-hint>legacy</role-hint> 1.12 +6 -1 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java Index: RepositoryCleaner.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- RepositoryCleaner.java 7 Apr 2005 16:37:18 -0000 1.11 +++ RepositoryCleaner.java 7 Apr 2005 21:26:21 -0000 1.12 @@ -23,6 +23,7 @@ import org.apache.maven.tools.repoclean.artifact.metadata.ProjectMetadata; import org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier; import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer; +import org.apache.maven.tools.repoclean.index.ArtifactIndexer; import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter; import org.codehaus.plexus.PlexusConstants; @@ -61,7 +62,9 @@ private ArtifactDigestVerifier artifactDigestVerifier; private MailSender mailSender; - + + private ArtifactIndexer artifactIndexer; + private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); private PlexusContainer container; @@ -145,6 +148,8 @@ logger.info( "Rewriting POMs and artifact files." ); } + artifactIndexer.writeAritfactIndex( artifacts, targetRepositoryBase ); + rewriteArtifactsAndPoms( artifacts, sourceRepo, targetRepo, configuration, reportsBase, sourceRepositoryBase, targetRepositoryBase, repoReporter ); }