1 /* 2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.tools.ant; 27 28 import java.util.LinkedList; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Properties; 32 import com.sun.javafx.tools.packager.HtmlParam; 33 import com.sun.javafx.tools.packager.Param; 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.types.DataType; 36 import org.apache.tools.ant.types.Reference; 37 38 /** 39 * Basic application descriptor. 40 * <p> 41 * Defines main components of application and default set of parameters. 42 * 43 * 44 * Examples: 45 * <pre> 46 * <info vendor="Uncle Joe" description="Test program"/> 47 * </pre> 48 * 49 * @ant.type name="application" category="javafx" 50 */ 51 public class Application extends DataType implements Cloneable { 52 String mainClass = null; 53 String module = null; 54 String preloaderClass = null; 55 String name = null; 56 List<Param> parameters = new LinkedList<Param>(); 57 List<HtmlParam> htmlParameters = new LinkedList<HtmlParam>(); 58 public List<Argument> arguments = new LinkedList<Argument>(); 59 String fallbackApp = null; 60 String id = null; 61 boolean embeddedIntoSwing = false; 62 String version = null; 63 Boolean daemon = null; 64 65 public void setVersion(String v) { 66 version = v; 67 } 68 69 public void setToolkit(String v) { 70 embeddedIntoSwing = "swing".equalsIgnoreCase(v); 71 } 72 73 /** 74 * Main class of AWT-based applet to be used if application fail to launch 75 * due to missing FX runtime and installation of JavaFX is not possible. 76 * 77 * @ant.not-required 78 */ 79 public void setFallbackClass(String v) { 80 fallbackApp = v; 81 } 82 83 public void setName(String v) { 84 name = v; 85 } 86 87 public Param createParam() { 88 Param p = new Param(); 89 parameters.add(p); 90 return p; 91 } 92 93 public void setParams(Properties props) { 94 if (props != null) { 95 for (Map.Entry en : props.entrySet()) { 96 Param p = new Param(); 97 p.setName((String)en.getKey()); 98 p.setValue((String)en.getValue()); 99 parameters.add(p); 100 } 101 } 102 } 103 104 public class Argument { 105 private String value; 106 107 public void addText(String value) { 108 this.value = value; 109 } 110 111 public String getValue() { 112 return this.value; 113 } 114 } 115 116 public Argument createArgument() { 117 Argument a = new Argument(); 118 arguments.add(a); 119 return a; 120 } 121 122 List<String> getArguments() { 123 List<String> lst = new LinkedList(); 124 for(Argument a: arguments) { 125 lst.add(a.value); 126 } 127 return lst; 128 } 129 130 public Object clone() { 131 try { 132 Application result = (Application) super.clone(); 133 return result; 134 } catch (CloneNotSupportedException e) { 135 throw new BuildException(e); 136 } 137 } 138 139 public HtmlParam createHtmlParam() { 140 HtmlParam p = new HtmlParam(); 141 htmlParameters.add(p); 142 return p; 143 } 144 145 /** 146 * Application id that can be used to obtain Javascript reference to the application in HTML. 147 * Same id can be also used to refer to application object in the ant task (using refid). 148 * 149 * @ant.not-required 150 */ 151 public void setId(String id) { 152 this.id = id; 153 } 154 155 @Override 156 public void setRefid(Reference id) { 157 this.id = id.getRefId(); 158 super.setRefid(id); 159 } 160 161 /** 162 * Main application class. 163 * 164 * @ant.required 165 */ 166 public void setMainClass(String v) { 167 mainClass = v; 168 } 169 170 /** 171 * Module containing the application class. 172 * 173 * @ant.not-required Default is to not bundle as a modular application. 174 */ 175 public String getModule() { 176 return this.module; 177 } 178 179 /** 180 * Module containing the application class. 181 * 182 * @ant.not-required Default is to not bundle as a modular application. 183 */ 184 public void setModule(String value) { 185 this.module = value; 186 } 187 188 /** 189 * Preloader class to be used. 190 * 191 * @ant.not-required Default is preloader shipped in JavaFX Runtime. 192 */ 193 public void setPreloaderClass(String v) { 194 preloaderClass = v; 195 } 196 197 /** 198 * Is this class a daemon/service? 199 * 200 * @ant.not-required Default is false, i.e. an interactive app 201 */ 202 public void setDaemon(boolean b) { 203 daemon = b; 204 } 205 206 //return instance that actually has data. Could be referenced object ... 207 public Application get() { 208 return isReference() ? 209 (Application) getRefid().getReferencedObject() : this; 210 } 211 212 public void selfcheck() { 213 if (get().mainClass == null) { 214 throw new BuildException("Application main class is required."); 215 } 216 } 217 218 @Override 219 public String toString() { 220 return "Application[id=" + id + ", mainClass=" + mainClass + "]"; 221 } 222 }