Commits

Tim Vernum  committed 9662f1e

Improve build files

  • Participants
  • Parent commits 24a3d62

Comments (0)

Files changed (4)

 
   <target name="all"   description="Build modules + runs tests">
     <recursive target="all" />
+    <antcall target="dist.zip" />
   </target>
   <target name="build" description="Build modules">
     <recursive target="build" />
 
   <target name="dist">
     <recursive target="dist" />
+    <antcall target="dist.zip" />
+  </target>
+
+  <target name="dist.zip">
     <zip destfile="syntactic.zip">
       <fileset dir="parser/output/ant/dist" />
       <fileset dir="convert/output/ant/dist" />

File convert/build.xml

 <!-- vim: set ft=ant ts=2 sts=2 expandtab shiftwidth=2  : -->
 <project name="syntactic-convert"  default="all" basedir="."  xmlns:ivy="antlib:org.apache.ivy.ant" >
 
-  <property name="output"         location="output/ant"         />
-  <property name="output.java"    location="output/ant/java"    />
-  <property name="output.classes" location="output/ant/classes" />
-  <property name="output.junit"   location="output/ant/junit"   />
-  <property name="output.dist"    location="output/ant/dist"   />
+  <property name="output"                location="output/ant"         />
+  <property name="output.classes"        location="output/ant/classes" />
+  <property name="output.classes.main"   location="${output.classes}/main" />
+  <property name="output.classes.test"   location="${output.classes}/test" />
+  <property name="output.junit"          location="output/ant/junit"   />
+  <property name="output.dist"           location="output/ant/dist"   />
 
-  <property name="java.parser.package" value="org/adjective/syntactic/parser" />
+  <target name="all"   description="Compile code, run tests &amp; build jar file" depends="build, test, dist" />
+  <target name="build" description="Compile code" depends="compile " />
 
-  <target name="all"   description="Builds parser + runs tests" depends="build, test, dist" />
-  <target name="build" description="Builds parser" depends="compile " />
+ 
+  <!-- ******************
+        Java Compilation 
+       ****************** -->
 
-  <target name="compile">
-    <mkdir dir="${output.classes}" />
+  <path id="path.compile.main" >
+     <pathelement location="../parser/output/ant/classes/parser" />
+  </path>
 
-    <javac 
-        deprecation="false" 
-        debug="true" 
-        destdir="${output.classes}">
+  <path id="path.compile.test" >
+     <pathelement location="${output.classes.main}" />
+     <path refid="path.compile.main" />
+     <fileset dir="../lib/test/" />
+  </path>
+ 
+  <macrodef name="compile">
+    <element name="source" />
+    <attribute name="out" />
+    <attribute name="classpath" />
+    <sequential>
+      <mkdir dir="@{out}" />
+      <javac 
+          deprecation="false" 
+          debug="true" 
+          destdir="@{out}">
 
-        <!-- <src path="${output.java}" />  -->
+          <source />
+          <classpath refid="@{classpath}" />
+      </javac>
+    </sequential>
+  </macrodef>
+
+  <target name="compile" depends="compile.main, compile.test" />
+
+  <target name="compile.main" >
+    <compile out="${output.classes.main}" classpath="path.compile.main" >
+      <source>
         <src path="source/java/main" /> 
+      </source>
+    </compile>
+  </target>
 
-        <classpath>
-        <!--
-            <fileset dir="lib" />
-        -->
-            <pathelement location="../parser/output/ant/classes/parser" />
-        </classpath>
-    </javac>
+  <target name="compile.test" >
+    <compile out="${output.classes.test}" classpath="path.compile.test" >
+      <source>
+        <src path="source/java/test" /> 
+      </source>
+    </compile>
   </target>
 
+  <!-- ************
+        Unit Tests 
+       ************ -->
+
   <target name="test">
     <mkdir dir="${output.junit}" />
     <junit fork="yes" forkmode="once"  dir="${basedir}" haltonerror="false" failureproperty="junit.failure" errorproperty="junit.error" >
       <classpath>
-        <fileset dir="lib" />
-        <pathelement location="${output.classes}" />
+        <pathelement location="${output.classes.main}" />
+        <path refid="path.compile.main" />
+        <pathelement location="${output.classes.test}" />
+        <fileset dir="../lib/test" />
       </classpath>
       <batchtest todir="${output.junit}">
         <fileset dir="source/java/test">
         <attribute name="Implementation-Revision" value="${hg.version}"/>
         <attribute name="Built-Date"              value="${tstamp.date} ${tstamp.time}"/>
       </manifest>
-      <fileset dir="${output.classes}" />
+      <fileset dir="${output.classes.main}" />
     </jar>
   </target>
 

File convert/source/java/main/org/adjective/syntactic/convert/j7to8/type/ClassType.java

     @Override
     public BaseType getBaseType()
     {
-        if (_cls.isPrimitive())
+        final Class<?> cls = getBaseComponentClass();
+        if (cls.isPrimitive())
         {
-            if (_cls == Void.TYPE)
+            if (cls == Void.TYPE)
             {
                 return BaseType.VOID;
             }
-            if (_cls == Boolean.TYPE)
+            if (cls == Boolean.TYPE)
             {
                 return BaseType.BOOLEAN;
             }
-            if (_cls == Byte.TYPE)
+            if (cls == Byte.TYPE)
             {
                 return BaseType.BYTE;
             }
-            if (_cls == Short.TYPE)
+            if (cls == Short.TYPE)
             {
                 return BaseType.SHORT;
             }
-            if (_cls == Integer.TYPE)
+            if (cls == Integer.TYPE)
             {
                 return BaseType.INT;
             }
-            if (_cls == Long.TYPE)
+            if (cls == Long.TYPE)
             {
                 return BaseType.LONG;
             }
-            if (_cls == Float.TYPE)
+            if (cls == Float.TYPE)
             {
                 return BaseType.FLOAT;
             }
-            if (_cls == Double.TYPE)
+            if (cls == Double.TYPE)
             {
                 return BaseType.DOUBLE;
             }
-            if (_cls == Character.TYPE)
+            if (cls == Character.TYPE)
             {
                 return BaseType.CHAR;
             }
         return BaseType.OBJECT;
     }
 
+    private Class<?> getBaseComponentClass()
+    {
+        Class<?> cls = _cls;
+        while(cls.isArray()) {
+            cls = cls.getComponentType();
+        }
+        return cls;
+    }
+
     @Override
     public String getTypeName()
     {
-        return _cls.getName();
+        return getBaseComponentClass().getName();
     }
 
     @Override

File convert/source/java/test/org/adjective/syntactic/convert/j7to8/type/ClassTypeTest.java

+/* ------------------------------------------------------------------------
+ * Copyright 2013 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.BaseType;
+import org.junit.*;
+
+import static org.junit.Assert.*;
+
+public class ClassTypeTest
+{
+    @Test
+    public void testPrimitiveArray()
+    {
+        Class cls = byte[][].class;
+        final ClassType type = new ClassType(cls);
+        assertEquals(2, type.getArrayDepth());
+        assertEquals(BaseType.BYTE, type.getBaseType());
+        assertEquals("byte", type.getTypeName());
+        assertEquals(1, type.getParameterizedTypeName().length);
+        assertEquals("byte", type.getParameterizedTypeName()[0].getName());
+        assertEquals(0, type.getParameterizedTypeName()[0].getParameters().length);
+    }
+}