From 0ac4faa6137ac5919c854bf83396335d5d9312df Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Fri, 9 Aug 2013 00:51:53 +0200 Subject: [PATCH] Added multi jvm test script and removed J2SE-1.5 compile errors. --- build.txt | 28 +++--- src/main/build/jvm-test.sh | 88 +++++++++++++++++++ .../java/org/x4o/xml/X4ODriverManager.java | 2 +- .../xml/element/AbstractElementClassBase.java | 2 +- .../org/x4o/xml/io/X4OWriterContextTest.java | 7 +- .../java/org/x4o/xml/io/X4OWriterTest.java | 31 +++++-- .../xml/eld/doc/api/ApiDocNodeWriterBean.java | 4 +- 7 files changed, 133 insertions(+), 29 deletions(-) create mode 100755 src/main/build/jvm-test.sh diff --git a/build.txt b/build.txt index 20398e4..1e02d93 100644 --- a/build.txt +++ b/build.txt @@ -1,24 +1,11 @@ Building X4O -You need a few software packages; -- java 1.5 or higher. -- maven 3 or higher. +Software requirements; +- JDK 1.5++ +- Maven 3.0.1++ (3.0.3++ for jdk5) --- Run multi jvm test -- - -todo make maven like; -note2: this does need maven 3.0.3++ in 3.0.1 there is some java6 classes. - -export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/;mvn clean test -export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/;mvn clean test -export JAVA_HOME=/usr/lib/jvm/j2sdk1.6-oracle/;mvn clean test -export JAVA_HOME=/usr/lib/jvm/j2sdk1.7-oracle/;mvn clean test -export JAVA_HOME=/usr/lib/jvm/jdk1.5.0_22/;~/bin/mvn3/apache-maven-3.0.3/bin/mvn clean test -#not working; -#export JAVA_HOME=/usr/lib/jvm/java-1.5.0-gcj-4.7/;~/bin/mvn3/apache-maven-3.0.3/bin/mvn clean test - -- Create package -- cd project-root/; @@ -43,6 +30,15 @@ mvn -Pant-update-schema-eld package; note: the do 'install' is because of circle plugins. +-- Run multi jvm test -- + +Run tests in all jvms; +src/main/build/jvm-test.sh + +Run tests in single jvm; +src/main/build/jvm-test.sh /usr/lib/jvm/jdk1.5.0_22/ + + -- Make release build -- # todo make work diff --git a/src/main/build/jvm-test.sh b/src/main/build/jvm-test.sh new file mode 100755 index 0000000..8aa4f04 --- /dev/null +++ b/src/main/build/jvm-test.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# +# Copyright (c) 2004-2013, Willem Cazander +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted provided +# that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions and the +# following disclaimer. +# * 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. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS 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 COPYRIGHT HOLDER OR 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. +# + +# Config script +# note: 3.0.3++ as in prev version there are some java6 classes. +MVN=~/bin/mvn3/apache-maven-3.0.3/bin/mvn; +MVN_ARG="clean test"; +JVMS=" + /usr/lib/jvm/java-6-openjdk-amd64/ + /usr/lib/jvm/java-7-openjdk-amd64/ + /usr/lib/jvm/j2sdk1.6-oracle/ + /usr/lib/jvm/j2sdk1.7-oracle/ + /usr/lib/jvm/jdk1.5.0_22/" +#/usr/lib/jvm/java-1.5.0-gcj-4.7/ + +# Goto project root; +cd `dirname $0`/../../..; + +# Print meta data +echo "Starting jvm tests"; +echo "Maven cmd: $MVN"; +echo "Maven arg: $MVN_ARG"; + +# Check conditions +if [ "" != "$1" ]; then + echo "Starting single jvm test;"; + JVMS=$1; +else + echo "Starting jvm tests;"; +fi; +echo ""; + +# Run tests per jvm +for JVM in $JVMS; do + JVM_KEY=`echo $JVM | sed 's/\/\|\-//g'|tr -d '.'`; + echo "Running in jvm: $JVM"; + if [ -e $JVM ]; then + export JAVA_HOME=$JVM; + $MVN $MVN_ARG; + RESULT=$?; + else + RESULT="JVM path not found"; + fi; + + export "JVM_RESULT""$JVM_KEY"="$RESULT"; +done; + +EXIT=0; +echo ""; +echo "Test summary;"; +for JVM in $JVMS; do + JVM_KEY=`echo $JVM | sed 's/\/\|\-//g'|tr -d '.'`; + RESULT=`eval echo \\${"JVM_RESULT""$JVM_KEY"}`; + echo -n "Result; "; + if [ "$RESULT" = "0" ]; then + echo -n "Success"; + else + echo -n "Failure"; + EXIT=1; + fi; + echo " in jvm: $JVM (status:$RESULT)"; +done; + +echo "All done."; + +# EOF +exit $EXIT; \ No newline at end of file diff --git a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java index c54b1ef..f8f41a3 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java +++ b/x4o-driver/src/main/java/org/x4o/xml/X4ODriverManager.java @@ -164,7 +164,7 @@ public final class X4ODriverManager { if (language==null) { throw new NullPointerException("Can't provider driver for null language."); } - if (language.isEmpty()) { + if (language.length()==0) { throw new IllegalArgumentException("Can't provider driver for empty language."); } if (instance.drivers.containsKey(language)) { diff --git a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java index cda20e2..a72c9a5 100644 --- a/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java +++ b/x4o-driver/src/main/java/org/x4o/xml/element/AbstractElementClassBase.java @@ -99,7 +99,7 @@ public abstract class AbstractElementClassBase extends AbstractElementMetaBase i if (namespaceUri==null) { throw new NullPointerException("Can't add parent tag with null namespace uri."); } - if (namespaceUri.isEmpty()) { + if (namespaceUri.length()==0) { throw new IllegalArgumentException("Can't add parent tag with empty namespace uri."); } List tags = elementParents.get(namespaceUri); diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java index 20b9030..1efc787 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterContextTest.java @@ -26,7 +26,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Scanner; import org.x4o.xml.X4ODriver; import org.x4o.xml.element.Element; @@ -76,7 +75,7 @@ public class X4OWriterContextTest extends TestCase { X4OWriterContext writer = driver.createWriterContext(); writer.writeFileContext(createContext(), outputFile); - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = X4OWriterTest.readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); @@ -107,7 +106,7 @@ public class X4OWriterContextTest extends TestCase { X4OWriterContext writer = driver.createWriterContext(); writer.writeFileContext(createContext(), outputFile.getAbsolutePath()); - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = X4OWriterTest.readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); @@ -143,7 +142,7 @@ public class X4OWriterContextTest extends TestCase { } finally { outputStream.close(); } - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = X4OWriterTest.readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); diff --git a/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterTest.java b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterTest.java index add5a4e..7638bdb 100644 --- a/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterTest.java +++ b/x4o-driver/src/test/java/org/x4o/xml/io/X4OWriterTest.java @@ -23,11 +23,15 @@ package org.x4o.xml.io; import java.awt.Component; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.OutputStream; -import java.util.Scanner; +import java.nio.charset.Charset; import org.x4o.xml.X4ODriver; import org.x4o.xml.io.X4OReader; @@ -47,13 +51,30 @@ import junit.framework.TestCase; */ public class X4OWriterTest extends TestCase { - private File createOutputFile() throws IOException { File outputFile = File.createTempFile("test-writer", ".xml"); outputFile.deleteOnExit(); return outputFile; } + static public String readFile(File file) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),Charset.forName("UTF-8"))); + try { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + sb.append('\n'); + line = br.readLine(); + } + String out = sb.toString(); + //System.out.println(out); + return out; + } finally { + br.close(); + } + } + public void testWriterSwiXmlOutput() throws Exception { Accelerator3 ac3 = new Accelerator3(false); SwingEngine engine = new SwingEngine(ac3); @@ -86,7 +107,7 @@ public class X4OWriterTest extends TestCase { TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); writer.writeFile(root, outputFile); - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); @@ -103,7 +124,7 @@ public class X4OWriterTest extends TestCase { TestObjectRoot root = reader.readResource("tests/attributes/test-bean.xml"); writer.writeFile(root, outputFile.getAbsolutePath()); - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); @@ -127,7 +148,7 @@ public class X4OWriterTest extends TestCase { } writer.writeFile(root, outputFile.getAbsolutePath()); - String text = new Scanner( outputFile ).useDelimiter("\\A").next(); + String text = readFile( outputFile ); outputFile.delete(); assertTrue(text.startsWith("")); diff --git a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java index 2c45144..e7229ca 100644 --- a/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java +++ b/x4o-eld-doc/src/main/java/org/x4o/xml/eld/doc/api/ApiDocNodeWriterBean.java @@ -79,10 +79,10 @@ public class ApiDocNodeWriterBean implements ApiDocNodeWriter { if (ammo.nodeBodyOrder()!=-1) { methodWriter.setNodeBodyOrder(ammo.nodeBodyOrder()); } - if (!ammo.contentGroup().isEmpty()) { + if (ammo.contentGroup().length()>0) { methodWriter.setContentGroup(ammo.contentGroup()); } - if (!ammo.contentGroupType().isEmpty()) { + if (ammo.contentGroupType().length()>0) { methodWriter.setContentGroupType(ammo.contentGroupType()); } doc.addNodeBodyWriter(methodWriter);