1 22 package org.objectweb.petals.tools.jbiplugin; 23 24 import java.io.DataInputStream ; 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileOutputStream ; 28 import java.util.zip.ZipEntry ; 29 import java.util.zip.ZipOutputStream ; 30 31 import org.apache.maven.model.Dependency; 32 import org.apache.maven.plugin.MojoExecutionException; 33 34 43 public class PackageServiceAssemblyMojo extends PackageAbstractMojo { 44 45 48 public void execute() throws MojoExecutionException { 49 try { 50 project.getArtifact().setFile(new File (outputDirectory 51 + File.separator + jbiName + ".zip")); 52 if (jbiDirectory.exists()) { 53 if (verbose) { 54 System.out.println("Start building JBI Service Assembly archive " 55 + new File (outputDirectory 56 + File.separator + jbiName + ".zip") 57 .getAbsolutePath()); 58 } 59 60 new File (outputDirectory 61 + File.separator + jbiName + ".zip").delete(); 62 63 outputDirectory.mkdirs(); 64 65 ZipOutputStream zipOutputStream = new ZipOutputStream ( 67 new FileOutputStream (new File (outputDirectory 68 + File.separator + jbiName + ".zip"))); 69 recurseDirectory(zipOutputStream, jbiDirectory, ""); 70 zipOutputStream.flush(); 71 72 addServiceUnitDepencies(zipOutputStream); 74 zipOutputStream.flush(); 75 76 zipOutputStream.close(); 77 if (verbose) { 78 System.out.println("JBI Service Assembly archive building done.\n"); 79 } 80 } 81 } catch (Exception e) { 82 e.printStackTrace(); 83 throw new MojoExecutionException(e.getLocalizedMessage(), e); 84 } 85 } 86 87 91 private void addServiceUnitDepencies(ZipOutputStream zipOutputStream) throws Exception { 92 93 for (Object object : project.getDependencies()) { 94 if (object instanceof Dependency) { 95 Dependency dep = (Dependency) object; 96 if ("zip".equals(dep.getType())) { 98 String zipDependencyFileName = dep.getArtifactId() + "-" + dep.getVersion() + ".zip"; 99 100 ZipEntry zipEntry = new ZipEntry (zipDependencyFileName); 101 DataInputStream dis = new DataInputStream (new FileInputStream ( 102 new File (localRepository.getBasedir() 103 + File.separator 104 + dep.getGroupId().replace(".", File.separator) 105 + File.separator + dep.getArtifactId() 106 + File.separator + dep.getVersion() 107 + File.separator + zipDependencyFileName))); 108 byte[] content = new byte[dis.available()]; 109 dis.readFully(content); 110 zipOutputStream.putNextEntry(zipEntry); 111 zipOutputStream.write(content); 112 zipOutputStream.closeEntry(); 113 if (verbose) { 114 System.out.println(" " 115 + zipDependencyFileName + " added to JBI Service Assembly archive"); 116 } 117 } 118 } 119 } 120 } 121 } 122 | Popular Tags |