Richard S. Hall | 6fe36b4 | 2009-07-13 13:25:46 +0000 | [diff] [blame^] | 1 | <?xml version="1.0"> |
| 2 | <!-- |
| 3 | Licensed to the Apache Software Foundation (ASF) under one |
| 4 | or more contributor license agreements. See the NOTICE file |
| 5 | distributed with this work for additional information |
| 6 | regarding copyright ownership. The ASF licenses this file |
| 7 | to you under the Apache License, Version 2.0 (the |
| 8 | "License"); you may not use this file except in compliance |
| 9 | with the License. You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, |
| 14 | software distributed under the License is distributed on an |
| 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | KIND, either express or implied. See the License for the |
| 17 | specific language governing permissions and limitations |
| 18 | under the License. |
| 19 | --> |
| 20 | <project name="common" |
| 21 | xmlns:ivy="antlib:org.apache.ivy.ant"> |
| 22 | <!-- a sample common ant build file, used for ivy multi-project tutorial |
| 23 | feel free to copy and adapt it to your own needs |
| 24 | Note that the only targets specific to ivy are: |
| 25 | load-ivy |
| 26 | resolve |
| 27 | report |
| 28 | ivy-new-version |
| 29 | publish |
| 30 | publish-local |
| 31 | |
| 32 | All other targets are usual ant based targets, which could have been written |
| 33 | in a build not depending at all on ivy: |
| 34 | resolve constructs a lib directory based upon ivy dependencies, and then the lib dir |
| 35 | is used as in any classical ant build |
| 36 | --> |
| 37 | |
| 38 | <property file="${common.dir}/build.properties"/> |
| 39 | |
| 40 | <!-- ================================= |
| 41 | target: load-ivy |
| 42 | this target is not necessary if you put ivy.jar in your ant lib directory |
| 43 | if you already have ivy 2.0 in your ant lib, you can simply remove this |
| 44 | target |
| 45 | ================================= --> |
| 46 | |
| 47 | <target name="load-ivy" depends="ivy-taskdefs"> |
| 48 | <ivy:settings file="${common.dir}/ivysettings.xml" /> |
| 49 | </target> |
| 50 | |
| 51 | <target name="ivy-taskdefs" unless="ivy.loaded"> |
| 52 | <property name="ivy.loaded" value="true"/> |
| 53 | <echo message="Loading Ivy ..."/> |
| 54 | <taskdef resource="org/apache/ivy/ant/antlib.xml" |
| 55 | uri="antlib:org.apache.ivy.ant" |
| 56 | classpath="${ivy.jar}"/> |
| 57 | |
| 58 | <taskdef name="sigil.bundle" |
| 59 | classname="org.cauldron.bld.ant.BundleTask" |
| 60 | classpath="${sigil-ivy-plugin.jar}"/> |
| 61 | </target> |
| 62 | |
| 63 | <path id="lib.path.id"> |
| 64 | <fileset dir="${lib.dir}" /> |
| 65 | </path> |
| 66 | |
| 67 | <path id="run.path.id"> |
| 68 | <path refid="lib.path.id" /> |
| 69 | <path location="${classes.dir}" /> |
| 70 | </path> |
| 71 | |
| 72 | |
| 73 | <!-- setup ivy default configuration with some custom info --> |
| 74 | <property name="ivy.local.default.root" value="${repository.dir}/local"/> |
| 75 | <property name="ivy.shared.default.root" value="${repository.dir}/shared"/> |
| 76 | |
| 77 | <!-- here is how we would have configured ivy if we had our own ivysettings file |
| 78 | <ivy:settings file="${common.dir}/ivysettings.xml" /> |
| 79 | --> |
| 80 | |
| 81 | <!-- ================================= |
| 82 | target: hello |
| 83 | ================================= --> |
| 84 | <target name="hello" description="--> identify project (useful to test buildlist)"> |
| 85 | <echo message="${ant.project.name}"/> |
| 86 | </target> |
| 87 | |
| 88 | <!-- ================================= |
| 89 | target: resolve |
| 90 | ================================= --> |
| 91 | <target name="resolve" depends="clean-lib, load-ivy" description="--> resolve and retrieve dependencies with ivy"> |
| 92 | <mkdir dir="${lib.dir}"/> <!-- not usually necessary, ivy creates the directory IF there are dependencies --> |
| 93 | |
| 94 | <!-- the call to resolve is not mandatory, retrieve makes an implicit call if we don't --> |
| 95 | <ivy:resolve file="${ivy.file}"/> |
| 96 | <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" /> |
| 97 | </target> |
| 98 | |
| 99 | <!-- ================================= |
| 100 | target: report |
| 101 | ================================= --> |
| 102 | <target name="report" depends="resolve" description="--> generates a report of dependencies"> |
| 103 | <ivy:report todir="${build.dir}"/> |
| 104 | </target> |
| 105 | |
| 106 | <!-- ================================= |
| 107 | target: compile |
| 108 | ================================= --> |
| 109 | <target name="compile" depends="resolve" description="--> compile the project"> |
| 110 | <mkdir dir="${classes.dir}" /> |
| 111 | <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id" debug="true" /> |
| 112 | </target> |
| 113 | |
| 114 | <!-- ================================= |
| 115 | target: run |
| 116 | ================================= --> |
| 117 | <target name="run" depends="version, compile" description="--> compile and run the project"> |
| 118 | <java classpathref="run.path.id" classname="${main.class.name}"/> |
| 119 | </target> |
| 120 | |
| 121 | <target name="ivy-new-version" depends="load-ivy" unless="ivy.new.revision"> |
| 122 | <!-- default module version prefix value --> |
| 123 | <property name="module.version.prefix" value="${module.version.target}-dev-b" /> |
| 124 | |
| 125 | <!-- asks to ivy an available version number --> |
| 126 | <ivy:info file="${ivy.file}" /> |
| 127 | <ivy:buildnumber |
| 128 | organisation="${ivy.organisation}" module="${ivy.module}" |
| 129 | revision="${module.version.prefix}" defaultBuildNumber="1" revSep=""/> |
| 130 | </target> |
| 131 | |
| 132 | <target name="local-version"> |
| 133 | <tstamp> |
| 134 | <format property="now" pattern="yyyyMMddHHmmss"/> |
| 135 | </tstamp> |
| 136 | <property name="ivy.new.revision" value="${module.version.target}-local-${now}"/> |
| 137 | </target> |
| 138 | |
| 139 | <target name="version" depends="ivy-new-version"> |
| 140 | <!-- create version file in classpath for later inclusion in jar --> |
| 141 | <mkdir dir="${classes.dir}"/> |
| 142 | <echo message="version=${ivy.new.revision}" file="${classes.dir}/${ant.project.name}.properties" append="false" /> |
| 143 | |
| 144 | <!-- load generated version properties file --> |
| 145 | <property file="${classes.dir}/${ant.project.name}.properties" /> |
| 146 | </target> |
| 147 | |
| 148 | <!-- ================================= |
| 149 | target: jar |
| 150 | ================================= --> |
| 151 | <target name="jar" depends="version, compile" description="--> make a jar file for this project"> |
| 152 | |
| 153 | <!-- |
| 154 | <jar destfile="${jar.file}"> |
| 155 | <fileset dir="${classes.dir}" /> |
| 156 | <manifest> |
| 157 | <attribute name="Built-By" value="${user.name}"/> |
| 158 | <attribute name="Build-Version" value="${version}" /> |
| 159 | </manifest> |
| 160 | </jar> |
| 161 | --> |
| 162 | |
| 163 | <sigil.bundle destpattern="${build.dir}/[id].[ext]" |
| 164 | classpathref="run.path.id"/> |
| 165 | </target> |
| 166 | |
| 167 | <!-- ================================= |
| 168 | target: publish |
| 169 | ================================= --> |
| 170 | <target name="publish" depends="clean-build, jar" description="--> publish this project in the ivy repository"> |
| 171 | <ivy:publish artifactspattern="${build.dir}/[artifact].[ext]" |
| 172 | resolver="shared" |
| 173 | pubrevision="${version}" |
| 174 | status="release" |
| 175 | /> |
| 176 | <echo message="project ${ant.project.name} released with version ${version}" /> |
| 177 | </target> |
| 178 | |
| 179 | <!-- ================================= |
| 180 | target: publish-local |
| 181 | ================================= --> |
| 182 | <target name="publish-local" depends="local-version, jar" description="--> publish this project in the local ivy repository"> |
| 183 | <ivy:publish artifactspattern="${build.dir}/[artifact].[ext]" |
| 184 | resolver="local" |
| 185 | pubrevision="${version}" |
| 186 | pubdate="${now}" |
| 187 | status="integration" |
| 188 | forcedeliver="true" |
| 189 | /> |
| 190 | <echo message="project ${ant.project.name} published locally with version ${version}" /> |
| 191 | </target> |
| 192 | |
| 193 | <!-- ================================= |
| 194 | target: clean-local |
| 195 | ================================= --> |
| 196 | <target name="clean-local" description="--> cleans the local repository for the current module"> |
| 197 | <delete dir="${ivy.local.default.root}/${ant.project.name}"/> |
| 198 | </target> |
| 199 | |
| 200 | <!-- ================================= |
| 201 | target: clean-lib |
| 202 | ================================= --> |
| 203 | <target name="clean-lib" description="--> clean the project libraries directory (dependencies)"> |
| 204 | <delete includeemptydirs="true" dir="${lib.dir}"/> |
| 205 | </target> |
| 206 | |
| 207 | <!-- ================================= |
| 208 | target: clean-build |
| 209 | ================================= --> |
| 210 | <target name="clean-build" description="--> clean the project built files"> |
| 211 | <delete includeemptydirs="true" dir="${build.dir}"/> |
| 212 | </target> |
| 213 | |
| 214 | <!-- ================================= |
| 215 | target: clean |
| 216 | ================================= --> |
| 217 | <target name="clean" depends="clean-build, clean-lib" description="--> clean the project" /> |
| 218 | </project> |