[jboss-cvs] JBossAS SVN: r108462 - in branches/JBPAPP_5_1/testsuite: src/main/org/jboss/test/util and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 6 03:54:11 EDT 2010
Author: pskopek at redhat.com
Date: 2010-10-06 03:54:11 -0400 (Wed, 06 Oct 2010)
New Revision: 108462
Added:
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java
Modified:
branches/JBPAPP_5_1/testsuite/
branches/JBPAPP_5_1/testsuite/build.xml
branches/JBPAPP_5_1/testsuite/src/stylesheets/junit-frames.xsl
Log:
CC: test reports have to include MD5SUM of tested jars.
Property changes on: branches/JBPAPP_5_1/testsuite
___________________________________________________________________
Name: svn:ignore
- .settings
output
build.log
run.tstamp
junit*.properties
20070819
20070821
.project_my
.classpath_my
+ .settings
output
build.log
run.tstamp
junit*.properties
20070819
20070821
.project_my
.classpath_my
assertion.xml
Modified: branches/JBPAPP_5_1/testsuite/build.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/build.xml 2010-10-05 23:37:12 UTC (rev 108461)
+++ branches/JBPAPP_5_1/testsuite/build.xml 2010-10-06 07:54:11 UTC (rev 108462)
@@ -1762,6 +1762,22 @@
<server:stop name="${conf}" />
</target>
+ <!-- Calculates MD5 sums for all libraries used while testing.
+ This will be used as proof of testing for CC evaluation.
+ -->
+ <target name="calculate-md5">
+ <mkdir dir="${build.reports}/html"/>
+
+ <java classname="org.jboss.test.util.CheckSumCalculator">
+ <classpath>
+ <pathelement location="${build.classes}" />
+ </classpath>
+ <arg line="-base ${jboss.dist}/ -output ${build.reports}/html/allmd5sum.txt -d ${jboss.dist}/lib -d ${jboss.dist}/server/cc/lib -d ${jboss.dist}/server/cc/deploy -d ${jboss.dist}/client"/>
+ </java>
+
+ </target>
+
+
<!--
| Tests for Common Criteria Evaluation. The JBoss server must be running with a security manager for those tests
| This target has to run with jboss.test.sign.jars property set to true.
@@ -1773,7 +1789,7 @@
<istrue value="${cc.sm.debug}"/>
</condition>
-->
-
+ <property name="cc-testify" value="true"/>
<delete dir="${jboss.dist}${/}server${/}cc" quiet="true"/>
<delete dir="${jboss.dist}${/}server${/}cc-audit" quiet="true"/>
@@ -1937,7 +1953,7 @@
<include name="org/jboss/test/jbossts/ASCrashRecovery02/TestWithJMS.class"/ -->
<!-- antcall target="tests-ts-crash-recovery-jms"/ -->
-
+ <antcall target="calculate-md5"/>
<antcall target="tests-report"/>
</target>
Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/CheckSumCalculator.java 2010-10-06 07:54:11 UTC (rev 108462)
@@ -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_5_1/testsuite/src/stylesheets/junit-frames.xsl
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/stylesheets/junit-frames.xsl 2010-10-05 23:37:12 UTC (rev 108461)
+++ branches/JBPAPP_5_1/testsuite/src/stylesheets/junit-frames.xsl 2010-10-06 07:54:11 UTC (rev 108462)
@@ -534,6 +534,7 @@
</xsl:for-each>
</table>
<xsl:call-template name="pageFooter"/>
+ <xsl:call-template name="cc-testify"/>
</body>
</html>
</xsl:template>
@@ -640,6 +641,33 @@
</table>
</xsl:template>
+<!-- Common Criteria Testify -->
+<xsl:template name="cc-testify">
+ <xsl:if test="//property[@name='cc-testify']/@value">
+ <p/>
+ <hr size="1"/>
+ <p/>
+ <h2>Common Criteria Testify</h2>
+ <a href="allmd5sum.txt">MD5 sums of involved libraries</a>
+ <p/>
+ <table class="details">
+ <tr>
+ <td>Hudson Job Name</td><td><xsl:value-of select="//property[@name='env.JOB_NAME']/@value"/></td>
+ </tr><tr>
+ <td>Build ID</td><td><xsl:value-of select="//property[@name='env.BUILD_ID']/@value"/></td>
+ </tr><tr>
+ <td>Build Tag</td><td><xsl:value-of select="//property[@name='env.BUILD_TAG']/@value"/></td>
+ </tr><tr>
+ <td>Build Number</td><td><xsl:value-of select="//property[@name='env.BUILD_NUMBER']/@value"/></td>
+ </tr><tr>
+ <td>Date</td><td><xsl:value-of select="//property[@name='TODAY']/@value"/></td>
+ </tr><tr>
+ <td>Time</td><td><xsl:value-of select="//property[@name='TIMENOW']/@value"/></td>
+ </tr>
+ </table>
+ </xsl:if>
+</xsl:template>
+
<!-- class header -->
<xsl:template name="testsuite.test.header">
<tr bgcolor="#A6CAF0" valign="top">
More information about the jboss-cvs-commits
mailing list