1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.FileWriter ; 24 import java.io.IOException ; 25 import java.util.jar.JarFile ; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.Task; 28 import org.apache.tools.ant.types.FileSet; 29 30 34 public class MakeMasterJNLP extends Task { 35 36 private FileSet files; 37 38 public FileSet createModules() 39 throws BuildException { 40 if (files != null) throw new BuildException("modules can be created just once"); 41 files = new FileSet(); 42 return files; 43 } 44 45 private File target; 46 public void setDir(File t) { 47 target = t; 48 } 49 50 private String masterPrefix = ""; 51 public void setCodeBase(String p) { 52 masterPrefix = p; 53 } 54 55 public void execute() throws BuildException { 56 if (target == null) throw new BuildException("Output dir must be provided"); 57 if (files == null) throw new BuildException("modules must be provided"); 58 59 try { 60 generateFiles(); 61 } catch (IOException ex) { 62 throw new BuildException(ex); 63 } 64 } 65 66 private void generateFiles() throws IOException , BuildException { 67 for (String nm : files.getDirectoryScanner(getProject()).getIncludedFiles()) { 68 File jar = new File (files.getDir(getProject()), nm); 69 70 if (!jar.canRead()) { 71 throw new BuildException("Cannot read file: " + jar); 72 } 73 74 JarFile theJar = new JarFile (jar); 75 String codenamebase = theJar.getManifest().getMainAttributes().getValue("OpenIDE-Module"); 76 if (codenamebase == null) { 77 throw new BuildException("Not a NetBeans Module: " + jar); 78 } 79 { 80 int slash = codenamebase.indexOf('/'); 81 if (slash >= 0) { 82 codenamebase = codenamebase.substring(0, slash); 83 } 84 } 85 String dashcnb = codenamebase.replace('.', '-'); 86 87 File n = new File (target, dashcnb + ".ref"); 88 FileWriter w = new FileWriter (n); 89 w.write(" <extension name='" + codenamebase + "' HREF='" + this.masterPrefix + dashcnb + ".jnlp' />\n"); 90 w.close(); 91 92 93 theJar.close(); 94 } 95 96 } 97 } 98 | Popular Tags |