diff options
-rwxr-xr-x | make/build.xml | 18 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/GlueGen.java | 3 | ||||
-rw-r--r-- | test/junit/com/sun/gluegen/BasicTest.java | 9 | ||||
-rw-r--r-- | test/junit/com/sun/gluegen/BuildUtil.java (renamed from test/junit/com/sun/gluegen/AbstractTest.java) | 67 | ||||
-rw-r--r-- | test/junit/com/sun/gluegen/StructAccessorTest.java | 33 | ||||
-rw-r--r-- | test/junit/com/sun/gluegen/build.xml | 15 |
6 files changed, 82 insertions, 63 deletions
diff --git a/make/build.xml b/make/build.xml index fdcdbb0..c7d3157 100755 --- a/make/build.xml +++ b/make/build.xml @@ -571,24 +571,24 @@ </target> <target name="test"> - <mkdir dir="${basedir}/../build/test/build/classes"/> - <mkdir dir="${basedir}/../build/test/results"/> + <mkdir dir="${gluegen.root}/build/test/build/classes"/> + <mkdir dir="${gluegen.root}/build/test/results"/> - <javac destdir="${basedir}/../build/test/build/classes" failonerror="false" source="1.5" srcdir="${basedir}/../test/junit" debug="true" debuglevel="lines,vars,source"> - <classpath path="${basedir}/../make/lib/junit-4.5.jar:${basedir}/../build/classes:${basedir}/../build/test/gensrc/java:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> + <javac destdir="${gluegen.root}/build/test/build/classes" failonerror="false" source="1.5" srcdir="${gluegen.root}/test/junit" debug="true" debuglevel="lines,vars,source"> + <classpath path="${gluegen.root}/make/lib/junit-4.5.jar:${gluegen.root}/build/classes:${gluegen.root}/build/test/gensrc/java:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> </javac> <junit forkmode="once" showoutput="true" fork="true"> - <jvmarg value="-Djava.library.path=${basedir}/../build/test/build/natives"/> - <batchtest todir="${basedir}/../build/test/results"> - <fileset dir="${basedir}/../build/test/build/classes"> - <include name="com/sun/gluegen/**"/> + <jvmarg value="-Djava.library.path=${gluegen.root}/build/test/build/natives"/> + <batchtest todir="${gluegen.root}/build/test/results"> + <fileset dir="${gluegen.root}/build/test/build/classes"> + <include name="com/sun/gluegen/**Test*"/> </fileset> <formatter usefile="false" type="brief"/> <formatter usefile="true" type="xml"/> </batchtest> <classpath> - <path path="${basedir}/../build/test/build/classes:${basedir}/../build/test/gensrc/java:${basedir}/../build/classes:${basedir}/../lib/antlr-3.2.jar:${basedir}/../make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> + <path path="${gluegen.root}/build/test/build/classes:${gluegen.root}/build/test/gensrc/java:${gluegen.root}/build/classes:${gluegen.root}/lib/antlr-3.2.jar:${gluegen.root}/make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> </classpath> </junit> </target> diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java index e046850..7c1fa4c 100644 --- a/src/java/com/sun/gluegen/GlueGen.java +++ b/src/java/com/sun/gluegen/GlueGen.java @@ -78,6 +78,7 @@ public class GlueGen implements GlueEmitterControls { } } + @SuppressWarnings("unchecked") public void run(String[] args) { try { Reader reader = null; @@ -338,7 +339,7 @@ public class GlueGen implements GlueEmitterControls { } } - public static void main(String[] args) { + public static void main(String... args) { new GlueGen().run(args); } diff --git a/test/junit/com/sun/gluegen/BasicTest.java b/test/junit/com/sun/gluegen/BasicTest.java index 89a4c21..dc6efb9 100644 --- a/test/junit/com/sun/gluegen/BasicTest.java +++ b/test/junit/com/sun/gluegen/BasicTest.java @@ -6,14 +6,16 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.junit.AfterClass; import org.junit.Test; import static java.lang.System.*; +import static com.sun.gluegen.BuildUtil.*; /** * * @author Michael Bien */ -public class BasicTest extends AbstractTest { +public class BasicTest { @Test public void generateBindingTest() { @@ -98,4 +100,9 @@ public class BasicTest extends AbstractTest { } + @AfterClass + public static void tearDown() { +// cleanGeneratedFiles(); + } + } diff --git a/test/junit/com/sun/gluegen/AbstractTest.java b/test/junit/com/sun/gluegen/BuildUtil.java index 9262347..de4f8e2 100644 --- a/test/junit/com/sun/gluegen/AbstractTest.java +++ b/test/junit/com/sun/gluegen/BuildUtil.java @@ -5,27 +5,21 @@ import java.net.URISyntaxException; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; import static java.lang.System.*; /** * @author Michael Bien */ -@Ignore -public abstract class AbstractTest { +public final class BuildUtil { - static final Project project = new Project(); + private static final Project project; - protected static String gluegenRoot; - protected static String path; - protected static String output; - + public static final String gluegenRoot; + public static final String path; + public static final String output; - @BeforeClass - public static void setUp() throws Exception { + static { out.println(" - - - System info - - - "); out.println("OS: " + System.getProperty("os.name")); @@ -33,7 +27,7 @@ public abstract class AbstractTest { // setup paths try { - File executionRoot = new File(AbstractTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + File executionRoot = new File(BuildUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI()); out.println("execution root: " + executionRoot); gluegenRoot = executionRoot.getParentFile().getParentFile().getParentFile().getParentFile().toString(); out.println("gluegen project root: " + gluegenRoot); @@ -48,13 +42,14 @@ public abstract class AbstractTest { out.println("output: "+output); out.println(" - - - - - - - - - - - - "); - deleteDirectory(new File(output+"/gensrc")); + cleanGeneratedFiles(); //setup ant build file + project = new Project(); project.setBaseDir(new File(gluegenRoot)); DefaultLogger logger = new DefaultLogger(); - logger.setErrorPrintStream(err); + logger.setErrorPrintStream(out); logger.setOutputPrintStream(out); logger.setMessageOutputLevel(Project.MSG_INFO); project.addBuildListener(logger); @@ -62,45 +57,53 @@ public abstract class AbstractTest { project.init(); File buildFile = new File(path, "build.xml"); + if(!buildFile.exists()) { + throw new RuntimeException("buildfile "+buildFile+" does not exist"); + } + ProjectHelper.configureProject(project, buildFile); } - @AfterClass - public static void tearDown() { -// deleteDirectory(new File(output)); + public static void cleanGeneratedFiles() { + out.println("cleaning generated files"); + deleteDirectory(new File(output+"/gensrc")); + out.println("done"); } /** * fails if ant script fails (which is a good thing). * executeTarget throws RuntimeException on failure */ - public final void compileJava() { + public static void compileJava() { + out.println("compiling java files"); project.executeTarget("compile.java"); + out.println("done"); } /** * fails if ant script fails (which is a good thing) * executeTarget throws RuntimeException on failure */ - public final void compileNatives() { + public static void compileNatives() { + out.println("compiling native files"); project.executeTarget("compile.native"); + out.println("done"); } - static final void generate(String config) { - out.println("generate: "+config); - GlueGen.main( - new String[] { - "-I"+path, - "-O"+output+"/gensrc", -// "-Ecom.sun.gluegen.DebugEmitter", - "-C"+path+"/"+config+".cfg", - path+"/"+config+".h" - } - ); + public static void generate(String bindingName) { + + out.println("generate binding: " + bindingName); + + GlueGen.main( "-I"+path, + "-O"+output+"/gensrc", + // "-Ecom.sun.gluegen.DebugEmitter", + "-C"+path+"/"+bindingName+".cfg", + path+"/"+bindingName+".h" ); + out.println("done"); } - static final void deleteDirectory(File path) { + public static void deleteDirectory(File path) { if(path.exists()) { File[] files = path.listFiles(); diff --git a/test/junit/com/sun/gluegen/StructAccessorTest.java b/test/junit/com/sun/gluegen/StructAccessorTest.java index f89eb43..0cd2953 100644 --- a/test/junit/com/sun/gluegen/StructAccessorTest.java +++ b/test/junit/com/sun/gluegen/StructAccessorTest.java @@ -14,14 +14,16 @@ import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; import junit.framework.Assert; +import org.junit.AfterClass; import org.junit.Test; import static java.lang.System.*; +import static com.sun.gluegen.BuildUtil.*; /** * * @author Michael Bien */ -public class StructAccessorTest extends AbstractTest { +public class StructAccessorTest { @Test public void generateStruct() { @@ -30,13 +32,13 @@ public class StructAccessorTest extends AbstractTest { @Test public void compileStructJava() { - super.compileJava(); + compileJava(); } @Test public void compileStructNatives() { // this will only copy gluegen-rt to the right place - super.compileNatives(); + compileNatives(); } @Test @@ -58,7 +60,7 @@ public class StructAccessorTest extends AbstractTest { // yeah, java 6 has even a compiler api... private void compile(File[] files, String destination) throws IOException { - out.println("compiling files:\n" + Arrays.asList(files)); + out.println("compiling files:\n " + Arrays.asList(files)); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>(); @@ -66,15 +68,17 @@ public class StructAccessorTest extends AbstractTest { Iterable<? extends JavaFileObject> fileObj = fileManager.getJavaFileObjects(files); - compiler.getTask( new OutputStreamWriter(out), - fileManager, - collector, - Arrays.asList("-d", destination/*, "-verbose"*/), - null, - fileObj ).call(); + boolean success = compiler.getTask( new OutputStreamWriter(out), + fileManager, + collector, + Arrays.asList("-d", destination/*, "-verbose"*/), + null, + fileObj ).call(); + + fileManager.close(); List<Diagnostic<? extends JavaFileObject>> list = collector.getDiagnostics(); - if(!list.isEmpty()) { + if(!list.isEmpty() || !success) { for (Diagnostic<? extends JavaFileObject> d : list) { out.println("Error on line "+ d.getLineNumber()); out.println("Compiler Message:\n"+d.getMessage(Locale.ENGLISH)); @@ -82,12 +86,13 @@ public class StructAccessorTest extends AbstractTest { Assert.fail("compilation failed"); } - fileManager.close(); - out.println("done"); } - + @AfterClass + public static void tearDown() { +// cleanGeneratedFiles(); + } } diff --git a/test/junit/com/sun/gluegen/build.xml b/test/junit/com/sun/gluegen/build.xml index 58ab781..08405bf 100644 --- a/test/junit/com/sun/gluegen/build.xml +++ b/test/junit/com/sun/gluegen/build.xml @@ -4,25 +4,28 @@ <description>Tests GlueGen</description> - <property name="gluegen.root" value="${basedir}" /> - <property name="build.dir" value="${gluegen.root}/build/test/build" /> - <property name="src.dir" value="${gluegen.root}/build/test/gensrc/java" /> + <property name="gluegen.root" value="${basedir}" /> + <property name="src.dir" value="${gluegen.root}/build/test/gensrc/java" /> + <property name="build.dir" value="${gluegen.root}/build/test/build" /> <!-- Pull in GlueGen cpptasks build file --> <import file="${gluegen.root}/make/gluegen-cpptasks.xml" /> - <target name="compile.java" depends="c.configure.linux"> + <target name="compile.java"> <echo message=" - - - compiling java files - - - "/> + <property name="build.dir.java" value="${build.dir}/classes"/> + <echo message="src: ${src.dir} "/> <echo message="build: ${build.dir.java} "/> + <echo message="jdkhome: ${jdk.home} "/> <mkdir dir="${build.dir.java}"/> - <javac destdir="${build.dir.java}" source="1.5" debug="true" verbose="true" debuglevel="lines,vars,source"> + <javac destdir="${build.dir.java}" source="1.5" failonerror="true" debug="true" verbose="true" debuglevel="lines,vars,source"> <src path="${src.dir}"/> - <classpath path="${basedir}/build/test/build/java:${basedir}/build/classes:${basedir}/build/test/gensrc/java:${basedir}/lib/antlr-2.7.7.jar:${basedir}/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> + <classpath path="${gluegen.root}/build/classes:${src.dir}:${gluegen.root}/build/antlr-3.2.jar:${gluegen.root}/make/lib/junit-4.5.jar:${jdk.home}/lib/tools.jar:${ant.core.lib}"/> </javac> <echo message=" - - - java files compiled - - - "/> |