Clean-ups. Reporters only write on error/warn...since info no longer exists, and file opening is lazy now.

Also, cleaner now checks to make sure the target file is missing and/or out of date before processing the source file. This should allow us to avoid reprocessing the whole source repo every time.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163774 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-04-05 02:47:43 +00:00
parent a90fdae557
commit 26ec2d757b
7 changed files with 25 additions and 69 deletions

View File

@ -199,12 +199,14 @@ public class RepositoryCleaner
boolean errorOccurred = false;
File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
if(artifactSource.exists())
{
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
artifact.setFile( artifactSource );
artifact.setFile( artifactSource );
boolean targetMissingOrOlder = !artifactTarget.exists() || artifactTarget.lastModified() < artifactSource.lastModified();
if(artifactSource.exists() && targetMissingOrOlder)
{
try
{
@ -230,10 +232,6 @@ public class RepositoryCleaner
copyArtifact( artifact, artifactTarget, artifactReporter );
}
else
{
artifactReporter.info( "Skipping artifact copy (we're in report-only mode)." );
}
}
catch ( Exception e )
{
@ -339,7 +337,6 @@ public class RepositoryCleaner
File targetParent = artifactTarget.getParentFile();
if ( !targetParent.exists() )
{
reporter.info( "Creating directory \'" + targetParent + "\'." );
targetParent.mkdirs();
}

View File

@ -52,9 +52,6 @@ public class ArtifactDigestVerifier
if ( verified )
{
reporter.info( "Source digest file for artifact[" + artifact.getId()
+ "] is okay, so we'll just copy it." );
if ( !reportOnly )
{
try
@ -69,10 +66,6 @@ public class ArtifactDigestVerifier
throw e;
}
}
else
{
reporter.info( "Skipping transfer of valid MD5 digest file (we're in report-only mode)." );
}
}
else
{
@ -88,16 +81,10 @@ public class ArtifactDigestVerifier
// in the target repo.
if ( !verified )
{
reporter.info( "Creating .md5 for artifact[" + artifact.getId() + "] in target repository." );
if ( !reportOnly )
{
artifactDigestor.createArtifactDigest( artifactTarget, digestTargetFile, ArtifactDigestor.MD5 );
}
else
{
reporter.info( "Skipping creation of MD5 digest for artifact (we're in report-only mode)." );
}
}
}

View File

@ -74,7 +74,7 @@ public class LegacyArtifactDiscoverer
if ( numberOfTokens != 3 )
{
reporter.info( "Artifact path: \'" + path
reporter.warn( "Artifact path: \'" + path
+ "\' does not match naming convention. Cannot reliably extract artifact information from path." );
return null;

View File

@ -37,8 +37,6 @@ public class Reporter
private static final String WARN_LEVEL = "[WARNING] ";
private static final String INFO_LEVEL = "[INFO] ";
private static final String ERROR_LEVEL = "[ERROR] ";
private File reportsFile;
@ -50,9 +48,8 @@ public class Reporter
private boolean hasWarning = false;
private Writer writer;
public Reporter( File reportsBase, String reportPath )
throws IOException
{
this.reportsFile = new File( reportsBase, reportPath );
@ -68,8 +65,11 @@ public class Reporter
+ "\' refers to a file, not a directory.\n" + "Cannot write report file: \'"
+ reportsFile.getAbsolutePath() + "\'." );
}
open();
}
public File getReportFile()
{
return reportsFile;
}
private void open()
@ -88,8 +88,7 @@ public class Reporter
{
if ( writer == null )
{
throw new IOException( "BufferedWriter instance in reporter: \'" + this
+ "\' is null. Cannot write message." );
open();
}
if ( message instanceof List )
@ -123,12 +122,6 @@ public class Reporter
write( new AppendingList( 2 ).append( WARN_LEVEL ).append( message ) );
}
public void info( String message )
throws IOException
{
write( new AppendingList( 2 ).append( INFO_LEVEL ).append( message ) );
}
public void error( String message, Throwable error )
throws IOException
{

View File

@ -74,7 +74,7 @@ public class V3PomRewriter
}
else
{
reporter.info( "POM for artifact[" + artifact.getId()
reporter.warn( "POM for artifact[" + artifact.getId()
+ "] does not exist in source repository. We will create a skeletal one here." );
v4Model = new Model();
@ -104,10 +104,6 @@ public class V3PomRewriter
IOUtil.close( toWriter );
}
}
else
{
reporter.info( "Skipping model write to target repository (we're in report-only mode)." );
}
}
}
@ -116,31 +112,30 @@ public class V3PomRewriter
{
if ( StringUtils.isEmpty( model.getModelVersion() ) )
{
reporter.info( "Setting modelVersion on v4 model to \'4.0.0\'" );
model.setModelVersion( "4.0.0" );
}
if ( StringUtils.isEmpty( model.getGroupId() ) )
{
reporter.info( "Setting groupId on model using artifact information." );
reporter.warn( "Setting groupId on model using artifact information." );
model.setGroupId( artifact.getGroupId() );
}
if ( StringUtils.isEmpty( model.getArtifactId() ) )
{
reporter.info( "Setting artifactId on model using artifact information." );
reporter.warn( "Setting artifactId on model using artifact information." );
model.setArtifactId( artifact.getArtifactId() );
}
if ( StringUtils.isEmpty( model.getVersion() ) )
{
reporter.info( "Setting version on model using artifact information." );
reporter.warn( "Setting version on model using artifact information." );
model.setVersion( artifact.getVersion() );
}
if ( StringUtils.isEmpty( model.getPackaging() ) )
{
reporter.info( "Setting packaging on model using artifact type information." );
reporter.warn( "Setting packaging on model using artifact type information." );
model.setPackaging( artifact.getType() );
}
}

View File

@ -92,10 +92,6 @@ public class V4PomRewriter
IOUtil.close( toWriter );
}
}
else
{
reporter.info( "Skipping model write to target repository (we're in report-only mode)." );
}
}
}
@ -104,31 +100,30 @@ public class V4PomRewriter
{
if ( StringUtils.isEmpty( model.getModelVersion() ) )
{
reporter.info( "Setting modelVersion on v4 model to \'4.0.0\'" );
model.setModelVersion( "4.0.0" );
}
if ( StringUtils.isEmpty( model.getGroupId() ) )
{
reporter.info( "Setting groupId on model using artifact information." );
reporter.warn( "Setting groupId on model using artifact information." );
model.setGroupId( artifact.getGroupId() );
}
if ( StringUtils.isEmpty( model.getArtifactId() ) )
{
reporter.info( "Setting artifactId on model using artifact information." );
reporter.warn( "Setting artifactId on model using artifact information." );
model.setArtifactId( artifact.getArtifactId() );
}
if ( StringUtils.isEmpty( model.getVersion() ) )
{
reporter.info( "Setting version on model using artifact information." );
reporter.warn( "Setting version on model using artifact information." );
model.setVersion( artifact.getVersion() );
}
if ( StringUtils.isEmpty( model.getPackaging() ) )
{
reporter.info( "Setting packaging on model using artifact type information." );
reporter.warn( "Setting packaging on model using artifact type information." );
model.setPackaging( artifact.getType() );
}
}

View File

@ -83,15 +83,6 @@ public class PomV3ToV4Translator
PomKey pomKey = new PomKey( groupId, artifactId, version );
StringBuffer logHeader = new StringBuffer();
logHeader.append( "Translation of POM {" ).append( v3Model.getGroupId() ).append( ":" ).append(
v3Model.getArtifactId() ).append(
":" ).append(
version ).append(
"}" );
reporter.info( "[START] " + logHeader.toString() );
warnOfUnsupportedMainModelElements( v3Model, reporter );
Model model = null;
@ -124,8 +115,6 @@ public class PomV3ToV4Translator
model.setUrl( v3Model.getUrl() );
model.setVersion( version );
reporter.info( "[END] " + logHeader.toString() );
}
catch ( PomTranslationException e )
{
@ -273,7 +262,7 @@ public class PomV3ToV4Translator
"\n" ).append(
"These values were extracted using the v3 report naming convention, but may be wrong." );
reporter.info( info.toString() );
reporter.warn( info.toString() );
Goal reportGoal = new Goal();