| 1 | <?xml version="1.0" encoding="UTF-8"?> |
|---|
| 2 | <!-- ====================================================================== |
|---|
| 3 | Jul 16, 2008 9:43:19 AM |
|---|
| 4 | |
|---|
| 5 | eclipse_build |
|---|
| 6 | A generic ant build that can build (almost) any eclipse project |
|---|
| 7 | |
|---|
| 8 | Omry Yadan (omry@yadan.net) |
|---|
| 9 | ====================================================================== --> |
|---|
| 10 | <project name="eclipse_build" default="build_local"> |
|---|
| 11 | <description> |
|---|
| 12 | A generic ant build that can build (almost) any eclipse project |
|---|
| 13 | </description> |
|---|
| 14 | |
|---|
| 15 | <!-- ================================= |
|---|
| 16 | target: default |
|---|
| 17 | ================================= --> |
|---|
| 18 | <target name="build_local" depends="setup,clean" description="A generic ant build that can build (almost) any eclipse project"> |
|---|
| 19 | |
|---|
| 20 | <eclipse_build_list rootdir="${workspace}" entry_project="${project}" result="projects" /> |
|---|
| 21 | |
|---|
| 22 | <mkdir dir="${build.output}" /> |
|---|
| 23 | <mkdir dir="${build.output}/temp" /> |
|---|
| 24 | <mkdir dir="${build.output}/temp/classes" /> |
|---|
| 25 | <mkdir dir="${build.output}/dist/lib" /> |
|---|
| 26 | |
|---|
| 27 | <antcall target="for_each_project"> |
|---|
| 28 | <param name="project" value="${project}" /> |
|---|
| 29 | <param name="projects" value="${projects}" /> |
|---|
| 30 | <param name="target" value="build_project" /> |
|---|
| 31 | </antcall> |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | <copy todir="${build.output}/dist"> |
|---|
| 35 | <fileset dir="${workspace}/${project}/" excludes="${bin.excludes}" includes="${bin.includes}" /> |
|---|
| 36 | </copy> |
|---|
| 37 | |
|---|
| 38 | <files_list dir="${build.output}/dist" includes="lib/**/*.jar" seperator=" " result="manifest.class.path" /> |
|---|
| 39 | <echo>manifest.class.path = ${manifest.class.path}</echo> |
|---|
| 40 | <jar destfile="${build.output}/dist/${jar.name}" basedir="${build.output}/temp/classes"> |
|---|
| 41 | <manifest> |
|---|
| 42 | <attribute name="Built-By" value="${user.name}" /> |
|---|
| 43 | <attribute name="Class-Path" value="${manifest.class.path}" /> |
|---|
| 44 | <attribute name="Main-Class" value="${main.class}" /> |
|---|
| 45 | </manifest> |
|---|
| 46 | </jar> |
|---|
| 47 | |
|---|
| 48 | <zip destfile="${build.output}/${zip.name}" |
|---|
| 49 | basedir="${build.output}/dist/" |
|---|
| 50 | includes="**/*" |
|---|
| 51 | /> |
|---|
| 52 | </target> |
|---|
| 53 | |
|---|
| 54 | <!-- - - - - - - - - - - - - - - - - - |
|---|
| 55 | target: build_project |
|---|
| 56 | - - - - - - - - - - - - - - - - - --> |
|---|
| 57 | <target name="build_project" depends="setup"> |
|---|
| 58 | |
|---|
| 59 | <!-- Create source path --> |
|---|
| 60 | <eclipse_cp action="src" rootdir="${workspace}" project="${proj}" result="proj.src" /> |
|---|
| 61 | <var name="build.sourcepath" value="" /> |
|---|
| 62 | <for list="${proj.src}" param="src" delimiter=";"> |
|---|
| 63 | <sequential> |
|---|
| 64 | <var name="build.sourcepath" value="${build.sourcepath};${workspace}${proj}/@{src}" /> |
|---|
| 65 | </sequential> |
|---|
| 66 | </for> |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | <!-- Create class path --> |
|---|
| 70 | <eclipse_cp action="libs" rootdir="${workspace}" project="${proj}" result="classpath" /> |
|---|
| 71 | |
|---|
| 72 | <var name="build.classpath" value="" /> |
|---|
| 73 | <for list="${classpath}" param="jar" delimiter=";"> |
|---|
| 74 | <sequential> |
|---|
| 75 | <var name="build.classpath" value="${build.classpath};${workspace}@{jar}" /> |
|---|
| 76 | </sequential> |
|---|
| 77 | </for> |
|---|
| 78 | |
|---|
| 79 | <echo>build.sourcepath for ${proj} = ${build.sourcepath}</echo> |
|---|
| 80 | <echo>build.classpath for ${proj} = ${build.classpath}</echo> |
|---|
| 81 | |
|---|
| 82 | <!-- compile project source --> |
|---|
| 83 | <if> |
|---|
| 84 | <equals arg1="${build.sourcepath}" arg2="" /> |
|---|
| 85 | <then> |
|---|
| 86 | <echo message="Nothing to compile at project ${proj} " level="warning" /> |
|---|
| 87 | </then> |
|---|
| 88 | <else> |
|---|
| 89 | <mkdir dir="${build.output}" /> |
|---|
| 90 | |
|---|
| 91 | <javac |
|---|
| 92 | source="${javac.source}" |
|---|
| 93 | target="${javac.target}" |
|---|
| 94 | srcdir="${build.sourcepath}" |
|---|
| 95 | destdir="${build.output}/temp/classes" |
|---|
| 96 | classpath="${build.classpath}" |
|---|
| 97 | debug="${javac.debug}" |
|---|
| 98 | debuglevel="${javac.debug.level}" |
|---|
| 99 | /> |
|---|
| 100 | |
|---|
| 101 | <!-- Copy non java files from source path into output dir --> |
|---|
| 102 | <for list="${proj.src}" param="src" delimiter=";"> |
|---|
| 103 | <sequential> |
|---|
| 104 | <copy todir="${build.output}/temp/classes"> |
|---|
| 105 | <fileset dir="${workspace}${proj}/@{src}"> |
|---|
| 106 | <exclude name="**/*.java" /> |
|---|
| 107 | </fileset> |
|---|
| 108 | </copy> |
|---|
| 109 | </sequential> |
|---|
| 110 | </for> |
|---|
| 111 | |
|---|
| 112 | <if> |
|---|
| 113 | <equals arg1="${export.all.jars}" arg2="false" /> |
|---|
| 114 | <then> |
|---|
| 115 | <eclipse_cp action="only_exported_libs" rootdir="${workspace}" project="${proj}" result="copy_list" /> |
|---|
| 116 | <echo>Adding exported libs to output lib dir : ${copy_list}</echo> |
|---|
| 117 | </then> |
|---|
| 118 | <else> |
|---|
| 119 | <eclipse_cp action="libs" rootdir="${workspace}" project="${proj}" result="copy_list" /> |
|---|
| 120 | <echo>Adding all libs to output lib dir : ${copy_list}</echo> |
|---|
| 121 | </else> |
|---|
| 122 | </if> |
|---|
| 123 | |
|---|
| 124 | <for list="${copy_list}" param="jar" delimiter=";"> |
|---|
| 125 | <sequential> |
|---|
| 126 | <copy tofile="${build.output}/dist/lib/@{jar}" file="${workspace}@{jar}" /> |
|---|
| 127 | </sequential> |
|---|
| 128 | </for> |
|---|
| 129 | </else> |
|---|
| 130 | </if> |
|---|
| 131 | </target> |
|---|
| 132 | |
|---|
| 133 | <!-- - - - - - - - - - - - - - - - - - |
|---|
| 134 | target: setup |
|---|
| 135 | - - - - - - - - - - - - - - - - - --> |
|---|
| 136 | <target name="setup"> |
|---|
| 137 | <property name="build.properties" value="build.properties"/> |
|---|
| 138 | |
|---|
| 139 | <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="antlib/ant-contrib-1.0b1.jar" /> |
|---|
| 140 | <taskdef resource="firefang_ant.properties" classpath="antlib/ant_tasks.jar" /> |
|---|
| 141 | <!-- |
|---|
| 142 | <taskdef resource="firefang_ant.properties" classpath="../ebuild/output/fragments/ant_tasks.jar" /> |
|---|
| 143 | --> |
|---|
| 144 | |
|---|
| 145 | <!-- Assert module to build is defined --> |
|---|
| 146 | <antcall target="assert_defined"> |
|---|
| 147 | <param name="param" value="project" /> |
|---|
| 148 | </antcall> |
|---|
| 149 | |
|---|
| 150 | <!-- load common properties --> |
|---|
| 151 | <loadproperties srcfile="common.properties"> |
|---|
| 152 | </loadproperties> |
|---|
| 153 | |
|---|
| 154 | <property name="project.dir" location="${workspace}/${project}" /> |
|---|
| 155 | |
|---|
| 156 | <!-- project specific build properties, may override common.properties --> |
|---|
| 157 | <var file="${project.dir}/${build.properties}" /> |
|---|
| 158 | |
|---|
| 159 | <property name="build.output" value="${workspace}/${project}/${build.dir}" /> |
|---|
| 160 | |
|---|
| 161 | </target> |
|---|
| 162 | |
|---|
| 163 | <!-- - - - - - - - - - - - - - - - - - |
|---|
| 164 | target: assert_defined |
|---|
| 165 | - - - - - - - - - - - - - - - - - --> |
|---|
| 166 | <target name="assert_defined"> |
|---|
| 167 | <for list="${param}" param="p" delimiter=","> |
|---|
| 168 | <sequential> |
|---|
| 169 | <fail unless="@{p}" message="@{p} not defined" /> |
|---|
| 170 | </sequential> |
|---|
| 171 | </for> |
|---|
| 172 | </target> |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | <target name="assert_defined_and_not_empty"> |
|---|
| 176 | <for list="${param}" param="p" delimiter=","> |
|---|
| 177 | <sequential> |
|---|
| 178 | <fail unless="@{p}" message="@{p} not defined" /> |
|---|
| 179 | <if> |
|---|
| 180 | <equals arg1="${@{p}}" arg2="" /> |
|---|
| 181 | <then> |
|---|
| 182 | <fail message="@{p} is empty" /> |
|---|
| 183 | </then> |
|---|
| 184 | </if> |
|---|
| 185 | </sequential> |
|---|
| 186 | </for> |
|---|
| 187 | </target> |
|---|
| 188 | |
|---|
| 189 | <target name="for_each_project"> |
|---|
| 190 | |
|---|
| 191 | <antcall target="assert_defined"> |
|---|
| 192 | <param name="param" value="projects,target" /> |
|---|
| 193 | </antcall> |
|---|
| 194 | |
|---|
| 195 | <for list="${projects}" param="proj" delimiter=","> |
|---|
| 196 | <sequential> |
|---|
| 197 | <echo>calling ${target} for ${workspace}@{proj}</echo> |
|---|
| 198 | <ant dir="." antfile="build.xml" inheritall="false" target="${target}"> |
|---|
| 199 | <property name="proj" value="@{proj}" /> |
|---|
| 200 | </ant> |
|---|
| 201 | </sequential> |
|---|
| 202 | </for> |
|---|
| 203 | </target> |
|---|
| 204 | |
|---|
| 205 | <!-- ================================= |
|---|
| 206 | target: clean |
|---|
| 207 | ================================= --> |
|---|
| 208 | <target name="clean" depends="setup" description="--> clean module and all dependent modules"> |
|---|
| 209 | <delete failonerror="false" dir="${build.output}" /> |
|---|
| 210 | </target> |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | </project> |
|---|