|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | + |
| 3 | +<project name="JavaExamples" default="build" |
| 4 | + xmlns:ivy="antlib:org.apache.ivy.ant"> |
| 5 | + |
| 6 | + <property environment="env"/> |
| 7 | + |
| 8 | + <property name="module.name" value="JavaExamples"/> |
| 9 | + <property name="module.version" value="1.2"/> |
| 10 | + |
| 11 | + |
| 12 | + <!-- Directory / File properties --> |
| 13 | + <property name="source.dir" location="src"/> |
| 14 | + <property name="java.source.dir" location="${source.dir}/java"/> |
| 15 | + <property name="resources.source.dir" location="${source.dir}/resources"/> |
| 16 | + <property name="release.source.dir" location="${source.dir}/release"/> |
| 17 | + |
| 18 | + <property name="lib.dir" location="lib"/> |
| 19 | + |
| 20 | + <property name="dist.dir" location="dist"/> |
| 21 | + <property name="classes.dir" location="${dist.dir}/classes"/> |
| 22 | + <property name="test.classes.dir" location="dist/classes"/> <!-- Because tests are embedded in the main code. --> |
| 23 | + |
| 24 | + |
| 25 | + <property name="release.dir" location="${dist.dir}/release"/> |
| 26 | + |
| 27 | + <property name="module.jar" location="${release.dir}/${module.name}.jar"/> |
| 28 | + <property name="release.zip" location="${dist.dir}/${module.name}-${module.version}.zip"/> |
| 29 | + |
| 30 | + |
| 31 | + <!-- Ivy Repository properties --> |
| 32 | + <property name="ivy-repository.dir" value="C:/Users/Basil/Dev/IvyRepository"/> |
| 33 | + <property name="ivy-repository-pattern" |
| 34 | + value="${ivy-repository.dir}/[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision].[ext]"/> |
| 35 | + |
| 36 | + <!-- Ivy Configuration. It is itself located in the repository, but we need to configure it manually. --> |
| 37 | + <property name="ivy.version" value="2.1.0-rc1"/> |
| 38 | + <property name="ivy.dir" location="${ivy-repository.dir}/org.apache.ivy/ivy/${ivy.version}"/> |
| 39 | + <path id="ivy.lib.path"> |
| 40 | + <fileset dir="${ivy.dir}" includes="ivy-${ivy.version}*.jar"/> |
| 41 | + </path> |
| 42 | + <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/> |
| 43 | + <ivy:configure file="${basedir}/ivysettings.xml" override="true"/> |
| 44 | + |
| 45 | + |
| 46 | + <!-- Targets --> |
| 47 | + |
| 48 | + <target name="init"> |
| 49 | + <record name="${basedir}/buildoutput.txt" loglevel="verbose" append="false"/> |
| 50 | + </target> |
| 51 | + |
| 52 | + <target name="clean" depends="init"> |
| 53 | + <delete dir="${dist.dir}"/> |
| 54 | + <ivy:cleancache/> |
| 55 | + </target> |
| 56 | + |
| 57 | + <target name="resolve-dependencies" depends="init" description="Resolve dependencies for this project."> |
| 58 | + <ivy:resolve/> |
| 59 | + |
| 60 | + <!-- For the report using outputpattern="[module]-[conf].[ext]" causes invalid links |
| 61 | + between configurations as links are built using default pattern apparently. |
| 62 | + --> |
| 63 | + <ivy:report todir="${dist.dir}" conf="*" graph="false" /> |
| 64 | + |
| 65 | + <ivy:retrieve pattern="${lib.dir}/[artifact](-[classifier]).[ext]" conf="runtime" sync="true"/> |
| 66 | + </target> |
| 67 | + |
| 68 | + <target name="compile.pre" depends="init"> |
| 69 | + <!-- Example of using Ivy CachePath |
| 70 | + <ivy:cachepath pathid="ivy.compile.classpath" conf="compile" /> |
| 71 | + --> |
| 72 | + |
| 73 | + <path id="compile.classpath"> |
| 74 | + <fileset dir="${lib.dir}" includes="*.jar"/> |
| 75 | + </path> |
| 76 | + </target> |
| 77 | + |
| 78 | + <target name="test.pre" depends="init"> |
| 79 | + |
| 80 | + <path id="runtests.classpath"> |
| 81 | + <pathelement location="${test.classes.dir}"/> |
| 82 | + <pathelement location="${classes.dir}"/> |
| 83 | + <fileset dir="${lib.dir}" includes="*.jar"/> |
| 84 | + </path> |
| 85 | + </target> |
| 86 | + |
| 87 | + <target name="compile" depends="compile.pre"> |
| 88 | + <mkdir dir="${classes.dir}"/> |
| 89 | + <javac debug="on" includeAntRuntime="false" |
| 90 | + destdir="${classes.dir}" |
| 91 | + classpathref="compile.classpath"> |
| 92 | + <src path="${java.source.dir}"/> |
| 93 | + </javac> |
| 94 | + </target> |
| 95 | + |
| 96 | + <target name="test" depends="init, test.pre"> |
| 97 | + <property name="test.reports.dir" location="${dist.dir}/test-reports"/> |
| 98 | + <mkdir dir="${test.reports.dir}"/> |
| 99 | + |
| 100 | + <junit fork="yes" failureproperty="tests.failed"> |
| 101 | + |
| 102 | + <classpath refid="runtests.classpath"/> |
| 103 | + <formatter type="brief" usefile="yes"/> |
| 104 | + <formatter type="brief" usefile="false"/> |
| 105 | + |
| 106 | + <batchtest fork="no" todir="${test.reports.dir}"> |
| 107 | + <fileset dir="${test.classes.dir}" includes="**/*Test.class" excludes="**/*$*.class **/Tests.class"/> |
| 108 | + </batchtest> |
| 109 | + </junit> |
| 110 | + <fail message="Tests failed." if="tests.failed"/> |
| 111 | + </target> |
| 112 | + |
| 113 | + <target name="package.pre" depends="init"> |
| 114 | + <mkdir dir="${release.dir}"/> |
| 115 | + </target> |
| 116 | + |
| 117 | + <target name="package-release-dir" depends="package.pre"> |
| 118 | + <copy todir="${release.dir}"> |
| 119 | + <fileset dir="${release.source.dir}"/> |
| 120 | + </copy> |
| 121 | + |
| 122 | + <copy todir="${release.dir}"> |
| 123 | + <fileset dir="${basedir}" includes=".classpath,.project,*.xml"/> |
| 124 | + </copy> |
| 125 | + |
| 126 | + <copy todir="${release.dir}/src/java"> |
| 127 | + <fileset dir="${java.source.dir}"/> |
| 128 | + </copy> |
| 129 | + </target> |
| 130 | + |
| 131 | + <target name="javadoc" depends="package.pre, package-release-dir"> |
| 132 | + <property name="javadoc.dir" location="${release.dir}/javadoc"/> |
| 133 | + |
| 134 | + <javadoc |
| 135 | + destdir="${javadoc.dir}" |
| 136 | + use="true" |
| 137 | + access="protected" |
| 138 | + failOnError="true" |
| 139 | + source="1.5" |
| 140 | + linksource="yes" |
| 141 | + windowtitle="Java Examples API Documentation" |
| 142 | + classpathref="compile.classpath" |
| 143 | + overview="${release.dir}/src/java/com/basilv/examples/overview.html" |
| 144 | + > |
| 145 | + |
| 146 | + <fileset dir="${release.dir}/src/java" includes="**/*.java" defaultexcludes="yes"/> |
| 147 | + |
| 148 | + <doctitle><![CDATA[<h1>Java Examples API Documentation</h1>]]></doctitle> |
| 149 | + <bottom><![CDATA[<small> Java Examples available from <a href="http://www.basilv.com/psd/software">http://www.basilv.com/psd/software</a> Copyright © 2009 by Basil Vandegriend. All Rights Reserved.</small>]]></bottom> |
| 150 | + |
| 151 | + <link href="http://java.sun.com/javase/6/docs/api/"/> |
| 152 | + </javadoc> |
| 153 | + </target> |
| 154 | + |
| 155 | + <target name="package" depends="package.pre, package-release-dir, javadoc"> |
| 156 | + <zip destfile="${release.zip}"> |
| 157 | + <zipfileset dir="${release.dir}" prefix="${module.name}-${module.version}"/> |
| 158 | + </zip> |
| 159 | + </target> |
| 160 | + |
| 161 | + <target name="dist" |
| 162 | + depends="init, compile, package" |
| 163 | + description="Produces distributables: compiles and packages the release."/> |
| 164 | + |
| 165 | + <target name="build" |
| 166 | + depends="init, dist, test" |
| 167 | + description="Produces distributables and tests."/> |
| 168 | + |
| 169 | + <target name="all" |
| 170 | + depends="init, clean, resolve-dependencies, build" |
| 171 | + description="Cleans and builds."/> |
| 172 | + |
| 173 | + |
| 174 | + <!-- Target for maintenance of our Ivy Repository. --> |
| 175 | + |
| 176 | + <macrodef name="do-install-from-m2-to-ivyrep"> |
| 177 | + <!-- These attributes are deliberately named the same as the ivy.xml file. --> |
| 178 | + <attribute name="org"/> |
| 179 | + <attribute name="name"/> |
| 180 | + <attribute name="rev"/> |
| 181 | + <attribute name="transitive" default="true"/> |
| 182 | + <sequential> |
| 183 | + <ivy:install from="maven2-repository" to="ivy-repository" |
| 184 | + organisation="@{org}" module="@{name}" revision="@{rev}" transitive="@{transitive}" overwrite="true"/> |
| 185 | + <!-- Use overwrite="true" because installing transitive dependencies is otherwise practically impossible. |
| 186 | + I'd prefer an option to ignore already-installed modules rather than overwriting. --> |
| 187 | + </sequential> |
| 188 | + </macrodef> |
| 189 | + |
| 190 | + <target name="install-from-m2-to-ivyrep" depends="init"> |
| 191 | + <do-install-from-m2-to-ivyrep org="jdepend" name="jdepend" rev="2.9.1" transitive="true"/> |
| 192 | + <do-install-from-m2-to-ivyrep org="com.sun.xml.bind" name="jaxb-impl" rev="2.1.10" transitive="true"/> |
| 193 | + <do-install-from-m2-to-ivyrep org="log4j" name="log4j" rev="1.2.15" transitive="false"/> |
| 194 | + <do-install-from-m2-to-ivyrep org="org.antlr" name="antlr" rev="3.1.3" transitive="true"/> |
| 195 | + <do-install-from-m2-to-ivyrep org="org.apache.ivy" name="ivy" rev="2.1.0-rc1" transitive="false"/> |
| 196 | + <do-install-from-m2-to-ivyrep org="org.hibernate" name="hibernate" rev="3.2.6.ga" transitive="false"/> |
| 197 | + <do-install-from-m2-to-ivyrep org="javax.servlet" name="servlet-api" rev="2.4" transitive="true"/> |
| 198 | + <do-install-from-m2-to-ivyrep org="junit" name="junit" rev="4.6" transitive="true"/> |
| 199 | + |
| 200 | + <!-- Install fails due to some optional dependencies that cannot be found or downloaded, apparently |
| 201 | + due to errors in the Maven repository. But these dependencies are not needed to compile or test. |
| 202 | + It would be nice to be able to specify configurations to install, rather than all of them, which |
| 203 | + would be another way to resolve this issue. |
| 204 | + --> |
| 205 | + <do-install-from-m2-to-ivyrep org="org.springframework" name="spring" rev="2.5.6" transitive="true"/> |
| 206 | + |
| 207 | + </target> |
| 208 | + |
| 209 | +</project> |