1 22 package org.objectweb.petals.tools.packageplugin; 23 24 import java.io.DataInputStream ; 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileOutputStream ; 28 import java.io.IOException ; 29 import java.util.List ; 30 import java.util.jar.Attributes ; 31 import java.util.jar.JarEntry ; 32 import java.util.jar.JarOutputStream ; 33 import java.util.jar.Manifest ; 34 35 import org.apache.commons.io.FileUtils; 36 import org.apache.maven.artifact.repository.ArtifactRepository; 37 import org.apache.maven.artifact.resolver.ArtifactResolver; 38 import org.apache.maven.model.Dependency; 39 import org.apache.maven.plugin.AbstractMojo; 40 import org.apache.maven.plugin.MojoExecutionException; 41 import org.apache.maven.project.MavenProject; 42 43 import org.objectweb.petals.tools.packageplugin.utils.CopyFileSetUtil; 44 45 56 public class PackageAssemblyMojo extends AbstractMojo { 57 58 61 protected ArtifactResolver artifactResolver; 62 63 70 protected ArtifactRepository localRepository; 71 72 79 protected MavenProject project; 80 81 88 protected File baseDir; 89 90 96 protected File petalsAssemblyDirectory; 97 98 99 102 public void execute() throws MojoExecutionException { 103 try { 104 prepare(); 106 107 copyRessources(); 109 110 copyLib(); 112 113 makeServerJar(); 115 116 fillExtrasDir(); 118 } catch (IOException e) { 119 throw new MojoExecutionException(e.getLocalizedMessage(), e); 120 } 121 } 122 123 127 protected void fillExtrasDir() throws IOException { 128 File componentCommonProjectDir = new File (baseDir + File.separator 130 + ".." + File.separator + ".." + File.separator + "components" 131 + File.separator + "common"); 132 133 File extrasDir = new File (petalsAssemblyDirectory + File.separator 134 + "extras"); 135 File componentCommonExtraDir = new File (extrasDir, "component-common"); 136 137 CopyFileSetUtil.copyFileSetToDirectory(new File ( 139 componentCommonProjectDir, "target"), componentCommonExtraDir, 140 "*.jar", ".svn", true); 141 142 CopyFileSetUtil.copyFileSetToDirectory(new File ( 144 componentCommonProjectDir, "target" + File.separator 145 + "dependencies"), componentCommonExtraDir, "*.jar", 146 ".svn", true); 147 148 } 149 150 151 156 protected void copyLib() throws IOException { 157 List dependencies = project.getDependencies(); 158 for (Object object : dependencies) { 159 Dependency dependency = (Dependency) object; 160 if (dependency.getScope() == null 161 || (dependency.getScope() != null && !dependency.getScope() 162 .equals("test"))) { 163 String jarName = dependency.getArtifactId() + "-" 164 + dependency.getVersion() + ".jar"; 165 FileUtils.copyFileToDirectory(new File (localRepository 166 .getBasedir() 167 + File.separator 168 + dependency.getGroupId().replace(".", File.separator) 169 + File.separator 170 + dependency.getArtifactId() 171 + File.separator 172 + dependency.getVersion() 173 + File.separator + jarName), new File ( 174 petalsAssemblyDirectory + File.separator + "lib")); 175 } 176 } 177 } 178 179 185 protected void copyRessources() throws IOException { 186 CopyFileSetUtil.copyFileSetToDirectory(new File (baseDir 188 + File.separator + "src" + File.separator + "scripts"), new File ( 189 petalsAssemblyDirectory + File.separator + "bin"), "**" 190 + File.separator + "*.*", ".svn", true); 191 CopyFileSetUtil.copyFileSetToDirectory(new File (baseDir 193 + File.separator + "src" + File.separator + "conf"), new File ( 194 petalsAssemblyDirectory + File.separator + "conf"), "**" 195 + File.separator + "*.*", ".svn", true); 196 197 CopyFileSetUtil.copyFileSetToDirectory(new File (baseDir 199 + File.separator + "src" + File.separator + "fractal"), 200 new File (petalsAssemblyDirectory + File.separator + "conf" 201 + File.separator + "adl"), "**" + File.separator 202 + "*.*", ".svn", true); 203 204 CopyFileSetUtil.copyFileSetToDirectory(new File (baseDir 206 + File.separator + "src" + File.separator + "schema"), 207 new File (petalsAssemblyDirectory + File.separator + "schema"), 208 "**" + File.separator + "*.*", ".svn", true); 209 210 CopyFileSetUtil.copyFileSetToDirectory(new File (baseDir 212 + File.separator + ".." + File.separator + ".." 213 + File.separator + "components"), new File ( 214 petalsAssemblyDirectory + File.separator + "components"), "**" 215 + File.separator + "target" + File.separator + "*.zip", false); 216 CopyFileSetUtil.copyFileSetToDirectory(baseDir, 218 petalsAssemblyDirectory, "*.txt", true); 219 220 File rootDemoDir = new File (baseDir + File.separator + ".." 222 + File.separator + ".." + File.separator + "demos"); 223 for (File demoDir : rootDemoDir.listFiles()) { 224 if (!demoDir.isDirectory() || demoDir.getName().startsWith(".")) { 225 continue; 227 } 228 String demoAssemblyDirName = demoDir.getName(); 229 CopyFileSetUtil.copyFileSetToDirectory(demoDir, new File ( 230 petalsAssemblyDirectory + File.separator + "demos" 231 + File.separator + demoAssemblyDirName), "**" 232 + File.separator + "target" + File.separator + "*.zip", 233 false); 234 CopyFileSetUtil.copyFileSetToDirectory(demoDir, new File ( 235 petalsAssemblyDirectory + File.separator + "demos" 236 + File.separator + demoAssemblyDirName), "**" 237 + File.separator + "target" + File.separator + "*.war", 238 false); 239 } 240 241 try { 243 File antProjectDir = new File (baseDir + File.separator + ".." 244 + File.separator + ".." + File.separator + "tools" 245 + File.separator + "ant"); 246 File antDistribDir = new File (petalsAssemblyDirectory 247 + File.separator + "ant"); 248 249 CopyFileSetUtil.copyFileSetToDirectory(new File (antProjectDir, 250 "target"), new File (antDistribDir, "lib"), "*.jar", true); 251 FileUtils.copyFileToDirectory(new File (antProjectDir, "src" 252 + File.separator + "distribution" + File.separator 253 + "README"), antDistribDir); 254 FileUtils.copyFileToDirectory( 255 new File (antProjectDir, "src" + File.separator 256 + "distribution" + File.separator + "TODO"), 257 antDistribDir); 258 FileUtils.copyFileToDirectory(new File (antProjectDir, "src" 259 + File.separator + "distribution" + File.separator 260 + "ant-sample.xml"), antDistribDir); 261 FileUtils.copyFileToDirectory(new File (antProjectDir, "src" 262 + File.separator + "distribution" + File.separator 263 + "taskdef.xml"), antDistribDir); 264 CopyFileSetUtil.copyFileSetToDirectory(new File (antProjectDir, 265 "target"), new File (antDistribDir, "lib"), "*.jar", true); 266 267 FileUtils.copyFileToDirectory(new File (baseDir + File.separator 269 + ".." + File.separator + ".." + File.separator + "demos" 270 + File.separator + "mortgage" + File.separator + "workflow" 271 + File.separator + "auto-install.xml"), new File ( 272 petalsAssemblyDirectory + File.separator + "demos" 273 + File.separator + "mortgage")); 274 275 FileUtils.copyFileToDirectory(new File (baseDir + File.separator 277 + ".." + File.separator + ".." + File.separator + "demos" 278 + File.separator + "mortgage" + File.separator + "workflow" 279 + File.separator + "auto-install.xml"), new File ( 280 petalsAssemblyDirectory + File.separator + "demos" 281 + File.separator + "mortgage")); 282 283 } catch (Exception e) { 284 } 287 } 288 289 294 protected void makeServerJar() throws IOException { 295 Manifest manifest = new Manifest (); 296 Attributes attributes = manifest.getMainAttributes(); 297 attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); 298 attributes.putValue("Created-By", "Petals Assembly"); 299 attributes.putValue("Built-By", System.getProperty("user.name")); 300 attributes.putValue("Package", "org.objectweb.petals"); 301 attributes.putValue("Build-Jdk", System.getProperty("java.version")); 302 303 String classpath = "../conf/ ../conf/adl/ ../lib-ext/"; 304 for (File file : new File (petalsAssemblyDirectory + File.separator 305 + "lib").listFiles()) { 306 classpath += " ../lib/" + file.getName(); 309 } 310 attributes.putValue("Class-Path", classpath); 311 312 attributes.putValue("Extension-Name", "petals"); 313 attributes.putValue("Specification-Title", "Petals Services Platform"); 314 attributes.putValue("Specification-Vendor", "ObjectWeb Consortium"); 315 attributes.putValue("Implementation-Title", "org.objectweb.petals"); 316 attributes.putValue("Implementation-Vendor", "ObjectWeb Consortium"); 317 318 String version = petalsAssemblyDirectory.getName(); 319 if (version.indexOf("-") > -1) { 320 version = version.substring(version.indexOf("-") + 1); 321 } 322 attributes.putValue("Implementation-Version", version); 323 attributes.putValue("Main-Class", 324 "org.objectweb.petals.system.launch.Launcher"); 325 326 JarOutputStream jarOutputStream = new JarOutputStream ( 327 new FileOutputStream (petalsAssemblyDirectory + File.separator 328 + "bin" + File.separator + "server.jar"), manifest); 329 330 JarEntry license = new JarEntry ("META-INF" + File.separator 332 + "LICENSE.txt"); 333 jarOutputStream.putNextEntry(license); 334 DataInputStream dis = new DataInputStream (new FileInputStream (baseDir 335 + File.separator + "LICENSE.txt")); 336 byte[] content = new byte[dis.available()]; 337 dis.readFully(content); 338 jarOutputStream.write(content); 339 jarOutputStream.closeEntry(); 340 341 jarOutputStream.flush(); 342 jarOutputStream.close(); 343 } 344 345 351 protected void prepare() throws IOException { 352 FileUtils.deleteDirectory(petalsAssemblyDirectory); 353 petalsAssemblyDirectory.mkdirs(); 354 355 new File (petalsAssemblyDirectory + File.separator + "logs").mkdirs(); 357 new File (petalsAssemblyDirectory + File.separator + "bin").mkdirs(); 359 new File (petalsAssemblyDirectory + File.separator + "conf").mkdirs(); 361 new File (petalsAssemblyDirectory + File.separator + "conf" 363 + File.separator + "adl").mkdirs(); 364 new File (petalsAssemblyDirectory + File.separator + "schema").mkdirs(); 366 new File (petalsAssemblyDirectory + File.separator + "lib").mkdirs(); 368 369 new File (petalsAssemblyDirectory + File.separator + "components") 371 .mkdirs(); 372 373 new File (petalsAssemblyDirectory + File.separator + "demos").mkdirs(); 375 376 377 new File (petalsAssemblyDirectory + File.separator + "ant").mkdirs(); 379 new File (petalsAssemblyDirectory + File.separator + "ant" 380 + File.separator + "lib").mkdirs(); 381 382 new File (petalsAssemblyDirectory + File.separator + "joram").mkdirs(); 384 385 new File (petalsAssemblyDirectory + File.separator + "extras" 387 + File.separator + "component-common").mkdirs(); 388 389 new File (petalsAssemblyDirectory + File.separator + "install").mkdirs(); 391 new File (petalsAssemblyDirectory + File.separator + "installed") 392 .mkdirs(); 393 new File (petalsAssemblyDirectory + File.separator + "uninstalled") 394 .mkdirs(); 395 new File (petalsAssemblyDirectory + File.separator + "work").mkdirs(); 396 new File (petalsAssemblyDirectory + File.separator + "lost+found") 397 .mkdirs(); 398 String repositoryDirectory = petalsAssemblyDirectory + File.separator 399 + "repository"; 400 new File (repositoryDirectory).mkdirs(); 401 new File (repositoryDirectory + File.separator + "components").mkdirs(); 402 new File (repositoryDirectory + File.separator + "shared-libraries").mkdirs(); 403 new File (repositoryDirectory + File.separator + "service-assemblies") 404 .mkdirs(); 405 406 407 } 408 409 } 410 | Popular Tags |