2532af985e09d9a375dfc9e35148ee474cef0bf6
[java-idp.git] / build.xml
1 <project name="Shibboleth Identity Provider" basedir="." default="install">
2
3         <!-- User based property file that overrides any property below -->
4         <property file="${user.name}-build.properties" />
5
6         <!-- Project based property file -->
7         <property file="build.properties" />
8
9         <!-- Installation specific property file -->
10         <property file="install.properties" />
11
12         <!-- Load ant-contrib tasks -->
13         <taskdef resource="net/sf/antcontrib/antlib.xml" />
14
15         <!-- Load Checkstyle tasks -->
16         <taskdef resource="checkstyletask.properties" />
17
18         <!-- Classpath for building core classes-->
19         <path id="build-path">
20                 <fileset dir="${build-lib.dir}" includes="**/*.jar" />
21                 <fileset dir="${lib.dir}" includes="**/*.jar" />
22         </path>
23
24         <!-- Classpath for testing classes-->
25         <path id="test-path">
26                 <path refid="build-path" />
27                 <pathelement location="${core-classes.dir}" />
28                 <pathelement location="${core-src.dir}" />
29                 <pathelement location="${test-classes.dir}" />
30                 <pathelement location="${test-classes.dir}/data" />
31                 <pathelement location="${test-classes.dir}/log4j.xml" />
32                 <pathelement location="${test-src.dir}" />
33                 <pathelement location="${classpathres.dir}" />
34         </path>
35
36         <!-- Prepare directory structure for build -->
37         <target name="build-init">
38                 <mkdir dir="${build.dir}" />
39         </target>
40
41         <!-- Compile core (non-test) classes -->
42         <target name="compile-core" depends="build-init, clean-compile">
43                 <mkdir dir="${core-prep-source.dir}" />
44                 <mkdir dir="${core-classes.dir}" />
45
46                 <copy todir="${core-prep-source.dir}" preservelastmodified="true">
47                         <fileset dir="${core-src.dir}" />
48                         <filterset begintoken="$" endtoken="$">
49                                 <filter token="IDP_HOME" value="${idp.home}" />
50                                 <filter token="IDP_VERSION" value="${version}" />
51                         </filterset>
52                 </copy>
53
54                 <javac srcdir="${core-prep-source.dir}" destdir="${core-classes.dir}" includes="**/*.java" debug="on" source="1.5">
55                         <classpath refid="build-path" />
56                 </javac>
57
58                 <delete dir="${core-prep-source.dir}" />
59                 
60         </target>
61
62         <!-- Compile unit test classes -->
63         <target name="compile-test" depends="compile-core">
64                 <mkdir dir="${test-classes.dir}" />
65
66                 <javac srcdir="${test-src.dir}" destdir="${test-classes.dir}" includes="**/*.java" debug="on" source="1.5">
67                         <classpath refid="test-path" />
68                 </javac>
69
70         </target>
71
72         <!-- Compile and run unit tests -->
73         <target name="test" depends="compile-core, compile-test" description="Runs the unit tests for the project.">
74                 <mkdir dir="${test-results.dir}" />
75
76                 <echo message="Excuting unit tests using endorsed directory ${java.endorsed.dirs}" />
77                 <junit printsummary="off" fork="yes" forkmode="once" haltonerror="false" haltonfailure="false" dir="${basedir}" errorproperty="testFailed">
78                         <jvmarg value="-Djava.endorsed.dirs=${java.endorsed.dirs}" />
79                         <classpath refid="test-path" />
80                         <formatter type="xml" />
81                         <batchtest todir="${test-results.dir}">
82                                 <fileset dir="${test-classes.dir}">
83                                         <include name="**/*Test.class" />
84                                 </fileset>
85                         </batchtest>
86                 </junit>
87                 <junitreport todir="${test-results.dir}">
88                         <fileset dir="${test-results.dir}">
89                                 <include name="TEST-*.xml" />
90                         </fileset>
91                         <report format="frames" todir="${test-report.dir}" />
92                 </junitreport>
93
94                 <echo message="Test report available at ${test-report.dir}/index.html" />
95                 <fail if="testFailed" message="Test failure; see ${test-report.dir}/index.html for more information." />
96         </target>
97
98         <!-- Javadoc core (non-test) classes -->
99         <target name="javadoc" description="Creates the JavaDoc documentatin for the project.">
100                 <mkdir dir="${javadoc.dir}" />
101                 <javadoc packagenames="org.opensaml.*" sourcepath="${core-src.dir}" destdir="${javadoc.dir}" author="false" version="true" windowtitle="${ant.project.name} ${version} Java API" doctitle="${ant.project.name} ${version} Java API" bottom="${copyright}" overview="${core-src.dir}/overview.html">
102                         <classpath refid="build-path" />
103                 </javadoc>
104         </target>
105
106         <!-- Removes previously compiled files -->
107         <target name="clean-compile">
108                 <delete dir="${build.dir}" />
109                 <delete dir="${dist.dir}" />
110         </target>
111
112         <!-- Removes all build generated content -->
113         <target name="clean" depends="clean-compile" description="Removes any artifact produced by the build process.">
114                 <delete dir="${javadoc.dir}" />
115                 <delete dir="${reports.dir}" />
116                 <delete dir="${dist.dir}" />
117         </target>
118
119         <!-- Create JAR file -->
120         <target name="package" depends="compile-core" description="Creates the project library jar file.">
121                 <mkdir dir="${dist.dir}" />
122
123                 <if>
124                         <equals arg1="${jdk.target}" arg2="1.4" />
125                         <then>
126                                 <java classname="com.rc.retroweaver.Weaver">
127                                         <arg value="-source" />
128                                         <arg value="${core-classes.dir}" />
129                                         <classpath>
130                                                 <fileset dir="${thirdpaty-lib.dir}">
131                                                         <include name="**/*.jar" />
132                                                 </fileset>
133                                         </classpath>
134                                 </java>
135
136                                 <echo message="**************************************************************" />
137                                 <echo message="    Remember, you must include the retroweaver-rt jar" />
138                                 <echo message="    file, located in the thirdparty-lib directory, along with the" />
139                                 <echo message="    ${jar.name} on your" />
140                                 <echo message="    classpath in order to use this with JDK 1.4" />
141                                 <echo message="**************************************************************" />
142
143                         </then>
144                 </if>
145
146                 <jar destfile="${dist.dir}/${jar.name}" whenempty="fail">
147                         <fileset dir="${classpathres.dir}" />
148                         <zipfileset dir="${metainf.dir}" prefix="META-INF/" />
149                         <zipfileset dir="${core-classes.dir}" />
150                 </jar>
151
152         </target>
153
154         <target name="install" depends="package" description="Installs the identity provider software.">
155                 <mkdir dir="${idp.home}" />
156                 <mkdir dir="${idp.home}/lib" />
157                 <mkdir dir="${idp.home}/conf" />
158                 <mkdir dir="${idp.home}/logs" />
159                 <mkdir dir="${idp.home}/bin" />
160                 <mkdir dir="${idp.home}/war" />
161                 <mkdir dir="${idp.home}/metadata" />
162         <mkdir dir="${idp.home}/credentials" />
163
164                 <copy todir="${idp.home}/lib" preservelastmodified="true">
165                         <fileset dir="${lib.dir}" />
166                         <fileset file="${dist.dir}/${jar.name}" />
167                         <fileset file="${build-lib.dir}/servlet-2.4.jar" />
168                 </copy>
169
170                 <if>
171                         <available file="${idp.home}/conf" />
172                         <then>
173                                 <mkdir dir="${idp.home}/conf.bak" />
174                                 <copy todir="${idp.home}/conf.bak" preservelastmodified="true">
175                                         <fileset dir="${idp.home}/conf" />
176                                 </copy>
177                         </then>
178                 </if>
179
180                 <copy todir="${idp.home}/conf" preservelastmodified="true" overwrite="${idp.overwrite-config}">
181                         <fileset dir="${conf.dir}" />
182                         <filterset begintoken="$" endtoken="$">
183                                 <filter token="IDP_HOME" value="${idp.home}" />
184                                 <filter token="IDP_VERSION" value="${version}" />
185                         </filterset>
186                 </copy>
187
188                 <copy todir="${idp.home}/bin" preservelastmodified="true">
189                         <fileset dir="${tools.dir}" />
190                         <filterset begintoken="$" endtoken="$">
191                                 <filter token="IDP_HOME" value="${idp.home}" />
192                                 <filter token="IDP_VERSION" value="${version}" />
193                         </filterset>
194                 </copy>
195
196                 <chmod file="${idp.home}/bin/*.sh" perm="+x" />
197
198                 <copy todir="${webinf-temp.dir}">
199                         <fileset dir="${webinf.dir}" />
200                         <filterset begintoken="$" endtoken="$">
201                                 <filter token="IDP_HOME" value="${idp.home}" />
202                                 <filter token="IDP_VERSION" value="${version}" />
203                         </filterset>
204                 </copy>
205                 <jar destfile="${idp.home}/war/${war.name}" whenempty="fail">
206                         <zipfileset dir="${webinf-temp.dir}" prefix="WEB-INF/" />
207                         <zipfileset dir="${webpages.dir}" prefix="" />
208                         <zipfileset dir="${lib.dir}" prefix="WEB-INF/lib/" />
209                         <zipfileset file="${dist.dir}/${jar.name}" prefix="WEB-INF/lib/" />
210                 </jar>
211
212         </target>
213
214         <!-- **************************************************************** -->
215         <!-- ***                                                          *** -->
216         <!-- ***                     Developer Tasks                      *** -->
217         <!-- ***                                                          *** -->
218         <!-- **************************************************************** -->
219
220         <!-- Checks code against style guidelines -->
221         <target name="checkstyle" description="Developer task: Produces coding standard compliance report.">
222                 <mkdir dir="${reports.dir}" />
223
224                 <checkstyle config="${basedir}/checkstyle.xml" failOnViolation="false" classpathref="build-path">
225                         <fileset dir="src" includes="**/*.java" />
226                         <formatter type="plain" toFile="${reports.dir}/checkstyle-report.txt" />
227                 </checkstyle>
228         </target>
229
230 </project>