[jboss-cvs] JBossAS SVN: r80549 - in branches/JBPAPP_4_2_0_GA_CP: test/src/main/org/jboss/test/util and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 5 06:48:51 EST 2008


Author: pskopek at redhat.com
Date: 2008-11-05 06:48:50 -0500 (Wed, 05 Nov 2008)
New Revision: 80549

Added:
   branches/JBPAPP_4_2_0_GA_CP/test/src/main/org/jboss/test/util/CheckSumCalculator.java
Removed:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
   branches/JBPAPP_4_2_0_GA_CP/testsuite/build.xml
Log:
JBPAPP-1356: Integrate changes to EJB3 Test Suite for Common Criteria
- fix md5 sum calculation for EJB3 testsuite

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2008-11-05 09:28:21 UTC (rev 80548)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2008-11-05 11:48:50 UTC (rev 80549)
@@ -5215,7 +5215,7 @@
 
       <java classname="org.jboss.test.util.CheckSumCalculator">
          <classpath>
-            <pathelement location="${project.root}/testsuite/output/classes"/>
+            <pathelement location="${basedir}/../test/output/classes"/>
          </classpath>
          <arg line="-base ${jboss.dist}/ -output ${build.reports}/html/allmd5sum.txt -d ${jboss.dist}/lib -d ${jboss.dist}/server/production/lib"/>
       </java>

Copied: branches/JBPAPP_4_2_0_GA_CP/test/src/main/org/jboss/test/util/CheckSumCalculator.java (from rev 80376, branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java)
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/test/src/main/org/jboss/test/util/CheckSumCalculator.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/test/src/main/org/jboss/test/util/CheckSumCalculator.java	2008-11-05 11:48:50 UTC (rev 80549)
@@ -0,0 +1,185 @@
+package org.jboss.test.util;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * This utility class calculates check sum of files specified. It is used for
+ * Common Criteria certification testify section produced by junit reports.
+ * 
+ * Called from build.xml as using <java .. > ant task.
+ * 
+ * @author pskopek at redhat.com
+ */
+public class CheckSumCalculator {
+
+   class DirSpec {
+      public String dirPath;
+      public String fileNameSuffix;
+   }
+   
+   
+   private LinkedList dirSpecs = new LinkedList();
+   private String outputFileName = "MD5SUM";
+   private String base = "";
+     
+   /**
+    * @param args
+    */
+   public static void main(String[] args) {
+      CheckSumCalculator csc = new CheckSumCalculator();
+      csc.parseArguments(args);
+      try {
+         csc.calculate();
+      }
+      catch (IOException e) {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public CheckSumCalculator() {
+   }
+   
+   public void parseArguments(String args[]) {
+      
+      boolean isDirectory = false;
+      boolean isOutput = false;
+      boolean isSuffix = false;
+      boolean isBase = false;
+      
+      for (int i = 0; i < args.length; i++) {
+         if (args[i].equals("-d")) {
+            isDirectory = true;
+         }
+         else if (args[i].equals("-output")) {
+            isOutput = true;
+         }
+         else if (args[i].equals("-s")) {
+            isSuffix = true;
+         }
+         else if (args[i].equals("-base")) {
+            isBase = true;
+         }
+         else {
+            
+            if (isDirectory) {
+               DirSpec ds = new DirSpec();
+               ds.dirPath = args[i].trim();
+               ds.fileNameSuffix = ".jar";
+               
+               dirSpecs.add(ds);
+            }
+            else if (isSuffix) {
+               ((DirSpec)dirSpecs.getLast()).fileNameSuffix = args[i].trim();
+            }
+            else if (isOutput) {
+               outputFileName = args[i].trim();
+            }
+            else if (isBase) {
+               base = args[i].trim();
+            }
+            
+            isDirectory = false;
+            isSuffix = false;
+            isOutput = false;
+            isBase = false;
+         }
+         
+         
+      }
+   }
+   
+   public void calculate() throws IOException {
+      
+      PrintWriter pw = new PrintWriter(outputFileName);
+      
+      Iterator dsIterator = dirSpecs.iterator();
+      while (dsIterator.hasNext()) {
+        DirSpec ds = (DirSpec)dsIterator.next(); 
+        
+        calculateDirectory(ds, pw);
+        
+      }
+      
+      pw.close();
+      
+      
+   }
+
+   
+   private void calculateDirectory(DirSpec ds, PrintWriter pw) throws IOException {
+      
+      File dir = new File(ds.dirPath);
+      
+      File[] content = dir.listFiles();
+      for (int i = 0; i < content.length; i++) {
+         if (content[i].isDirectory()) {
+            DirSpec innerDir = new DirSpec();
+            innerDir.dirPath = content[i].getCanonicalPath();
+            innerDir.fileNameSuffix = ds.fileNameSuffix;
+            calculateDirectory(innerDir, pw);
+         }
+         else if (content[i].isFile() && content[i].getName().endsWith(ds.fileNameSuffix)) {
+            pw.print(calculateFileCheckSum(content[i]));
+            pw.print("  ");
+            
+            String canonicalPath = content[i].getCanonicalPath(); 
+            if (canonicalPath.startsWith(base)) {
+               canonicalPath = canonicalPath.substring(base.length());
+            }
+            pw.println(canonicalPath);
+            
+         }
+      }
+      
+   }
+   
+   
+   private String calculateFileCheckSum(File f) throws IOException {
+      
+      BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+      
+      byte[] buf = new byte[2048];
+      
+      MessageDigest md;
+      try {
+      md = MessageDigest.getInstance("MD5");
+      }
+      catch (NoSuchAlgorithmException e) {
+         throw new IllegalArgumentException(e);
+      }
+      
+      int len;
+      while ((len = in.read(buf, 0, buf.length)) > -1) {
+         md.update(buf, 0, len);
+      }
+      in.close();
+   
+      return CheckSumCalculator.convertToHex(md.digest());
+      
+      
+   }
+
+   private static String convertToHex(byte[] data) {
+      StringBuffer buf = new StringBuffer();
+      for (int i = 0; i < data.length; i++) {
+       int halfbyte = (data[i] >>> 4) & 0x0F;
+       int two_halfs = 0;
+       do {
+          if ((0 <= halfbyte) && (halfbyte <= 9))
+                 buf.append((char) ('0' + halfbyte));
+             else
+                buf.append((char) ('a' + (halfbyte - 10)));
+          halfbyte = data[i] & 0x0F;
+       } while(two_halfs++ < 1);
+      }
+      return buf.toString();
+  }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/build.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/build.xml	2008-11-05 09:28:21 UTC (rev 80548)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/build.xml	2008-11-05 11:48:50 UTC (rev 80549)
@@ -900,7 +900,7 @@
     
     <java classname="org.jboss.test.util.CheckSumCalculator">
       <classpath>
-        <pathelement location="${basedir}/output/classes"/>
+        <pathelement location="${basedir}/../test/output/classes"/>
       </classpath>
       <arg line="-base ${jboss.dist}/ -output ${build.reports}/html/allmd5sum.txt -d ${jboss.dist}/lib -d ${jboss.dist}/server/cc/lib"/>
     </java>

Deleted: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java	2008-11-05 09:28:21 UTC (rev 80548)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java	2008-11-05 11:48:50 UTC (rev 80549)
@@ -1,185 +0,0 @@
-package org.jboss.test.util;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-/**
- * This utility class calculates check sum of files specified. It is used for
- * Common Criteria certification testify section produced by junit reports.
- * 
- * Called from build.xml as using <java .. > ant task.
- * 
- * @author pskopek at redhat.com
- */
-public class CheckSumCalculator {
-
-   class DirSpec {
-      public String dirPath;
-      public String fileNameSuffix;
-   }
-   
-   
-   private LinkedList dirSpecs = new LinkedList();
-   private String outputFileName = "MD5SUM";
-   private String base = "";
-     
-   /**
-    * @param args
-    */
-   public static void main(String[] args) {
-      CheckSumCalculator csc = new CheckSumCalculator();
-      csc.parseArguments(args);
-      try {
-         csc.calculate();
-      }
-      catch (IOException e) {
-         throw new RuntimeException(e);
-      }
-   }
-
-   public CheckSumCalculator() {
-   }
-   
-   public void parseArguments(String args[]) {
-      
-      boolean isDirectory = false;
-      boolean isOutput = false;
-      boolean isSuffix = false;
-      boolean isBase = false;
-      
-      for (int i = 0; i < args.length; i++) {
-         if (args[i].equals("-d")) {
-            isDirectory = true;
-         }
-         else if (args[i].equals("-output")) {
-            isOutput = true;
-         }
-         else if (args[i].equals("-s")) {
-            isSuffix = true;
-         }
-         else if (args[i].equals("-base")) {
-            isBase = true;
-         }
-         else {
-            
-            if (isDirectory) {
-               DirSpec ds = new DirSpec();
-               ds.dirPath = args[i].trim();
-               ds.fileNameSuffix = ".jar";
-               
-               dirSpecs.add(ds);
-            }
-            else if (isSuffix) {
-               ((DirSpec)dirSpecs.getLast()).fileNameSuffix = args[i].trim();
-            }
-            else if (isOutput) {
-               outputFileName = args[i].trim();
-            }
-            else if (isBase) {
-               base = args[i].trim();
-            }
-            
-            isDirectory = false;
-            isSuffix = false;
-            isOutput = false;
-            isBase = false;
-         }
-         
-         
-      }
-   }
-   
-   public void calculate() throws IOException {
-      
-      PrintWriter pw = new PrintWriter(outputFileName);
-      
-      Iterator dsIterator = dirSpecs.iterator();
-      while (dsIterator.hasNext()) {
-        DirSpec ds = (DirSpec)dsIterator.next(); 
-        
-        calculateDirectory(ds, pw);
-        
-      }
-      
-      pw.close();
-      
-      
-   }
-
-   
-   private void calculateDirectory(DirSpec ds, PrintWriter pw) throws IOException {
-      
-      File dir = new File(ds.dirPath);
-      
-      File[] content = dir.listFiles();
-      for (int i = 0; i < content.length; i++) {
-         if (content[i].isDirectory()) {
-            DirSpec innerDir = new DirSpec();
-            innerDir.dirPath = content[i].getCanonicalPath();
-            innerDir.fileNameSuffix = ds.fileNameSuffix;
-            calculateDirectory(innerDir, pw);
-         }
-         else if (content[i].isFile() && content[i].getName().endsWith(ds.fileNameSuffix)) {
-            pw.print(calculateFileCheckSum(content[i]));
-            pw.print("  ");
-            
-            String canonicalPath = content[i].getCanonicalPath(); 
-            if (canonicalPath.startsWith(base)) {
-               canonicalPath = canonicalPath.substring(base.length());
-            }
-            pw.println(canonicalPath);
-            
-         }
-      }
-      
-   }
-   
-   
-   private String calculateFileCheckSum(File f) throws IOException {
-      
-      BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
-      
-      byte[] buf = new byte[2048];
-      
-      MessageDigest md;
-      try {
-      md = MessageDigest.getInstance("MD5");
-      }
-      catch (NoSuchAlgorithmException e) {
-         throw new IllegalArgumentException(e);
-      }
-      
-      int len;
-      while ((len = in.read(buf, 0, buf.length)) > -1) {
-         md.update(buf, 0, len);
-      }
-      in.close();
-   
-      return CheckSumCalculator.convertToHex(md.digest());
-      
-      
-   }
-
-   private static String convertToHex(byte[] data) {
-      StringBuffer buf = new StringBuffer();
-      for (int i = 0; i < data.length; i++) {
-       int halfbyte = (data[i] >>> 4) & 0x0F;
-       int two_halfs = 0;
-       do {
-          if ((0 <= halfbyte) && (halfbyte <= 9))
-                 buf.append((char) ('0' + halfbyte));
-             else
-                buf.append((char) ('a' + (halfbyte - 10)));
-          halfbyte = data[i] & 0x0F;
-       } while(two_halfs++ < 1);
-      }
-      return buf.toString();
-  }
-}




More information about the jboss-cvs-commits mailing list