dae4678c9a5d96f8c229a1fcf6b1987919b38d33
[parser.git] / verigraph / build.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  Copyright (c) 2017 Politecnico di Torino and others.
4
5  All rights reserved. This program and the accompanying materials
6  are made available under the terms of the Apache License, Version 2.0
7  which accompanies this distribution, and is available at
8  http://www.apache.org/licenses/LICENSE-2.0
9 -->
10 <project name="Verigraph" default="generate-war" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
11   <description>
12       Script for Verigraph
13   </description>
14
15   <property name="root.location" location="." />
16   <!-- The location to be used for class files -->
17   <property name="src.dir" location="${root.location}/src" />
18   <property name="gen.dir" location="${root.location}/gen-src" />
19   <property name="war.dir" location="${root.location}/war" />
20   <property name="grpc.dir" value="${src.dir}/it/polito/verigraph/grpc" />
21   <property name="path.prefix" value="it/polito" />
22   <property name="build.dir" location="${root.location}/build" />
23   <property name="lib.dir" location="${root.location}/lib" />
24   <property name="schemadir" location="${root.location}/schema" />
25   <property name="schemafile" value="xml_components.xsd" />
26   <property name="testfile" value="test.py" />
27   <property name="target" value="1.8" />
28   <property name="source" value="1.8" />
29   <property name="gen-tomcat-service.dir" location="${root.location}/target" />
30   <property name="resources.dir" location="${root.location}/webapp" />
31   <property name="gen-war.dir" location="${root.location}/war" />
32   <property name="jsonschemafolder.dir" location="${root.location}/jsonschema" />
33   <property name="test.dir" location="${root.location}/tester" />
34   <property name="iteration" value="1" />
35
36   <path id="z3.classpath">
37     <pathelement location="${lib.dir}/com.microsoft.z3.jar" />
38   </path>
39
40
41   <import file="tomcat-build.xml" />
42
43   <target name="mvn-init" unless="compile.classpath" xmlns:artifact="urn:maven-artifact-ant">
44     <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpath="lib/maven-ant-tasks-2.1.3.jar" />
45     <condition property="maven.repo.local" value="${maven.repo.local}" else="${user.home}/.m2/repository">
46       <isset property="maven.repo.local" />
47     </condition>
48     <echo>maven.repo.local=${maven.repo.local}</echo>
49     <artifact:localRepository id="local.repository" path="${maven.repo.local}" />
50     <artifact:pom file="pom.xml" id="maven.project" />
51     <artifact:dependencies pathId="compile.classpath" filesetId="compile.fileset" useScope="compile">
52       <pom refid="maven.project" />
53       <localRepository refid="local.repository" />
54     </artifact:dependencies>
55     <artifact:dependencies pathId="test.classpath" filesetId="test.fileset" useScope="test">
56       <pom refid="maven.project" />
57       <localRepository refid="local.repository" />
58     </artifact:dependencies>
59     <artifact:dependencies pathId="runtime.classpath" filesetId="runtime.fileset" useScope="runtime">
60       <pom refid="maven.project" />
61       <localRepository refid="local.repository" />
62     </artifact:dependencies>
63     <artifact:dependencies pathId="build.classpath" filesetId="build.fileset">
64       <pom refid="maven.project" />
65       <localRepository refid="local.repository" />
66     </artifact:dependencies>
67   </target>
68
69
70   <target name="init">
71     <mkdir dir="${build.dir}" />
72     <mkdir dir="${gen-tomcat-service.dir}" />
73     <mkdir dir="${gen-war.dir}" />
74     <mkdir dir="${gen.dir}" />
75     <mkdir dir="${lib.dir}" />
76     <get dest="${lib.dir}">
77       <url url="https://github.com/Z3Prover/z3/releases/download/z3-4.5.0/z3-4.5.0-x86-win.zip" />
78       <url url="http://central.maven.org/maven2/org/apache/maven/maven-ant-tasks/2.1.3/maven-ant-tasks-2.1.3.jar" />
79     </get>
80     <unzip src="${lib.dir}/z3-4.5.0-x86-win.zip" dest="${lib.dir}" overwrite="true">
81       <patternset>
82         <include name="**/**/com.microsoft.z3.jar" />
83       </patternset>
84       <mapper type="flatten" />
85     </unzip>
86     <delete file="${lib.dir}/z3-4.5.0-x86-win.zip" />
87   </target>
88
89         
90   <target name="-chk-bindings">
91     <uptodate property="generate-bindings.notRequired" targetfile="${src.dir}/.flagfile">
92       <srcfiles dir="${schemadir}" includes="${schemafile}" />
93     </uptodate>
94   </target>
95
96         
97   <target name="generate-bindings" unless="generate-bindings.notRequired" depends="init" description="Create the value classes">
98     <exec executable="xjc" failonerror="true">
99       <arg line="-d ${gen.dir} -p it.polito.neo4j.jaxb ${schemadir}/${schemafile}" />
100     </exec>
101     <touch file="${src.dir}/.flagfile" />
102   </target>
103
104         
105   <!-- The target for compiling the Verigraph application -->
106   <target name="build-service" depends="init, generate-bindings, mvn-init">
107     <echo>Building verigraph (if needed)...</echo>
108     <javac destdir="${build.dir}" debug="${debug}" debuglevel="${debuglevel}" source="${source}" target="${target}" includeantruntime="false">
109       <classpath>
110         <path id="compile.classpath" />
111         <path id="z3.classpath" />
112       </classpath>
113       <src path="${src.dir}" />
114       <src path="${gen.dir}" />
115       <src path="${basedir}/gen-protobuf" />
116       <include name="${path.prefix}/**/*.java" />
117       <exclude name="main/proto/" />
118     </javac>
119     <echo>Done.</echo>
120   </target>
121
122
123   <macrodef name="war-exploded">
124     <sequential>
125       <copy toDir="${gen-tomcat-service.dir}" overwrite="true">
126         <fileset dir="${resources.dir}" />
127       </copy>
128       <copy toDir="${gen-tomcat-service.dir}" overwrite="true">
129         <fileset dir=".">
130           <include name="server.properties" />
131         </fileset>
132       </copy>
133       <!-- copy class files to WEB-INF/classes directory -->
134       <copy toDir="${gen-tomcat-service.dir}/WEB-INF/classes" overwrite="true">
135         <fileset dir="${build.dir}">
136           <exclude name="verigraph.proto" />
137           <exclude name="src/main/proto" />
138         </fileset>
139       </copy>
140       <!-- copy jsonschema folder to WEB-INF/classes directory -->
141       <copy toDir="${gen-tomcat-service.dir}/jsonschema" overwrite="true">
142         <fileset dir="${jsonschemafolder.dir}" />
143       </copy>
144       <!-- copy lib files to WEB-INF/lib directory -->
145       <copy toDir="${gen-tomcat-service.dir}/maven-lib" overwrite="true">
146         <fileset refid="runtime.fileset">
147         </fileset>
148       </copy>
149       <copy toDir="${gen-tomcat-service.dir}/WEB-INF/lib" overwrite="true" flatten="true">
150         <fileset dir="${gen-tomcat-service.dir}/maven-lib">
151           <include name="**/**/*.jar" />
152         </fileset>
153       </copy>
154       <delete dir="${gen-tomcat-service.dir}/maven-lib" />
155
156       <!-- Make the jar that includes only the classes needed for verigraph models -->
157       <jar destfile="${gen-tomcat-service.dir}/WEB-INF/lib/mcnet.jar">
158         <fileset dir="${build.dir}">
159           <include name="it/polito/verigraph/mcnet/**/*.class" />
160         </fileset>
161       </jar>
162       <!-- Copy the z3 library -->
163       <copy toDir="${gen-tomcat-service.dir}/WEB-INF/lib" overwrite="true" flatten="true">
164         <file name="${lib.dir}/com.microsoft.z3.jar" />
165       </copy>
166     </sequential>
167   </macrodef>
168
169         
170   <target name="war-exploded" depends="build-service">
171     <war-exploded />
172   </target>
173
174         
175   <target name="generate-war" depends="war-exploded">
176     <war destfile="${gen-war.dir}/${serviceName}.war" basedir="${gen-tomcat-service.dir}">
177       <exclude name="protoc-dependencies/" />
178       <exclude name="protoc-plugins/" />
179       <exclude name="classes/" />
180       <exclude />
181     </war>
182   </target>
183
184         
185   <!-- launch test python test -->
186   <target name="run-test">
187     <exec dir="${test.dir}" executable="python">
188       <arg value="${testfile}" />
189       <arg value="-iteration " />
190       <arg value="${iteration}" />
191     </exec>
192   </target>
193
194
195
196   <!-- target for cleaning -->
197   <target name="clean">
198     <delete dir="${build.dir}" />
199     <delete dir="${gen.dir}" />
200     <delete dir="${gen-tomcat-service.dir}" />
201     <delete dir="${war.dir}" />
202     <delete dir="${lib.dir}" />
203   </target>
204
205
206 </project>