include ePTID examples from Ian
[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         <jar destfile="${dist.dir}/${jar.name}" whenempty="fail">
145             <fileset dir="${classpathres.dir}" />
146             <zipfileset dir="${metainf.dir}" prefix="META-INF/" />
147             <zipfileset dir="${core-classes.dir}" />
148         </jar>
149
150     </target>
151
152     <target name="install" description="Installs the identity provider software.">
153         <input message="Is this a new installation? Answering yes will overwrite your current configuration. [yes|no]"
154                addproperty="new.install"
155                defaultvalue="no" />
156
157         <if>
158             <equals arg1="${new.install}" arg2="yes" />
159             <then>
160                 <input message="Where should the Shibboleth Identity Provider software be installed? [default: ${idp.home}]"
161                        addproperty="idp.home.input"
162                        defaultvalue="${idp.home}" />
163                 <var name="idp.home" value="${idp.home.input}" />
164
165                 <input message="What is the hostname of the Shibboleth Identity Provider server? [default: ${idp.hostname}]"
166                        addproperty="idp.hostname.input"
167                        defaultvalue="${idp.hostname}" />
168                 <var name="idp.hostname" value="${idp.hostname.input}" />
169                 
170                 <input message="A keystore is about to be generated for you. Please enter a password that will be used to protect it."
171                        addproperty="idp.keystore.pass" />
172
173                 <propertyfile file="install.properties">
174                     <entry key="idp.home" value="${idp.home.input}" />
175                     <entry key="idp.hostname" value="${idp.hostname.input}" />
176                 </propertyfile>
177
178                 <mkdir dir="${idp.home}" />
179                 <mkdir dir="${idp.home}/bin" />
180                 <mkdir dir="${idp.home}/conf" />
181                 <mkdir dir="${idp.home}/credentials" />
182                 <mkdir dir="${idp.home}/lib" />
183                 <mkdir dir="${idp.home}/lib/endorsed" />
184                 <mkdir dir="${idp.home}/logs" />
185                 <mkdir dir="${idp.home}/metadata" />
186                 <mkdir dir="${idp.home}/war" />
187
188                 <var name="idp.entity.id" value="https://${idp.hostname}/idp/shibboleth" />
189
190                 <regexSplit input="${idp.hostname}" regex="^.*\.(.*\..*$)" addproperty="idp.scope" />
191
192                 <echo message="Generating signing and encryption key, certificate, and keystore. " />
193                 <selfSignedCert hostname="${idp.hostname}"
194                                 privateKeyFile="${idp.home}/credentials/idp.key"
195                                 certificateFile="${idp.home}/credentials/idp.crt"
196                                 keystoreFile="${idp.home}/credentials/idp.jks"
197                                 keystorePassword="${idp.keystore.pass}"
198                                 uriSubjectAltNames="${idp.entity.id}"/>
199
200                 <copy todir="${idp.home}/bin" preservelastmodified="true">
201                     <fileset dir="${tools.dir}" />
202                     <filterset begintoken="$" endtoken="$">
203                         <filter token="IDP_HOME" value="${idp.home}" />
204                         <filter token="IDP_VERSION" value="${version}" />
205                     </filterset>
206                 </copy>
207                 <chmod file="${idp.home}/bin/*.sh" perm="+x" />
208
209                 <copy todir="${idp.home}/conf" preservelastmodified="true" overwrite="true">
210                     <fileset dir="${conf.dir}" />
211                     <filterset begintoken="$" endtoken="$">
212                         <filter token="IDP_HOME" value="${idp.home}" />
213                         <filter token="IDP_VERSION" value="${version}" />
214                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
215                         <filter token="IDP_SCOPE" value="${idp.scope}" />
216                         <filter token="IDP_CERTIFICATE" value="${idp.cert}" />
217                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
218                     </filterset>
219                 </copy>
220
221                 <stringFromFile input="${idp.home}/credentials/idp.crt" addProperty="idp.cert" />
222                 <regexSplit input="${idp.cert}"
223                             regex="\A.*-----\s((?:.*\s)*)-----END.*\Z"
224                             addproperty="idp.metadata.cert" />
225                 <copy todir="${idp.home}/metadata" preservelastmodified="true" overwrite="true">
226                     <fileset dir="${metadata.dir}" />
227                     <filterset begintoken="$" endtoken="$">
228                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
229                         <filter token="IDP_SCOPE" value="${idp.scope}" />
230                         <filter token="IDP_CERTIFICATE" value="${idp.metadata.cert}" />
231                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
232                     </filterset>
233                 </copy>
234             </then>
235         </if>
236
237         <copy todir="${idp.home}/lib" preservelastmodified="true">
238             <fileset dir="${lib.dir}" />
239             <fileset file="${dist.dir}/${jar.name}" />
240             <fileset file="${build-lib.dir}/servlet-2.4.jar" />
241         </copy>
242             
243         <copy todir="${idp.home}/lib/endorsed" preservelastmodified="true" failonerror="false">
244             <fileset dir="endorsed" />
245         </copy>
246
247         <copy todir="${webinf-temp.dir}">
248             <fileset dir="${webinf.dir}" />
249             <filterset begintoken="$" endtoken="$">
250                 <filter token="IDP_HOME" value="${idp.home}" />
251                 <filter token="IDP_VERSION" value="${version}" />
252             </filterset>
253         </copy>
254
255         <jar destfile="${idp.home}/war/${war.name}" whenempty="fail">
256             <zipfileset dir="${webinf-temp.dir}" prefix="WEB-INF/" />
257             <zipfileset dir="${webpages.dir}" prefix="" />
258             <zipfileset dir="${lib.dir}" prefix="WEB-INF/lib/" />
259             <zipfileset file="${dist.dir}/${jar.name}" prefix="WEB-INF/lib/" />
260         </jar>
261     </target>
262
263     <!-- **************************************************************** -->
264     <!-- ***                                                          *** -->
265     <!-- ***                     Developer Tasks                      *** -->
266     <!-- ***                                                          *** -->
267     <!-- **************************************************************** -->
268
269     <!-- Checks code against style guidelines -->
270     <target name="checkstyle" description="Developer task: Produces coding standard compliance report.">
271         <mkdir dir="${reports.dir}" />
272
273         <checkstyle config="${basedir}/checkstyle.xml" failOnViolation="false" classpathref="build-path">
274             <fileset dir="src" includes="**/*.java" />
275             <formatter type="plain" toFile="${reports.dir}/checkstyle-report.txt" />
276         </checkstyle>
277     </target>
278
279 </project>