1 /* 2 * Copyright (c) 2011, 2014, 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 preloaderClass = null; 54 String name = null; 55 List<Param> parameters = new LinkedList<Param>(); 56 List<HtmlParam> htmlParameters = new LinkedList<HtmlParam>(); 57 public List<Argument> arguments = new LinkedList<Argument>(); 58 String fallbackApp = null; 59 String id = null; 60 boolean embeddedIntoSwing = false; 61 String version = null; 62 Boolean daemon = null; 63 64 public void setVersion(String v) { 65 version = v; 66 } 67 68 public void setToolkit(String v) { 69 embeddedIntoSwing = "swing".equalsIgnoreCase(v); 70 } 71 72 /** 73 * Main class of AWT-based applet to be used if application fail to launch 74 * due to missing FX runtime and installation of JavaFX is not possible. 75 * 76 * @ant.not-required 77 */ 78 public void setFallbackClass(String v) { 79 fallbackApp = v; 80 } 81 82 public void setName(String v) { 83 name = v; 84 } 85 86 public Param createParam() { 87 Param p = new Param(); 88 parameters.add(p); 89 return p; 90 } 91 92 public void setParams(Properties props) { 93 if (props != null) { 94 for (Map.Entry en : props.entrySet()) { 95 Param p = new Param(); 96 p.setName((String)en.getKey()); 97 p.setValue((String)en.getValue()); 98 parameters.add(p); 99 } 100 } 101 } 102 103 public class Argument { 104 String value; 105 106 public void addText(String v) { 107 value = getProject().replaceProperties(v); 108 } 109 } 110 111 public Argument createArgument() { 112 Argument a = new Argument(); 113 arguments.add(a); 114 return a; 115 } 116 117 List<String> getArguments() { 118 List<String> lst = new LinkedList(); 119 for(Argument a: arguments) { 120 lst.add(a.value); 121 } 122 return lst; 123 } 124 125 public Object clone() { 126 try { 127 Application result = (Application) super.clone(); 128 return result; 129 } catch (CloneNotSupportedException e) { 130 throw new BuildException(e); 131 } 132 } 133 134 public HtmlParam createHtmlParam() { 135 HtmlParam p = new HtmlParam(); 136 htmlParameters.add(p); 137 return p; 138 } 139 140 /** 141 * Application id that can be used to obtain Javascript reference to the application in HTML. 142 * Same id can be also used to refer to application object in the ant task (using refid). 143 * 144 * @ant.not-required 145 */ 146 public void setId(String id) { 147 this.id = id; 148 } 149 150 @Override 151 public void setRefid(Reference id) { 152 this.id = id.getRefId(); 153 super.setRefid(id); 154 } 155 156 /** 157 * Main application class. 158 * 159 * @ant.required 160 */ 161 public void setMainClass(String v) { 162 mainClass = v; 163 } 164 165 /** 166 * Preloader class to be used. 167 * 168 * @ant.not-required Default is preloader shipped in JavaFX Runtime. 169 */ 170 public void setPreloaderClass(String v) { 171 preloaderClass = v; 172 } 173 174 /** 175 * Is this class a daemon/service? 176 * 177 * @ant.not-required Default is false, i.e. an interactive app 178 */ 179 public void setDaemon(boolean b) { 180 daemon = b; 181 } 182 183 //return instance that actually has data. Could be referenced object ... 184 public Application get() { 185 return isReference() ? 186 (Application) getRefid().getReferencedObject() : this; 187 } 188 189 public void selfcheck() { 190 if (get().mainClass == null) { 191 throw new BuildException("Application main class is required."); 192 } 193 } 194 195 @Override 196 public String toString() { 197 return "Application[id="+id+", mainClass="+mainClass+"]"; 198 } 199 }