diff --git a/sandbox/repoclean/pom.xml b/sandbox/repoclean/pom.xml index 5ece9d148f..20c874602b 100644 --- a/sandbox/repoclean/pom.xml +++ b/sandbox/repoclean/pom.xml @@ -32,6 +32,11 @@ maven-artifact 2.0-beta-1 + + org.apache.maven + maven-project + 2.0-beta-1 + org.apache.maven maven-artifact-manager diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java deleted file mode 100644 index 5b30988c97..0000000000 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.apache.maven.tools.repoclean.artifact.metadata; - -/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.repository.ArtifactRepository; - -/** - * Attach a POM to an artifact. - * - * @author Brett Porter - * @version $Id$ - */ -public class ProjectMetadata - implements ArtifactMetadata -{ - private final Artifact artifact; - - public ProjectMetadata( Artifact artifact ) - { - this.artifact = artifact; - } - - public Artifact getArtifact() - { - return artifact; - } - - public String getFilename() - { - return getArtifact().getArtifactId() + "-" + getArtifact().getVersion() + ".pom"; - } - - public void storeInLocalRepository( ArtifactRepository localRepository ) - throws ArtifactMetadataRetrievalException - { - // not used in repoclean. - } - - public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager ) - { - // not used - TODO: again indicates bad design? - } - - public void setArtifact( Artifact artifact ) - { - // this should be immutable... - } - - public boolean exists() - { - return artifact.getFile() != null && artifact.getFile().exists(); - } - - public boolean storedInArtifactDirectory() - { - return true; - } - - public String getGroupId() - { - return artifact.getGroupId(); - } - - public String getArtifactId() - { - return artifact.getArtifactId(); - } - - public String getVersion() - { - return artifact.getVersion(); - } - - public String getBaseVersion() - { - return artifact.getBaseVersion(); - } -} diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java deleted file mode 100644 index d536ca025f..0000000000 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.tools.repoclean.digest;/* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author jdcasey - */ -public class DigestVerificationException - extends Exception -{ - - public DigestVerificationException() - { - } - - public DigestVerificationException( String message ) - { - super( message ); - } - - public DigestVerificationException( String message, Throwable cause ) - { - super( message, cause ); - } - - public DigestVerificationException( Throwable cause ) - { - super( cause ); - } - -} \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java index edfb21bd3f..fa61470575 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java @@ -18,12 +18,15 @@ package org.apache.maven.tools.repoclean.phase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.metadata.ReleaseArtifactMetadata; -import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata; 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.SnapshotArtifactRepositoryMetadata; +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.artifact.metadata.ProjectMetadata; import org.apache.maven.tools.repoclean.digest.DigestException; import org.apache.maven.tools.repoclean.digest.DigestVerifier; import org.apache.maven.tools.repoclean.report.ReportWriteException; @@ -40,6 +43,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -51,7 +55,9 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Reader; import java.io.StringReader; +import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -208,27 +214,25 @@ public class RewritePhase Reporter artifactReporter, boolean reportOnly ) throws Exception { - // SNAPSHOT metadata - ArtifactMetadata snapshot = new SnapshotArtifactMetadata( artifact ); + ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File snapshotSource = new File( sourceBase, sourceRepo.pathOfArtifactMetadata( snapshot ) ); - File snapshotTarget = new File( targetBase, targetRepo.pathOfArtifactMetadata( snapshot ) ); + File metadataSource = new File( sourceBase, sourceRepo.pathOfRemoteRepositoryMetadata( metadata ) ); + File metadataTarget = new File( targetBase, targetRepo.pathOfRemoteRepositoryMetadata( metadata ) ); - freshenSupplementalMetadata( snapshotSource, snapshotTarget, transaction, artifactReporter, reportOnly ); + mergeMetadata( metadataSource, metadataTarget, transaction, artifactReporter, reportOnly ); - // RELEASE metadata - ArtifactMetadata release = new ReleaseArtifactMetadata( artifact ); + metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File releaseSource = new File( sourceBase, sourceRepo.pathOfArtifactMetadata( release ) ); - File releaseTarget = new File( targetBase, targetRepo.pathOfArtifactMetadata( release ) ); + metadataSource = new File( sourceBase, sourceRepo.pathOfRemoteRepositoryMetadata( metadata ) ); + metadataTarget = new File( targetBase, targetRepo.pathOfRemoteRepositoryMetadata( metadata ) ); - freshenSupplementalMetadata( releaseSource, releaseTarget, transaction, artifactReporter, reportOnly ); + mergeMetadata( metadataSource, metadataTarget, 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 ); + ArtifactMetadata pom = new ProjectArtifactMetadata( artifact, null ); - File sourcePom = new File( sourceBase, sourceRepo.pathOfArtifactMetadata( pom ) ); - File targetPom = new File( targetBase, targetRepo.pathOfArtifactMetadata( pom ).replace( '+', '-' ) ); + File sourcePom = new File( sourceBase, sourceRepo.pathOfRemoteRepositoryMetadata( pom ) ); + File targetPom = new File( targetBase, targetRepo.pathOfRemoteRepositoryMetadata( pom ).replace( '+', '-' ) ); String pomContents = null; @@ -242,7 +246,7 @@ public class RewritePhase { shouldRewritePom = false; - freshenSupplementalMetadata( sourcePom, targetPom, transaction, artifactReporter, reportOnly ); + copyMetadata( sourcePom, targetPom, transaction, artifactReporter, reportOnly ); } } else if ( targetPom.exists() ) @@ -268,7 +272,7 @@ public class RewritePhase transaction.addFile( targetPom ); bridgedTargetPom = new File( targetBase, - bridgingLayout.pathOfArtifactMetadata( pom ).replace( '+', '-' ) ); + bridgingLayout.pathOfRemoteRepositoryMetadata( pom ).replace( '+', '-' ) ); transaction.addFile( bridgedTargetPom ); @@ -322,8 +326,78 @@ public class RewritePhase } } - private void freshenSupplementalMetadata( File source, File target, RewriteTransaction transaction, - Reporter artifactReporter, boolean reportOnly ) + private void mergeMetadata( File source, File target, RewriteTransaction transaction, Reporter artifactReporter, + boolean reportOnly ) + throws IOException, DigestException, ReportWriteException, XmlPullParserException + { + if ( source.exists() ) + { + if ( !target.exists() ) + { + copyMetadata( source, target, transaction, artifactReporter, reportOnly ); + } + else + { + MetadataXpp3Reader mappingReader = new MetadataXpp3Reader(); + + Metadata sourceMetadata = null; + + Reader reader = null; + + try + { + reader = new FileReader( source ); + + sourceMetadata = mappingReader.read( reader ); + } + finally + { + IOUtil.close( reader ); + reader = null; + } + + 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 void copyMetadata( File source, File target, RewriteTransaction transaction, Reporter artifactReporter, + boolean reportOnly ) throws IOException, DigestException, ReportWriteException { if ( source.exists() ) @@ -428,7 +502,7 @@ public class RewritePhase return false; } - freshenSupplementalMetadata( targetPom, bridgedTargetPom, transaction, reporter, reportOnly ); + copyMetadata( targetPom, bridgedTargetPom, transaction, reporter, reportOnly ); return true; }