blob: 3836dd5c351e3f492c1387c52da311360cc52f82 [file] [log] [blame]
j18024043c58b22016-09-20 16:59:10 +08001<!--
2 Copyright 2016 Huawei Technologies Co., Ltd.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
j180240d089cf22016-09-14 15:00:54 +080016<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 <modelVersion>4.0.0</modelVersion>
19 <parent>
20 <groupId>org.openo.gso.gui</groupId>
21 <artifactId>gso-gui</artifactId>
22 <version>1.0.0-SNAPSHOT</version>
23 </parent>
24 <artifactId>servicegateway</artifactId>
25 <name>servicegateway</name>
26 <packaging>pom</packaging>
27
28 <properties>
29 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30 </properties>
31 <modules>
32 <module>service</module>
33 <module>deployment</module>
34 </modules>
35
36 <profiles>
37 <profile>
38 <activation>
39 <file>
40 <exists>src/main/release/pub</exists>
41 </file>
42 </activation>
43 <build>
44 <plugins>
45 <plugin>
46 <groupId>org.apache.maven.plugins</groupId>
47 <artifactId>maven-compiler-plugin</artifactId>
48 <version>3.3</version>
49 <configuration>
50 <source>1.8</source>
51 <target>1.8</target>
52 </configuration>
53 </plugin>
54 <plugin>
55 <groupId>org.apache.maven.plugins</groupId>
56 <artifactId>maven-dependency-plugin</artifactId>
57 <version>2.10</version>
58 <executions>
59 <execution>
60 <id>copy-dependencies</id>
61 <phase>package</phase>
62 <goals>
63 <goal>copy-dependencies</goal>
64 </goals>
65 <configuration>
66 <outputDirectory>${project.build.directory}/deploydependencis</outputDirectory>
67 <overWriteReleases>false</overWriteReleases>
68 <overWriteSnapshots>false</overWriteSnapshots>
69 <overWriteIfNewer>true</overWriteIfNewer>
70 <includeScope>compile</includeScope>
71 <includeScope>runtime</includeScope>
72 </configuration>
73 </execution>
74 </executions>
75 </plugin>
76 <plugin>
77 <groupId>org.codehaus.gmaven</groupId>
78 <artifactId>gmaven-plugin</artifactId>
79 <version>1.5</version>
80 <executions>
81 <execution>
82 <id>make new jar</id>
83 <phase>package</phase>
84 <goals>
85 <goal>execute</goal>
86 </goals>
87 <configuration>
88 <source>
89 private String getWebContextFromManifest(File warFile) {
90 String context = null;
91 java.util.jar.JarFile jarFile = null;
92 try {
93 jarFile = new java.util.jar.JarFile(warFile);
94 context =
95 jarFile.getManifest().getMainAttributes().getValue("WebContext-Name");
96 context = context == null ? "ROOT" : context;
97 context = context.replace("\", "/");
98 context = context.replaceAll("[/]{2,}", "/");
99 context = context.endsWith("/") ? context.substring(0, context.length() - 1) : context;
100 context = context.startsWith("/") ? context.substring(1, context.length()) : context;
101 context = context.replaceAll("/", "#");
102 return context;
103 } catch (Exception e) {
104 System.out.println("-------------------context eror: ",e);
105 context = "ROOT";
106 } finally {
107 if (jarFile != null) {
108 jarFile.close();
109 }
110 }
111 System.out.println("-------------------context is: " + context);
112 return context;
113 }
114
115 System.out.println("------------------------------1")
116 List contexts=new ArrayList();
117 deploydependencisdir = "${project.build.directory}/deploydependencis";
118 unzipdir =
119 "${project.build.directory}/deployunzip";
120 outputdir =
121 "${project.build.directory}/deployoutput";
122 resourcesdir =
123 "${project.basedir}/src/main/release";
124 jarsdir = "${unzipdir}/lib";
125 toolpath =
126 "${project.build.directory}/deployoutputjars";
127
128 System.out.println("------------------------------2")
129 ant = new AntBuilder()
130 ant.delete(dir: "${unzipdir}")
131 ant.mkdir(dir: "${unzipdir}")
132 ant.mkdir(dir:
133 toolpath)
134 ant.delete(dir: "${outputdir}")
135 ant.mkdir(dir: "${outputdir}")
136 ant.delete(dir: "${jarsdir}")
137 ant.mkdir(dir: "${jarsdir}")
138 outputFileName =
139 "${project.name}"
140
141 System.out.println("------------------------------3")
142 if(new
143 File("${deploydependencisdir}").exists()){
144 for (File file : new File("${deploydependencisdir}").listFiles())
145 {
146 String filePath = file.getAbsolutePath();
147 fileName = file.getName();
148 if (fileName.endsWith(".war")) {
149 context = getWebContextFromManifest(file)
150 ant.mkdir(dir: "${unzipdir}/webapps/" + context)
151 ant.unzip(src: filePath, dest: "${unzipdir}/webapps/" + context)
152 ant.copy(todir: toolpath) {
153 fileset(dir: "${unzipdir}/webapps/" + context + "/WEB-INF/lib") {
154 include(name: "*.jar")
155 }
156 }
157
158 }
159 }
160
161 contexts.add(toolpath)
162 ant.copy(todir: toolpath) {
163 fileset(dir: "${deploydependencisdir}") {
164 include(name: "*.jar")
165 }
166 }
167 }
168
169
170 System.out.println("------------------------------4")
171 ant.copy(todir: toolpath) {
172 fileset(dir: "${project.build.directory}") {
173 include(name: "*.jar")
174 }
175 }
176
177 ant.copy(todir: "${unzipdir}") {
178 fileset(dir: "${resourcesdir}") {
179 include(name: "**")
180 }
181 }
182
183
184 /* compile python .py files. */
185 System.out.println("------------------------------5------------------")
186 pythonFile = "${project.basedir}/src/main/python";
187 if(new
188 File(pythonFile).exists()) {
189 try {
190 ant.exec(dir: "${project.basedir}/src/main/python", executable: "python") {
191 arg(value: "-m")
192 arg(value: "compileall")
193 arg(value: ".")
194 }
195
196 ant.copy(todir: "${unzipdir}") {
197 fileset(dir: "${project.basedir}/src/main/python") {
198 include(name: "**/*.*")
199 exclude(name: "**/*.py")
200 }
201 }
202 } catch (Exception eee) {
203 System.out.println("----------------&gt;&gt;&gt;"+eee.toString())
204 }
205 }
206
207 /* copy all dependencies to $APP_ROOT/lib. */
208 System.out.println("------------------------------6------------------")
209 for(String temPath : contexts)
210 {
211 if(new File(temPath).exists())
212 {
213 try {
214 for (File file : new File(temPath).listFiles()) {
215 fileName = file.getName();
216 if (fileName.endsWith(".jar")) {
217 ant.copy(file: file.getAbsolutePath(), todir: "${jarsdir}")
218 }
219 }
220 } catch (Exception e) {
221 e.printStackTrace()
222 }
223 }
224 }
225
226 /* deploy the upzip file to ${outputdir}/${outputFileName} */
227 System.out.println("------------------------------7------------------")
228 outputFileName =
229 outputFileName.endsWith("Deployment")?outputFileName:outputFileName+"Deployment";
230 outputFileName = outputFileName.substring(0, outputFileName.length() -
231 "Deployment".length());
232 outputFileName = outputFileName +
233 "-${project.version}.zip";
234
235 outputFileName = outputFileName.replace("-SNAPSHOT",
236 "." + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(
237 new Date()));
238
239 ant.delete(dir: "${unzipdir}/webapps/ROOT/WEB-INF/lib");
240 ant.mkdir(dir:
241 "${unzipdir}/webapps/ROOT/WEB-INF/lib");
242 ant.copy(todir:
243 "${unzipdir}/webapps/ROOT/WEB-INF/lib") {
244 fileset(dir: "${unzipdir}/lib") {
245 include(name: "org.openo.common-services.common-utilities.commonlib.db-*.jar")
246 include(name: "org.openo.common-services.common-utilities.commonlib.cbb-*.jar")
247 }
248 }
249
250 ant.delete() {
251 fileset(dir: "${unzipdir}/lib") {
252 include(name: "org.openo.common-services.common-utilities.commonlib.db-*.jar")
253 include(name: "org.openo.common-services.common-utilities.commonlib.cbb-*.jar")
254 }
255 }
256
257 /* generate dependencies.list in $APP_ROOT/lib. Requirement for install disk size. */
258 System.out.println("------------------------------8------------------")
259 dependenciesPath="${unzipdir}/lib";
260 try {
261 def writer = new File(dependenciesPath+"/dependencies.list").newWriter('UTF-8')
262 for (String fileName : new File(dependenciesPath).list()) {
263 if (fileName.endsWith(".jar")) {
264 writer.writeLine(fileName);
265 }
266 }
267 writer.close()
268 } catch (Exception e) {
269 e.printStackTrace()
270 }
271
272 /* make the archive. */
273 System.out.println("------------------------------9------------------")
274 ant.zip(destfile:
275 "${outputdir}/${outputFileName}") {
276 fileset(dir: "${unzipdir}") {
277 exclude(name: "**/.gitignore")
278 }
279 }
280
281 System.out.println("------------------------------done")
282 </source>
283 </configuration>
284 </execution>
285 </executions>
286 </plugin>
287 </plugins>
288 </build>
289 </profile>
290 </profiles>
291</project>