jvanzyl     2002/07/21 15:14:36

  Added:       src/plugins-build/deploy/src/java/org/apache/maven
                        MD5Sum.java
  Log:
  o making a general deploy plugin so that deploying any artifact can be
    handled. right now there are separate deploy targets in each of the artifact
    producing plugins which will not scale with the introduction of new
    artifacts. adding a little md5 sum routine that we can use to make sure
    that the file is intact upon the delivery and that it hasn't been
    tampered with. we can get more sophisticated but using the md5 should
    fix the problem of incomplete JARs being used in builds.
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-maven/src/plugins-build/deploy/src/java/org/apache/maven/MD5Sum.java
  
  Index: MD5Sum.java
  ===================================================================
  package org.apache.maven;
  
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.StringWriter;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  
  import java.security.MessageDigest;
  
  /**
   * Encode an MD5 digest into a String. <p>
   *
   * The 128 bit MD5 hash is converted into a 32 character long String. Each
   * character of the String is the hexadecimal representation of 4 bits of the
   * digest.
   *
   * @author Remy Maucherat
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/21 22:14:36 $
   */
  public class MD5Sum
  {
  
      // ----------------------------------------------------- Instance Variables
  
      private final static char[] hexadecimal =
          {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
          'a', 'b', 'c', 'd', 'e', 'f'};
  
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * Encodes the 128 bit (16 bytes) MD5 into a 32 character String.
       *
       * @param binaryData Array containing the digest
       * @return Encoded MD5, or null if encoding failed
       */
      public String encode(byte[] binaryData)
      {
  
          if (binaryData.length != 16)
          {
              return null;
          }
  
          char[] buffer = new char[32];
  
          for (int i = 0; i < 16; i++)
          {
              int low = (int) (binaryData[i] & 0x0f);
              int high = (int) ((binaryData[i] & 0xf0) >> 4);
              buffer[i * 2] = hexadecimal[high];
              buffer[i * 2 + 1] = hexadecimal[low];
          }
  
          return new String(buffer);
      }
  
      /**
       * Pull in static content and store it
       */
      public static byte[] getBytes(File file)
          throws Exception
      {
          StringWriter sw = new StringWriter();
          BufferedReader reader = new BufferedReader(new InputStreamReader(new 
FileInputStream(file)));
  
          char buf[] = new char[1024];
          int len = 0;
  
          while ((len = reader.read(buf, 0, 1024)) != -1)
          {
              sw.write(buf, 0, len);
          }
  
          return sw.toString().getBytes();
      }
  
      /**
       * The main program for the MD5Sum class
       */
      public static void main(String[] args)
          throws Exception
      {
          System.out.println(">> " + args.length);
      
          if (args.length != 1)
          {
              return;
          }
  
          File file = new File(args[0]);
          if (!file.exists())
          {
              System.out.println("Specified file " + file + " doesn't exist.");
              System.exit(1);
          }
  
          MD5Sum md5 = new MD5Sum();
          MessageDigest md5Helper = MessageDigest.getInstance("MD5");
          System.out.println(md5.encode(md5Helper.digest(getBytes(file))));
      }
  }
  
  
  
  

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

Reply via email to