From 0db2b646d23049f80b0beb13c4c45740172fcab7 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 8 Jun 2005 20:19:41 +0000 Subject: [PATCH] JIRA issues fixed: MRM-1 MRM-7 MRM-3 MRM-5 o Pipelining all logging through a single Reporter now, to repository.report.txt o Disabled WARNING reports by default, add 'reportWarnings=true' to config file to enable them. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189629 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/tools/repoclean/Main.java | 8 +- .../tools/repoclean/RepositoryCleaner.java | 2 +- .../RepositoryCleanerConfiguration.java | 12 ++ .../artifact/metadata/ProjectMetadata.java | 10 +- .../discover/LegacyArtifactDiscoverer.java | 2 +- .../tools/repoclean/phase/RewritePhase.java | 183 ++++++++---------- .../tools/repoclean/report/FileReporter.java | 29 ++- .../repoclean/rewrite/V3PomRewriter.java | 20 +- 8 files changed, 129 insertions(+), 137 deletions(-) diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java index 65a221ed5e..4493a61a83 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java @@ -141,6 +141,7 @@ public class Main config.setReportsPath( props.getProperty( "reportsPath" ) ); config.setBlacklistedPatterns( props.getProperty( "blacklistedPatterns" ) ); config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue() ); + config.setReportWarningEnabled( Boolean.valueOf( props.getProperty( "reportWarnings", "false" ) ).booleanValue() ); config.setMailErrorReport( Boolean.valueOf( props.getProperty( "errorReport.mailOnError", "false" ) ) .booleanValue() ); @@ -150,7 +151,7 @@ public class Main config.setErrorReportToAddress( props.getProperty( "errorReport.toAddress" ) ); config.setErrorReportToName( props.getProperty( "errorReport.toName" ) ); config.setErrorReportLink( props.getProperty( "errorReport.link" ) ); - + return config; } @@ -176,14 +177,15 @@ public class Main + "errorReport.toName=Developers List\n" + "\n" + "# [DEFAULT VALUE: legacy]\n" + "#sourceRepositoryLayout=[legacy|default]\n\n" + "# [DEFAULT VALUE: v3]\n" + "# [DEFAULT VALUE: default]\n" + "#targetRepositoryLayout=[legacy|default]\n" - + "# [DEFAULT VALUE: localhost]\n" + "#errorReport.smtpHost=\n" + "\n" ); + + "# [DEFAULT VALUE: localhost]\n" + "#errorReport.smtpHost=\n" + + "# [DEFAULT VALUE: false]\n" + "#reportWarnings=[true|false]\n" + "\n" ); } private static void printUsage() { System.out.println( "Required input is missing.\n\n" + "Usage:\n" + "--------------------------------------------------\n\n" - + "repoclean -h|-template|\n" ); + + "repoclean [--force] -h|-template|\n" ); } } \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java index 622fdd57d8..2fa3dda833 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java @@ -79,7 +79,7 @@ public class RepositoryCleaner FileReporter repoReporter = null; try { - repoReporter = new FileReporter( reportsBase, "repository.report.txt" ); + repoReporter = new FileReporter( reportsBase, "repository.report.txt", configuration.isReportWarningEnabled() ); List artifacts; diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java index 8ec293a57c..872b339699 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java @@ -52,6 +52,8 @@ public class RepositoryCleanerConfiguration private boolean force; private String blacklistedPatterns; + + private boolean reportWarningEnabled = false; public void setSourceRepositoryPath( String sourceRepositoryPath ) { @@ -203,4 +205,14 @@ public class RepositoryCleanerConfiguration this.errorReportLink = errorReportLink; } + public boolean isReportWarningEnabled() + { + return reportWarningEnabled; + } + + public void setReportWarningEnabled( boolean reportWarningEnabled ) + { + this.reportWarningEnabled = reportWarningEnabled; + } + } \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java index 4db8b48084..b2653b7553 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java @@ -66,26 +66,26 @@ public class ProjectMetadata public boolean exists() { - return false; + return artifact.getFile() != null && artifact.getFile().exists(); } public String getGroupId() { - return null; + return artifact.getGroupId(); } public String getArtifactId() { - return null; + return artifact.getArtifactId(); } public String getVersion() { - return null; + return artifact.getVersion(); } public String getBaseVersion() { - return null; + return artifact.getBaseVersion(); } } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java index cd0eb83f82..73370e75a8 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java @@ -141,7 +141,7 @@ public class LegacyArtifactDiscoverer + "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" - + "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])"; + + "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "([AaBb][_.0-9]*)"; // let's discover the version, and whatever's leftover will be either // a classifier, or part of the artifactId, depending on position. diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java index f2bf38ba35..c97d83366b 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java @@ -10,7 +10,6 @@ import org.apache.maven.tools.repoclean.RepositoryCleanerConfiguration; import org.apache.maven.tools.repoclean.artifact.metadata.ProjectMetadata; import org.apache.maven.tools.repoclean.digest.DigestException; import org.apache.maven.tools.repoclean.digest.DigestVerifier; -import org.apache.maven.tools.repoclean.report.FileReporter; import org.apache.maven.tools.repoclean.report.ReportWriteException; import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter; @@ -37,6 +36,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; +import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; @@ -70,29 +70,46 @@ public class RewritePhase public List execute( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo, RepositoryCleanerConfiguration configuration, File reportsBase, Reporter repoReporter ) - throws Exception + throws ReportWriteException { Logger logger = getLogger(); List rewritten = new ArrayList(); - File sourceBase = new File( new URL( sourceRepo.getUrl() ).getPath() ); + File sourceBase = null; + try + { + sourceBase = new File( new URL( sourceRepo.getUrl() ).getPath() ); + } + catch ( MalformedURLException e ) + { + repoReporter.error( "Cannot construct source repository base File for: " + sourceRepo, e ); - File targetBase = new File( new URL( targetRepo.getUrl() ).getPath() ); + return null; + } + + File targetBase = null; + try + { + targetBase = new File( new URL( targetRepo.getUrl() ).getPath() ); + } + catch ( MalformedURLException e ) + { + repoReporter.error( "Cannot construct target repository base File for: " + targetRepo, e ); + + return null; + } for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); - + RewriteTransaction transaction = new RewriteTransaction( artifact ); String artifactReportPath = buildArtifactReportPath( artifact ); - FileReporter artifactReporter = null; try { - artifactReporter = new FileReporter( reportsBase, artifactReportPath ); - boolean errorOccurred = false; File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) ); @@ -110,37 +127,27 @@ public class RewritePhase { transaction.addFile( artifactTarget ); - try + if ( !configuration.reportOnly() ) { - if ( !configuration.reportOnly() ) + if ( logger.isDebugEnabled() ) { - if ( logger.isDebugEnabled() ) - { - logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" ); - logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" ); - } - - File targetParent = artifactTarget.getParentFile(); - if ( !targetParent.exists() ) - { - targetParent.mkdirs(); - } - - if ( logger.isDebugEnabled() ) - { - logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource - + "\' to \'" + artifactTarget + "\'." ); - } - - copyArtifact( artifact, artifactTarget, artifactReporter ); + logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" ); + logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" ); } - } - catch ( Exception e ) - { - repoReporter.error( "Error transferring artifact[" + artifact.getId() - + "] to the target repository.", e ); - throw e; + File targetParent = artifactTarget.getParentFile(); + if ( !targetParent.exists() ) + { + targetParent.mkdirs(); + } + + if ( logger.isDebugEnabled() ) + { + logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource + + "\' to \'" + artifactTarget + "\'." ); + } + + copyArtifact( artifact, artifactTarget, repoReporter ); } if ( logger.isDebugEnabled() ) @@ -149,46 +156,27 @@ public class RewritePhase + artifact.getGroupId() + "\'" ); } - try - { - digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, artifactReporter, - configuration.reportOnly() ); - } - catch ( Exception e ) - { - repoReporter.error( "Error verifying digest for artifact[" + artifact.getId() + "]", e ); - - throw e; - } - - try - { - rewriteMetadata( artifact, transaction, sourceBase, sourceRepo, targetBase, targetRepo, - artifactReporter, configuration.reportOnly() ); - } - catch ( Exception e ) - { - repoReporter.error( "Error rewriting POM for artifact[" + artifact.getId() - + "] into the target repository.\n Error message: " + e.getMessage() ); - - throw e; - } + digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, repoReporter, + configuration.reportOnly() ); + rewriteMetadata( artifact, transaction, sourceBase, sourceRepo, targetBase, targetRepo, + repoReporter, configuration.reportOnly() ); + rewritten.add( artifact ); } else if ( !targetMissingOrOlder ) { - artifactReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'" + repoReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'" + artifact.getId() + "\' in path: \'" + artifactSource + "\' with target path: " + artifactTarget + ")." ); } else { - artifactReporter.error( "Cannot find source file for artifact: \'" + artifact.getId() + repoReporter.error( "Cannot find source file for artifact: \'" + artifact.getId() + "\' under path: \'" + artifactSource + "\'" ); } - if ( artifactReporter.hasError() ) + if ( repoReporter.hasError() ) { repoReporter.warn( "Error(s) occurred while rewriting artifact: \'" + artifact.getId() + "\' or its POM." ); @@ -213,15 +201,8 @@ public class RewritePhase repoReporter.warn( "NOT Rolling back conversion for: " + artifact + "; we are in --force mode." ); } - artifactReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId() - + "\'. See report at: \'" + artifactReportPath + "\'.", e ); - } - finally - { - if ( artifactReporter != null ) - { - artifactReporter.close(); - } + repoReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId() + + "\'.", e ); } } @@ -290,47 +271,39 @@ public class RewritePhase transaction.addFile( bridgedTargetPom ); + File targetPomParent = targetPom.getParentFile(); + if ( !targetPomParent.exists() ) + { + targetPomParent.mkdirs(); + } + + FileWriter to = null; try { - File targetPomParent = targetPom.getParentFile(); - if ( !targetPomParent.exists() ) + StringReader from = null; + if ( pomContents != null ) { - targetPomParent.mkdirs(); + from = new StringReader( pomContents ); } - FileWriter to = null; - try - { - StringReader from = null; - if ( pomContents != null ) - { - from = new StringReader( pomContents ); - } - - to = new FileWriter( targetPom ); - - artifactPomRewriter.rewrite( artifact, from, to, artifactReporter, reportOnly ); - } - finally - { - IOUtil.close( to ); - } - - boolean wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter, - transaction, reportOnly ); - - digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly ); - - if ( wroteBridge ) - { - digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter, - reportOnly ); - } + to = new FileWriter( targetPom ); + artifactPomRewriter.rewrite( artifact, from, to, artifactReporter, reportOnly ); } - catch ( Exception e ) + finally { - throw e; + IOUtil.close( to ); + } + + boolean wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter, + transaction, reportOnly ); + + digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly ); + + if ( wroteBridge ) + { + digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter, + reportOnly ); } } finally @@ -421,7 +394,7 @@ public class RewritePhase + ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + version + ".report.txt"; } - private void copyArtifact( Artifact artifact, File artifactTarget, FileReporter reporter ) + private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter ) throws IOException { File artifactSource = artifact.getFile(); diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java index e632fe921a..701b825c37 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java @@ -50,8 +50,12 @@ public class FileReporter private Writer writer; - public FileReporter( File reportsBase, String reportPath ) + private final boolean warningsEnabled; + + public FileReporter( File reportsBase, String reportPath, boolean warningsEnabled ) { + this.warningsEnabled = warningsEnabled; + this.reportsFile = new File( reportsBase, reportPath ); File parentDir = reportsFile.getParentFile(); @@ -126,22 +130,37 @@ public class FileReporter public void warn( String message ) throws ReportWriteException { - hasWarning = true; - write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) ); + if( warningsEnabled ) + { + hasWarning = true; + String source = getSourceLine(); + write( new AppendingList( 3 ).append( WARN_LEVEL ).append( source ).append( message ) ); + } } public void error( String message, Throwable error ) throws ReportWriteException { hasError = true; - write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( message ).append( error ) ); + String source = getSourceLine(); + write( new AppendingList( 4 ).append( ERROR_LEVEL ).append( source ).append( message ).append( error ) ); } public void error( String message ) throws ReportWriteException { hasError = true; - write( new AppendingList( 2 ).append( ERROR_LEVEL ).append( message ) ); + String source = getSourceLine(); + write( new AppendingList( 3 ).append( ERROR_LEVEL ).append( source ).append( message ) ); + } + + private String getSourceLine() + { + NullPointerException npe = new NullPointerException(); + + StackTraceElement element = npe.getStackTrace()[2]; + + return " Reported from: (" + element.getClassName() + "." + element.getMethodName() + "(..):" + element.getLineNumber() + ")\n"; } private CharSequence format( List messageParts ) diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java index f6874bcafb..7283809e92 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java @@ -43,24 +43,10 @@ public class V3PomRewriter if( from != null ) { - org.apache.maven.model.v3_0_0.Model v3Model = null; - try - { - MavenXpp3Reader v3Reader = new MavenXpp3Reader(); + MavenXpp3Reader v3Reader = new MavenXpp3Reader(); - v3Model = v3Reader.read( from ); - } - catch ( Exception e ) - { - reporter.error( "Invalid v3 POM at: \'" + from + "\'. Cannot read.", e ); - - throw e; - } - - if ( v3Model != null ) - { - v4Model = translator.translate( v3Model, reporter ); - } + org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( from ); + v4Model = translator.translate( v3Model, reporter ); } else {