Author: brett
Date: Mon Sep 19 00:52:26 2005
New Revision: 290084

URL: http://svn.apache.org/viewcvs?rev=290084&view=rev
Log:
add metadata for new artifact

Modified:
    
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
    
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java
    
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
    
maven/components/trunk/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml

Modified: 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java?rev=290084&r1=290083&r2=290084&view=diff
==============================================================================
--- 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
 (original)
+++ 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
 Mon Sep 19 00:52:26 2005
@@ -73,8 +73,7 @@
 
         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 @@
                     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 );
@@ -113,8 +110,6 @@
                         {
                             logger.debug( "Rewriting POMs and artifact files." 
);
                         }
-
-                        //                        List originalArtifacts = new 
ArrayList( artifacts );
 
                         List rewritten = rewritePhase.execute( artifacts, 
sourceRepo, targetRepo, configuration,
                                                                reportsBase, 
repoReporter );

Modified: 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java?rev=290084&r1=290083&r2=290084&view=diff
==============================================================================
--- 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java
 (original)
+++ 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java
 Mon Sep 19 00:52:26 2005
@@ -33,7 +33,6 @@
  */
 public class Digestor
 {
-
     public static final String ROLE = Digestor.class.getName();
 
     public static final String MD5 = "MD5";
@@ -58,6 +57,25 @@
         {
             throw new DigestException( "Cannot write digest to file: \'" + 
digestFile + "\'", e );
         }
+    }
+
+    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 )

Modified: 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java?rev=290084&r1=290083&r2=290084&view=diff
==============================================================================
--- 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
 (original)
+++ 
maven/components/trunk/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/phase/RewritePhase.java
 Mon Sep 19 00:52:26 2005
@@ -22,13 +22,16 @@
 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.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 @@
 {
     private DigestVerifier digestVerifier;
 
+    private Digestor artifactDigestor;
+
     private ArtifactRepositoryLayout bridgingLayout;
 
     private PlexusContainer container;
@@ -219,14 +225,43 @@
         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,74 +361,90 @@
         }
     }
 
-    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 );
-                }
-                finally
-                {
-                    IOUtil.close( reader );
-                    reader = null;
-                }
+                    MetadataXpp3Writer mappingWriter = new 
MetadataXpp3Writer();
 
-                Metadata targetMetadata = null;
+                    mappingWriter.write( writer, targetMetadata );
 
-                try
-                {
-                    reader = new FileReader( target );
-
-                    targetMetadata = mappingReader.read( reader );
+                    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 );
+                    IOUtil.close( writer );
                 }
+            }
+        }
+    }
 
-                boolean changed = false;
-
-                changed |= targetMetadata.merge( sourceMetadata );
+    private Metadata readMetadata( File source, Artifact artifact )
+        throws IOException, XmlPullParserException
+    {
+        Metadata sourceMetadata = null;
 
-                if ( changed )
-                {
-                    Writer writer = null;
-                    try
-                    {
-                        target.getParentFile().mkdirs();
-                        writer = new FileWriter( target );
+        if ( source.exists() )
+        {
+            Reader reader = null;
 
-                        MetadataXpp3Writer mappingWriter = new 
MetadataXpp3Writer();
+            try
+            {
+                reader = new FileReader( source );
 
-                        mappingWriter.write( writer, targetMetadata );
-                    }
-                    finally
-                    {
-                        IOUtil.close( writer );
-                    }
-                }
+                MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
 
-                digestVerifier.verifyDigest( source, target, transaction, 
artifactReporter, reportOnly );
+                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,

Modified: 
maven/components/trunk/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml?rev=290084&r1=290083&r2=290084&view=diff
==============================================================================
--- 
maven/components/trunk/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml
 (original)
+++ 
maven/components/trunk/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml
 Mon Sep 19 00:52:26 2005
@@ -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>
     <!--



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to