001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2me.cdc.project.savaje;
043:
044: import java.io.File;
045: import java.io.FileWriter;
046: import java.io.IOException;
047: import java.io.PrintWriter;
048: import java.util.LinkedList;
049: import java.util.List;
050: import java.util.StringTokenizer;
051:
052: import org.apache.tools.ant.*;
053: import org.apache.tools.ant.types.*;
054:
055: /**
056: * @author suchys
057: */
058: public class SavajeJnlpBuilder extends Task {
059: private File dir;
060: private String file;
061:
062: private String codebase;
063: private String extensionBase;
064:
065: private String distJar;
066: private String smallIcon;
067: private String focusedIcon;
068:
069: private String applicationTitle;
070: private String applicationVendor;
071: private String applicationIcon;
072: private String applicationDescription;
073: private String mainClass;
074: private String applicationArgs;
075: private boolean debug;
076: private String debugPort;
077:
078: private List filesets = new LinkedList(); // List<FileSet>
079:
080: public void addFileset(FileSet fs) {
081: filesets.add(fs);
082: }
083:
084: public void setDir(File dir) {
085: this .dir = dir;
086: }
087:
088: public void setFile(String file) {
089: this .file = file;
090: }
091:
092: public void setCodebase(String codebase) {
093: this .codebase = codebase;
094: }
095:
096: public void setExtensionBase(String extensionBase) {
097: this .extensionBase = extensionBase;
098: }
099:
100: public void setDistJar(String distJar) {
101: this .distJar = distJar;
102: }
103:
104: public void setSmallIcon(String smallIcon) {
105: this .smallIcon = smallIcon;
106: }
107:
108: public void setFocusedIcon(String focusedIcon) {
109: this .focusedIcon = focusedIcon;
110: }
111:
112: public void setApplicationTitle(String applicationTitle) {
113: this .applicationTitle = applicationTitle;
114: }
115:
116: public void setApplicationVendor(String applicationVendor) {
117: this .applicationVendor = applicationVendor;
118: }
119:
120: public void setApplicationIcon(String applicationIcon) {
121: this .applicationIcon = applicationIcon;
122: }
123:
124: public void setApplicationDescription(String applicationDescription) {
125: this .applicationDescription = applicationDescription;
126: }
127:
128: public void setMainClass(String mainClass) {
129: this .mainClass = mainClass;
130: }
131:
132: public void setApplicationArgs(String applicationArgs) {
133: this .applicationArgs = applicationArgs;
134: }
135:
136: public void execute() throws BuildException {
137: if (!dir.exists())
138: throw new BuildException("Target directory does not exist");
139: if (!dir.isDirectory())
140: throw new BuildException("Target directory is a file");
141:
142: if (file == null)
143: throw new BuildException(
144: "Target file name is not specified");
145: if (distJar == null)
146: throw new BuildException(
147: "Target file name is not specified");
148: if (codebase == null)
149: throw new BuildException("Codebase is not specified");
150: //if (extensionBase == null) throw new BuildException("Extension base is not specified");
151: if (applicationTitle == null)
152: throw new BuildException(
153: "Application title is not specified");
154: if (applicationVendor == null)
155: throw new BuildException(
156: "Application vendor is not specified");
157: if (applicationDescription == null)
158: throw new BuildException(
159: "Application icon is not specified");
160: if (mainClass == null)
161: throw new BuildException("main class is not specified");
162:
163: final File targetFile = new File(dir, file);
164: final FileWriter fileWriter;
165: try {
166: fileWriter = new FileWriter(targetFile);
167: final PrintWriter printW = new PrintWriter(fileWriter);
168:
169: printW
170: .println("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
171: printW.println("<jnlp codebase=\"sb:///" + codebase
172: + "/\">");
173: printW.println();
174: printW.println(" <resources>");
175: printW.println(" <j2se version=\"1.4+\"/>");
176: printW.println(" <jar href=\"lib/classes.jar\"/>");
177: if (smallIcon != null && smallIcon.length() != 0
178: && smallIcon.indexOf("${") == -1)
179: printW
180: .println(" <property name=\"icon.small\" value=\""
181: + smallIcon + "\"/>");
182: if (focusedIcon != null && focusedIcon.length() != 0
183: && focusedIcon.indexOf("${") == -1)
184: printW
185: .println(" <property name=\"icon.focused\" value=\""
186: + focusedIcon + "\"/>");
187: //printW.println(" <extension href=\"" + extensionBase + file + "\"/>");
188: printW.println(" </resources>");
189: printW.println();
190: if (debug && debugPort != null && debugPort.length() != 0) {
191: this .getProject().log(
192: "Adding debug information to jnlp file.");
193: printW.println(" <resources os=\"savaJe\">");
194: printW
195: .println(" <property name=\"flag\" value=\"-g\"/>");
196: printW.println(" </resources>");
197: printW.println();
198:
199: String dbg = "port=" + debugPort + " suspend=y "; //NOI18N (note there must be a whitespace at the end!
200: if (applicationArgs == null) {
201: applicationArgs = dbg;
202: } else {
203: applicationArgs = dbg + applicationArgs;
204: }
205: }
206: printW.println(" <information>");
207: printW.println(" <title>" + applicationTitle
208: + "</title>");
209: printW.println(" <vendor>" + applicationVendor
210: + "</vendor>");
211: if (applicationIcon != null
212: && applicationIcon.length() != 0
213: && applicationIcon.indexOf("${") == -1) {
214: printW.println(" <icon href=\"" + applicationIcon
215: + "\"/>");
216: }
217: if (applicationDescription.length() != 0)
218: printW.println(" <description>"
219: + applicationDescription + "</description>");
220: printW.println(" </information>");
221: printW.println();
222: printW.println(" <application-desc main-class=\""
223: + mainClass + "\">");
224: if (applicationArgs != null) {
225: final StringTokenizer stringTokenizer = new StringTokenizer(
226: applicationArgs, " ");
227: while (stringTokenizer.hasMoreTokens()) {
228: printW.println(" <argument>"
229: + stringTokenizer.nextToken()
230: + "</argument>");
231: }
232: }
233: printW.println(" </application-desc>");
234: printW.println();
235: printW.println("</jnlp>");
236:
237: printW.close();
238: } catch (IOException e) {
239: throw new BuildException(e);
240: }
241: }
242:
243: public void setDebug(boolean debug) {
244: this .debug = debug;
245: }
246:
247: public void setDebugPort(String debugPort) {
248: this.debugPort = debugPort;
249: }
250: }
|