Add sources for Hello World tutorial
authorGintas Grigelionis <gintas@apache.org>
Mon, 12 Mar 2018 18:31:45 +0000 (19:31 +0100)
committerGintas Grigelionis <gintas@apache.org>
Mon, 12 Mar 2018 18:31:45 +0000 (19:31 +0100)
13 files changed:
manual/tutorial-HelloWorldWithAnt.html
src/tutorial/hello-world/01-simple/build.xml [new file with mode: 0644]
src/tutorial/hello-world/01-simple/src/oata/HelloWorld.java [new file with mode: 0644]
src/tutorial/hello-world/02-logging/build.xml [new file with mode: 0644]
src/tutorial/hello-world/02-logging/src/oata/HelloWorld.java [new file with mode: 0644]
src/tutorial/hello-world/03-testing/build.xml [new file with mode: 0644]
src/tutorial/hello-world/03-testing/src/log4j.properties [new file with mode: 0644]
src/tutorial/hello-world/03-testing/src/oata/HelloWorld.java [new file with mode: 0644]
src/tutorial/hello-world/03-testing/src/oata/HelloWorldTest.java [new file with mode: 0644]
src/tutorial/hello-world/final/build.xml [new file with mode: 0644]
src/tutorial/hello-world/final/src/log4j.properties [new file with mode: 0644]
src/tutorial/hello-world/final/src/oata/HelloWorld.java [new file with mode: 0644]
src/tutorial/hello-world/final/src/oata/HelloWorldTest.java [new file with mode: 0644]

index b349bab..5b02d6a 100644 (file)
@@ -409,7 +409,7 @@ junit instruction to our buildfile:</p>
             &lt;/classpath&gt;
 
             &lt;batchtest fork="yes"&gt;
-                &lt;fileset dir="${src.dir}" includes="*Test.java"/&gt;
+                &lt;fileset dir="${src.dir}" includes="**/*Test.java"/&gt;
             &lt;/batchtest&gt;
         &lt;/junit&gt;
     &lt;/target&gt;</b>
diff --git a/src/tutorial/hello-world/01-simple/build.xml b/src/tutorial/hello-world/01-simple/build.xml
new file mode 100644 (file)
index 0000000..2da99b0
--- /dev/null
@@ -0,0 +1,37 @@
+<project name="HelloWorld" basedir="." default="main">
+
+    <property name="src.dir"     value="src"/>
+
+    <property name="build.dir"   value="build"/>
+    <property name="classes.dir" value="${build.dir}/classes"/>
+    <property name="jar.dir"     value="${build.dir}/jar"/>
+
+    <property name="main-class"  value="oata.HelloWorld"/>
+
+    <target name="clean">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <target name="compile">
+        <mkdir dir="${classes.dir}"/>
+        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}"/>
+    </target>
+
+    <target name="jar" depends="compile">
+        <mkdir dir="${jar.dir}"/>
+        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
+            <manifest>
+                <attribute name="Main-Class" value="${main-class}"/>
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="run" depends="jar">
+        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
+    </target>
+
+    <target name="clean-build" depends="clean,jar"/>
+
+    <target name="main" depends="clean,run"/>
+
+</project>
diff --git a/src/tutorial/hello-world/01-simple/src/oata/HelloWorld.java b/src/tutorial/hello-world/01-simple/src/oata/HelloWorld.java
new file mode 100644 (file)
index 0000000..b2e7230
--- /dev/null
@@ -0,0 +1,7 @@
+package oata;
+
+public class HelloWorld {
+    public static void main(String[] args) {
+        System.out.println("Hello World");
+    }
+}
diff --git a/src/tutorial/hello-world/02-logging/build.xml b/src/tutorial/hello-world/02-logging/build.xml
new file mode 100644 (file)
index 0000000..8206cc8
--- /dev/null
@@ -0,0 +1,47 @@
+<project name="HelloWorld" basedir="." default="main">
+
+    <property name="src.dir"     value="src"/>
+
+    <property name="build.dir"   value="build"/>
+    <property name="classes.dir" value="${build.dir}/classes"/>
+    <property name="jar.dir"     value="${build.dir}/jar"/>
+    <property name="lib.dir"     value="lib"/>
+
+    <path id="classpath">
+        <fileset dir="${lib.dir}" includes="**/*.jar"/>
+    </path>
+
+    <property name="main-class"  value="oata.HelloWorld"/>
+
+    <target name="clean">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <target name="compile">
+        <mkdir dir="${classes.dir}"/>
+        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+    </target>
+
+    <target name="jar" depends="compile">
+        <mkdir dir="${jar.dir}"/>
+        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
+            <manifest>
+                <attribute name="Main-Class" value="${main-class}"/>
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="run" depends="jar">
+        <java classname="${main-class}" fork="true">
+            <classpath>
+                <path refid="classpath"/>
+                <path location="${jar.dir}/${ant.project.name}.jar"/>
+            </classpath>
+        </java>
+    </target>
+
+    <target name="clean-build" depends="clean,jar"/>
+
+    <target name="main" depends="clean,run"/>
+
+</project>
diff --git a/src/tutorial/hello-world/02-logging/src/oata/HelloWorld.java b/src/tutorial/hello-world/02-logging/src/oata/HelloWorld.java
new file mode 100644 (file)
index 0000000..751dcc9
--- /dev/null
@@ -0,0 +1,13 @@
+package oata;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.BasicConfigurator;
+
+public class HelloWorld {
+    static Logger logger = Logger.getLogger(HelloWorld.class);
+
+    public static void main(String[] args) {
+        BasicConfigurator.configure();
+        logger.info("Hello World");          // the old System.out-statement
+    }
+}
diff --git a/src/tutorial/hello-world/03-testing/build.xml b/src/tutorial/hello-world/03-testing/build.xml
new file mode 100644 (file)
index 0000000..9ebe9ba
--- /dev/null
@@ -0,0 +1,64 @@
+<project name="HelloWorld" basedir="." default="main">
+
+    <property name="src.dir"     value="src"/>
+
+    <property name="build.dir"   value="build"/>
+    <property name="classes.dir" value="${build.dir}/classes"/>
+    <property name="jar.dir"     value="${build.dir}/jar"/>
+    <property name="lib.dir"     value="lib"/>
+
+    <path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
+    <path id="classpath">
+        <fileset dir="${lib.dir}" includes="**/*.jar"/>
+    </path>
+
+    <property name="main-class"  value="oata.HelloWorld"/>
+
+    <target name="clean">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <target name="compile">
+        <mkdir dir="${classes.dir}"/>
+        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+        <copy todir="${classes.dir}">
+            <fileset dir="${src.dir}" excludes="**/*.java"/>
+        </copy>
+    </target>
+
+    <target name="jar" depends="compile">
+        <mkdir dir="${jar.dir}"/>
+        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
+            <manifest>
+                <attribute name="Main-Class" value="${main-class}"/>
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="run" depends="jar">
+        <java classname="${main-class}" fork="true">
+            <classpath>
+                <path refid="classpath"/>
+                <path refid="application"/>
+            </classpath>
+        </java>
+    </target>
+
+    <target name="junit" depends="jar">
+        <junit printsummary="yes">
+            <classpath>
+                <path refid="classpath"/>
+                <path refid="application"/>
+            </classpath>
+
+            <batchtest fork="yes">
+                <fileset dir="${src.dir}" includes="**/*Test.java"/>
+            </batchtest>
+        </junit>
+    </target>
+
+    <target name="clean-build" depends="clean,jar"/>
+
+    <target name="main" depends="clean,run"/>
+
+</project>
diff --git a/src/tutorial/hello-world/03-testing/src/log4j.properties b/src/tutorial/hello-world/03-testing/src/log4j.properties
new file mode 100644 (file)
index 0000000..111e080
--- /dev/null
@@ -0,0 +1,6 @@
+log4j.rootLogger=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%m%n
diff --git a/src/tutorial/hello-world/03-testing/src/oata/HelloWorld.java b/src/tutorial/hello-world/03-testing/src/oata/HelloWorld.java
new file mode 100644 (file)
index 0000000..73c3229
--- /dev/null
@@ -0,0 +1,11 @@
+package oata;
+
+import org.apache.log4j.Logger;
+
+public class HelloWorld {
+    static Logger logger = Logger.getLogger(HelloWorld.class);
+
+    public static void main(String[] args) {
+        logger.info("Hello World");          // the old System.out-statement
+    }
+}
diff --git a/src/tutorial/hello-world/03-testing/src/oata/HelloWorldTest.java b/src/tutorial/hello-world/03-testing/src/oata/HelloWorldTest.java
new file mode 100644 (file)
index 0000000..d08244f
--- /dev/null
@@ -0,0 +1,18 @@
+package oata;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class HelloWorldTest {
+
+    @Test
+    public void testNothing() {
+    }
+
+    @Test
+    public void testWillAlwaysFail() {
+        fail("An error message");
+    }
+
+}
diff --git a/src/tutorial/hello-world/final/build.xml b/src/tutorial/hello-world/final/build.xml
new file mode 100644 (file)
index 0000000..d2f25fb
--- /dev/null
@@ -0,0 +1,75 @@
+<project name="HelloWorld" basedir="." default="main">
+
+    <property name="src.dir"     value="src"/>
+
+    <property name="build.dir"   value="build"/>
+    <property name="classes.dir" value="${build.dir}/classes"/>
+    <property name="jar.dir"     value="${build.dir}/jar"/>
+    <property name="lib.dir"     value="lib"/>
+    <property name="report.dir"  value="${build.dir}/junitreport"/>
+
+    <path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
+    <path id="classpath">
+        <fileset dir="${lib.dir}" includes="**/*.jar"/>
+    </path>
+
+    <property name="main-class"  value="oata.HelloWorld"/>
+
+    <target name="clean">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <target name="compile">
+        <mkdir dir="${classes.dir}"/>
+        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+        <copy todir="${classes.dir}">
+            <fileset dir="${src.dir}" excludes="**/*.java"/>
+        </copy>
+    </target>
+
+    <target name="jar" depends="compile">
+        <mkdir dir="${jar.dir}"/>
+        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
+            <manifest>
+                <attribute name="Main-Class" value="${main-class}"/>
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="run" depends="jar">
+        <java classname="${main-class}" fork="true">
+            <classpath>
+                <path refid="classpath"/>
+                <path refid="application"/>
+            </classpath>
+        </java>
+    </target>
+
+    <target name="junit" depends="jar">
+        <mkdir dir="${report.dir}"/>
+        <junit printsummary="yes" tempdir="${build.dir}">
+            <classpath>
+                <path refid="classpath"/>
+                <path refid="application"/>
+            </classpath>
+
+            <formatter type="xml"/>
+
+            <batchtest fork="yes" todir="${report.dir}">
+                <fileset dir="${src.dir}" includes="**/*Test.java"/>
+            </batchtest>
+        </junit>
+    </target>
+
+    <target name="junitreport">
+        <junitreport todir="${report.dir}">
+            <fileset dir="${report.dir}" includes="TEST-*.xml"/>
+            <report todir="${report.dir}"/>
+        </junitreport>
+    </target>
+
+    <target name="clean-build" depends="clean,jar"/>
+
+    <target name="main" depends="clean,run"/>
+
+</project>
diff --git a/src/tutorial/hello-world/final/src/log4j.properties b/src/tutorial/hello-world/final/src/log4j.properties
new file mode 100644 (file)
index 0000000..111e080
--- /dev/null
@@ -0,0 +1,6 @@
+log4j.rootLogger=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%m%n
diff --git a/src/tutorial/hello-world/final/src/oata/HelloWorld.java b/src/tutorial/hello-world/final/src/oata/HelloWorld.java
new file mode 100644 (file)
index 0000000..73c3229
--- /dev/null
@@ -0,0 +1,11 @@
+package oata;
+
+import org.apache.log4j.Logger;
+
+public class HelloWorld {
+    static Logger logger = Logger.getLogger(HelloWorld.class);
+
+    public static void main(String[] args) {
+        logger.info("Hello World");          // the old System.out-statement
+    }
+}
diff --git a/src/tutorial/hello-world/final/src/oata/HelloWorldTest.java b/src/tutorial/hello-world/final/src/oata/HelloWorldTest.java
new file mode 100644 (file)
index 0000000..d08244f
--- /dev/null
@@ -0,0 +1,18 @@
+package oata;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class HelloWorldTest {
+
+    @Test
+    public void testNothing() {
+    }
+
+    @Test
+    public void testWillAlwaysFail() {
+        fail("An error message");
+    }
+
+}