-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
225 lines (188 loc) · 7.08 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!--
Copyright (c) 2010, Benjamin P. Wood and Adrian Sampson, University of Washington
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University of Washington nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project name="oshajava" default="build">
<!-- properties -->
<property name="top.package" value="${ant.project.name}" />
<property name="src.dir" value="src" />
<property name="libs.dir" value="libs" />
<property name="asm.version" value="3.2" />
<property name="asm.lib" value="${libs.dir}/asm-${asm.version}/lib" />
<property name="asm.src.dir" value="${libs.dir}/asm-${asm.version}/src" />
<property name="acme.src.dir" value="${libs.dir}/acmeutils/src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="bin.dir" value="${build.dir}/bin" />
<property name="runtime.bin" value="${bin.dir}/oshajava" />
<property name="compiler.bin" value="${bin.dir}/oshajavac" />
<property name="paths.script" value="setup.sh" />
<property name="module.rm.bin" value="${bin.dir}/oshamodrm" />
<property name="module.prettyprinter" value="${bin.dir}/oshamodpp" />
<property name="agent.jar" value="${build.dir}/${ant.project.name}.jar" />
<property name="annotation.jar" value="${agent.jar}" />
<property name="agent.class" value="${top.package}.instrument.InstrumentationAgent" />
<property name="premain.class" value="${top.package}.runtime.Config" />
<property name="main.class" value="${top.package}.runtime.OshaJavaMain" />
<property name="processor.class" value="${top.package}.spec.SpecProcessor" />
<property name="class.loader" value="${top.package}.instrument.InstrumentingClassLoader" />
<!-- build targets -->
<target name="build" depends="jar,bin" description="Build ${ant.project.name}." />
<target name="clean" description="Clean build files.">
<delete dir="${build.dir}" />
<delete file="${paths.script}" />
</target>
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${asm.src.dir}" destdir="${classes.dir}" />
<javac srcdir="${acme.src.dir}" destdir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}">
<exclude name="**/oshajava/rtviz/*" />
<!-- <classpath path=".:libs/prefuse.jar"/> -->
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="${agent.jar}" index="true">
<manifest>
<attribute name="Premain-Class" value="${premain.class}" />
<attribute name="Agent-Class" value="${agent.class}" />
</manifest>
<service type="javax.annotation.processing.Processor" provider="${processor.class}" />
<fileset dir="${classes.dir}" includes="**/*.class" />
<!-- <zipfileset src="libs/prefuse.jar" /> -->
<!-- <indexjars refid="libs.classpath" /> -->
</jar>
</target>
<target name="bin">
<mkdir dir="${bin.dir}" />
<!-- Generate setup.sh to set some environment variables. -->
<echo file="${paths.script}">export PATH=$$PATH:${basedir}/${bin.dir}
export OSHAJAVA_JAR=${basedir}/${agent.jar}
export OSHAJAVA_ANNOTATION_CLASSPATH=$$OSHAJAVA_JAR
export OSHAJAVA_CLASSPATH=$$OSHAJAVA_JAR
export OSHAJAVA_PROCESSOR_CLASS=${processor.class}
</echo>
<!-- Generate the javac wrapper script -->
<echo file="${compiler.bin}">#!/bin/sh
JAVAC=javac
case "$1" in
-version)
version
exit
;;
-javac=*)
JAVAC=`echo "$1" | sed -e "s+-javac=++"`
shift
;;
esac
#echo $JAVAC -Xbootclasspath/a:${basedir}/${agent.jar} -processorpath ${basedir}/${agent.jar} -processor ${processor.class} $$@
$$JAVAC -Xbootclasspath/a:${basedir}/${agent.jar} -processorpath ${basedir}/${agent.jar} -processor ${processor.class} $$@
</echo>
<!-- Generate the java wrapper script -->
<echo file="${runtime.bin}">#!/bin/sh
OSHA_ARGS=""
JVM_ARGS=""
JVM="java"
## read osha args
while [ -n "$1" -a "-javaOptions" != "$1" -a "--" != "$1" ]
do
case "$1" in
-java=*)
JVM=`echo "$1" | sed -e "s+-java=++"`
if [ -z "$OSHA_ARGS" ]
then
OSHA_ARGS="$1"
else
OSHA_ARGS="$OSHA_ARGS,$1"
fi
;;
-*)
if [ -z "$OSHA_ARGS" ]
then
OSHA_ARGS="$1"
else
OSHA_ARGS="$OSHA_ARGS,$1"
fi
;;
esac
shift
done
if [ "-javaOptions" = "$1" ]
then
shift
fi
## read java args
while [ -n "$1" -a "--" != "$1" ]
do
case "$1" in
-jar)
shift
CLASSPATH="$1:$CLASSPATH"
test -d "META-INF" && mv META-INF META-INF.oshajava.back
jar xf $$1 META-INF/MANIFEST.MF
MAIN=`grep "^Main-Class:" META-INF/MANIFEST | awk '{print $2}'`
rm -rf META-INF
test -d "META-INF.oshajava.back" && mv META-INF.oshajava.back META-INF
;;
-cp|-classpath)
shift
CLASSPATH="$CLASSPATH:$1"
;;
*)
JVM_ARGS="$$JVM_ARGS $1"
;;
esac
shift
done
if [ -n "$1" ]
then
shift
fi
test -z "$1" && OSHA_ARGS="$OSHA_ARGS,-help"
export CLASSPATH
#echo $$JVM -javaagent:${basedir}/${agent.jar}=$$OSHA_ARGS -Xbootclasspath/a:${basedir}/${agent.jar} $$JVM_ARGS ${main.class} $$MAIN $$@
$$JVM -version
$$JVM -javaagent:${basedir}/${agent.jar}=$$OSHA_ARGS -Xbootclasspath/a:${basedir}/${agent.jar} $$JVM_ARGS ${main.class} $$MAIN $$@
</echo>
<!-- Generate the module rm script -->
<echo file="${module.rm.bin}">#!/usr/bin/env ruby
classpath = ENV['CLASSPATH']
if ARGV.first == "-cp" or ARGV.first == "-classpath"
classpath = ARGV[1]
end
classpath ||= "."
classpath.split(":").each do |d|
system "find #{d} -name '*.omi' -delete"
system "find #{d} -name '*.oms' -delete"
system "find #{d} -name '*.omm' -delete"
end
</echo>
<echo file="${module.prettyprinter}">#!/bin/sh
java -cp ${basedir}/${agent.jar} oshajava.util.ObjectFilePrinter $@
</echo>
<!-- make everything in build/bin executable -->
<chmod perm="a+x" type="file">
<fileset dir="${bin.dir}" includes="*" />
</chmod>
</target>
</project>