Jenkins进阶系列之——16一个完整的JENKINS下的ANT BUILD.XML文件

释放双眼,带上耳机,听听看~!

 2014-12-08:已不再担任SCM和CI的职位,Jenkins系列的文章如无必要不会再维护。

网上看见的,确实很全,该有的基本都覆盖到了。自己拿来稍微改改就可以用了。

注:property中的value是你自己的一些本地变量。需要改成自己的 


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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
1<?xml version="1.0" encoding="UTF-8"?>
2<project name="genwar" default="all" basedir=".">
3
4    <description> - Generate war file - </description>
5
6    <property environment="env" />
7
8    <property name="debuglevel" value="source,lines,vars" />
9    <property name="target" value="1.6" />
10    <property name="source" value="1.6" />
11
12    <property name="output.dir" location="." />
13    <property name="output.file" value="new_cos.war" />
14
15    <property name="project.build" location="./build" />
16    <property name="project.src" location="./src" />
17    <property name="project.web" location="../web" />
18    <property name="project.lib" location="./lib" />
19    <property name="project.res" location="./res" />
20    <property name="project.svc" location="./svc" />
21
22    <property name="project.war" location="${project.build}/${output.file}" />
23
24    <property name="tmp" location="${project.build}/tmp" />
25    <property name="tmp.src" location="${tmp}/src" />
26    <property name="tmp.lib" location="${project.web}/WEB-INF/lib" />
27    <property name="tmp.bin" location="${tmp}/bin" />
28    <property name="tmp.web" location="${tmp}/web" />
29    <property name="tmp.classes" location="${tmp}/classes" />
30
31    <property name="checkstyle.dir" location="./ant-task/checkstyle" />
32    <property name="findbugs.dir" location="./ant-task/findbugs/home" />
33    <property name="findbugs.report.dir" location="./ant-task/findbugs" />
34    <property name="junit.reports.dir" value="./ant-task/junit/reports" />
35    <property name="junit.class.dir" value="./ant-task/junit/bin" />
36    <property name="junit.test.src" location="./test/java" />
37    <property name="junit.test.resources" location="./test/resources" />
38
39    <path id="javaclass.path">
40        <pathelement path="${env.classpath}" />
41        <pathelement path="${env.JBOSS_HOME}/server/all/lib/servlet-api.jar" />
42        <pathelement path="${env.JBOSS_HOME}/server/all/lib/jsp-api.jar" />
43        <fileset dir="${tmp.lib}" includes="*.jar" />
44        <!-- <fileset dir="${project.lib}" includes="*.jar" /> -->
45    </path>
46
47    <path id="findbugs.path">
48        <fileset dir="${findbugs.dir}" includes="**/*.jar" />
49    </path>
50
51    <target name="clean">
52        <delete file="${output.dir}/${output.file}" failonerror="false" />
53        <delete dir="${project.build}" failonerror="false" />
54        <mkdir dir="${project.build}" />
55    </target>
56
57    <target name="all" depends="clean,buildwar" />
58
59    <target name="initdir">
60
61        <echo message="Init directories " />
62
63        <delete dir="${tmp}" failonerror="false" />
64
65        <mkdir dir="${tmp}" />
66
67        <mkdir dir="${tmp.src}" />
68        <copy todir="${tmp.src}">
69            <fileset dir="${project.src}" excludes="**/.svn/**" />
70        </copy>
71
72        <mkdir dir="${tmp.lib}" />
73        <!--
74        <copy todir="${tmp.lib}">
75            <fileset dir="${project.web}/WEB-INF/lib" includes="*.jar" />
76        </copy>
77        -->
78
79        <mkdir dir="${tmp.bin}" />
80
81        <mkdir dir="${tmp.web}/WEB-INF/lib" />
82
83        <delete dir="${tmp.web}/WEB-INF/classes" failonerror="false" />
84        <mkdir dir="${tmp.web}/WEB-INF/classes" />
85
86    </target>
87
88    <target name="compilejava" depends="initdir">
89        <echo message="Compiling java code " />
90
91        <javac debug="true" debuglevel="${debuglevel}" destdir="${tmp.bin}" source="${source}" target="${target}" encoding="UTF-8">
92            <src path="${tmp.src}" />
93            <classpath refid="javaclass.path" />
94        </javac>
95
96        <copy todir="${tmp.web}/WEB-INF/classes" includeemptydirs="false">
97            <fileset dir="${tmp.src}">
98                <exclude name="**/*.java" />
99            </fileset>
100        </copy>
101        <copy todir="${tmp.web}/WEB-INF/classes" includeemptydirs="false">
102            <fileset dir="${tmp.bin}">
103                <include name="**/*.class" />
104            </fileset>
105        </copy>
106    </target>
107
108    <target name="compilejava-without-copy" depends="initdir">
109        <echo message="Compiling java code " />
110
111        <javac debug="true" debuglevel="${debuglevel}" destdir="${tmp.bin}" source="${source}" target="${target}" encoding="UTF-8">
112            <src path="${tmp.src}" />
113            <classpath refid="javaclass.path" />
114        </javac>
115
116    </target>
117
118    <target name="buildwar" depends="compilejava">
119
120        <echo message="Packing war file " />
121
122        <copy todir="${tmp.web}">
123            <fileset dir="${project.web}" excludes="**/.svn/**" />
124        </copy>
125
126        <delete file="${project.war}" failonerror="false" />
127        <war destfile="${project.war}" basedir="${tmp.web}" webxml="${tmp.web}/WEB-INF/web.xml" encoding="utf-8" />
128        <delete dir="${tmp}" failonerror="false" />
129
130        <delete file="${output.dir}/${output.file}" failonerror="false" />
131        <move todir="${output.dir}" includeemptydirs="false" filtering="true">
132            <fileset dir="${project.build}">
133                <include name="**/*.war" />
134            </fileset>
135        </move>
136
137        <delete dir="${project.build}" failonerror="false" />
138
139    </target>
140
141    <taskdef resource="checkstyletask.properties"
142         classpath="${checkstyle.dir}/checkstyle-5.5-all.jar"/>
143
144    <target name="checkstyle"
145        description="Generates a report of code convention violations.">
146
147        <checkstyle config="${checkstyle.dir}/my_check.xml"
148            failureProperty="checkstyle.failure" failOnViolation="false">
149            <formatter type="xml" tofile="${checkstyle.dir}/checkstyle_report.xml" />
150            <fileset dir="${project.src}" includes="**/*.java" />
151        </checkstyle>
152
153        <!-- style in="checkstyle_report.xml" out="checkstyle_report.html"
154            style="checkstyle.xsl" /-->
155
156    </target>
157
158    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
159        classpathref ="findbugs.path"/>
160
161    <target name="findbugs" depends="compilejava-without-copy"
162        description="用Findbugs检查代码错误.">
163        <echo>开始用Findbugs检查代码错误</echo>
164        <findbugs home="${findbugs.dir}" output="xml"
165            outputFile="${findbugs.report.dir}/findbugs_report.xml" >
166            <auxClasspath >
167                <path refid="junit.test.lib.path" />
168            </auxClasspath>
169            <!--auxClasspath path="${basedir}/lib/Regex.jar" /-->
170            <sourcePath path="${tmp.src}" />
171            <class location="${tmp.bin}" />
172        </findbugs>
173        <echo>Findbugs检查代码错误完成</echo>
174
175        <delete dir="${project.build}" failonerror="false" />
176    </target>
177    
178    <target name="junit-init" >
179        <delete dir="${junit.class.dir}" failonerror="false" />
180        <mkdir dir="${junit.class.dir}" />
181        <delete dir="${junit.reports.dir}/result-xml" failonerror="false" />
182        <mkdir dir="${junit.reports.dir}/result-xml" />
183        <delete dir="${junit.reports.dir}/html" failonerror="false" />
184        <mkdir dir="${junit.reports.dir}/html" />
185        <delete dir="${junit.reports.dir}/html-result" failonerror="false" />
186        <mkdir dir="${junit.reports.dir}/html-result" />
187    </target>
188
189
190    <target name="junit-compile" depends="junit-init">
191        <echo message="${project.web}/WEB-INF/lib"/>
192        <javac srcdir="${project.src}" destdir="${junit.class.dir}" source="${source}" target="${target}" encoding="UTF-8">
193            <classpath refid="junit.test.lib.path" />
194        </javac>
195        <javac srcdir="${junit.test.src}" destdir="${junit.class.dir}" source="${source}" target="${target}" encoding="UTF-8">
196            <classpath refid="junit.test.lib.path" />
197        </javac>
198        <copy todir="${junit.class.dir}">
199            <fileset dir="${junit.test.resources}">
200                <include name="**/*.xml" />
201            </fileset>
202        </copy>
203        <copy todir="${junit.class.dir}">
204            <fileset dir="${project.src}">
205                <include name="**/*.xml" />
206            </fileset>
207        </copy>
208    </target>
209
210    <path id="junit.test.lib.path">
211        <pathelement path="${env.JBOSS_HOME}/server/all/lib/servlet-api.jar" />
212        <pathelement path="${env.JBOSS_HOME}/server/all/lib/jsp-api.jar" />
213        <pathelement path="${env.JBOSS_HOME}/server/all/lib/jboss-j2ee.jar" />
214        <fileset dir="${project.web}/WEB-INF/lib" includes="**/*.jar" />
215        <fileset dir="${project.lib}" includes="**/*.jar" />
216    </path>
217    
218
219    <target name="junit-test" depends="junit-compile">
220        <junit printsummary="yes">
221            <classpath>
222                <!-- 指定lib和class路径,class和jar的声明不能混在一起 -->
223                <pathelement location="${junit.class.dir}" />
224                <path refid="junit.test.lib.path" />
225            </classpath>
226            <batchtest todir="${junit.reports.dir}/result-xml">
227                <fileset dir="${junit.test.src}" includes="**/*TestCase.java" />
228                <formatter type="xml" />
229            </batchtest>
230        </junit>
231        <junitreport todir="${junit.reports.dir}/html-result">
232            <!-- 指定测试结果的XML,即上一步产生的XML -->
233            <fileset dir="${junit.reports.dir}/result-xml">
234                <include name="TEST-*.xml" />
235            </fileset>
236            <!-- 根据测试结果XML,生成TESTS-TestSuites.xml,并由此产生HTML文件 -->
237            <report format="frames" todir="${junit.reports.dir}/html" />
238            <!--
239            -->
240        </junitreport>
241    </target>
242</project>
243

给TA打赏
共{{data.count}}人
人已打赏
安全经验

职场中的那些话那些事

2021-9-24 20:41:29

安全经验

MMORPG服务器架构

2021-11-28 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索