mirror of https://github.com/apache/maven.git
some minor cleanups
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@226729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b147d6329b
commit
34e0267062
|
@ -69,14 +69,14 @@ public class RewritePhase
|
|||
private PlexusContainer container;
|
||||
|
||||
public List execute( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo,
|
||||
RepositoryCleanerConfiguration configuration, File reportsBase, Reporter repoReporter )
|
||||
RepositoryCleanerConfiguration configuration, File reportsBase, Reporter repoReporter )
|
||||
throws ReportWriteException
|
||||
{
|
||||
Logger logger = getLogger();
|
||||
|
||||
List rewritten = new ArrayList();
|
||||
|
||||
File sourceBase = null;
|
||||
File sourceBase;
|
||||
try
|
||||
{
|
||||
sourceBase = new File( new URL( sourceRepo.getUrl() ).getPath() );
|
||||
|
@ -88,7 +88,7 @@ public class RewritePhase
|
|||
return null;
|
||||
}
|
||||
|
||||
File targetBase = null;
|
||||
File targetBase;
|
||||
try
|
||||
{
|
||||
targetBase = new File( new URL( targetRepo.getUrl() ).getPath() );
|
||||
|
@ -106,22 +106,18 @@ public class RewritePhase
|
|||
|
||||
RewriteTransaction transaction = new RewriteTransaction( artifact );
|
||||
|
||||
String artifactReportPath = buildArtifactReportPath( artifact );
|
||||
|
||||
try
|
||||
{
|
||||
boolean errorOccurred = false;
|
||||
|
||||
File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
|
||||
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ).replace( '+',
|
||||
'-' ) );
|
||||
File artifactTarget = new File( targetRepo.getBasedir(),
|
||||
targetRepo.pathOf( artifact ).replace( '+', '-' ) );
|
||||
|
||||
transaction.addFile( artifactTarget );
|
||||
|
||||
artifact.setFile( artifactSource );
|
||||
|
||||
boolean targetMissingOrOlder = !artifactTarget.exists()
|
||||
|| artifactTarget.lastModified() < artifactSource.lastModified();
|
||||
boolean targetMissingOrOlder = !artifactTarget.exists() ||
|
||||
artifactTarget.lastModified() < artifactSource.lastModified();
|
||||
|
||||
if ( artifactSource.exists() && ( configuration.force() || targetMissingOrOlder ) )
|
||||
{
|
||||
|
@ -143,17 +139,17 @@ public class RewritePhase
|
|||
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
|
||||
+ "\' to \'" + artifactTarget + "\'." );
|
||||
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource +
|
||||
"\' to \'" + artifactTarget + "\'." );
|
||||
}
|
||||
|
||||
copyArtifact( artifact, artifactTarget, repoReporter );
|
||||
copyArtifact( artifact, artifactTarget );
|
||||
}
|
||||
|
||||
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() + "\'" );
|
||||
}
|
||||
|
||||
digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, repoReporter,
|
||||
|
@ -166,14 +162,14 @@ public class RewritePhase
|
|||
}
|
||||
else if ( !targetMissingOrOlder )
|
||||
{
|
||||
repoReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'"
|
||||
+ artifact.getId() + "\' in path: \'" + artifactSource + "\' with target path: "
|
||||
+ artifactTarget + ")...SKIPPING" );
|
||||
repoReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'" +
|
||||
artifact.getId() + "\' in path: \'" + artifactSource + "\' with target path: " +
|
||||
artifactTarget + ")...SKIPPING" );
|
||||
}
|
||||
else
|
||||
{
|
||||
repoReporter.warn( "Cannot find source file for artifact: \'" + artifact.getId()
|
||||
+ "\' under path: \'" + artifactSource + "\'...SKIPPING" );
|
||||
repoReporter.warn( "Cannot find source file for artifact: \'" + artifact.getId() +
|
||||
"\' under path: \'" + artifactSource + "\'...SKIPPING" );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
|
@ -187,7 +183,8 @@ public class RewritePhase
|
|||
}
|
||||
catch ( RollbackException re )
|
||||
{
|
||||
repoReporter.error( "Error rolling back conversion transaction (artifact: " + artifact.getId() + ").", re );
|
||||
repoReporter.error(
|
||||
"Error rolling back conversion transaction (artifact: " + artifact.getId() + ").", re );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -195,20 +192,20 @@ public class RewritePhase
|
|||
repoReporter.warn( "NOT Rolling back conversion for: " + artifact + "; we are in --force mode." );
|
||||
}
|
||||
|
||||
repoReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId()
|
||||
+ "\'.", e );
|
||||
repoReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'.",
|
||||
e );
|
||||
}
|
||||
}
|
||||
|
||||
logger.info( "Actual number of artifacts rewritten: " + rewritten.size() + " (" + ( rewritten.size() * 2 )
|
||||
+ " including POMs)." );
|
||||
logger.info( "Actual number of artifacts rewritten: " + rewritten.size() + " (" + rewritten.size() * 2 +
|
||||
" including POMs)." );
|
||||
|
||||
return rewritten;
|
||||
}
|
||||
|
||||
private void rewriteMetadata( Artifact artifact, RewriteTransaction transaction, File sourceBase,
|
||||
ArtifactRepository sourceRepo, File targetBase, ArtifactRepository targetRepo,
|
||||
Reporter artifactReporter, boolean reportOnly )
|
||||
ArtifactRepository sourceRepo, File targetBase, ArtifactRepository targetRepo,
|
||||
Reporter artifactReporter, boolean reportOnly )
|
||||
throws Exception
|
||||
{
|
||||
// SNAPSHOT metadata
|
||||
|
@ -217,8 +214,7 @@ public class RewritePhase
|
|||
File snapshotSource = new File( sourceBase, sourceRepo.pathOfMetadata( snapshot ) );
|
||||
File snapshotTarget = new File( targetBase, targetRepo.pathOfMetadata( snapshot ) );
|
||||
|
||||
freshenSupplementalMetadata( snapshot, snapshotSource, snapshotTarget, transaction, artifactReporter,
|
||||
reportOnly );
|
||||
freshenSupplementalMetadata( snapshotSource, snapshotTarget, transaction, artifactReporter, reportOnly );
|
||||
|
||||
// RELEASE metadata
|
||||
ArtifactMetadata release = new ReleaseArtifactMetadata( artifact );
|
||||
|
@ -226,7 +222,7 @@ public class RewritePhase
|
|||
File releaseSource = new File( sourceBase, sourceRepo.pathOfMetadata( release ) );
|
||||
File releaseTarget = new File( targetBase, targetRepo.pathOfMetadata( release ) );
|
||||
|
||||
freshenSupplementalMetadata( release, releaseSource, releaseTarget, transaction, artifactReporter, reportOnly );
|
||||
freshenSupplementalMetadata( releaseSource, releaseTarget, transaction, artifactReporter, reportOnly );
|
||||
|
||||
// The rest is for POM metadata - translation and bridging of locations in the target repo may be required.
|
||||
ArtifactMetadata pom = new ProjectMetadata( artifact );
|
||||
|
@ -246,10 +242,10 @@ public class RewritePhase
|
|||
{
|
||||
shouldRewritePom = false;
|
||||
|
||||
freshenSupplementalMetadata( pom, sourcePom, targetPom, transaction, artifactReporter, reportOnly );
|
||||
freshenSupplementalMetadata( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
|
||||
}
|
||||
}
|
||||
else if( targetPom.exists() )
|
||||
else if ( targetPom.exists() )
|
||||
{
|
||||
// we have a target pom for this artifact already, and we'll only be making up a new pom.
|
||||
// let's leave the existing one alone.
|
||||
|
@ -299,8 +295,8 @@ public class RewritePhase
|
|||
IOUtil.close( to );
|
||||
}
|
||||
|
||||
wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
|
||||
transaction, reportOnly );
|
||||
wroteBridge = bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter, transaction,
|
||||
reportOnly );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -321,14 +317,12 @@ public class RewritePhase
|
|||
|
||||
if ( wroteBridge )
|
||||
{
|
||||
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
|
||||
reportOnly );
|
||||
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter, reportOnly );
|
||||
}
|
||||
}
|
||||
|
||||
private void freshenSupplementalMetadata( ArtifactMetadata metadata, File source, File target,
|
||||
RewriteTransaction transaction, Reporter artifactReporter,
|
||||
boolean reportOnly )
|
||||
private void freshenSupplementalMetadata( File source, File target, RewriteTransaction transaction,
|
||||
Reporter artifactReporter, boolean reportOnly )
|
||||
throws IOException, DigestException, ReportWriteException
|
||||
{
|
||||
if ( source.exists() )
|
||||
|
@ -386,19 +380,7 @@ public class RewritePhase
|
|||
}
|
||||
}
|
||||
|
||||
private String buildArtifactReportPath( Artifact artifact )
|
||||
{
|
||||
String classifier = artifact.getClassifier();
|
||||
String groupId = artifact.getGroupId().replace( '.', '/' );
|
||||
String artifactId = artifact.getArtifactId();
|
||||
String type = artifact.getType();
|
||||
String version = artifact.getVersion();
|
||||
|
||||
return groupId + "/" + artifactId + "/" + type + "/"
|
||||
+ ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + version + ".report.txt";
|
||||
}
|
||||
|
||||
private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter )
|
||||
private void copyArtifact( Artifact artifact, File artifactTarget )
|
||||
throws IOException
|
||||
{
|
||||
File artifactSource = artifact.getFile();
|
||||
|
@ -433,19 +415,19 @@ public class RewritePhase
|
|||
}
|
||||
}
|
||||
|
||||
private boolean bridgePomLocations( ArtifactMetadata pom, File targetPom, File bridgedTargetPom, Reporter reporter,
|
||||
RewriteTransaction transaction, boolean reportOnly )
|
||||
private boolean bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter,
|
||||
RewriteTransaction transaction, boolean reportOnly )
|
||||
throws IOException, ReportWriteException, DigestException
|
||||
{
|
||||
if ( targetPom.equals( bridgedTargetPom ) )
|
||||
{
|
||||
reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom
|
||||
+ "; legacy-compatible path is the same as the converted POM itself." );
|
||||
reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom +
|
||||
"; legacy-compatible path is the same as the converted POM itself." );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
freshenSupplementalMetadata( pom, targetPom, bridgedTargetPom, transaction, reporter, reportOnly );
|
||||
freshenSupplementalMetadata( targetPom, bridgedTargetPom, transaction, reporter, reportOnly );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -279,13 +279,11 @@ public class PomV3ToV4Translator
|
|||
|
||||
reportPlugin.setArtifactId( reportPluginName );
|
||||
|
||||
reportPlugin.setVersion( "1.0-SNAPSHOT" );
|
||||
|
||||
StringBuffer info = new StringBuffer();
|
||||
|
||||
info.append( "Using some contrived information for report: \'" ).append( reportName ).append( "\'.\n" )
|
||||
info.append( "Using some derived information for report: \'" ).append( reportName ).append( "\'.\n" )
|
||||
.append( "\to groupId: \'maven\'\n" ).append( "\to artifactId: \'" ).append( reportPluginName )
|
||||
.append( "\'\n" ).append( "\to version: \'1.0-SNAPSHOT\'\n" ).append( "\to goal: \'report\'\n" )
|
||||
.append( "\'\n" ).append( "\to goal: \'report\'\n" )
|
||||
.append( "\n" )
|
||||
.append( "These values were extracted using the v3 report naming convention, but may be wrong." );
|
||||
|
||||
|
@ -655,7 +653,6 @@ public class PomV3ToV4Translator
|
|||
Plugin plugin = new Plugin();
|
||||
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||
plugin.setArtifactId( "surefire" );
|
||||
plugin.setVersion( "1.0-SNAPSHOT" );
|
||||
|
||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||
|
||||
|
|
Loading…
Reference in New Issue