Author: krosenvold
Date: Tue Jul 30 21:55:13 2013
New Revision: 1508659

URL: http://svn.apache.org/r1508659
Log:
Converted to m-s-u and removed p-digester

Added:
    
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/SimpleDigester.java
Removed:
    
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/Utils.java
Modified:
    maven/plugins/trunk/maven-install-plugin/pom.xml
    
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
    
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
    
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
    
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java

Modified: maven/plugins/trunk/maven-install-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/pom.xml?rev=1508659&r1=1508658&r2=1508659&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-install-plugin/pom.xml Tue Jul 30 21:55:13 2013
@@ -98,15 +98,20 @@ under the License.
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-utils</artifactId>
-      <version>3.0.7</version>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-digest</artifactId>
-      <version>1.0</version>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <version>1.6</version>
     </dependency>
+      <dependency>
+          <groupId>org.apache.maven.shared</groupId>
+          <artifactId>maven-shared-utils</artifactId>
+          <version>0.4</version>
+      </dependency>
+      <dependency>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-utils</artifactId>
+          <version>3.0.7</version>
+      </dependency>
   </dependencies>
 
   <contributors>

Modified: 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java?rev=1508659&r1=1508658&r2=1508659&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
 Tue Jul 30 21:55:13 2013
@@ -32,9 +32,7 @@ import org.apache.maven.plugin.AbstractM
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.codehaus.plexus.digest.Digester;
-import org.codehaus.plexus.digest.DigesterException;
-import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.shared.utils.io.FileUtils;
 
 /**
  * Common fields for installation mojos.
@@ -75,17 +73,9 @@ public abstract class AbstractInstallMoj
     @Parameter( property = "updateReleaseInfo", defaultValue = "false" )
     protected boolean updateReleaseInfo;
 
-    /**
-     * Digester for MD5.
-     */
-    @Component( hint = "md5" )
-    protected Digester md5Digester;
+    protected final SimpleDigester md5Digester = SimpleDigester.md5();
 
-    /**
-     * Digester for SHA-1.
-     */
-    @Component( hint = "sha1" )
-    protected Digester sha1Digester;
+    protected final SimpleDigester sha1Digester = SimpleDigester.sha1();
 
     /**
      * Gets the path of the specified artifact within the local repository. 
Note that the returned path need not exist
@@ -192,32 +182,24 @@ public abstract class AbstractInstallMoj
      *            <code>null</code>.
      * @throws MojoExecutionException If the checksum could not be installed.
      */
-    private void installChecksum( File originalFile, File installedFile, 
Digester digester, String ext )
+    private void installChecksum( File originalFile, File installedFile, 
SimpleDigester digester, String ext )
         throws MojoExecutionException
     {
         String checksum;
         getLog().debug( "Calculating " + digester.getAlgorithm() + " checksum 
for " + originalFile );
-        try
-        {
-            checksum = digester.calc( originalFile );
-        }
-        catch ( DigesterException e )
-        {
-            throw new MojoExecutionException( "Failed to calculate " + 
digester.getAlgorithm() + " checksum for "
-                + originalFile, e );
-        }
+        checksum = digester.calc(originalFile);
 
         File checksumFile = new File( installedFile.getAbsolutePath() + ext );
         getLog().debug( "Installing checksum to " + checksumFile );
         try
         {
+            //noinspection ResultOfMethodCallIgnored
             checksumFile.getParentFile().mkdirs();
-            FileUtils.fileWrite( checksumFile.getAbsolutePath(), "UTF-8", 
checksum );
+            FileUtils.fileWrite(checksumFile.getAbsolutePath(), "UTF-8", 
checksum);
         }
         catch ( IOException e )
         {
             throw new MojoExecutionException( "Failed to install checksum to " 
+ checksumFile, e );
         }
     }
-
 }

Modified: 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=1508659&r1=1508658&r2=1508659&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
 Tue Jul 30 21:55:13 2013
@@ -51,10 +51,10 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 import org.apache.maven.project.validation.ModelValidationResult;
 import org.apache.maven.project.validation.ModelValidator;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.WriterFactory;
+import org.apache.maven.shared.utils.io.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.apache.maven.shared.utils.ReaderFactory;
+import org.apache.maven.shared.utils.WriterFactory;
 
 /**
  * Installs a file in the local repository.

Added: 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/SimpleDigester.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/SimpleDigester.java?rev=1508659&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/SimpleDigester.java
 (added)
+++ 
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/SimpleDigester.java
 Tue Jul 30 21:55:13 2013
@@ -0,0 +1,96 @@
+package org.apache.maven.plugin.install;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.commons.codec.binary.Hex;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.*;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class SimpleDigester {
+
+    private final MessageDigest messageDigest;
+    private static final int bufsize = 65536;
+
+    public SimpleDigester(String algorithm) {
+        try
+        {
+            messageDigest = MessageDigest.getInstance( algorithm );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            throw new RuntimeException( "Unable to initialize digest " + 
algorithm + " : "
+                    + e.getMessage() );
+        }
+    }
+
+    public static SimpleDigester md5(){
+        return new SimpleDigester("MD5");
+    }
+
+    public static SimpleDigester sha1(){
+        return new SimpleDigester("SHA-1");
+    }
+
+    public String getAlgorithm() {
+        return messageDigest.getAlgorithm();
+    }
+
+    public String calc( File file ) throws MojoExecutionException {
+        FileInputStream fis = null;
+        BufferedInputStream bis = null;
+
+        try
+        {
+            fis = new FileInputStream( file );
+            int bufsiz = (int) Math.min(file.length(), bufsize);
+            bis = new BufferedInputStream(fis, bufsiz);
+            messageDigest.reset();
+            update(bis);
+            return Hex.encodeHexString(messageDigest.digest());
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Failed to calculate " + 
messageDigest.getAlgorithm() + " checksum for "
+                    + file, e );
+        } finally
+        {
+            IOUtil.close(bis);
+            IOUtil.close( fis );
+        }
+    }
+
+    private void update( InputStream is )
+            throws IOException {
+            byte[] buffer = new byte[bufsize];
+            int size = is.read( buffer, 0, bufsize );
+            while ( size >= 0 )
+            {
+                messageDigest.update( buffer, 0, size );
+                size = is.read( buffer, 0, bufsize );
+            }
+    }
+}

Modified: 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java?rev=1508659&r1=1508658&r2=1508659&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
 (original)
+++ 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
 Tue Jul 30 21:55:13 2013
@@ -22,9 +22,9 @@ package org.apache.maven.plugin.install;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
+import org.apache.maven.shared.utils.ReaderFactory;
+import org.apache.maven.shared.utils.io.FileUtils;
+import org.apache.maven.shared.utils.io.IOUtil;
 
 import java.io.File;
 import java.io.Reader;

Modified: 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java?rev=1508659&r1=1508658&r2=1508659&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
 (original)
+++ 
maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
 Tue Jul 30 21:55:13 2013
@@ -26,7 +26,7 @@ import org.apache.maven.plugin.install.s
 import org.apache.maven.plugin.install.stubs.InstallArtifactStub;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.shared.utils.io.FileUtils;
 
 import java.io.File;
 import java.util.ArrayList;


Reply via email to