Converting to ant freeform script as it allows to demonstrate the amoeba effect
1.1 --- a/samples/composition/build.xml Sat Jun 14 09:51:03 2008 +0200
1.2 +++ b/samples/composition/build.xml Sat Jun 14 09:51:04 2008 +0200
1.3 @@ -1,69 +1,56 @@
1.4 <?xml version="1.0" encoding="UTF-8"?>
1.5 -<!-- You may freely edit this file. See commented blocks below for -->
1.6 -<!-- some examples of how to customize the build. -->
1.7 -<!-- (If you delete it and reopen the project it will be recreated.) -->
1.8 -<project name="composition" default="default" basedir=".">
1.9 - <description>Builds, tests, and runs the project composition.</description>
1.10 - <import file="nbproject/build-impl.xml"/>
1.11 - <!--
1.12 +<project name="Build Script" default="test" basedir=".">
1.13 + <target name="clean">
1.14 + <delete dir="build"/>
1.15 + </target>
1.16 +
1.17 + <target name="build">
1.18 + <ant dir="../libs/"/>
1.19 +
1.20 + <antcall target="-build-one">
1.21 + <param name="version" value="api1.0"/>
1.22 + </antcall>
1.23 + <antcall target="-build-one">
1.24 + <param name="version" value="api2.0"/>
1.25 + </antcall>
1.26 +
1.27 + <antcall target="-build-one">
1.28 + <param name="version" value="test"/>
1.29 + <param name="cp" location="build/api1.0/classes"/>
1.30 + </antcall>
1.31 + </target>
1.32 +
1.33 + <target name="test" depends="build">
1.34 + <echo level="info" message="Running the Implementation against Version 1.0 of the API. This should succeeds."/>
1.35 + <antcall target="-run-one">
1.36 + <param name="version" value="api1.0"/>
1.37 + </antcall>
1.38 + <echo level="info" message="Running the Implementation against Version 2.0 of the API. This should fail."/>
1.39 + <antcall target="-run-one">
1.40 + <param name="version" value="api2.0"/>
1.41 + </antcall>
1.42 + </target>
1.43
1.44 - There exist several targets which are by default empty and which can be
1.45 - used for execution of your tasks. These targets are usually executed
1.46 - before and after some main targets. They are:
1.47 -
1.48 - -pre-init: called before initialization of project properties
1.49 - -post-init: called after initialization of project properties
1.50 - -pre-compile: called before javac compilation
1.51 - -post-compile: called after javac compilation
1.52 - -pre-compile-single: called before javac compilation of single file
1.53 - -post-compile-single: called after javac compilation of single file
1.54 - -pre-compile-test: called before javac compilation of JUnit tests
1.55 - -post-compile-test: called after javac compilation of JUnit tests
1.56 - -pre-compile-test-single: called before javac compilation of single JUnit test
1.57 - -post-compile-test-single: called after javac compilation of single JUunit test
1.58 - -pre-jar: called before JAR building
1.59 - -post-jar: called after JAR building
1.60 - -post-clean: called after cleaning build products
1.61 -
1.62 - (Targets beginning with '-' are not intended to be called on their own.)
1.63 -
1.64 - Example of inserting an obfuscator after compilation could look like this:
1.65 -
1.66 - <target name="-post-compile">
1.67 - <obfuscate>
1.68 - <fileset dir="${build.classes.dir}"/>
1.69 - </obfuscate>
1.70 - </target>
1.71 -
1.72 - For list of available properties check the imported
1.73 - nbproject/build-impl.xml file.
1.74 -
1.75 -
1.76 - Another way to customize the build is by overriding existing main targets.
1.77 - The targets of interest are:
1.78 -
1.79 - -init-macrodef-javac: defines macro for javac compilation
1.80 - -init-macrodef-junit: defines macro for junit execution
1.81 - -init-macrodef-debug: defines macro for class debugging
1.82 - -init-macrodef-java: defines macro for class execution
1.83 - -do-jar-with-manifest: JAR building (if you are using a manifest)
1.84 - -do-jar-without-manifest: JAR building (if you are not using a manifest)
1.85 - run: execution of project
1.86 - -javadoc-build: Javadoc generation
1.87 - test-report: JUnit report generation
1.88 -
1.89 - An example of overriding the target for project execution could look like this:
1.90 -
1.91 - <target name="run" depends="composition-impl.jar">
1.92 - <exec dir="bin" executable="launcher.exe">
1.93 - <arg file="${dist.jar}"/>
1.94 - </exec>
1.95 - </target>
1.96 -
1.97 - Notice that the overridden target depends on the jar target and not only on
1.98 - the compile target as the regular run target does. Again, for a list of available
1.99 - properties which you can use, check the target you are overriding in the
1.100 - nbproject/build-impl.xml file.
1.101 -
1.102 - -->
1.103 +
1.104 + <!-- support methods -->
1.105 +
1.106 + <target name="-run-one">
1.107 + <fail message="You need to specify API version number" unless="version"/>
1.108 + <java classpath="build/${version}/classes:build/impl/classes" classname="impl.Impl"
1.109 + failonerror="true"
1.110 + />
1.111 + </target>
1.112 +
1.113 + <target name="-build-one">
1.114 + <fail message="You need to specify version number" unless="version"/>
1.115 +
1.116 + <mkdir dir="build/${version}/classes"/>
1.117 + <property name="cp" value=""/>
1.118 + <javac
1.119 + srcdir="src-${version}"
1.120 + destdir="build/${version}/classes"
1.121 + source="1.5" target="1.5"
1.122 + classpath="${cp}"
1.123 + />
1.124 + </target>
1.125 </project>
2.1 --- a/samples/composition/nbproject/project.xml Sat Jun 14 09:51:03 2008 +0200
2.2 +++ b/samples/composition/nbproject/project.xml Sat Jun 14 09:51:04 2008 +0200
2.3 @@ -1,16 +1,89 @@
2.4 <?xml version="1.0" encoding="UTF-8"?>
2.5 -<project xmlns="http://www.netbeans.org/ns/project/1">
2.6 - <type>org.netbeans.modules.java.j2seproject</type>
2.7 +<project xmlns="http://www.netbeans.org/ns/project/1" xmlns:ns4="null">
2.8 + <type>org.netbeans.modules.ant.freeform</type>
2.9 <configuration>
2.10 - <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
2.11 + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
2.12 <name>composition</name>
2.13 - <minimum-ant-version>1.6.5</minimum-ant-version>
2.14 - <source-roots>
2.15 - <root id="src.dir"/>
2.16 - </source-roots>
2.17 - <test-roots>
2.18 - <root id="test.src.dir"/>
2.19 - </test-roots>
2.20 - </data>
2.21 + </general-data>
2.22 + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2">
2.23 + <!-- Do not use Project Properties customizer when editing this file manually. -->
2.24 + <name>composition</name>
2.25 + <properties/>
2.26 + <folders>
2.27 + <source-folder>
2.28 + <label>src-api1.0</label>
2.29 + <type>java</type>
2.30 + <location>src-api1.0</location>
2.31 + <encoding>UTF-8</encoding>
2.32 + </source-folder>
2.33 + <source-folder>
2.34 + <label>src-api2.0</label>
2.35 + <type>java</type>
2.36 + <location>src-api2.0</location>
2.37 + <encoding>UTF-8</encoding>
2.38 + </source-folder>
2.39 + <source-folder>
2.40 + <label>test</label>
2.41 + <type>java</type>
2.42 + <location>src-test</location>
2.43 + <encoding>UTF-8</encoding>
2.44 + </source-folder>
2.45 + </folders>
2.46 + <ide-actions>
2.47 + <action name="build">
2.48 + <target>build</target>
2.49 + </action>
2.50 + <action name="clean">
2.51 + <target>clean</target>
2.52 + </action>
2.53 + <action name="test">
2.54 + <target>test</target>
2.55 + </action>
2.56 + <action name="rebuild">
2.57 + <target>clean</target>
2.58 + <target>build</target>
2.59 + </action>
2.60 + </ide-actions>
2.61 + <view>
2.62 + <items>
2.63 + <source-folder style="packages">
2.64 + <label>API Version 1.0</label>
2.65 + <location>src-api1.0</location>
2.66 + </source-folder>
2.67 + <source-folder style="packages">
2.68 + <label>API Version 2.0</label>
2.69 + <location>src-api2.0</location>
2.70 + </source-folder>
2.71 + <source-folder style="packages">
2.72 + <label>Usage of the API</label>
2.73 + <location>src-test</location>
2.74 + </source-folder>
2.75 + <source-file>
2.76 + <location>build.xml</location>
2.77 + </source-file>
2.78 + </items>
2.79 + <context-menu>
2.80 + <ide-action name="build"/>
2.81 + <ide-action name="rebuild"/>
2.82 + <ide-action name="clean"/>
2.83 + <ide-action name="test"/>
2.84 + </context-menu>
2.85 + </view>
2.86 + </general-data>
2.87 + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1">
2.88 + <compilation-unit>
2.89 + <package-root>src-api1.0</package-root>
2.90 + <source-level>1.5</source-level>
2.91 + </compilation-unit>
2.92 + <compilation-unit>
2.93 + <package-root>src-api2.0</package-root>
2.94 + <source-level>1.5</source-level>
2.95 + </compilation-unit>
2.96 + <compilation-unit>
2.97 + <package-root>src-test</package-root>
2.98 + <classpath mode="compile">src-api1.0</classpath>
2.99 + <source-level>1.5</source-level>
2.100 + </compilation-unit>
2.101 + </java-data>
2.102 </configuration>
2.103 </project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/samples/composition/src-api1.0/api/Arithmetica.java Sat Jun 14 09:51:04 2008 +0200
3.3 @@ -0,0 +1,28 @@
3.4 +package api;
3.5 +
3.6 +/** Class to simplify arithmetical operations.
3.7 + *
3.8 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.9 + */
3.10 +public class Arithmetica {
3.11 + public int sumTwo(int one, int second) {
3.12 + return one + second;
3.13 + }
3.14 +
3.15 + public int sumAll(int... numbers) {
3.16 + int sum = numbers[0];
3.17 + for (int i = 1; i < numbers.length; i++) {
3.18 + sum = sumTwo(sum, numbers[i]);
3.19 + }
3.20 + return sum;
3.21 + }
3.22 +
3.23 + public int sumRange(int from, int to) {
3.24 + int len = to - from;
3.25 + int[] array = new int[len + 1];
3.26 + for (int i = 0; i <= len; i++) {
3.27 + array[i] = from + i;
3.28 + }
3.29 + return sumAll(array);
3.30 + }
3.31 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/samples/composition/src-api2.0/api/Arithmetica.java Sat Jun 14 09:51:04 2008 +0200
4.3 @@ -0,0 +1,23 @@
4.4 +package api;
4.5 +
4.6 +/** Class to simplify arithmetical operations.
4.7 + *
4.8 + * @author Jaroslav Tulach <jtulach@netbeans.org>
4.9 + */
4.10 +public class Arithmetica {
4.11 + public int sumTwo(int one, int second) {
4.12 + return one + second;
4.13 + }
4.14 +
4.15 + public int sumAll(int... numbers) {
4.16 + int sum = numbers[0];
4.17 + for (int i = 1; i < numbers.length; i++) {
4.18 + sum = sumTwo(sum, numbers[i]);
4.19 + }
4.20 + return sum;
4.21 + }
4.22 +
4.23 + public int sumRange(int from, int to) {
4.24 + return (from + to) * (from - to + 1) / 2;
4.25 + }
4.26 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/samples/composition/src-test/api/ArithmeticaTest.java Sat Jun 14 09:51:04 2008 +0200
5.3 @@ -0,0 +1,46 @@
5.4 +/*
5.5 + * Žluťoučký kůň je naše hříbátko.
5.6 + * and open the template in the editor.
5.7 + */
5.8 +
5.9 +package api;
5.10 +
5.11 +import junit.framework.TestCase;
5.12 +
5.13 +/**
5.14 + *
5.15 + * @author Jaroslav Tulach <jtulach@netbeans.org>
5.16 + */
5.17 +public class ArithmeticaTest extends TestCase {
5.18 +
5.19 + public ArithmeticaTest(String testName) {
5.20 + super(testName);
5.21 + }
5.22 +
5.23 + @Override
5.24 + protected void setUp() throws Exception {
5.25 + super.setUp();
5.26 + }
5.27 +
5.28 + @Override
5.29 + protected void tearDown() throws Exception {
5.30 + super.tearDown();
5.31 + }
5.32 +
5.33 + public void testSumTwo() {
5.34 + Arithmetica instance = new Arithmetica();
5.35 + assertEquals("+", 5, instance.sumTwo(3, 2));
5.36 + }
5.37 +
5.38 + public void testSumAll() {
5.39 + Arithmetica instance = new Arithmetica();
5.40 + assertEquals("+", 6, instance.sumAll(3, 2, 1));
5.41 + }
5.42 +
5.43 + public void testSumRange() {
5.44 + Arithmetica instance = new Arithmetica();
5.45 + assertEquals("+", 6, instance.sumRange(1, 3));
5.46 + assertEquals("10", 55, instance.sumRange(1, 10));
5.47 + }
5.48 +
5.49 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/samples/composition/src-test/api/FactorialTest.java Sat Jun 14 09:51:04 2008 +0200
6.3 @@ -0,0 +1,53 @@
6.4 +/*
6.5 + * Žluťoučký kůň je naše hříbátko.
6.6 + * and open the template in the editor.
6.7 + */
6.8 +
6.9 +package api;
6.10 +
6.11 +import junit.framework.TestCase;
6.12 +
6.13 +/**
6.14 + *
6.15 + * @author Jaroslav Tulach <jtulach@netbeans.org>
6.16 + */
6.17 +public class FactorialTest extends TestCase {
6.18 +
6.19 + public FactorialTest(String testName) {
6.20 + super(testName);
6.21 + }
6.22 +
6.23 + @Override
6.24 + protected void setUp() throws Exception {
6.25 + super.setUp();
6.26 + }
6.27 +
6.28 + @Override
6.29 + protected void tearDown() throws Exception {
6.30 + super.tearDown();
6.31 + }
6.32 +
6.33 + public void testFactorial3() {
6.34 + assertEquals(6, Factorial.factorial(3));
6.35 + }
6.36 +
6.37 + public void testFactorial5() {
6.38 + assertEquals(120, Factorial.factorial(5));
6.39 + }
6.40 +
6.41 + /** Class showing inventive, non-expected use of
6.42 + * Arithmetica methods to do multiplication instead of
6.43 + * addition.
6.44 + */
6.45 + private static class Factorial extends Arithmetica {
6.46 + public static int factorial(int n) {
6.47 + return new Factorial().sumRange(1, n);
6.48 + }
6.49 + @Override
6.50 + public int sumTwo(int one, int second) {
6.51 + return one * second;
6.52 + }
6.53 + }
6.54 +
6.55 +
6.56 +}