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;
|
private PlexusContainer container;
|
||||||
|
|
||||||
public List execute( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo,
|
public List execute( List artifacts, ArtifactRepository sourceRepo, ArtifactRepository targetRepo,
|
||||||
RepositoryCleanerConfiguration configuration, File reportsBase, Reporter repoReporter )
|
RepositoryCleanerConfiguration configuration, File reportsBase, Reporter repoReporter )
|
||||||
throws ReportWriteException
|
throws ReportWriteException
|
||||||
{
|
{
|
||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
|
|
||||||
List rewritten = new ArrayList();
|
List rewritten = new ArrayList();
|
||||||
|
|
||||||
File sourceBase = null;
|
File sourceBase;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sourceBase = new File( new URL( sourceRepo.getUrl() ).getPath() );
|
sourceBase = new File( new URL( sourceRepo.getUrl() ).getPath() );
|
||||||
|
@ -88,7 +88,7 @@ public class RewritePhase
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
File targetBase = null;
|
File targetBase;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
targetBase = new File( new URL( targetRepo.getUrl() ).getPath() );
|
targetBase = new File( new URL( targetRepo.getUrl() ).getPath() );
|
||||||
|
@ -103,25 +103,21 @@ public class RewritePhase
|
||||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) it.next();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
RewriteTransaction transaction = new RewriteTransaction( artifact );
|
|
||||||
|
|
||||||
String artifactReportPath = buildArtifactReportPath( artifact );
|
RewriteTransaction transaction = new RewriteTransaction( artifact );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boolean errorOccurred = false;
|
|
||||||
|
|
||||||
File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
|
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 );
|
transaction.addFile( artifactTarget );
|
||||||
|
|
||||||
artifact.setFile( artifactSource );
|
artifact.setFile( artifactSource );
|
||||||
|
|
||||||
boolean targetMissingOrOlder = !artifactTarget.exists()
|
boolean targetMissingOrOlder = !artifactTarget.exists() ||
|
||||||
|| artifactTarget.lastModified() < artifactSource.lastModified();
|
artifactTarget.lastModified() < artifactSource.lastModified();
|
||||||
|
|
||||||
if ( artifactSource.exists() && ( configuration.force() || targetMissingOrOlder ) )
|
if ( artifactSource.exists() && ( configuration.force() || targetMissingOrOlder ) )
|
||||||
{
|
{
|
||||||
|
@ -143,17 +139,17 @@ public class RewritePhase
|
||||||
|
|
||||||
if ( logger.isDebugEnabled() )
|
if ( logger.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
|
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource +
|
||||||
+ "\' to \'" + artifactTarget + "\'." );
|
"\' to \'" + artifactTarget + "\'." );
|
||||||
}
|
}
|
||||||
|
|
||||||
copyArtifact( artifact, artifactTarget, repoReporter );
|
copyArtifact( artifact, artifactTarget );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( logger.isDebugEnabled() )
|
if ( logger.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
|
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'" +
|
||||||
+ artifact.getGroupId() + "\'" );
|
artifact.getGroupId() + "\'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, repoReporter,
|
digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, repoReporter,
|
||||||
|
@ -161,19 +157,19 @@ public class RewritePhase
|
||||||
|
|
||||||
rewriteMetadata( artifact, transaction, sourceBase, sourceRepo, targetBase, targetRepo,
|
rewriteMetadata( artifact, transaction, sourceBase, sourceRepo, targetBase, targetRepo,
|
||||||
repoReporter, configuration.reportOnly() );
|
repoReporter, configuration.reportOnly() );
|
||||||
|
|
||||||
rewritten.add( artifact );
|
rewritten.add( artifact );
|
||||||
}
|
}
|
||||||
else if ( !targetMissingOrOlder )
|
else if ( !targetMissingOrOlder )
|
||||||
{
|
{
|
||||||
repoReporter.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: "
|
artifact.getId() + "\' in path: \'" + artifactSource + "\' with target path: " +
|
||||||
+ artifactTarget + ")...SKIPPING" );
|
artifactTarget + ")...SKIPPING" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
repoReporter.warn( "Cannot find source file for artifact: \'" + artifact.getId()
|
repoReporter.warn( "Cannot find source file for artifact: \'" + artifact.getId() +
|
||||||
+ "\' under path: \'" + artifactSource + "\'...SKIPPING" );
|
"\' under path: \'" + artifactSource + "\'...SKIPPING" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
|
@ -187,7 +183,8 @@ public class RewritePhase
|
||||||
}
|
}
|
||||||
catch ( RollbackException re )
|
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
|
else
|
||||||
|
@ -195,20 +192,20 @@ public class RewritePhase
|
||||||
repoReporter.warn( "NOT Rolling back conversion for: " + artifact + "; we are in --force mode." );
|
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()
|
repoReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'.",
|
||||||
+ "\'.", e );
|
e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info( "Actual number of artifacts rewritten: " + rewritten.size() + " (" + ( rewritten.size() * 2 )
|
logger.info( "Actual number of artifacts rewritten: " + rewritten.size() + " (" + rewritten.size() * 2 +
|
||||||
+ " including POMs)." );
|
" including POMs)." );
|
||||||
|
|
||||||
return rewritten;
|
return rewritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewriteMetadata( Artifact artifact, RewriteTransaction transaction, File sourceBase,
|
private void rewriteMetadata( Artifact artifact, RewriteTransaction transaction, File sourceBase,
|
||||||
ArtifactRepository sourceRepo, File targetBase, ArtifactRepository targetRepo,
|
ArtifactRepository sourceRepo, File targetBase, ArtifactRepository targetRepo,
|
||||||
Reporter artifactReporter, boolean reportOnly )
|
Reporter artifactReporter, boolean reportOnly )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// SNAPSHOT metadata
|
// SNAPSHOT metadata
|
||||||
|
@ -217,8 +214,7 @@ public class RewritePhase
|
||||||
File snapshotSource = new File( sourceBase, sourceRepo.pathOfMetadata( snapshot ) );
|
File snapshotSource = new File( sourceBase, sourceRepo.pathOfMetadata( snapshot ) );
|
||||||
File snapshotTarget = new File( targetBase, targetRepo.pathOfMetadata( snapshot ) );
|
File snapshotTarget = new File( targetBase, targetRepo.pathOfMetadata( snapshot ) );
|
||||||
|
|
||||||
freshenSupplementalMetadata( snapshot, snapshotSource, snapshotTarget, transaction, artifactReporter,
|
freshenSupplementalMetadata( snapshotSource, snapshotTarget, transaction, artifactReporter, reportOnly );
|
||||||
reportOnly );
|
|
||||||
|
|
||||||
// RELEASE metadata
|
// RELEASE metadata
|
||||||
ArtifactMetadata release = new ReleaseArtifactMetadata( artifact );
|
ArtifactMetadata release = new ReleaseArtifactMetadata( artifact );
|
||||||
|
@ -226,7 +222,7 @@ public class RewritePhase
|
||||||
File releaseSource = new File( sourceBase, sourceRepo.pathOfMetadata( release ) );
|
File releaseSource = new File( sourceBase, sourceRepo.pathOfMetadata( release ) );
|
||||||
File releaseTarget = new File( targetBase, targetRepo.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.
|
// The rest is for POM metadata - translation and bridging of locations in the target repo may be required.
|
||||||
ArtifactMetadata pom = new ProjectMetadata( artifact );
|
ArtifactMetadata pom = new ProjectMetadata( artifact );
|
||||||
|
@ -246,10 +242,10 @@ public class RewritePhase
|
||||||
{
|
{
|
||||||
shouldRewritePom = false;
|
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.
|
// 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.
|
// let's leave the existing one alone.
|
||||||
|
@ -257,9 +253,9 @@ public class RewritePhase
|
||||||
}
|
}
|
||||||
|
|
||||||
File bridgedTargetPom = null;
|
File bridgedTargetPom = null;
|
||||||
|
|
||||||
boolean wroteBridge = false;
|
boolean wroteBridge = false;
|
||||||
|
|
||||||
if ( shouldRewritePom )
|
if ( shouldRewritePom )
|
||||||
{
|
{
|
||||||
ArtifactPomRewriter artifactPomRewriter = null;
|
ArtifactPomRewriter artifactPomRewriter = null;
|
||||||
|
@ -299,8 +295,8 @@ public class RewritePhase
|
||||||
IOUtil.close( to );
|
IOUtil.close( to );
|
||||||
}
|
}
|
||||||
|
|
||||||
wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
|
wroteBridge = bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter, transaction,
|
||||||
transaction, reportOnly );
|
reportOnly );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -316,19 +312,17 @@ public class RewritePhase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
|
digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
|
||||||
|
|
||||||
if ( wroteBridge )
|
if ( wroteBridge )
|
||||||
{
|
{
|
||||||
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
|
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter, reportOnly );
|
||||||
reportOnly );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void freshenSupplementalMetadata( ArtifactMetadata metadata, File source, File target,
|
private void freshenSupplementalMetadata( File source, File target, RewriteTransaction transaction,
|
||||||
RewriteTransaction transaction, Reporter artifactReporter,
|
Reporter artifactReporter, boolean reportOnly )
|
||||||
boolean reportOnly )
|
|
||||||
throws IOException, DigestException, ReportWriteException
|
throws IOException, DigestException, ReportWriteException
|
||||||
{
|
{
|
||||||
if ( source.exists() )
|
if ( source.exists() )
|
||||||
|
@ -386,19 +380,7 @@ public class RewritePhase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildArtifactReportPath( Artifact artifact )
|
private void copyArtifact( Artifact artifact, File artifactTarget )
|
||||||
{
|
|
||||||
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 )
|
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
File artifactSource = artifact.getFile();
|
File artifactSource = artifact.getFile();
|
||||||
|
@ -433,19 +415,19 @@ public class RewritePhase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean bridgePomLocations( ArtifactMetadata pom, File targetPom, File bridgedTargetPom, Reporter reporter,
|
private boolean bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter,
|
||||||
RewriteTransaction transaction, boolean reportOnly )
|
RewriteTransaction transaction, boolean reportOnly )
|
||||||
throws IOException, ReportWriteException, DigestException
|
throws IOException, ReportWriteException, DigestException
|
||||||
{
|
{
|
||||||
if ( targetPom.equals( bridgedTargetPom ) )
|
if ( targetPom.equals( bridgedTargetPom ) )
|
||||||
{
|
{
|
||||||
reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom
|
reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom +
|
||||||
+ "; legacy-compatible path is the same as the converted POM itself." );
|
"; legacy-compatible path is the same as the converted POM itself." );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
freshenSupplementalMetadata( pom, targetPom, bridgedTargetPom, transaction, reporter, reportOnly );
|
freshenSupplementalMetadata( targetPom, bridgedTargetPom, transaction, reporter, reportOnly );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,13 +279,11 @@ public class PomV3ToV4Translator
|
||||||
|
|
||||||
reportPlugin.setArtifactId( reportPluginName );
|
reportPlugin.setArtifactId( reportPluginName );
|
||||||
|
|
||||||
reportPlugin.setVersion( "1.0-SNAPSHOT" );
|
|
||||||
|
|
||||||
StringBuffer info = new StringBuffer();
|
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( "\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( "\n" )
|
||||||
.append( "These values were extracted using the v3 report naming convention, but may be wrong." );
|
.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 plugin = new Plugin();
|
||||||
plugin.setGroupId( "org.apache.maven.plugins" );
|
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||||
plugin.setArtifactId( "surefire" );
|
plugin.setArtifactId( "surefire" );
|
||||||
plugin.setVersion( "1.0-SNAPSHOT" );
|
|
||||||
|
|
||||||
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
Xpp3Dom config = new Xpp3Dom( "configuration" );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue