KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > MakeMasterJNLP


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import java.io.File JavaDoc;
23 import java.io.FileWriter JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.jar.JarFile JavaDoc;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Task;
28 import org.apache.tools.ant.types.FileSet;
29
30 /** Generates JNLP files for signed versions of the module JAR files.
31  *
32  * @author Jaroslav Tulach
33  */

34 public class MakeMasterJNLP extends Task {
35     /** the files to work on */
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 JavaDoc target;
46     public void setDir(File JavaDoc t) {
47         target = t;
48     }
49     
50     private String JavaDoc masterPrefix = "";
51     public void setCodeBase(String JavaDoc 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 JavaDoc ex) {
62             throw new BuildException(ex);
63         }
64     }
65     
66     private void generateFiles() throws IOException JavaDoc, BuildException {
67         for (String JavaDoc nm : files.getDirectoryScanner(getProject()).getIncludedFiles()) {
68             File JavaDoc jar = new File JavaDoc (files.getDir(getProject()), nm);
69             
70             if (!jar.canRead()) {
71                 throw new BuildException("Cannot read file: " + jar);
72             }
73             
74             JarFile JavaDoc theJar = new JarFile JavaDoc(jar);
75             String JavaDoc 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 JavaDoc dashcnb = codenamebase.replace('.', '-');
86
87             File JavaDoc n = new File JavaDoc(target, dashcnb + ".ref");
88             FileWriter JavaDoc w = new FileWriter JavaDoc(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