aboutsummaryrefslogtreecommitdiffstats
path: root/servicegateway/pom.xml
blob: 660e55d4712193548f5ed624d516ddd029d8332e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
      <groupId>org.openo.gso.gui</groupId>
      <artifactId>gso-gui</artifactId>
      <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>servicegateway</artifactId>
    <name>servicegateway</name>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <modules>
        <module>service</module>
        <module>deployment</module>
    </modules>

    <profiles>
        <profile>
            <activation>
                <file>
                    <exists>src/main/release/pub</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.10</version>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/deploydependencis</outputDirectory>
                                    <overWriteReleases>false</overWriteReleases>
                                    <overWriteSnapshots>false</overWriteSnapshots>
                                    <overWriteIfNewer>true</overWriteIfNewer>
                                    <includeScope>compile</includeScope>
                                    <includeScope>runtime</includeScope>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.gmaven</groupId>
                        <artifactId>gmaven-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>make new jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <source>
                                        private String getWebContextFromManifest(File warFile) {
                                        String context = null;
                                        java.util.jar.JarFile jarFile = null;
                                        try {
                                        jarFile = new java.util.jar.JarFile(warFile);
                                        context =
                                        jarFile.getManifest().getMainAttributes().getValue("WebContext-Name");
                                        context = context == null ? "ROOT" : context;
                                        context = context.replace("\", "/");
                                        context = context.replaceAll("[/]{2,}", "/");
                                        context = context.endsWith("/") ? context.substring(0, context.length() - 1) : context;
                                        context = context.startsWith("/") ? context.substring(1, context.length()) : context;
                                        context = context.replaceAll("/", "#");
                                        return context;
                                        } catch (Exception e) {
                                        System.out.println("-------------------context eror: ",e);
                                        context = "ROOT";
                                        } finally {
                                        if (jarFile != null) {
                                        jarFile.close();
                                        }
                                        }
                                        System.out.println("-------------------context is: " + context);
                                        return context;
                                        }

                                        System.out.println("------------------------------1")
                                        List contexts=new ArrayList();
                                        deploydependencisdir = "${project.build.directory}/deploydependencis";
                                        unzipdir =
                                        "${project.build.directory}/deployunzip";
                                        outputdir =
                                        "${project.build.directory}/deployoutput";
                                        resourcesdir =
                                        "${project.basedir}/src/main/release";
                                        jarsdir = "${unzipdir}/lib";
                                        toolpath =
                                        "${project.build.directory}/deployoutputjars";

                                        System.out.println("------------------------------2")
                                        ant = new AntBuilder()
                                        ant.delete(dir: "${unzipdir}")
                                        ant.mkdir(dir: "${unzipdir}")
                                        ant.mkdir(dir:
                                        toolpath)
                                        ant.delete(dir: "${outputdir}")
                                        ant.mkdir(dir: "${outputdir}")
                                        ant.delete(dir: "${jarsdir}")
                                        ant.mkdir(dir: "${jarsdir}")
                                        outputFileName =
                                        "${project.name}"

                                        System.out.println("------------------------------3")
                                        if(new
                                        File("${deploydependencisdir}").exists()){
                                        for (File file : new File("${deploydependencisdir}").listFiles())
                                        {
                                        String filePath = file.getAbsolutePath();
                                        fileName = file.getName();
                                        if (fileName.endsWith(".war")) {
                                        context = getWebContextFromManifest(file)
                                        ant.mkdir(dir: "${unzipdir}/webapps/" + context)
                                        ant.unzip(src: filePath, dest: "${unzipdir}/webapps/" + context)
                                        ant.copy(todir: toolpath) {
                                        fileset(dir: "${unzipdir}/webapps/" + context + "/WEB-INF/lib") {
                                        include(name: "*.jar")
                                        }
                                        }

                                        }
                                        }

                                        contexts.add(toolpath)
                                        ant.copy(todir: toolpath) {
                                        fileset(dir: "${deploydependencisdir}") {
                                        include(name: "*.jar")
                                        }
                                        }
                                        }


                                        System.out.println("------------------------------4")
                                        ant.copy(todir: toolpath) {
                                        fileset(dir: "${project.build.directory}") {
                                        include(name: "*.jar")
                                        }
                                        }

                                        ant.copy(todir: "${unzipdir}") {
                                        fileset(dir: "${resourcesdir}") {
                                        include(name: "**")
                                        }
                                        }


                                        /* compile python .py files. */
                                        System.out.println("------------------------------5------------------")
                                        pythonFile = "${project.basedir}/src/main/python";
                                        if(new
                                        File(pythonFile).exists()) {
                                        try {
                                        ant.exec(dir: "${project.basedir}/src/main/python", executable: "python") {
                                        arg(value: "-m")
                                        arg(value: "compileall")
                                        arg(value: ".")
                                        }

                                        ant.copy(todir: "${unzipdir}") {
                                        fileset(dir: "${project.basedir}/src/main/python") {
                                        include(name: "**/*.*")
                                        exclude(name: "**/*.py")
                                        }
                                        }
                                        } catch (Exception eee) {
                                        System.out.println("----------------&gt;&gt;&gt;"+eee.toString())
                                        }
                                        }

                                        /* copy all dependencies to $APP_ROOT/lib. */
                                        System.out.println("------------------------------6------------------")
                                        for(String temPath : contexts)
                                        {
                                        if(new File(temPath).exists())
                                        {
                                        try {
                                        for (File file : new File(temPath).listFiles()) {
                                        fileName = file.getName();
                                        if (fileName.endsWith(".jar")) {
                                        ant.copy(file: file.getAbsolutePath(), todir: "${jarsdir}")
                                        }
                                        }
                                        } catch (Exception e) {
                                        e.printStackTrace()
                                        }
                                        }
                                        }

                                        /* deploy the upzip file to ${outputdir}/${outputFileName} */
                                        System.out.println("------------------------------7------------------")
                                        outputFileName =
                                        outputFileName.endsWith("Deployment")?outputFileName:outputFileName+"Deployment";
                                        outputFileName = outputFileName.substring(0, outputFileName.length() -
                                        "Deployment".length());
                                        outputFileName = outputFileName +
                                        "-${project.version}.zip";

                                        outputFileName = outputFileName.replace("-SNAPSHOT",
                                        "." + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(
                                        new Date()));

                                        ant.delete(dir: "${unzipdir}/webapps/ROOT/WEB-INF/lib");
                                        ant.mkdir(dir:
                                        "${unzipdir}/webapps/ROOT/WEB-INF/lib");
                                        ant.copy(todir:
                                        "${unzipdir}/webapps/ROOT/WEB-INF/lib") {
                                        fileset(dir: "${unzipdir}/lib") {
                                        include(name: "org.openo.common-services.common-utilities.commonlib.db-*.jar")
                                        include(name: "org.openo.common-services.common-utilities.commonlib.cbb-*.jar")
                                        }
                                        }

                                        ant.delete() {
                                        fileset(dir: "${unzipdir}/lib") {
                                        include(name: "org.openo.common-services.common-utilities.commonlib.db-*.jar")
                                        include(name: "org.openo.common-services.common-utilities.commonlib.cbb-*.jar")
                                        }
                                        }

                                        /* generate dependencies.list in $APP_ROOT/lib. Requirement for install disk size. */
                                        System.out.println("------------------------------8------------------")
                                        dependenciesPath="${unzipdir}/lib";
                                        try {
                                        def writer = new File(dependenciesPath+"/dependencies.list").newWriter('UTF-8')
                                        for (String fileName : new File(dependenciesPath).list()) {
                                        if (fileName.endsWith(".jar")) {
                                        writer.writeLine(fileName);
                                        }
                                        }
                                        writer.close()
                                        } catch (Exception e) {
                                        e.printStackTrace()
                                        }

                                        /* make the archive. */
                                        System.out.println("------------------------------9------------------")
                                        ant.zip(destfile:
                                        "${outputdir}/${outputFileName}") {
                                        fileset(dir: "${unzipdir}") {
                                        exclude(name: "**/.gitignore")
                                        }
                                        }

                                        System.out.println("------------------------------done")
                                    </source>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>