mirror of https://github.com/apache/maven.git
add metadata for new artifact
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
386cc730ed
commit
52d376bf7f
|
@ -73,8 +73,7 @@ public class RepositoryCleaner
|
|||
|
||||
File targetRepositoryBase = normalizeTargetRepositoryBase( configuration.getTargetRepositoryPath() );
|
||||
|
||||
// do not proceed if we cannot produce reports, or if the repository is
|
||||
// invalid.
|
||||
// do not proceed if we cannot produce reports, or if the repository is invalid.
|
||||
if ( reportsBase != null && sourceRepositoryBase != null && targetRepositoryBase != null )
|
||||
{
|
||||
Logger logger = getLogger();
|
||||
|
@ -96,15 +95,13 @@ public class RepositoryCleaner
|
|||
try
|
||||
{
|
||||
sourceLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
|
||||
configuration
|
||||
.getSourceRepositoryLayout() );
|
||||
configuration.getSourceRepositoryLayout() );
|
||||
|
||||
ArtifactRepository sourceRepo = new DefaultArtifactRepository( "source", "file://" +
|
||||
sourceRepositoryBase.getAbsolutePath(), sourceLayout );
|
||||
|
||||
targetLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
|
||||
configuration
|
||||
.getTargetRepositoryLayout() );
|
||||
configuration.getTargetRepositoryLayout() );
|
||||
|
||||
ArtifactRepository targetRepo = new DefaultArtifactRepository( "target", "file://" +
|
||||
targetRepositoryBase.getAbsolutePath(), targetLayout );
|
||||
|
@ -114,8 +111,6 @@ public class RepositoryCleaner
|
|||
logger.debug( "Rewriting POMs and artifact files." );
|
||||
}
|
||||
|
||||
// List originalArtifacts = new ArrayList( artifacts );
|
||||
|
||||
List rewritten = rewritePhase.execute( artifacts, sourceRepo, targetRepo, configuration,
|
||||
reportsBase, repoReporter );
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.security.NoSuchAlgorithmException;
|
|||
*/
|
||||
public class Digestor
|
||||
{
|
||||
|
||||
public static final String ROLE = Digestor.class.getName();
|
||||
|
||||
public static final String MD5 = "MD5";
|
||||
|
@ -60,6 +59,25 @@ public class Digestor
|
|||
}
|
||||
}
|
||||
|
||||
public File getDigestFile( File artifactFile, String algorithm )
|
||||
throws NoSuchAlgorithmException
|
||||
{
|
||||
String extension;
|
||||
if ( SHA.equals( algorithm ) )
|
||||
{
|
||||
extension = "sha1";
|
||||
}
|
||||
else if ( MD5.equals( algorithm ) )
|
||||
{
|
||||
extension = "md5";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NoSuchAlgorithmException( "Unknown algorithm " + algorithm );
|
||||
}
|
||||
return new File( artifactFile.getParentFile(), artifactFile.getName() + "." + extension );
|
||||
}
|
||||
|
||||
public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm )
|
||||
throws DigestException
|
||||
{
|
||||
|
|
|
@ -22,13 +22,16 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
|
||||
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
|
||||
import org.apache.maven.tools.repoclean.RepositoryCleanerConfiguration;
|
||||
import org.apache.maven.tools.repoclean.digest.DigestException;
|
||||
import org.apache.maven.tools.repoclean.digest.DigestVerifier;
|
||||
import org.apache.maven.tools.repoclean.digest.Digestor;
|
||||
import org.apache.maven.tools.repoclean.report.ReportWriteException;
|
||||
import org.apache.maven.tools.repoclean.report.Reporter;
|
||||
import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter;
|
||||
|
@ -60,6 +63,7 @@ import java.io.StringReader;
|
|||
import java.io.Writer;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -70,6 +74,8 @@ public class RewritePhase
|
|||
{
|
||||
private DigestVerifier digestVerifier;
|
||||
|
||||
private Digestor artifactDigestor;
|
||||
|
||||
private ArtifactRepositoryLayout bridgingLayout;
|
||||
|
||||
private PlexusContainer container;
|
||||
|
@ -219,14 +225,43 @@ public class RewritePhase
|
|||
File metadataSource = new File( sourceBase, sourceRepo.pathOfRemoteRepositoryMetadata( metadata ) );
|
||||
File metadataTarget = new File( targetBase, targetRepo.pathOfRemoteRepositoryMetadata( metadata ) );
|
||||
|
||||
mergeMetadata( metadataSource, metadataTarget, transaction, artifactReporter, reportOnly );
|
||||
Metadata sourceMetadata = readMetadata( metadataSource, artifact );
|
||||
if ( sourceMetadata.getVersioning() == null )
|
||||
{
|
||||
sourceMetadata.setVersioning( new Versioning() );
|
||||
}
|
||||
if ( !sourceMetadata.getVersioning().getVersions().contains( artifact.getBaseVersion() ) )
|
||||
{
|
||||
sourceMetadata.getVersioning().addVersion( artifact.getBaseVersion() );
|
||||
}
|
||||
mergeMetadata( sourceMetadata, metadataTarget, reportOnly );
|
||||
|
||||
metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
|
||||
metadataSource = new File( sourceBase, sourceRepo.pathOfRemoteRepositoryMetadata( metadata ) );
|
||||
metadataTarget = new File( targetBase, targetRepo.pathOfRemoteRepositoryMetadata( metadata ) );
|
||||
|
||||
mergeMetadata( metadataSource, metadataTarget, transaction, artifactReporter, reportOnly );
|
||||
sourceMetadata = readMetadata( metadataSource, artifact );
|
||||
if ( artifact.isSnapshot() )
|
||||
{
|
||||
if ( sourceMetadata.getVersioning() == null )
|
||||
{
|
||||
sourceMetadata.setVersioning( new Versioning() );
|
||||
}
|
||||
if ( sourceMetadata.getVersioning().getSnapshot() == null )
|
||||
{
|
||||
sourceMetadata.getVersioning().setSnapshot( new Snapshot() );
|
||||
}
|
||||
|
||||
int i = artifact.getVersion().indexOf( '-' );
|
||||
if ( i >= 0 )
|
||||
{
|
||||
Snapshot snapshot = sourceMetadata.getVersioning().getSnapshot();
|
||||
snapshot.setTimestamp( artifact.getVersion().substring( 0, i ) );
|
||||
snapshot.setBuildNumber( Integer.valueOf( artifact.getVersion().substring( i + 1 ) ).intValue() );
|
||||
}
|
||||
}
|
||||
mergeMetadata( sourceMetadata, metadataTarget, reportOnly );
|
||||
|
||||
// The rest is for POM metadata - translation and bridging of locations in the target repo may be required.
|
||||
ArtifactMetadata pom = new ProjectArtifactMetadata( artifact, null );
|
||||
|
@ -326,76 +361,92 @@ public class RewritePhase
|
|||
}
|
||||
}
|
||||
|
||||
private void mergeMetadata( File source, File target, RewriteTransaction transaction, Reporter artifactReporter,
|
||||
boolean reportOnly )
|
||||
throws IOException, DigestException, ReportWriteException, XmlPullParserException
|
||||
private void mergeMetadata( Metadata sourceMetadata, File target, boolean reportOnly )
|
||||
throws IOException, DigestException, XmlPullParserException, NoSuchAlgorithmException
|
||||
{
|
||||
if ( source.exists() )
|
||||
if ( target.exists() )
|
||||
{
|
||||
if ( !target.exists() )
|
||||
{
|
||||
copyMetadata( source, target, transaction, artifactReporter, reportOnly );
|
||||
}
|
||||
else
|
||||
Metadata targetMetadata = null;
|
||||
|
||||
Reader reader = null;
|
||||
|
||||
try
|
||||
{
|
||||
reader = new FileReader( target );
|
||||
|
||||
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
|
||||
|
||||
Metadata sourceMetadata = null;
|
||||
targetMetadata = mappingReader.read( reader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
|
||||
Reader reader = null;
|
||||
boolean changed = targetMetadata.merge( sourceMetadata );
|
||||
|
||||
if ( changed )
|
||||
{
|
||||
Writer writer = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( source );
|
||||
target.getParentFile().mkdirs();
|
||||
writer = new FileWriter( target );
|
||||
|
||||
sourceMetadata = mappingReader.read( reader );
|
||||
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
|
||||
|
||||
mappingWriter.write( writer, targetMetadata );
|
||||
|
||||
if ( !reportOnly )
|
||||
{
|
||||
File digestFile = artifactDigestor.getDigestFile( target, Digestor.MD5 );
|
||||
artifactDigestor.createArtifactDigest( target, digestFile, Digestor.MD5 );
|
||||
digestFile = artifactDigestor.getDigestFile( target, Digestor.SHA );
|
||||
artifactDigestor.createArtifactDigest( target, digestFile, Digestor.SHA );
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
reader = null;
|
||||
IOUtil.close( writer );
|
||||
}
|
||||
|
||||
Metadata targetMetadata = null;
|
||||
|
||||
try
|
||||
{
|
||||
reader = new FileReader( target );
|
||||
|
||||
targetMetadata = mappingReader.read( reader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
changed |= targetMetadata.merge( sourceMetadata );
|
||||
|
||||
if ( changed )
|
||||
{
|
||||
Writer writer = null;
|
||||
try
|
||||
{
|
||||
target.getParentFile().mkdirs();
|
||||
writer = new FileWriter( target );
|
||||
|
||||
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
|
||||
|
||||
mappingWriter.write( writer, targetMetadata );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( writer );
|
||||
}
|
||||
}
|
||||
|
||||
digestVerifier.verifyDigest( source, target, transaction, artifactReporter, reportOnly );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Metadata readMetadata( File source, Artifact artifact )
|
||||
throws IOException, XmlPullParserException
|
||||
{
|
||||
Metadata sourceMetadata = null;
|
||||
|
||||
if ( source.exists() )
|
||||
{
|
||||
Reader reader = null;
|
||||
|
||||
try
|
||||
{
|
||||
reader = new FileReader( source );
|
||||
|
||||
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
|
||||
|
||||
sourceMetadata = mappingReader.read( reader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
if ( sourceMetadata == null )
|
||||
{
|
||||
sourceMetadata = new Metadata();
|
||||
|
||||
sourceMetadata.setGroupId( artifact.getGroupId() );
|
||||
sourceMetadata.setArtifactId( artifact.getArtifactId() );
|
||||
sourceMetadata.setVersion( artifact.getBaseVersion() );
|
||||
}
|
||||
return sourceMetadata;
|
||||
}
|
||||
|
||||
private void copyMetadata( File source, File target, RewriteTransaction transaction, Reporter artifactReporter,
|
||||
boolean reportOnly )
|
||||
throws IOException, DigestException, ReportWriteException
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
<requirement>
|
||||
<role>org.apache.maven.tools.repoclean.digest.DigestVerifier</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.tools.repoclean.digest.Digestor</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<!--
|
||||
|
|
Loading…
Reference in New Issue