From 666c60dea6668db3dae494f38241e6cfd3f42730 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 20 Apr 2005 23:39:30 +0000 Subject: [PATCH] o Fixed, pending changes to DefaultRepositoryLayout as outlined in MNG-321 PR: MNG-332 git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163990 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/repoclean/RepositoryCleaner.java | 34 ++++++++++++++- .../layout/AlphaBridgingRepositoryLayout.java | 43 +++++++++++++++++++ .../resources/META-INF/plexus/components.xml | 15 +++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/layout/AlphaBridgingRepositoryLayout.java diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java index c07e7f1d80..6a73701a7a 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java @@ -25,6 +25,8 @@ import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer; import org.apache.maven.tools.repoclean.index.ArtifactIndexer; import org.apache.maven.tools.repoclean.report.FileReporter; +import org.apache.maven.tools.repoclean.report.ReportWriteException; +import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; @@ -62,6 +64,8 @@ public class RepositoryCleaner private ArtifactDigestVerifier artifactDigestVerifier; + private ArtifactRepositoryLayout bridgingLayout; + private MailSender mailSender; private ArtifactIndexer artifactIndexer; @@ -241,7 +245,7 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR Logger logger = getLogger(); ArtifactPomRewriter artifactPomRewriter = null; - + try { logger.info( "Rewriting up to " + artifacts.size() + " artifacts (Should be " + ( artifacts.size() * 2 ) @@ -337,11 +341,15 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) ); File targetPom = new File( targetRepositoryBase, targetRepo.pathOfMetadata( pom ) ); + + File bridgedTargetPom = new File( targetRepositoryBase, bridgingLayout.pathOfMetadata( pom ) ); try { artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter, configuration.reportOnly() ); + + bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter ); } catch ( Exception e ) { @@ -393,6 +401,30 @@ else if( !targetMissingOrOlder ) } } + private void bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter ) throws IOException, ReportWriteException + { + 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."); + } + + FileInputStream in = null; + FileOutputStream out = null; + + try + { + in = new FileInputStream(targetPom); + out = new FileOutputStream(bridgedTargetPom); + + IOUtil.copy(in, out); + } + finally + { + IOUtil.close(in); + IOUtil.close(out); + } + } + private String buildArtifactReportPath( Artifact artifact ) { String classifier = artifact.getClassifier(); diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/layout/AlphaBridgingRepositoryLayout.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/layout/AlphaBridgingRepositoryLayout.java new file mode 100644 index 0000000000..854ad3926d --- /dev/null +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/layout/AlphaBridgingRepositoryLayout.java @@ -0,0 +1,43 @@ +package org.apache.maven.tools.repoclean.artifact.layout; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; + +/* + * 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. + */ + +public class AlphaBridgingRepositoryLayout + extends DefaultRepositoryLayout +{ + + public String pathOfMetadata( ArtifactMetadata metadata ) + throws ArtifactPathFormatException + { + Artifact artifact = metadata.getArtifact(); + + StringBuffer path = new StringBuffer(); + + path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' ); + path.append( artifact.getArtifactId() ).append( '/' ); + path.append( artifact.getBaseVersion() ).append( '/' ); + path.append( metadata.getFilename() ); + + return path.toString(); + } + +} diff --git a/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml b/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml index 4ef6d77166..f9593cb62a 100644 --- a/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml +++ b/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml @@ -1,5 +1,15 @@ + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + alpha-bridging + org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout + + + org.apache.maven.artifact.handler.manager.ArtifactHandlerManager + + +