1<?xml version='1.0' encoding='UTF-8'?>
2<project name="Jar Jar Links" default="jar" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
3    <property file="${user.home}/build.properties" />
4    <property file="build.properties" />
5
6    <property name="javadoc.access" value="public"/>
7
8    <property name="compile.source" value="1.5"/>
9    <property name="compile.target" value="1.5"/>
10    <property name="compile.bootclasspath" value=""/>
11    <property name="compile.extdirs" value=""/>
12
13    <property name="compile.debug" value="true"/>
14    <property name="compile.deprecation" value="false"/>
15    <property name="compile.optimize" value="false"/>
16
17    <property name="src" location="src" />
18	<property name="build" location="build" />
19	<property name="dist" location="dist" />
20
21    <!-- define Maven coordinates -->
22	<property name="groupId" value="com.googlecode.jarjar" />
23	<property name="artifactId" value="jarjar" />
24    <property name="version" value="1.4"/>
25
26    <!-- define artifacts' name, which follows the convention of Maven -->
27	<property name="maven-jar" value="${dist}/${artifactId}-${version}.jar" />
28	<property name="maven-javadoc-jar" value="${dist}/${artifactId}-${version}-javadoc.jar" />
29	<property name="maven-sources-jar" value="${dist}/${artifactId}-${version}-sources.jar" />
30
31    <!-- defined maven snapshots and staging repository id and url -->
32	<property name="maven-snapshots-repository-id" value="sonatype-nexus-snapshots" />
33	<property name="maven-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
34	<property name="maven-staging-repository-id" value="sonatype-nexus-staging" />
35	<property name="maven-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
36
37
38    <property name="jarfile" value="dist/jarjar-${version}.jar"/>
39    <property name="jarfile.util" value="dist/jarjar-util-${version}.jar"/>
40    <property name="jarfile.mojo" value="dist/jarjar-plugin-${version}.jar"/>
41
42    <property name="test.jar" value="build/rejar.jar"/>
43
44    <target name="init">
45        <echo>bootclasspath ${compile.bootclasspath}</echo>
46        <tstamp/>
47        <path id="path.build">
48            <fileset dir="lib" includes="**/*.jar"/>
49        </path>
50        <path id="path.run">
51            <path refid="path.build"/>
52            <pathelement path="build/main"/>
53        </path>
54        <path id="path.test">
55            <path refid="path.run"/>
56            <pathelement path="build/test"/>
57        </path>
58    </target>
59
60    <macrodef name="compile">
61        <attribute name="module"/>
62        <attribute name="refid"/>
63        <attribute name="bootclasspath" default=""/>
64        <sequential>
65            <mkdir dir="build/@{module}"/>
66            <copy todir="build/@{module}">
67                <fileset dir="src/@{module}" excludes="**/*.java"/>
68            </copy>
69            <javac includeantruntime="true" srcdir="src/@{module}" destdir="build/@{module}"
70              source="${compile.source}"
71              target="${compile.target}" bootclasspath="@{bootclasspath}" extdirs="${compile.extdirs}"
72              debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
73                 <classpath refid="@{refid}"/>
74                 <compilerarg value="-Xlint"/>
75            </javac>
76        </sequential>
77    </macrodef>
78
79    <target name="compile" depends="init" description="Compile">
80        <compile module="main" refid="path.build" bootclasspath="${compile.bootclasspath}"/>
81        <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpathref="path.run"/>
82    </target>
83
84    <target name="compile-test" depends="compile" description="Compile tests">
85        <compile module="test" refid="path.run"/>
86    </target>
87
88    <target name="clean" description="Clean">
89        <delete dir="build"/>
90        <delete dir="dist"/>
91        <delete dir="dist/javadoc"/>
92    </target>
93
94    <target name="jar" depends="compile" description="Create Jar">
95        <mkdir dir="dist"/>
96        <jarjar jarfile="${jarfile}">
97            <fileset dir="build/main"/>
98            <zipfileset src="lib/asm-4.0.jar"/>
99            <zipfileset src="lib/asm-commons-4.0.jar">
100                <include name="org/objectweb/asm/commons/Remap*.class"/>
101                <include name="org/objectweb/asm/commons/LocalVariablesSorter.class"/>
102            </zipfileset>
103        	<keep pattern="com.tonicsystems.jarjar.Main"/>
104            <keep pattern="com.tonicsystems.jarjar.JarJarTask"/>
105            <rule pattern="com.tonicsystems.jarjar.util.**" result="com.tonicsystems.jarjar.ext_util.@1"/>
106            <rule pattern="org.objectweb.asm.**" result="com.tonicsystems.jarjar.asm.@1"/>
107            <manifest>
108                <attribute name="Main-Class" value="com.tonicsystems.jarjar.Main"/>
109                <attribute name="Implementation-Version" value="${version}"/>
110            </manifest>
111        </jarjar>
112    </target>
113
114    <target name="jar-util" depends="compile" description="Create utility Jar">
115        <mkdir dir="dist"/>
116        <jar jarfile="${jarfile.util}">
117            <fileset dir="build/main" includes="com/tonicsystems/jarjar/util/**"/>
118        </jar>
119    </target>
120
121	<target name="dist" depends="jar,dist-src,javadoc" description="generate the distribution">
122        <copy file="${dist}/jarjar-src-${version}.zip" tofile="${maven-sources-jar}" />
123        <jar jarfile="${maven-javadoc-jar}">
124			<fileset dir="${dist}/javadoc" />
125		</jar>
126	</target>
127
128    <!-- before this, update project version (both build.xml and pom.xml) from SNAPSHOT to RELEASE -->
129	<target name="stage" depends="dist" description="deploy release version to Maven staging repository">
130		<!-- sign and deploy the main artifact -->
131		<artifact:mvn>
132			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
133			<arg value="-Durl=${maven-staging-repository-url}" />
134			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
135			<arg value="-DpomFile=pom.xml" />
136			<arg value="-Dfile=${maven-jar}" />
137            <arg value="-Pgpg" />
138		</artifact:mvn>
139
140		<!-- sign and deploy the sources artifact -->
141		<artifact:mvn>
142			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
143			<arg value="-Durl=${maven-staging-repository-url}" />
144			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
145			<arg value="-DpomFile=pom.xml" />
146			<arg value="-Dfile=${maven-sources-jar}" />
147			<arg value="-Dclassifier=sources" />
148            <arg value="-Pgpg" />
149		</artifact:mvn>
150
151		<!-- sign and deploy the javadoc artifact -->
152		<artifact:mvn>
153			<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
154			<arg value="-Durl=${maven-staging-repository-url}" />
155			<arg value="-DrepositoryId=${maven-staging-repository-id}" />
156			<arg value="-DpomFile=pom.xml" />
157			<arg value="-Dfile=${maven-javadoc-jar}" />
158			<arg value="-Dclassifier=javadoc" />
159            <arg value="-Pgpg" />
160		</artifact:mvn>
161	</target>
162
163    <target name="dist-src" depends="compile" description="Create source distribution">
164        <mkdir dir="${dist}"/>
165        <zip destfile="${dist}/jarjar-src-${version}.zip">
166            <zipfileset dir="src" excludes="**/*.save" prefix="jarjar-${version}/src"/>
167            <zipfileset dir="lib" prefix="jarjar-${version}/lib"/>
168            <zipfileset dir="maven" prefix="jarjar-${version}/maven"/>
169            <zipfileset dir="." includes="build.xml,COPYING" prefix="jarjar-${version}"/>
170        </zip>
171    </target>
172
173    <target name="mojo" depends="jar" description="Create Maven plugin">
174        <mkdir dir="dist"/>
175        <copy todir="dist/maven">
176            <fileset dir="maven"/>
177            <filterset>
178                <filter token="VERSION" value="${version}"/>
179            </filterset>
180        </copy>
181        <jar jarfile="${jarfile.mojo}">
182            <zipfileset src="${jarfile}"/>
183            <zipfileset dir="dist/maven" prefix="META-INF/maven" includes="plugin.xml"/>
184            <zipfileset
185              dir="dist/maven"
186              prefix="META-INF/maven/com.tonicsystems.jarjar/jarjar-plugin"
187              includes="pom.xml,pom.properties"/>
188        </jar>
189    </target>
190
191    <target name="test" depends="junit,test-rejar,test-manifest,test-enum" description="Run tests"/>
192
193    <target name="junit" depends="compile-test">
194        <junit haltonfailure="on">
195            <!-- <jvmarg value="-Xint"/> -->
196            <!-- <jvmarg value="-Xprof"/> -->
197            <!-- <jvmarg value="-server"/> -->
198            <formatter type="plain" usefile="false"/>
199            <classpath refid="path.test"/>
200            <batchtest>
201                <fileset dir="src/test" includes="**/*Test.java"/>
202            </batchtest>
203        </junit>
204    </target>
205
206    <target name="test-rejar" depends="jar">
207        <taskdef name="jarjar2" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${jarfile}"/>
208        <delete file="${test.jar}"/>
209        <jarjar2 jarfile="${test.jar}">
210            <fileset dir="build/main"/>
211            <zipfileset src="lib/asm-4.0.jar"/>
212            <zipfileset src="lib/asm-commons-4.0.jar"/>
213            <rule pattern="org.objectweb.asm.**" result="com.tonicsystems.jarjar.asm.@1"/>
214        </jarjar2>
215        <delete file="${test.jar}"/>
216    </target>
217
218    <target name="test-enum" depends="compile">
219        <delete file="build/enumtest.jar"/>
220        <jarjar jarfile="build/enumtest.jar" verbose="true">
221            <zipfileset src="src/test/enumtest.jar"/>
222            <rule pattern="foo.**" result="bar.@1"/>
223        </jarjar>
224        <java classpath="build/enumtest.jar" classname="bar.EnumTest"/>
225        <!-- TODO: check output -->
226        <!-- <delete file="build/enumtest.jar"/> -->
227    </target>
228
229    <target name="test-manifest" depends="compile">
230        <delete>
231            <fileset dir="build" includes="manifest*.jar"/>
232        </delete>
233        <jar jarfile="build/manifest1.jar">
234            <manifest>
235                <attribute name="Built-By" value="Chris"/>
236                <attribute name="Specification-Title" value="Example"/>
237            </manifest>
238        </jar>
239        <jar jarfile="build/manifest2.jar">
240            <manifest>
241                <attribute name="Built-By" value="CJN"/>
242                <attribute name="Implementation-Title" value="common"/>
243            </manifest>
244        </jar>
245        <jar jarfile="build/manifest3.jar" filesetmanifest="merge">
246            <zipfileset src="build/manifest1.jar"/>
247            <zipfileset src="build/manifest2.jar"/>
248        </jar>
249        <jarjar jarfile="build/manifest4.jar" filesetmanifest="merge">
250            <zipfileset src="build/manifest1.jar"/>
251            <zipfileset src="build/manifest2.jar"/>
252        </jarjar>
253        <!-- TODO: check manifest contents here -->
254    </target>
255
256    <!-- TODO: reference ant javadocs -->
257    <target name="javadoc" depends="compile" description="Generate the javadoc">
258        <mkdir dir="dist/javadoc"/>
259        <javadoc
260          sourcepath="${src}/main"
261          destdir="${dist}/javadoc"
262          access="${javadoc.access}"
263          failonerror="true"
264          packagenames="com.tonicsystems.jarjar.*"
265          classpathref="path.run"
266          Author="true"
267          Version="true"
268          Use="true"
269        />
270    </target>
271</project>
272