/* * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.javafx.tools.ant; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import com.sun.javafx.tools.packager.HtmlParam; import com.sun.javafx.tools.packager.Param; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.DataType; import org.apache.tools.ant.types.Reference; /** * Basic application descriptor. *

* Defines main components of application and default set of parameters. * * * Examples: *

 *    <info vendor="Uncle Joe" description="Test program"/>
 * 
* * @ant.type name="application" category="javafx" */ public class Application extends DataType implements Cloneable { String mainClass = null; String preloaderClass = null; String name = null; List parameters = new LinkedList(); List htmlParameters = new LinkedList(); public List arguments = new LinkedList(); String fallbackApp = null; String id = null; boolean embeddedIntoSwing = false; String version = null; Boolean daemon = null; public List addModule = new LinkedList(); public List limitModule = new LinkedList(); String jdkModulePath; boolean detectModules; public void setVersion(String v) { version = v; } public void setToolkit(String v) { embeddedIntoSwing = "swing".equalsIgnoreCase(v); } /** * Main class of AWT-based applet to be used if application fail to launch * due to missing FX runtime and installation of JavaFX is not possible. * * @ant.not-required */ public void setFallbackClass(String v) { fallbackApp = v; } public void setName(String v) { name = v; } public Param createParam() { Param p = new Param(); parameters.add(p); return p; } public void setParams(Properties props) { if (props != null) { for (Map.Entry en : props.entrySet()) { Param p = new Param(); p.setName((String)en.getKey()); p.setValue((String)en.getValue()); parameters.add(p); } } } public class Argument { String value; public void addText(String v) { value = getProject().replaceProperties(v); } } public Argument createArgument() { Argument a = new Argument(); arguments.add(a); return a; } List getArguments() { List lst = new LinkedList(); for(Argument a: arguments) { lst.add(a.value); } return lst; } public Object clone() { try { Application result = (Application) super.clone(); return result; } catch (CloneNotSupportedException e) { throw new BuildException(e); } } public HtmlParam createHtmlParam() { HtmlParam p = new HtmlParam(); htmlParameters.add(p); return p; } /** * Application id that can be used to obtain Javascript reference to the application in HTML. * Same id can be also used to refer to application object in the ant task (using refid). * * @ant.not-required */ public void setId(String id) { this.id = id; } @Override public void setRefid(Reference id) { this.id = id.getRefId(); super.setRefid(id); } /** * Main application class. * * @ant.required */ public void setMainClass(String v) { mainClass = v; } /** * Preloader class to be used. * * @ant.not-required Default is preloader shipped in JavaFX Runtime. */ public void setPreloaderClass(String v) { preloaderClass = v; } /** * Is this class a daemon/service? * * @ant.not-required Default is false, i.e. an interactive app */ public void setDaemon(boolean b) { daemon = b; } /** * "addModule" declaration for the application's runtime. * * Modules can be specified per-element, or comma/colon/semi-colon/space separated * * @ant.not-required Default is to bundle the whole platform */ public Argument createAddModule() { Argument a = new Argument(); addModule.add(a); return a; } /** * "addModule" declaration for the application's runtime * * @ant.not-required Default is to bundle the whole platform */ List getAddModule() { List lst = new LinkedList(); for(Argument a: arguments) { for (String s : a.value.split("[:;,\\s]+")) { lst.add(s); } } return lst; } /** * "limitModule" declaration for the application's runtime. * * Modules can be specified per-element, or comma/colon/semi-colon/space separated * * @ant.not-required Default is to bundle the whole platform */ public Argument createLimitModule() { Argument a = new Argument(); addModule.add(a); return a; } /** * "limitModule" declaration for the application's runtime * * @ant.not-required Default is to bundle the whole platform */ List getLimitModule() { List lst = new LinkedList(); for(Argument a: arguments) { for (String s : a.value.split("[:;,\\s]+")) { lst.add(s); } } return lst; } /** * Whether or not the bundler should attempt to detect and add used modules */ public boolean getDetectModules() { return detectModules; } /** * Whether or not the bundler should attempt to detect and add used modules * @ant.not-required default is false */ public void setDetectModules(boolean Value) { this.detectModules = Value; } /** * Module path within the running applicaiton */ public String getJdkModulePath() { return jdkModulePath; } /** * Module path within the running applicaiton * * @ant.not-required default is $PACKAGEPATH/modules */ public void setJdkModulePath(String Value) { this.jdkModulePath = Value; } //return instance that actually has data. Could be referenced object ... public Application get() { return isReference() ? (Application) getRefid().getReferencedObject() : this; } public void selfcheck() { if (get().mainClass == null) { throw new BuildException("Application main class is required."); } } @Override public String toString() { return "Application[id="+id+", mainClass="+mainClass+"]"; } }