mirror of https://github.com/apache/maven.git
added ability to mail out the repository-level report contents in the event an error occurs...also the ability to configure the email options using the config properties file.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163821 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
910c773fa5
commit
5653c7e402
|
@ -37,14 +37,16 @@ ret=$?; if [ $ret != 0 ]; then exit $ret; fi
|
|||
echo ""
|
||||
|
||||
cp -f target/repoclean-1.0-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/plexus/jars/plexus-utils-1.0-alpha-2-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/classworlds/jars/classworlds-1.1-alpha-1.jar $1/lib
|
||||
cp -f $2/org.apache.maven/jars/maven-artifact-2.0-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/org.apache.maven/jars/maven-model-2.0-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/maven/jars/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/maven/jars/wagon-file-1.0-alpha-2-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/maven/jars/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/plexus/plexus-container-default/1.0-alpha-2/plexus-container-default-1.0-alpha-2.jar $1/lib
|
||||
cp -f $2/plexus/plexus-utils/1.0-alpha-2/plexus-utils-1.0-alpha-2.jar $1/lib
|
||||
cp -f $2/plexus/plexus-mail-sender-api/1.0-alpha-1-SNAPSHOT/plexus-mail-sender-api-1.0-alpha-1-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/plexus/plexus-mail-sender-simple/1.0-alpha-1-SNAPSHOT/plexus-mail-sender-simple-1.0-alpha-1-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/classworlds/classworlds/1.1-alpha-1/classworlds-1.1-alpha-1.jar $1/lib
|
||||
cp -f $2/org/apache/maven/maven-artifact/2.0-SNAPSHOT/maven-artifact-2.0-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/org/apache/maven/maven-model/2.0-SNAPSHOT/maven-model-2.0-SNAPSHOT.jar $1/lib
|
||||
cp -f $2/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-2/wagon-provider-api-1.0-alpha-2.jar $1/lib
|
||||
cp -f $2/org/apache/maven/wagon/wagon-file/1.0-alpha-2/wagon-file-1.0-alpha-2.jar $1/lib
|
||||
cp -f $2/org/apache/maven/wagon/wagon-http-lightweight/1.0-alpha-2/wagon-http-lightweight-1.0-alpha-2.jar $1/lib
|
||||
|
||||
echo "Copying startup script, and changing its permissions to '+x'..."
|
||||
echo ""
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
CP=./lib/repoclean-1.0-SNAPSHOT.jar
|
||||
CP=$CP:./lib/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar
|
||||
CP=$CP:./lib/plexus-utils-1.0-alpha-2-SNAPSHOT.jar
|
||||
CP=$CP:./lib/plexus-container-default-1.0-alpha-2.jar
|
||||
CP=$CP:./lib/plexus-utils-1.0-alpha-2.jar
|
||||
CP=$CP:./lib/plexus-mail-sender-api-1.0-alpha-1-SNAPSHOT.jar
|
||||
CP=$CP:./lib/plexus-mail-sender-simple-1.0-alpha-1-SNAPSHOT.jar
|
||||
CP=$CP:./lib/classworlds-1.1-alpha-1.jar
|
||||
CP=$CP:./lib/maven-artifact-2.0-SNAPSHOT.jar
|
||||
CP=$CP:./lib/maven-model-2.0-SNAPSHOT.jar
|
||||
CP=$CP:./lib/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar
|
||||
CP=$CP:./lib/wagon-file-1.0-alpha-2-SNAPSHOT.jar
|
||||
CP=$CP:./lib/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar
|
||||
CP=$CP:./lib/wagon-provider-api-1.0-alpha-2.jar
|
||||
CP=$CP:./lib/wagon-file-1.0-alpha-2.jar
|
||||
CP=$CP:./lib/wagon-http-lightweight-1.0-alpha-2.jar
|
||||
|
||||
cygwin=false
|
||||
case "`uname`" in
|
||||
|
|
|
@ -101,6 +101,14 @@ public class Main
|
|||
config.setReportsPath( props.getProperty( "reportsPath" ) );
|
||||
config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue() );
|
||||
|
||||
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" ) );
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -108,26 +116,39 @@ public class Main
|
|||
{
|
||||
System.out.println( "repoclean: Repository Cleaner/Converter.\n\n"
|
||||
+ "Usage: repoclean -h|-template|<configuration-properties-file>\n\n"
|
||||
+ "Where the configuration properfies file can contain the following options:\n"
|
||||
+ "---------------------------------------------------------------------------\n"
|
||||
+ "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
|
||||
+ "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + "sourcePomType=[v3|v4] #[DEFAULT: v3]\n"
|
||||
+ "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
|
||||
+ "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n"
|
||||
+ "reportsPath=/path/to/reports/directory #[REQUIRED]\n" + "reportOnly=[true|false] #[REQUIRED]\n" + "\n" );
|
||||
+ " Use the '-template' option to see sample configuration file options.\n"
|
||||
+ "\n" );
|
||||
}
|
||||
|
||||
private static void printTemplate()
|
||||
{
|
||||
System.out.println( "# ---------------------------------------------------------------------------\n"
|
||||
+ "# repoclean: Repository Cleaner/Converter.\n" + "# This configuration auto-generated on: "
|
||||
+ new java.util.Date() + "\n"
|
||||
+ "# repoclean: Repository Cleaner/Converter.\n"
|
||||
+ "# This configuration auto-generated on: " + new java.util.Date() + "\n"
|
||||
+ "# ---------------------------------------------------------------------------\n\n"
|
||||
+ "# [REQUIRED OPTIONS]\n" + "sourceRepositoryPath=/path/to/repository/root\n"
|
||||
+ "targetRepositoryPath=/path/to/repository/root\n" + "reportsPath=/path/to/reports/directory\n"
|
||||
+ "reportOnly=[true|false]\n\n" + "# [DEFAULT VALUE: legacy]\n"
|
||||
+ "#sourceRepositoryLayout=[legacy|default]\n\n" + "# [DEFAULT VALUE: v3]\n" + "#sourcePomType=[v3|v4]\n\n"
|
||||
+ "# [DEFAULT VALUE: default]\n" + "#targetRepositoryLayout=[legacy|default]\n" + "\n" );
|
||||
+ "# [REQUIRED OPTIONS]\n"
|
||||
+ "sourceRepositoryPath=/path/to/repository/root\n"
|
||||
+ "targetRepositoryPath=/path/to/repository/root\n"
|
||||
+ "reportsPath=/path/to/reports/directory\n"
|
||||
+ "reportOnly=[true|false]\n"
|
||||
+ "\n"
|
||||
+ "errorReport.mailOnError=[true|false]\n"
|
||||
+ "errorReport.fromAddress=admin@somewhere.com\n"
|
||||
+ "errorReport.fromName=Admin\n"
|
||||
+ "errorReport.subject=[REPOCLEAN] Error!\n"
|
||||
+ "errorReport.toAddress=dev@somewhere.com\n"
|
||||
+ "errorReport.toName=Developers List\n"
|
||||
+ "\n"
|
||||
+ "# [DEFAULT VALUE: legacy]\n"
|
||||
+ "#sourceRepositoryLayout=[legacy|default]\n\n"
|
||||
+ "# [DEFAULT VALUE: v3]\n"
|
||||
+ "#sourcePomType=[v3|v4]\n\n"
|
||||
+ "# [DEFAULT VALUE: default]\n"
|
||||
+ "#targetRepositoryLayout=[legacy|default]\n"
|
||||
+ "# [DEFAULT VALUE: localhost]\n"
|
||||
+ "#errorReport.smtpHost=<hostname>\n"
|
||||
+ "\n" );
|
||||
}
|
||||
|
||||
private static void printUsage()
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RepositoryCleaner
|
|||
public static final String ROLE = RepositoryCleaner.class.getName();
|
||||
|
||||
private ArtifactDigestVerifier artifactDigestVerifier;
|
||||
|
||||
|
||||
private MailSender mailSender;
|
||||
|
||||
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
|
||||
|
@ -74,7 +74,7 @@ public class RepositoryCleaner
|
|||
File sourceRepositoryBase = normalizeSourceRepositoryBase( configuration.getSourceRepositoryPath() );
|
||||
|
||||
File targetRepositoryBase = normalizeTargetRepositoryBase( configuration.getTargetRepositoryPath() );
|
||||
|
||||
|
||||
boolean mailReport = false;
|
||||
|
||||
// do not proceed if we cannot produce reports, or if the repository is
|
||||
|
@ -93,14 +93,15 @@ public class RepositoryCleaner
|
|||
List artifacts = null;
|
||||
try
|
||||
{
|
||||
artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE,
|
||||
artifactDiscoverer = (ArtifactDiscoverer) container.lookup(
|
||||
ArtifactDiscoverer.ROLE,
|
||||
configuration.getSourceRepositoryLayout() );
|
||||
|
||||
if ( logger.isInfoEnabled() )
|
||||
{
|
||||
logger.info( "Discovering artifacts." );
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter );
|
||||
|
@ -143,7 +144,7 @@ public class RepositoryCleaner
|
|||
{
|
||||
logger.info( "Rewriting POMs and artifact files." );
|
||||
}
|
||||
|
||||
|
||||
rewriteArtifactsAndPoms( artifacts, sourceRepo, targetRepo, configuration, reportsBase,
|
||||
sourceRepositoryBase, targetRepositoryBase, repoReporter );
|
||||
}
|
||||
|
@ -170,59 +171,62 @@ public class RepositoryCleaner
|
|||
{
|
||||
logger.warn( "Warning encountered while rewriting one or more artifacts from source repository to target repository." );
|
||||
}
|
||||
|
||||
if(repoReporter.hasError())
|
||||
|
||||
if ( repoReporter.hasError() )
|
||||
{
|
||||
mailReport = true;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(repoReporter != null)
|
||||
if ( repoReporter != null )
|
||||
{
|
||||
repoReporter.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(mailReport)
|
||||
|
||||
if ( mailReport && configuration.mailErrorReport() )
|
||||
{
|
||||
String reportContents = readReportFile(repoReporter.getReportFile());
|
||||
|
||||
String reportContents = readReportFile( repoReporter.getReportFile() );
|
||||
|
||||
MailMessage message = new MailMessage();
|
||||
message.setContent(reportContents);
|
||||
message.setSubject("[REPOCLEAN] Error converting repository.");
|
||||
message.setFromName("Repoclean");
|
||||
message.setFromAddress("jdcasey@codehaus.org");
|
||||
message.setSendDate(new Date());
|
||||
message.addTo("Maven-2 Developers List", "m2-dev@maven.apache.org");
|
||||
|
||||
mailSender.send(message);
|
||||
message.setContent( reportContents );
|
||||
message.setSubject( configuration.getErrorReportSubject() );
|
||||
message.setFromName( configuration.getErrorReportFromName() );
|
||||
message.setFromAddress( configuration.getErrorReportFromAddress() );
|
||||
message.setSendDate( new Date() );
|
||||
message.addTo( configuration.getErrorReportToName(), configuration.getErrorReportToAddress() );
|
||||
|
||||
mailSender.setSmtpHost( configuration.getErrorReportSmtpHost() );
|
||||
|
||||
mailSender.send( message );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String readReportFile( File reportFile ) throws IOException
|
||||
private String readReportFile( File reportFile )
|
||||
throws IOException
|
||||
{
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader(reportFile);
|
||||
|
||||
reader = new FileReader( reportFile );
|
||||
|
||||
StringBuffer reportContent = new StringBuffer();
|
||||
char[] buffer = new char[512];
|
||||
int read = -1;
|
||||
|
||||
while((read = reader.read(buffer)) > -1)
|
||||
|
||||
while ( ( read = reader.read( buffer ) ) > -1 )
|
||||
{
|
||||
reportContent.append(buffer, 0, read);
|
||||
reportContent.append( buffer, 0, read );
|
||||
}
|
||||
|
||||
|
||||
return reportContent.toString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(reader);
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,13 +241,14 @@ public class RepositoryCleaner
|
|||
|
||||
try
|
||||
{
|
||||
logger.info("Rewriting " + artifacts.size() + " artifacts (Should be " + (artifacts.size() * 2) + " rewrites including POMs).");
|
||||
logger.info( "Rewriting " + artifacts.size() + " artifacts (Should be " + ( artifacts.size() * 2 )
|
||||
+ " rewrites including POMs)." );
|
||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
|
||||
String artifactReportPath = buildArtifactReportPath(artifact);
|
||||
|
||||
String artifactReportPath = buildArtifactReportPath( artifact );
|
||||
|
||||
Reporter artifactReporter = null;
|
||||
try
|
||||
{
|
||||
|
@ -255,17 +260,18 @@ public class RepositoryCleaner
|
|||
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
|
||||
|
||||
artifact.setFile( artifactSource );
|
||||
|
||||
boolean targetMissingOrOlder = !artifactTarget.exists() || artifactTarget.lastModified() < artifactSource.lastModified();
|
||||
|
||||
if(artifactSource.exists() && targetMissingOrOlder)
|
||||
|
||||
boolean targetMissingOrOlder = !artifactTarget.exists()
|
||||
|| artifactTarget.lastModified() < artifactSource.lastModified();
|
||||
|
||||
if ( artifactSource.exists() && targetMissingOrOlder )
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if ( !configuration.reportOnly() )
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" );
|
||||
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
|
||||
|
@ -299,8 +305,8 @@ public class RepositoryCleaner
|
|||
{
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
|
||||
+ artifact.getGroupId() + "\'" );
|
||||
logger.debug( "working on digest for artifact[" + artifact.getId()
|
||||
+ "] with groupId: \'" + artifact.getGroupId() + "\'" );
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -317,8 +323,9 @@ public class RepositoryCleaner
|
|||
if ( !errorOccurred )
|
||||
{
|
||||
ArtifactMetadata pom = new ProjectMetadata( artifact );
|
||||
|
||||
artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE,
|
||||
|
||||
artifactPomRewriter = (ArtifactPomRewriter) container.lookup(
|
||||
ArtifactPomRewriter.ROLE,
|
||||
configuration.getSourcePomVersion() );
|
||||
|
||||
File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) );
|
||||
|
@ -340,18 +347,20 @@ public class RepositoryCleaner
|
|||
}
|
||||
else
|
||||
{
|
||||
artifactReporter.error("Cannot find source file for artifact: \'" + artifact.getId() + "\' under path: \'" + artifactSource + "\'");
|
||||
artifactReporter.error( "Cannot find source file for artifact: \'" + artifact.getId()
|
||||
+ "\' under path: \'" + artifactSource + "\'" );
|
||||
}
|
||||
|
||||
|
||||
if ( artifactReporter.hasError() )
|
||||
{
|
||||
repoReporter.warn( "Error(s) occurred while rewriting artifact: \'" + artifact.getId()
|
||||
+ "\' or its POM." );
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
catch ( Exception e )
|
||||
{
|
||||
artifactReporter.error("Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'. See report at: \'" + artifactReportPath + "\'.", e);
|
||||
artifactReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId()
|
||||
+ "\'. See report at: \'" + artifactReportPath + "\'.", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -374,15 +383,16 @@ public class RepositoryCleaner
|
|||
private String buildArtifactReportPath( Artifact artifact )
|
||||
{
|
||||
String classifier = artifact.getClassifier();
|
||||
|
||||
return artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getType() + "/" + ((classifier != null)?(classifier + "-"):("")) + artifact.getVersion() + ".report.txt";
|
||||
|
||||
return artifact.getGroupId().replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getType()
|
||||
+ "/" + ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + artifact.getVersion() + ".report.txt";
|
||||
}
|
||||
|
||||
private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter )
|
||||
throws IOException
|
||||
{
|
||||
File artifactSource = artifact.getFile();
|
||||
|
||||
|
||||
InputStream inStream = null;
|
||||
OutputStream outStream = null;
|
||||
try
|
||||
|
|
|
@ -37,6 +37,20 @@ public class RepositoryCleanerConfiguration
|
|||
|
||||
private boolean reportOnly;
|
||||
|
||||
private String errorReportSubject;
|
||||
|
||||
private String errorReportFromName;
|
||||
|
||||
private String errorReportFromAddress;
|
||||
|
||||
private String errorReportToName;
|
||||
|
||||
private String errorReportToAddress;
|
||||
|
||||
private String errorReportSmtpHost;
|
||||
|
||||
private boolean mailErrorReport;
|
||||
|
||||
public void setSourceRepositoryPath( String sourceRepositoryPath )
|
||||
{
|
||||
this.sourceRepositoryPath = sourceRepositoryPath;
|
||||
|
@ -107,4 +121,73 @@ public class RepositoryCleanerConfiguration
|
|||
return reportOnly;
|
||||
}
|
||||
|
||||
public void setErrorReportSubject( String errorReportSubject )
|
||||
{
|
||||
this.errorReportSubject = errorReportSubject;
|
||||
}
|
||||
|
||||
public String getErrorReportSubject()
|
||||
{
|
||||
return errorReportSubject;
|
||||
}
|
||||
|
||||
public String getErrorReportFromAddress()
|
||||
{
|
||||
return errorReportFromAddress;
|
||||
}
|
||||
|
||||
public void setErrorReportFromAddress( String errorReportFromAddress )
|
||||
{
|
||||
this.errorReportFromAddress = errorReportFromAddress;
|
||||
}
|
||||
|
||||
public String getErrorReportFromName()
|
||||
{
|
||||
return errorReportFromName;
|
||||
}
|
||||
|
||||
public void setErrorReportFromName( String errorReportFromName )
|
||||
{
|
||||
this.errorReportFromName = errorReportFromName;
|
||||
}
|
||||
|
||||
public String getErrorReportSmtpHost()
|
||||
{
|
||||
return errorReportSmtpHost;
|
||||
}
|
||||
|
||||
public void setErrorReportSmtpHost( String errorReportSmtpHost )
|
||||
{
|
||||
this.errorReportSmtpHost = errorReportSmtpHost;
|
||||
}
|
||||
|
||||
public String getErrorReportToAddress()
|
||||
{
|
||||
return errorReportToAddress;
|
||||
}
|
||||
|
||||
public void setErrorReportToAddress( String errorReportToAddress )
|
||||
{
|
||||
this.errorReportToAddress = errorReportToAddress;
|
||||
}
|
||||
|
||||
public String getErrorReportToName()
|
||||
{
|
||||
return errorReportToName;
|
||||
}
|
||||
|
||||
public void setErrorReportToName( String errorReportToName )
|
||||
{
|
||||
this.errorReportToName = errorReportToName;
|
||||
}
|
||||
|
||||
public void setMailErrorReport( boolean mailErrorReport )
|
||||
{
|
||||
this.mailErrorReport = mailErrorReport;
|
||||
}
|
||||
|
||||
public boolean mailErrorReport()
|
||||
{
|
||||
return mailErrorReport;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue