jdcasey 2005/04/19 13:05:16 Modified: sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover DefaultArtifactDiscoverer.java LegacyArtifactDiscoverer.java ArtifactDiscoverer.java sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite ArtifactPomRewriter.java V3PomRewriter.java V4PomRewriter.java sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report Reporter.java sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean RepositoryCleanerConfiguration.java RepositoryCleaner.java Main.java sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest ArtifactDigestVerifier.java sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate PomV3ToV4Translator.java Added: sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report ReportWriteException.java FileReporter.java sandbox/repoclean/src/site/apt transition-to-repo-management.apt sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean TestSupport.java sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/report DummyReporter.java sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/translate PomV3ToV4TranslatorTest.java Log: Implemented list items #2 and #3 from the main issue (scope from m1, and plugin entry translation in POMs). Tests included. PR: MNG-309 Revision Changes Path 1.4 +3 -3 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java Index: DefaultArtifactDiscoverer.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DefaultArtifactDiscoverer.java 1 Apr 2005 00:24:44 -0000 1.3 +++ DefaultArtifactDiscoverer.java 19 Apr 2005 20:05:15 -0000 1.4 @@ -4,7 +4,7 @@ import org.apache.maven.artifact.construction.ArtifactConstructionSupport; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.IOUtil; @@ -36,7 +36,7 @@ private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); - public List discoverArtifacts( File repositoryBase, Reporter reporter ) + public List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception { List artifacts = new ArrayList(); @@ -64,7 +64,7 @@ return artifacts; } - private Artifact buildArtifact( File repositoryBase, String path, Reporter reporter ) + private Artifact buildArtifact( File repositoryBase, String path, FileReporter reporter ) throws Exception { Artifact result = null; 1.8 +3 -3 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java Index: LegacyArtifactDiscoverer.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- LegacyArtifactDiscoverer.java 5 Apr 2005 02:47:43 -0000 1.7 +++ LegacyArtifactDiscoverer.java 19 Apr 2005 20:05:15 -0000 1.8 @@ -16,7 +16,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.construction.ArtifactConstructionSupport; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.DirectoryScanner; @@ -38,7 +38,7 @@ private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); - public List discoverArtifacts( File repositoryBase, Reporter reporter ) + public List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception { List artifacts = new ArrayList(); @@ -65,7 +65,7 @@ return artifacts; } - private Artifact buildArtifact( String path, Reporter reporter ) + private Artifact buildArtifact( String path, FileReporter reporter ) throws Exception { StringTokenizer tokens = new StringTokenizer( path, "/\\" ); 1.4 +2 -2 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java Index: ArtifactDiscoverer.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ArtifactDiscoverer.java 4 Apr 2005 03:43:11 -0000 1.3 +++ ArtifactDiscoverer.java 19 Apr 2005 20:05:15 -0000 1.4 @@ -1,6 +1,6 @@ package org.apache.maven.tools.repoclean.discover; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import java.io.File; import java.util.List; @@ -43,6 +43,6 @@ "**/REPOSITORY-V*.txt" }; - List discoverArtifacts( File repositoryBase, Reporter reporter ) throws Exception; + List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception; } \ No newline at end of file 1.2 +2 -2 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/ArtifactPomRewriter.java Index: ArtifactPomRewriter.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/ArtifactPomRewriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ArtifactPomRewriter.java 23 Mar 2005 04:53:29 -0000 1.1 +++ ArtifactPomRewriter.java 19 Apr 2005 20:05:15 -0000 1.2 @@ -1,7 +1,7 @@ package org.apache.maven.tools.repoclean.rewrite; import org.apache.maven.artifact.Artifact; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import java.io.File; @@ -30,6 +30,6 @@ public static final String ROLE = ArtifactPomRewriter.class.getName(); - void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly ) throws Exception; + void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly ) throws Exception; } 1.4 +3 -3 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java Index: V3PomRewriter.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- V3PomRewriter.java 5 Apr 2005 02:47:43 -0000 1.3 +++ V3PomRewriter.java 19 Apr 2005 20:05:15 -0000 1.4 @@ -4,7 +4,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; @@ -38,7 +38,7 @@ { private PomV3ToV4Translator translator; - public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly ) + public void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly ) throws Exception { Model v4Model = null; @@ -107,7 +107,7 @@ } } - private void validateV4Basics( Model model, Artifact artifact, Reporter reporter ) + private void validateV4Basics( Model model, Artifact artifact, FileReporter reporter ) throws Exception { if ( StringUtils.isEmpty( model.getModelVersion() ) ) 1.4 +3 -3 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V4PomRewriter.java Index: V4PomRewriter.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V4PomRewriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- V4PomRewriter.java 5 Apr 2005 02:47:43 -0000 1.3 +++ V4PomRewriter.java 19 Apr 2005 20:05:15 -0000 1.4 @@ -21,7 +21,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; @@ -35,7 +35,7 @@ public class V4PomRewriter implements ArtifactPomRewriter { - public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly ) + public void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly ) throws Exception { Model model = null; @@ -95,7 +95,7 @@ } } - private void validateBasics( Model model, Artifact artifact, Reporter reporter ) + private void validateBasics( Model model, Artifact artifact, FileReporter reporter ) throws Exception { if ( StringUtils.isEmpty( model.getModelVersion() ) ) 1.4 +18 -166 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/Reporter.java Index: Reporter.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/Reporter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Reporter.java 5 Apr 2005 02:47:43 -0000 1.3 +++ Reporter.java 19 Apr 2005 20:05:15 -0000 1.4 @@ -1,185 +1,37 @@ package org.apache.maven.tools.repoclean.report; -/* ==================================================================== - * Copyright 2001-2004 The Apache Software Foundation. +/* + * 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 + * 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 + * 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. - * ==================================================================== + * 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. */ -import org.codehaus.plexus.util.IOUtil; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * @author jdcasey - */ -public class Reporter +public interface Reporter { - private static final String WARN_LEVEL = "[WARNING] "; - - private static final String ERROR_LEVEL = "[ERROR] "; - - private File reportsFile; + public void close(); - private List messages = new ArrayList(); + public boolean hasWarning(); - private boolean hasError = false; - - private boolean hasWarning = false; - - private Writer writer; - - public Reporter( File reportsBase, String reportPath ) - { - this.reportsFile = new File( reportsBase, reportPath ); - - File parentDir = reportsFile.getParentFile(); - if ( !parentDir.exists() ) - { - parentDir.mkdirs(); - } - - if ( !parentDir.isDirectory() ) - { - throw new IllegalArgumentException( "path: \'" + parentDir.getAbsolutePath() - + "\' refers to a file, not a directory.\n" + "Cannot write report file: \'" - + reportsFile.getAbsolutePath() + "\'." ); - } - } - - public File getReportFile() - { - return reportsFile; - } - - private void open() - throws IOException - { - this.writer = new FileWriter( reportsFile ); - } - - public void close() - { - IOUtil.close( writer ); - } - - private void write( Object message ) - throws IOException - { - if ( writer == null ) - { - open(); - } - - if ( message instanceof List ) - { - writer.write( format( (List) message ).toString() ); - } - else - { - writer.write( String.valueOf( message ) ); - } - - writer.write( '\n' ); - - writer.flush(); - } - - public boolean hasWarning() - { - return hasWarning; - } - - public boolean hasError() - { - return hasError; - } + public boolean hasError(); public void warn( String message ) - throws IOException - { - hasWarning = true; - write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) ); - } + throws ReportWriteException; public void error( String message, Throwable error ) - throws IOException - { - hasError = true; - write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( message ).append( error ) ); - } + throws ReportWriteException; public void error( String message ) - throws IOException - { - hasError = true; - write( new AppendingList( 2 ).append( ERROR_LEVEL ).append( message ) ); - } - - private CharSequence format( List messageParts ) - { - StringBuffer buffer = new StringBuffer(); - for ( Iterator it = messageParts.iterator(); it.hasNext(); ) - { - Object part = it.next(); - if ( part instanceof Throwable ) - { - part = formatThrowable( (Throwable) part ); - } - - buffer.append( part ); - } - - return buffer; - } - - private String formatThrowable( Throwable throwable ) - { - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter( sWriter ); - - throwable.printStackTrace( pWriter ); - - return sWriter.toString(); - } - - private static class AppendingList - extends ArrayList - { - public AppendingList() - { - } - - public AppendingList( int size ) - { - super( size ); - } - - public AppendingList append( Object item ) - { - super.add( item ); - return this; - } - } + throws ReportWriteException; } \ No newline at end of file 1.1 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/ReportWriteException.java Index: ReportWriteException.java =================================================================== package org.apache.maven.tools.repoclean.report; /* * 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. */ public class ReportWriteException extends Exception { public ReportWriteException( String message, Throwable cause ) { super( message, cause ); } public ReportWriteException( String message ) { super( message ); } public ReportWriteException( Throwable cause ) { super( cause ); } } 1.1 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java Index: FileReporter.java =================================================================== package org.apache.maven.tools.repoclean.report; /* ==================================================================== * Copyright 2001-2004 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. * ==================================================================== */ import org.codehaus.plexus.util.IOUtil; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * @author jdcasey */ public class FileReporter implements Reporter { private static final String WARN_LEVEL = "[WARNING] "; private static final String ERROR_LEVEL = "[ERROR] "; private File reportsFile; private List messages = new ArrayList(); private boolean hasError = false; private boolean hasWarning = false; private Writer writer; public FileReporter( File reportsBase, String reportPath ) { this.reportsFile = new File( reportsBase, reportPath ); File parentDir = reportsFile.getParentFile(); if ( !parentDir.exists() ) { parentDir.mkdirs(); } if ( !parentDir.isDirectory() ) { throw new IllegalArgumentException( "path: \'" + parentDir.getAbsolutePath() + "\' refers to a file, not a directory.\n" + "Cannot write report file: \'" + reportsFile.getAbsolutePath() + "\'." ); } } public File getReportFile() { return reportsFile; } private void open() throws IOException { this.writer = new FileWriter( reportsFile ); } public void close() { IOUtil.close( writer ); } private void write( Object message ) throws ReportWriteException { try { if ( writer == null ) { open(); } if ( message instanceof List ) { writer.write( format( (List) message ).toString() ); } else { writer.write( String.valueOf( message ) ); } writer.write( '\n' ); writer.flush(); } catch ( IOException e ) { throw new ReportWriteException( "Cannot write message: " + message + " due to an I/O error.", e ); } } public boolean hasWarning() { return hasWarning; } public boolean hasError() { return hasError; } public void warn( String message ) throws ReportWriteException { hasWarning = true; write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) ); } public void error( String message, Throwable error ) throws ReportWriteException { hasError = true; write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( message ).append( error ) ); } public void error( String message ) throws ReportWriteException { hasError = true; write( new AppendingList( 2 ).append( ERROR_LEVEL ).append( message ) ); } private CharSequence format( List messageParts ) { StringBuffer buffer = new StringBuffer(); for ( Iterator it = messageParts.iterator(); it.hasNext(); ) { Object part = it.next(); if ( part instanceof Throwable ) { part = formatThrowable( (Throwable) part ); } buffer.append( part ); } return buffer; } private String formatThrowable( Throwable throwable ) { StringWriter sWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter( sWriter ); throwable.printStackTrace( pWriter ); return sWriter.toString(); } private static class AppendingList extends ArrayList { public AppendingList() { } public AppendingList( int size ) { super( size ); } public AppendingList append( Object item ) { super.add( item ); return this; } } } 1.1 maven-components/sandbox/repoclean/src/site/apt/transition-to-repo-management.apt Index: transition-to-repo-management.apt =================================================================== --- Transitioning from Repository Conversion to Repository Management --- John Casey --- 19-Apr-2005 --- Notes on Transitioning Repoclean from a Conversion Tool to a Management Tool * Abstract Repoclean was born a conversion tool, with the primary purpose of performing the initial conversion between maven1 and maven2 repository formats. As such, it has facilities for translating POMs, restructuring artifact directories, repairing checksums, and more. However, it has become exceedingly clear with the first alpha release of maven2 that we need a tool to perform smart mirroring of artifacts and metadata between m1 and m2 repositories. To that end, we must redesign and refactor repoclean (the closest thing to a solution we currently have), and transform it from a one-off project to an active part of the maven toolset. * Execution Modes While these execution modes are in various states of development, we need to formalize these options in the configuration and repair any gaps in the implementation. ** Support for m1-to-m1 synchronization We need to support blacklisting and other features relevant to m1 repositories in this feature. In the feature list below, I'll note which ones are applicable to m1. ** Support for m2-to-m2 synchronization We'll need to support normalization and blacklisting for synchronization of a feeder m2 repository to our canonical m2 repository. ** Support for m2-to-m1 synchronization We have to be able to do bidirectional synchronization, for the case where one or more of our feeder repositories transitions to maven2 while we're still supporting maven1 users. This really should only involve any normalization that we'd normally do in a m2-to-m2 sync process, plus forced usage of the legacy repository layout and translation of POMs. ** Support for m1-to-m2 synchronization This one should be mostly complete, with only new features still needing implementation. * Features * Required Modifications ** Add CLI for parsing command-line modifications to config files, and for "--force". ** Add SHA-1 checksum file support. 1.3 +12 -12 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java Index: RepositoryCleanerConfiguration.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RepositoryCleanerConfiguration.java 6 Apr 2005 20:15:07 -0000 1.2 +++ RepositoryCleanerConfiguration.java 19 Apr 2005 20:05:15 -0000 1.3 @@ -47,9 +47,9 @@ private String errorReportToAddress; - private String errorReportSmtpHost; - private boolean mailErrorReport; + + private boolean force; public void setSourceRepositoryPath( String sourceRepositoryPath ) { @@ -151,16 +151,6 @@ this.errorReportFromName = errorReportFromName; } - public String getErrorReportSmtpHost() - { - return errorReportSmtpHost; - } - - public void setErrorReportSmtpHost( String errorReportSmtpHost ) - { - this.errorReportSmtpHost = errorReportSmtpHost; - } - public String getErrorReportToAddress() { return errorReportToAddress; @@ -190,4 +180,14 @@ { return mailErrorReport; } + + public boolean force() + { + return force; + } + + public void setForce( boolean force ) + { + this.force = force; + } } \ No newline at end of file 1.13 +8 -11 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- RepositoryCleaner.java 7 Apr 2005 21:26:21 -0000 1.12 +++ RepositoryCleaner.java 19 Apr 2005 20:05:15 -0000 1.13 @@ -24,7 +24,7 @@ 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.report.FileReporter; import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; @@ -86,10 +86,10 @@ { Logger logger = getLogger(); - Reporter repoReporter = null; + FileReporter repoReporter = null; try { - repoReporter = new Reporter( reportsBase, "repository.report.txt" ); + repoReporter = new FileReporter( reportsBase, "repository.report.txt" ); ArtifactDiscoverer artifactDiscoverer = null; @@ -197,13 +197,10 @@ MailMessage message = new MailMessage(); message.setContent( reportContents ); message.setSubject( configuration.getErrorReportSubject() ); - message.setFromName( configuration.getErrorReportFromName() ); - message.setFromAddress( configuration.getErrorReportFromAddress() ); + message.setFrom( configuration.getErrorReportFromName(), configuration.getErrorReportFromAddress() ); message.setSendDate( new Date() ); message.addTo( configuration.getErrorReportToName(), configuration.getErrorReportToAddress() ); - mailSender.setSmtpHost( configuration.getErrorReportSmtpHost() ); - mailSender.send( message ); } } @@ -237,7 +234,7 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo, RepositoryCleanerConfiguration configuration, File reportsBase, - File sourceRepositoryBase, File targetRepositoryBase, Reporter repoReporter ) + File sourceRepositoryBase, File targetRepositoryBase, FileReporter repoReporter ) throws Exception { Logger logger = getLogger(); @@ -256,10 +253,10 @@ String artifactReportPath = buildArtifactReportPath( artifact ); - Reporter artifactReporter = null; + FileReporter artifactReporter = null; try { - artifactReporter = new Reporter( reportsBase, artifactReportPath ); + artifactReporter = new FileReporter( reportsBase, artifactReportPath ); boolean errorOccurred = false; @@ -398,7 +395,7 @@ + "/" + ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + artifact.getVersion() + ".report.txt"; } - private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter ) + private void copyArtifact( Artifact artifact, File artifactTarget, FileReporter reporter ) throws IOException { File artifactSource = artifact.getFile(); 1.6 +27 -19 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Main.java 6 Apr 2005 20:15:07 -0000 1.5 +++ Main.java 19 Apr 2005 20:05:15 -0000 1.6 @@ -49,31 +49,40 @@ System.exit( 0 ); } - Embedder embedder = new Embedder(); try { - embedder.start( new ClassWorld() ); - RepositoryCleanerConfiguration config = buildConfig( args[0] ); - RepositoryCleaner cleaner = null; - try - { - cleaner = (RepositoryCleaner) embedder.lookup( RepositoryCleaner.ROLE ); - - cleaner.cleanRepository( config ); - } - finally - { - if ( cleaner != null ) - { - embedder.release( cleaner ); - } - } + launch( config ); + + System.exit( 0 ); } - catch ( Throwable e ) + catch ( Exception e ) { e.printStackTrace(); + + System.exit( 1 ); + } + } + + public static void launch( RepositoryCleanerConfiguration config ) throws Exception + { + Embedder embedder = new Embedder(); + embedder.start( new ClassWorld() ); + + RepositoryCleaner cleaner = null; + try + { + cleaner = (RepositoryCleaner) embedder.lookup( RepositoryCleaner.ROLE ); + + cleaner.cleanRepository( config ); + } + finally + { + if ( cleaner != null ) + { + embedder.release( cleaner ); + } } } @@ -104,7 +113,6 @@ config.setMailErrorReport( Boolean.valueOf( props.getProperty( "errorReport.mailOnError", "false") ).booleanValue() ); config.setErrorReportFromAddress( props.getProperty( "errorReport.fromAddress" ) ); config.setErrorReportFromName( props.getProperty( "errorReport.fromName" ) ); - config.setErrorReportSmtpHost( props.getProperty( "errorReport.smtpHost", "localhost" ) ); config.setErrorReportSubject( props.getProperty( "errorReport.subject" ) ); config.setErrorReportToAddress( props.getProperty( "errorReport.toAddress" ) ); config.setErrorReportToName( props.getProperty( "errorReport.toName" ) ); 1.5 +2 -2 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java Index: ArtifactDigestVerifier.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ArtifactDigestVerifier.java 5 Apr 2005 02:47:43 -0000 1.4 +++ ArtifactDigestVerifier.java 19 Apr 2005 20:05:15 -0000 1.5 @@ -18,7 +18,7 @@ */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.report.FileReporter; import org.codehaus.plexus.util.FileUtils; import java.io.File; @@ -34,7 +34,7 @@ private ArtifactDigestor artifactDigestor; - public void verifyDigest( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly ) throws Exception + public void verifyDigest( Artifact artifact, File artifactTarget, FileReporter reporter, boolean reportOnly ) throws Exception { // create the digest source file from which to copy/verify. File digestSourceFile = new File( artifact.getFile() + ".md5" ); 1.1 maven-components/sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/TestSupport.java Index: TestSupport.java =================================================================== package org.apache.maven.tools.repoclean; import java.io.File; import java.net.URL; /* * 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. */ public final class TestSupport { private static final String REPO_MARKER = "repo-marker.txt"; private static final int MY_PACKAGE_TRIM = TestSupport.class.getPackage().getName().length() + 1; private TestSupport() { } public static String getMyRepositoryPath(Object testInstance) { Class testClass = testInstance.getClass(); String myRepo = testClass.getName().substring(MY_PACKAGE_TRIM); return getRepositoryPath(myRepo); } public static String getRepositoryPath( String relativePath ) { String base = relativePath.replace('.', '/'); if(!base.endsWith("/")) { base += "/"; } ClassLoader cloader = Thread.currentThread().getContextClassLoader(); URL repoMarkerResource = cloader.getResource(base + REPO_MARKER); File repoMarker = new File(repoMarkerResource.getPath()).getAbsoluteFile(); return repoMarker.getParentFile().getPath(); } } 1.1 maven-components/sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/report/DummyReporter.java Index: DummyReporter.java =================================================================== package org.apache.maven.tools.repoclean.report; /* * 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. */ public class DummyReporter implements Reporter { public void close() { } public boolean hasWarning() { return false; } public boolean hasError() { return false; } public void warn( String message ) throws ReportWriteException { log( "[WARNING]", message, null ); } public void error( String message, Throwable error ) throws ReportWriteException { log( "[ERROR]", message, error ); } public void error( String message ) throws ReportWriteException { log( "[ERROR]", message, null ); } private void log( String classifier, String message, Throwable error ) { System.out.println( classifier + " " + message ); if ( error != null ) { error.printStackTrace(); } } } 1.1 maven-components/sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4TranslatorTest.java Index: PomV3ToV4TranslatorTest.java =================================================================== package org.apache.maven.tools.repoclean.translate; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.tools.repoclean.report.DummyReporter; import org.apache.maven.tools.repoclean.report.Reporter; import org.codehaus.plexus.PlexusTestCase; /* * 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. */ public class PomV3ToV4TranslatorTest extends PlexusTestCase { public void testShouldConvertScopePropertyToDependencyScope() throws Exception { PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE ); Reporter reporter = new DummyReporter(); org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency(); v3Dep.setGroupId( "testGroup" ); v3Dep.setArtifactId( "testArtifact" ); v3Dep.setVersion( "1.0" ); v3Dep.addProperty( "scope", "test" ); org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model(); v3Model.addDependency( v3Dep ); Model result = translator.translate( v3Model, reporter ); assertEquals( "test", ( (Dependency) result.getDependencies().get( 0 ) ).getScope() ); } public void testShouldConvertDependencyWithTypePluginToBuildPluginEntry() throws Exception { PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE ); Reporter reporter = new DummyReporter(); org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency(); v3Dep.setGroupId( "testGroup" ); v3Dep.setArtifactId( "testArtifact" ); v3Dep.setVersion( "1.0" ); v3Dep.setType( "plugin" ); org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model(); v3Model.addDependency( v3Dep ); Model result = translator.translate( v3Model, reporter ); Build build = result.getBuild(); Plugin plugin = (Plugin) build.getPlugins().get( 0 ); assertEquals( "testGroup", plugin.getGroupId() ); assertEquals( "testArtifact", plugin.getArtifactId() ); assertEquals( "1.0", plugin.getVersion() ); } public void testShouldConvertDependencyWithTypePluginAndGroupMavenToBuildPluginEntryWithOAMPluginsGroup() throws Exception { PomV3ToV4Translator translator = (PomV3ToV4Translator) lookup( PomV3ToV4Translator.ROLE ); Reporter reporter = new DummyReporter(); org.apache.maven.model.v3_0_0.Dependency v3Dep = new org.apache.maven.model.v3_0_0.Dependency(); v3Dep.setGroupId( "maven" ); v3Dep.setArtifactId( "testArtifact" ); v3Dep.setVersion( "1.0" ); v3Dep.setType( "plugin" ); org.apache.maven.model.v3_0_0.Model v3Model = new org.apache.maven.model.v3_0_0.Model(); v3Model.addDependency( v3Dep ); Model result = translator.translate( v3Model, reporter ); Build build = result.getBuild(); Plugin plugin = (Plugin) build.getPlugins().get( 0 ); assertEquals( "org.apache.maven.plugins", plugin.getGroupId() ); assertEquals( "testArtifact", plugin.getArtifactId() ); assertEquals( "1.0", plugin.getVersion() ); } } 1.6 +143 -67 maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java Index: PomV3ToV4Translator.java =================================================================== RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PomV3ToV4Translator.java 5 Apr 2005 02:47:43 -0000 1.5 +++ PomV3ToV4Translator.java 19 Apr 2005 20:05:15 -0000 1.6 @@ -19,6 +19,7 @@ import org.apache.maven.model.Resource; import org.apache.maven.model.Scm; import org.apache.maven.model.Site; +import org.apache.maven.tools.repoclean.report.ReportWriteException; import org.apache.maven.tools.repoclean.report.Reporter; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; @@ -54,74 +55,88 @@ { public static final String ROLE = PomV3ToV4Translator.class.getName(); + + private transient List discoveredPlugins = new ArrayList(); public Model translate( org.apache.maven.model.v3_0_0.Model v3Model, Reporter reporter ) - throws Exception + throws ReportWriteException { - String groupId = v3Model.getGroupId(); - String artifactId = v3Model.getArtifactId(); - - String id = v3Model.getId(); - if ( StringUtils.isNotEmpty( id ) ) + try { - if ( StringUtils.isEmpty( groupId ) ) + String groupId = v3Model.getGroupId(); + String artifactId = v3Model.getArtifactId(); + + String id = v3Model.getId(); + if ( StringUtils.isNotEmpty( id ) ) { - groupId = id; + if ( StringUtils.isEmpty( groupId ) ) + { + groupId = id; + } + + if ( StringUtils.isEmpty( artifactId ) ) + { + artifactId = id; + } } - if ( StringUtils.isEmpty( artifactId ) ) + String version = v3Model.getCurrentVersion(); + if ( version == null ) { - artifactId = id; + version = v3Model.getVersion(); } - } - String version = v3Model.getCurrentVersion(); - if ( version == null ) - { - version = v3Model.getVersion(); - } + PomKey pomKey = new PomKey( groupId, artifactId, version ); - PomKey pomKey = new PomKey( groupId, artifactId, version ); + warnOfUnsupportedMainModelElements( v3Model, reporter ); - warnOfUnsupportedMainModelElements( v3Model, reporter ); + Model model = null; + try + { + model = new Model(); + model.setArtifactId( v3Model.getArtifactId() ); - Model model = null; - try - { - model = new Model(); - model.setArtifactId( v3Model.getArtifactId() ); - model.setBuild( translateBuild( v3Model.getBuild(), reporter ) ); - model.setCiManagement( translateCiManagementInfo( v3Model.getBuild() ) ); - model.setContributors( translateContributors( v3Model.getContributors() ) ); + // moved this above the translation of the build, to allow + // additional plugins to be defined in v3 poms via + // <dependency><type>plugin</type></dependency> + model.setDependencies( translateDependencies( v3Model.getDependencies() ) ); + + model.setBuild( translateBuild( v3Model.getBuild(), reporter ) ); + model.setCiManagement( translateCiManagementInfo( v3Model.getBuild() ) ); + model.setContributors( translateContributors( v3Model.getContributors() ) ); + + model.setDescription( v3Model.getDescription() ); + model.setDevelopers( translateDevelopers( v3Model.getDevelopers() ) ); - model.setDependencies( translateDependencies( v3Model.getDependencies() ) ); - model.setDescription( v3Model.getDescription() ); - model.setDevelopers( translateDevelopers( v3Model.getDevelopers() ) ); + model.setDistributionManagement( translateDistributionManagement( pomKey, v3Model ) ); - model.setDistributionManagement( translateDistributionManagement( pomKey, v3Model ) ); + model.setGroupId( v3Model.getGroupId() ); + model.setInceptionYear( v3Model.getInceptionYear() ); + model.setIssueManagement( translateIssueManagement( v3Model ) ); - model.setGroupId( v3Model.getGroupId() ); - model.setInceptionYear( v3Model.getInceptionYear() ); - model.setIssueManagement( translateIssueManagement( v3Model ) ); + model.setLicenses( translateLicenses( v3Model.getLicenses() ) ); + model.setMailingLists( translateMailingLists( v3Model.getMailingLists() ) ); + model.setModelVersion( "4.0.0" ); + model.setName( v3Model.getName() ); + model.setOrganization( translateOrganization( v3Model.getOrganization(), reporter ) ); + model.setPackaging( "jar" ); + model.setReports( translateReports( v3Model.getReports(), reporter ) ); + model.setScm( translateScm( v3Model ) ); + model.setUrl( v3Model.getUrl() ); - model.setLicenses( translateLicenses( v3Model.getLicenses() ) ); - model.setMailingLists( translateMailingLists( v3Model.getMailingLists() ) ); - model.setModelVersion( "4.0.0" ); - model.setName( v3Model.getName() ); - model.setOrganization( translateOrganization( v3Model.getOrganization(), reporter ) ); - model.setPackaging( "jar" ); - model.setReports( translateReports( v3Model.getReports(), reporter ) ); - model.setScm( translateScm( v3Model ) ); - model.setUrl( v3Model.getUrl() ); + model.setVersion( version ); + } + catch ( PomTranslationException e ) + { + reporter.error( "Invalid POM detected. Cannot translate.", e ); + } - model.setVersion( version ); + return model; } - catch ( PomTranslationException e ) + finally { - reporter.error( "Invalid POM detected. Cannot translate.", e ); + this.discoveredPlugins.clear(); } - - return model; } private CiManagement translateCiManagementInfo( org.apache.maven.model.v3_0_0.Build v3Build ) @@ -148,7 +163,7 @@ } private void warnOfUnsupportedMainModelElements( org.apache.maven.model.v3_0_0.Model v3Model, Reporter reporter ) - throws Exception + throws ReportWriteException { if ( StringUtils.isNotEmpty( v3Model.getExtend() ) ) { @@ -216,7 +231,7 @@ } private Reports translateReports( List v3Reports, Reporter reporter ) - throws Exception + throws ReportWriteException { Reports reports = null; if ( v3Reports != null && !v3Reports.isEmpty() ) @@ -280,7 +295,7 @@ private org.apache.maven.model.Organization translateOrganization( org.apache.maven.model.v3_0_0.Organization v3Organization, Reporter reporter ) - throws Exception + throws ReportWriteException { Organization organization = null; @@ -486,26 +501,72 @@ { org.apache.maven.model.v3_0_0.Dependency v3Dep = (org.apache.maven.model.v3_0_0.Dependency) it.next(); - Dependency dep = new Dependency(); - - String artifactId = v3Dep.getArtifactId(); - String groupId = v3Dep.getGroupId(); - - if(StringUtils.isNotEmpty(artifactId) && StringUtils.isNotEmpty(groupId)) + String type = v3Dep.getType(); + if( "plugin".equals( type ) ) { - dep.setGroupId(groupId); - dep.setArtifactId(artifactId); + String groupId = v3Dep.getGroupId(); + + if( "maven".equals( groupId ) ) + { + groupId = "org.apache.maven.plugins"; + } + + Plugin plugin = new Plugin(); + plugin.setGroupId( groupId ); + plugin.setArtifactId( v3Dep.getArtifactId() ); + plugin.setVersion( v3Dep.getVersion() ); + + Xpp3Dom config = new Xpp3Dom( "configuration" ); + + Properties props = v3Dep.getProperties(); + + if ( !props.isEmpty() ) + { + for ( Iterator propertyIterator = props.keySet().iterator(); it.hasNext(); ) + { + String key = (String) propertyIterator.next(); + String value = props.getProperty( key ); + + Xpp3Dom child = new Xpp3Dom( key ); + child.setValue( value ); + + config.addChild( child ); + } + } + + plugin.setConfiguration( config ); + + this.discoveredPlugins.add( plugin ); } else { - dep.setGroupId(v3Dep.getId()); - dep.setArtifactId(v3Dep.getId()); - } + Dependency dep = new Dependency(); + + String artifactId = v3Dep.getArtifactId(); + String groupId = v3Dep.getGroupId(); + + if(StringUtils.isNotEmpty(artifactId) && StringUtils.isNotEmpty(groupId)) + { + dep.setGroupId(groupId); + dep.setArtifactId(artifactId); + } + else + { + dep.setGroupId(v3Dep.getId()); + dep.setArtifactId(v3Dep.getId()); + } - dep.setVersion( v3Dep.getVersion() ); - dep.setType( v3Dep.getType() ); + dep.setVersion( v3Dep.getVersion() ); + dep.setType( v3Dep.getType() ); + + String scope = v3Dep.getProperty( "scope" ); + if( scope != null && scope.trim().length() > 0 ) + { + dep.setScope( scope ); + } - deps.add( dep ); + deps.add( dep ); + } } } @@ -539,7 +600,7 @@ } private Build translateBuild( org.apache.maven.model.v3_0_0.Build v3Build, Reporter reporter ) - throws Exception + throws ReportWriteException { Build build = null; if ( v3Build != null ) @@ -566,7 +627,7 @@ if ( notEmpty( testIncludes ) || notEmpty( testExcludes ) ) { Plugin plugin = new Plugin(); - plugin.setGroupId( "maven" ); + plugin.setGroupId( "org.apache.maven.plugins" ); plugin.setArtifactId( "surefire" ); plugin.setVersion( "1.0-SNAPSHOT" ); @@ -611,12 +672,27 @@ } } } + + if(!this.discoveredPlugins.isEmpty()) + { + if(build == null) + { + build = new Build(); + } + + for ( Iterator it = this.discoveredPlugins.iterator(); it.hasNext(); ) + { + Plugin plugin = (Plugin) it.next(); + + build.addPlugin( plugin ); + } + } return build; } private void warnOfUnsupportedBuildElements( org.apache.maven.model.v3_0_0.Build v3Build, Reporter reporter ) - throws Exception + throws ReportWriteException { if ( notEmpty( v3Build.getSourceModifications() ) ) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]