afd2a0a81cd6bf33eba44ba8101f738dc5387827
[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 Internet2 ant extensions -->
16     <taskdef resource="edu/internet2/middleware/ant/antlib.xml" />
17
18     <!-- Load Checkstyle tasks -->
19     <taskdef resource="checkstyletask.properties" />
20
21     <!-- Classpath for building core classes-->
22     <path id="build-path">
23         <fileset dir="${build-lib.dir}" includes="**/*.jar" />
24         <fileset dir="${lib.dir}" includes="**/*.jar" />
25     </path>
26
27     <!-- Classpath for testing classes-->
28     <path id="test-path">
29         <path refid="build-path" />
30         <pathelement location="${core-classes.dir}" />
31         <pathelement location="${core-src.dir}" />
32         <pathelement location="${test-classes.dir}" />
33         <pathelement location="${test-classes.dir}/data" />
34         <pathelement location="${test-classes.dir}/log4j.xml" />
35         <pathelement location="${test-src.dir}" />
36         <pathelement location="${classpathres.dir}" />
37     </path>
38
39     <!-- Prepare directory structure for build -->
40     <target name="build-init">
41         <mkdir dir="${build.dir}" />
42     </target>
43
44     <!-- Compile core (non-test) classes -->
45     <target name="compile-core" depends="build-init, clean-compile">
46         <mkdir dir="${core-prep-source.dir}" />
47         <mkdir dir="${core-classes.dir}" />
48
49         <copy todir="${core-prep-source.dir}" preservelastmodified="true">
50             <fileset dir="${core-src.dir}" />
51             <filterset begintoken="$" endtoken="$">
52                 <filter token="IDP_HOME" value="${idp.home}" />
53                 <filter token="IDP_VERSION" value="${version}" />
54             </filterset>
55         </copy>
56
57         <javac srcdir="${core-prep-source.dir}"
58                destdir="${core-classes.dir}"
59                includes="**/*.java"
60                debug="on"
61                source="1.5">
62             <classpath refid="build-path" />
63         </javac>
64
65         <delete dir="${core-prep-source.dir}" />
66
67     </target>
68
69     <!-- Compile unit test classes -->
70     <target name="compile-test" depends="compile-core">
71         <mkdir dir="${test-classes.dir}" />
72
73         <javac srcdir="${test-src.dir}" destdir="${test-classes.dir}" includes="**/*.java" debug="on" source="1.5">
74             <classpath refid="test-path" />
75         </javac>
76
77     </target>
78
79     <!-- Compile and run unit tests -->
80     <target name="test" depends="compile-core, compile-test" description="Runs the unit tests for the project.">
81         <mkdir dir="${test-results.dir}" />
82
83         <echo message="Excuting unit tests using endorsed directory ${java.endorsed.dirs}" />
84         <junit printsummary="off"
85                fork="yes"
86                forkmode="once"
87                haltonerror="false"
88                haltonfailure="false"
89                dir="${basedir}"
90                errorproperty="testFailed">
91             <jvmarg value="-Djava.endorsed.dirs=${java.endorsed.dirs}" />
92             <classpath refid="test-path" />
93             <formatter type="xml" />
94             <batchtest todir="${test-results.dir}">
95                 <fileset dir="${test-classes.dir}">
96                     <include name="**/*Test.class" />
97                 </fileset>
98             </batchtest>
99         </junit>
100         <junitreport todir="${test-results.dir}">
101             <fileset dir="${test-results.dir}">
102                 <include name="TEST-*.xml" />
103             </fileset>
104             <report format="frames" todir="${test-report.dir}" />
105         </junitreport>
106
107         <echo message="Test report available at ${test-report.dir}/index.html" />
108         <fail if="testFailed" message="Test failure; see ${test-report.dir}/index.html for more information." />
109     </target>
110
111     <!-- Javadoc core (non-test) classes -->
112     <target name="javadoc" description="Creates the JavaDoc documentatin for the project.">
113         <mkdir dir="${javadoc.dir}" />
114         <javadoc packagenames="org.opensaml.*"
115                  sourcepath="${core-src.dir}"
116                  destdir="${javadoc.dir}"
117                  author="false"
118                  version="true"
119                  windowtitle="${ant.project.name} ${version} Java API"
120                  doctitle="${ant.project.name} ${version} Java API"
121                  bottom="${copyright}"
122                  overview="${core-src.dir}/overview.html">
123             <classpath refid="build-path" />
124         </javadoc>
125     </target>
126
127     <!-- Removes previously compiled files -->
128     <target name="clean-compile">
129         <delete dir="${build.dir}" />
130         <delete dir="${dist.dir}" />
131     </target>
132
133     <!-- Removes all build generated content -->
134     <target name="clean" depends="clean-compile" description="Removes any artifact produced by the build process.">
135         <delete dir="${javadoc.dir}" />
136         <delete dir="${reports.dir}" />
137         <delete dir="${dist.dir}" />
138     </target>
139
140     <!-- Create JAR file -->
141     <target name="package" depends="compile-core" description="Creates the project library jar file.">
142         <mkdir dir="${dist.dir}" />
143
144         <if>
145             <equals arg1="${jdk.target}" arg2="1.4" />
146             <then>
147                 <java classname="com.rc.retroweaver.Weaver">
148                     <arg value="-source" />
149                     <arg value="${core-classes.dir}" />
150                     <classpath>
151                         <fileset dir="${thirdpaty-lib.dir}">
152                             <include name="**/*.jar" />
153                         </fileset>
154                     </classpath>
155                 </java>
156
157                 <echo message="**************************************************************" />
158                 <echo message="    Remember, you must include the retroweaver-rt jar" />
159                 <echo message="    file, located in the thirdparty-lib directory, along with the" />
160                 <echo message="    ${jar.name} on your" />
161                 <echo message="    classpath in order to use this with JDK 1.4" />
162                 <echo message="**************************************************************" />
163
164             </then>
165         </if>
166
167         <jar destfile="${dist.dir}/${jar.name}" whenempty="fail">
168             <fileset dir="${classpathres.dir}" />
169             <zipfileset dir="${metainf.dir}" prefix="META-INF/" />
170             <zipfileset dir="${core-classes.dir}" />
171         </jar>
172
173     </target>
174
175     <target name="install" depends="package" description="Installs the identity provider software.">
176         <mkdir dir="${idp.home}" />
177         <mkdir dir="${idp.home}/bin" />
178         <mkdir dir="${idp.home}/conf" />
179         <mkdir dir="${idp.home}/credentials" />
180         <mkdir dir="${idp.home}/lib" />
181         <mkdir dir="${idp.home}/logs" />
182         <mkdir dir="${idp.home}/metadata" />
183         <mkdir dir="${idp.home}/war" />
184
185
186         <input message="Is this a new installation? Answering yes will overwrite your current configuration. [yes|no]"
187                addproperty="new.install"
188                defaultvalue="no" />
189
190         <if>
191             <equals arg1="${new.install}" arg2="yes" />
192             <then>
193                 <input message="Where should the Shibboleth Identity Provider software be installed? [default: ${idp.home}]"
194                        addproperty="idp.home.input"
195                        defaultvalue="${idp.home}" />
196                 <var name="idp.home" value="${idp.home.input}" />
197
198                 <input message="What is the hostname of the Shibboleth Identity Provider server? [default: ${idp.hostname}]"
199                        addproperty="idp.hostname.inout"
200                     defaultvalue="${idp.hostname}"/>
201                 <var name="idp.hostname" value="${idp.hostname.input}" />
202
203                 <propertyfile file="build.properties">
204                     <var name="idp.hostname" value="${idp.hostname}" />
205                     <entry key="idp.home" value="${idp.home}" />
206                 </propertyfile>
207
208                 <var name="idp.entity.id" value="https://${idp.hostname}/shibboleth" />
209
210                 <regexSplit input="${idp.hostname}" regex="^.*\.(.*\..*$)" addproperty="idp.scope" />
211
212                 <echo message="Generating signing and encryption key and certificate. " />
213                 <selfSignedCert hostname="${idp.hostname}"
214                                 privateKeyFile="${idp.home}/credentials/idp.key"
215                                 certificateFile="${idp.home}/credentials/idp.crt" />
216
217                 <copy todir="${idp.home}/bin" preservelastmodified="true">
218                     <fileset dir="${tools.dir}" />
219                     <filterset begintoken="$" endtoken="$">
220                         <filter token="IDP_HOME" value="${idp.home}" />
221                         <filter token="IDP_VERSION" value="${version}" />
222                     </filterset>
223                 </copy>
224                 <chmod file="${idp.home}/bin/*.sh" perm="+x" />
225
226                 <copy todir="${idp.home}/conf" preservelastmodified="true" overwrite="${idp.overwrite-config}">
227                     <fileset dir="${conf.dir}" />
228                     <filterset begintoken="$" endtoken="$">
229                         <filter token="IDP_HOME" value="${idp.home}" />
230                         <filter token="IDP_VERSION" value="${version}" />
231                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
232                         <filter token="IDP_SCOPE" value="${idp.scope}" />
233                         <filter token="IDP_CERTIFICATE" value="${idp.cert}" />
234                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
235                     </filterset>
236                 </copy>
237
238                 <stringFromFile input="${idp.home}/credentials/idp.crt" addProperty="idp.cert" />
239                 <regexSplit input="${idp.cert}"
240                             regex="\A.*-----\s((?:.*\s)*)-----END.*\Z"
241                             addproperty="idp.metadata.cert" />
242                 <copy todir="${idp.home}/metadata" preservelastmodified="true" overwrite="${idp.overwrite-config}">
243                     <fileset dir="${metadata.dir}" />
244                     <filterset begintoken="$" endtoken="$">
245                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
246                         <filter token="IDP_SCOPE" value="${idp.scope}" />
247                         <filter token="IDP_CERTIFICATE" value="${idp.metadata.cert}" />
248                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
249                     </filterset>
250                 </copy>
251             </then>
252         </if>
253
254         <copy todir="${idp.home}/lib" preservelastmodified="true">
255             <fileset dir="${lib.dir}" />
256             <fileset file="${dist.dir}/${jar.name}" />
257             <fileset file="${build-lib.dir}/servlet-2.4.jar" />
258         </copy>
259
260         <copy todir="${webinf-temp.dir}">
261             <fileset dir="${webinf.dir}" />
262             <filterset begintoken="$" endtoken="$">
263                 <filter token="IDP_HOME" value="${idp.home}" />
264                 <filter token="IDP_VERSION" value="${version}" />
265             </filterset>
266         </copy>
267
268         <jar destfile="${idp.home}/war/${war.name}" whenempty="fail">
269             <zipfileset dir="${webinf-temp.dir}" prefix="WEB-INF/" />
270             <zipfileset dir="${webpages.dir}" prefix="" />
271             <zipfileset dir="${lib.dir}" prefix="WEB-INF/lib/" />
272             <zipfileset file="${dist.dir}/${jar.name}" prefix="WEB-INF/lib/" />
273         </jar>
274     </target>
275
276
277     <!-- **************************************************************** -->
278     <!-- ***                                                          *** -->
279     <!-- ***                     Developer Tasks                      *** -->
280     <!-- ***                                                          *** -->
281     <!-- **************************************************************** -->
282
283     <!-- Checks code against style guidelines -->
284     <target name="checkstyle" description="Developer task: Produces coding standard compliance report.">
285         <mkdir dir="${reports.dir}" />
286
287         <checkstyle config="${basedir}/checkstyle.xml" failOnViolation="false" classpathref="build-path">
288             <fileset dir="src" includes="**/*.java" />
289             <formatter type="plain" toFile="${reports.dir}/checkstyle-report.txt" />
290         </checkstyle>
291     </target>
292
293 </project>