1 /*
   2  * Copyright (c) 2011, 2013, 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.io.File;
  29 import java.util.LinkedList;
  30 import java.util.List;
  31 import org.apache.tools.ant.BuildException;
  32 import org.apache.tools.ant.types.DataType;
  33 
  34 /**
  35  * Defines application platform requirements.
  36  *
  37  * Examples:
  38  * <pre>
  39  *    &lt;fx:platform javafx="2.0" j2se="7.0"/&gt;
  40  * </pre>
  41  * Application need JavaFX Runtime version 2.0 or later and JRE version 7.0 or later.
  42  *
  43  * Examples:
  44  * <pre>
  45  *    &lt;fx:platform javafx="2.0"&gt;
  46  *       &lt;jvmarg value="-Xmx400m"/&gt;
  47  *       &lt;jvmarg value="-verbose:jni"/&gt;
  48  *       &lt;property name="purpose" value="sample"/&gt;
  49  *    &lt;/fx:platform&gt;
  50  * </pre>
  51  * Application need JavaFX Runtime version 2.0 and need to be run in JVM launched
  52  * with "-Xmx400 -verbose:jni -Dpurpose=sample".
  53  *
  54  * @ant.type name="platform" category="javafx"
  55  */
  56 
  57 public class Platform extends DataType {
  58     /**
  59      * Optional element (could be used multiple times).
  60      *
  61      * JVM argument to be set in the JVM where application is executed.
  62      *
  63      * @ant.not-required
  64      */
  65     public static class Jvmarg {
  66         String value;
  67 
  68         /**
  69          * Value of JVM argument.
  70          *
  71          * @ant.required
  72          */
  73         public void setValue(String v) {
  74             value = v;
  75         }
  76     }
  77 
  78     /**
  79      * Optional element (could be used multiple times).
  80      *
  81      * Java property to be set in the JVM where application is executed.
  82      *
  83      * @ant.not-required
  84      */
  85     public static class Property {
  86         String value;
  87         String name;
  88 
  89         /**
  90          * Value of property to be set.
  91          *
  92          * @ant.required
  93          */
  94         public void setValue(String v) {
  95             value = v;
  96         }
  97 
  98         /**
  99          * Name of property to be set.
 100          *
 101          * @ant.required
 102          */
 103         public void setName(String v) {
 104             name = v;
 105         }
 106     }
 107 
 108     String javaRoot = null; //used for self-contained apps
 109     String j2se = null;
 110     String javafx = null;
 111     List<Property> properties = new LinkedList<Property>();
 112     List<Jvmarg> jvmargs = new LinkedList<Jvmarg>();
 113     List<Property> jvmUserArgs = new LinkedList<Property>();
 114 
 115     /**
 116      * Minimum version of JRE required by application.
 117      *
 118      * @ant.not-required Default is any JRE supporting JavaFX.
 119      */
 120     public void setJ2se(String v) {
 121         j2se = v;
 122     }
 123 
 124     /**
 125      * Minimum version of JavaFX required by application.
 126      *
 127      * @ant.not-required Default is 2.0.
 128      */
 129     public void setJavafx(String v) {
 130         javafx = v;
 131     }
 132 
 133     public final static String USE_SYSTEM_JRE = "";
 134 
 135     public Property createProperty() {
 136         Property t = new Property();
 137         properties.add(t);
 138         return t;
 139     }
 140 
 141     public Jvmarg createJvmarg() {
 142         Jvmarg t = new Jvmarg();
 143         jvmargs.add(t);
 144         return t;
 145     }
 146 
 147     public Property createJVMUserArg() {
 148         Property t = new Property();
 149         jvmUserArgs.add(t);
 150         return t;
 151     }
 152 
 153     //real object could be available by link
 154     public Platform get() {
 155         if (isReference()) {
 156             return (Platform) getRefid().getReferencedObject();
 157         }
 158         return this;
 159     }
 160 }