tag attempted authentication trip
[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                 <propertyfile file="install.properties">
171                     <entry key="idp.home" value="${idp.home.input}" />
172                     <entry key="idp.hostname" value="${idp.hostname.input}" />
173                 </propertyfile>
174
175                 <mkdir dir="${idp.home}" />
176                 <mkdir dir="${idp.home}/bin" />
177                 <mkdir dir="${idp.home}/conf" />
178                 <mkdir dir="${idp.home}/credentials" />
179                 <mkdir dir="${idp.home}/lib" />
180                 <mkdir dir="${idp.home}/logs" />
181                 <mkdir dir="${idp.home}/metadata" />
182                 <mkdir dir="${idp.home}/war" />
183
184                 <var name="idp.entity.id" value="https://${idp.hostname}/idp/shibboleth" />
185
186                 <regexSplit input="${idp.hostname}" regex="^.*\.(.*\..*$)" addproperty="idp.scope" />
187
188                 <echo message="Generating signing and encryption key and certificate. " />
189                 <selfSignedCert hostname="${idp.hostname}"
190                                 privateKeyFile="${idp.home}/credentials/idp.key"
191                                 certificateFile="${idp.home}/credentials/idp.crt" />
192
193                 <copy todir="${idp.home}/bin" preservelastmodified="true">
194                     <fileset dir="${tools.dir}" />
195                     <filterset begintoken="$" endtoken="$">
196                         <filter token="IDP_HOME" value="${idp.home}" />
197                         <filter token="IDP_VERSION" value="${version}" />
198                     </filterset>
199                 </copy>
200                 <chmod file="${idp.home}/bin/*.sh" perm="+x" />
201
202                 <copy todir="${idp.home}/conf" preservelastmodified="true" overwrite="true">
203                     <fileset dir="${conf.dir}" />
204                     <filterset begintoken="$" endtoken="$">
205                         <filter token="IDP_HOME" value="${idp.home}" />
206                         <filter token="IDP_VERSION" value="${version}" />
207                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
208                         <filter token="IDP_SCOPE" value="${idp.scope}" />
209                         <filter token="IDP_CERTIFICATE" value="${idp.cert}" />
210                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
211                     </filterset>
212                 </copy>
213
214                 <stringFromFile input="${idp.home}/credentials/idp.crt" addProperty="idp.cert" />
215                 <regexSplit input="${idp.cert}"
216                             regex="\A.*-----\s((?:.*\s)*)-----END.*\Z"
217                             addproperty="idp.metadata.cert" />
218                 <copy todir="${idp.home}/metadata" preservelastmodified="true" overwrite="true">
219                     <fileset dir="${metadata.dir}" />
220                     <filterset begintoken="$" endtoken="$">
221                         <filter token="IDP_ENTITY_ID" value="${idp.entity.id}" />
222                         <filter token="IDP_SCOPE" value="${idp.scope}" />
223                         <filter token="IDP_CERTIFICATE" value="${idp.metadata.cert}" />
224                         <filter token="IDP_HOSTNAME" value="${idp.hostname}" />
225                     </filterset>
226                 </copy>
227             </then>
228         </if>
229
230         <copy todir="${idp.home}/lib" preservelastmodified="true">
231             <fileset dir="${lib.dir}" />
232             <fileset file="${dist.dir}/${jar.name}" />
233             <fileset file="${build-lib.dir}/servlet-2.4.jar" />
234         </copy>
235
236         <copy todir="${webinf-temp.dir}">
237             <fileset dir="${webinf.dir}" />
238             <filterset begintoken="$" endtoken="$">
239                 <filter token="IDP_HOME" value="${idp.home}" />
240                 <filter token="IDP_VERSION" value="${version}" />
241             </filterset>
242         </copy>
243
244         <jar destfile="${idp.home}/war/${war.name}" whenempty="fail">
245             <zipfileset dir="${webinf-temp.dir}" prefix="WEB-INF/" />
246             <zipfileset dir="${webpages.dir}" prefix="" />
247             <zipfileset dir="${lib.dir}" prefix="WEB-INF/lib/" />
248             <zipfileset file="${dist.dir}/${jar.name}" prefix="WEB-INF/lib/" />
249         </jar>
250     </target>
251
252
253     <!-- **************************************************************** -->
254     <!-- ***                                                          *** -->
255     <!-- ***                     Developer Tasks                      *** -->
256     <!-- ***                                                          *** -->
257     <!-- **************************************************************** -->
258
259     <!-- Checks code against style guidelines -->
260     <target name="checkstyle" description="Developer task: Produces coding standard compliance report.">
261         <mkdir dir="${reports.dir}" />
262
263         <checkstyle config="${basedir}/checkstyle.xml" failOnViolation="false" classpathref="build-path">
264             <fileset dir="src" includes="**/*.java" />
265             <formatter type="plain" toFile="${reports.dir}/checkstyle-report.txt" />
266         </checkstyle>
267     </target>
268
269 </project>