1 /* 2 * Copyright (c) 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 test.sandbox.app; 27 28 import javafx.animation.KeyFrame; 29 import javafx.animation.Timeline; 30 import javafx.application.Application; 31 import javafx.scene.Scene; 32 import javafx.stage.Stage; 33 import javafx.util.Duration; 34 35 import static test.sandbox.Constants.*; 36 37 /** 38 * FX application to test running with a security manager installed. Note that 39 * the toolkit will be initialized by the Java 8 launcher. 40 */ 41 public class FXApp extends Application { 42 43 /** 44 * @param args the command line arguments 45 */ 46 public static void main(String[] args) { 47 Util.setupTimeoutThread(); 48 49 try { 50 try { 51 // Ensure that we are running with a restrictive 52 // security manager 53 System.getProperty("sun.something"); 54 System.err.println("*** Did not get expected security exception"); 55 System.exit(ERROR_NO_SECURITY_EXCEPTION); 56 } catch (SecurityException ex) { 57 // This is expected 58 } 59 Application.launch(args); 60 } catch (SecurityException ex) { 61 ex.printStackTrace(System.err); 62 System.exit(ERROR_SECURITY_EXCEPTION); 63 } catch (RuntimeException ex) { 64 ex.printStackTrace(System.err); 65 Throwable cause = ex.getCause(); 66 if (cause instanceof ExceptionInInitializerError) { 67 cause = cause.getCause(); 68 if (cause instanceof SecurityException) { 69 System.exit(ERROR_SECURITY_EXCEPTION); 70 } 71 } 72 System.exit(ERROR_UNEXPECTED_EXCEPTION); 73 } catch (Error | Exception t) { 74 t.printStackTrace(System.err); 75 System.exit(ERROR_UNEXPECTED_EXCEPTION); 76 } 77 } 78 79 @Override 80 public void start(final Stage stage) { 81 try { 82 Scene scene = Util.createScene(); 83 stage.setScene(scene); 84 stage.setX(0); 85 stage.setY(0); 86 stage.show(); 87 88 // Hide the stage after the specified amount of time 89 KeyFrame kf = new KeyFrame(Duration.millis(SHOWTIME), e -> stage.hide()); 90 Timeline timeline = new Timeline(kf); 91 timeline.play(); 92 } catch (SecurityException ex) { 93 ex.printStackTrace(System.err); 94 System.exit(ERROR_SECURITY_EXCEPTION); 95 } catch (Error | Exception ex) { 96 ex.printStackTrace(System.err); 97 System.exit(ERROR_UNEXPECTED_EXCEPTION); 98 } 99 } 100 101 @Override public void stop() { 102 System.exit(ERROR_NONE); 103 } 104 105 }