You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/06/08 22:19:43 UTC
svn commit: r189629 - in
/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean:
Main.java RepositoryCleaner.java RepositoryCleanerConfiguration.java
artifact/metadata/ProjectMetadata.java
discover/LegacyArtifactDiscoverer.java phase/RewritePhase.java
report/FileReporter.java rewrite/V3PomRewriter.java
Author: jdcasey
Date: Wed Jun 8 13:19:41 2005
New Revision: 189629
URL: http://svn.apache.org/viewcvs?rev=189629&view=rev
Log:
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.
Modified:
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java Wed Jun 8 13:19:41 2005
@@ -141,6 +141,7 @@
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 @@
config.setErrorReportToAddress( props.getProperty( "errorReport.toAddress" ) );
config.setErrorReportToName( props.getProperty( "errorReport.toName" ) );
config.setErrorReportLink( props.getProperty( "errorReport.link" ) );
-
+
return config;
}
@@ -176,14 +177,15 @@
+ "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=<hostname>\n" + "\n" );
+ + "# [DEFAULT VALUE: localhost]\n" + "#errorReport.smtpHost=<hostname>\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|<configuration-properties-file>\n" );
+ + "repoclean [--force] -h|-template|<configuration-properties-file>\n" );
}
}
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java Wed Jun 8 13:19:41 2005
@@ -79,7 +79,7 @@
FileReporter repoReporter = null;
try
{
- repoReporter = new FileReporter( reportsBase, "repository.report.txt" );
+ repoReporter = new FileReporter( reportsBase, "repository.report.txt", configuration.isReportWarningEnabled() );
List artifacts;
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java Wed Jun 8 13:19:41 2005
@@ -52,6 +52,8 @@
private boolean force;
private String blacklistedPatterns;
+
+ private boolean reportWarningEnabled = false;
public void setSourceRepositoryPath( String sourceRepositoryPath )
{
@@ -201,6 +203,16 @@
public void setErrorReportLink( String errorReportLink )
{
this.errorReportLink = errorReportLink;
+ }
+
+ public boolean isReportWarningEnabled()
+ {
+ return reportWarningEnabled;
+ }
+
+ public void setReportWarningEnabled( boolean reportWarningEnabled )
+ {
+ this.reportWarningEnabled = reportWarningEnabled;
}
}
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java Wed Jun 8 13:19:41 2005
@@ -66,26 +66,26 @@
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();
}
}
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java Wed Jun 8 13:19:41 2005
@@ -141,7 +141,7 @@
+ "([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.
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java Wed Jun 8 13:19:41 2005
@@ -10,7 +10,6 @@
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.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 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 @@
{
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 + "\'." );
- }
+ logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" );
+ logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
+ }
- copyArtifact( artifact, artifactTarget, artifactReporter );
+ File targetParent = artifactTarget.getParentFile();
+ if ( !targetParent.exists() )
+ {
+ targetParent.mkdirs();
+ }
+
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
+ + "\' to \'" + artifactTarget + "\'." );
}
- }
- catch ( Exception e )
- {
- repoReporter.error( "Error transferring artifact[" + artifact.getId()
- + "] to the target repository.", e );
- throw e;
+ copyArtifact( artifact, artifactTarget, repoReporter );
}
if ( logger.isDebugEnabled() )
@@ -149,46 +156,27 @@
+ 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 @@
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 @@
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 );
- }
+ to = new FileWriter( targetPom );
- boolean wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
- transaction, reportOnly );
+ artifactPomRewriter.rewrite( artifact, from, to, artifactReporter, reportOnly );
+ }
+ finally
+ {
+ IOUtil.close( to );
+ }
- digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
+ boolean wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
+ transaction, reportOnly );
- if ( wroteBridge )
- {
- digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
- reportOnly );
- }
+ digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
- }
- catch ( Exception e )
+ if ( wroteBridge )
{
- throw e;
+ digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
+ reportOnly );
}
}
finally
@@ -421,7 +394,7 @@
+ ( ( 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();
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/FileReporter.java Wed Jun 8 13:19:41 2005
@@ -50,8 +50,12 @@
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 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 )
Modified: maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java?rev=189629&r1=189628&r2=189629&view=diff
==============================================================================
--- maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java (original)
+++ maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java Wed Jun 8 13:19:41 2005
@@ -43,24 +43,10 @@
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
{
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org