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