Skip to content

Commit

Permalink
Towards JavaFX support
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed Dec 6, 2018
1 parent cb8f0a1 commit ba952b1
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018, 2018, 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.oracle.svm.hosted.javafx;

import java.util.Objects;
import java.util.stream.Stream;

import org.graalvm.nativeimage.Feature;
import org.graalvm.nativeimage.RuntimeClassInitialization;
import org.graalvm.nativeimage.RuntimeReflection;

import com.oracle.svm.hosted.FeatureImpl;

final class JavaFXFeature implements Feature {

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return getJavaFXApplication(access) != null;
}

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
/*
* Include subclasses of javafx.application.Application for reflection so users don't have
* to do it every time.
*
* See javafx.application.Application#launch(java.lang.String...).
*/
((FeatureImpl.BeforeAnalysisAccessImpl) access)
.findSubclasses(getJavaFXApplication(access))
.forEach(RuntimeReflection::register);

/*
* Static initializers that are not supported in JavaFX.
*/
Stream.of("com.sun.javafx.tk.quantum.QuantumRenderer", "javafx.stage.Screen", "com.sun.javafx.scene.control.behavior.BehaviorBase", "com.sun.javafx.scene.control.skin.BehaviorSkinBase",
"javafx.scene.control.SkinBase", "javafx.scene.control.Control", "javafx.scene.control.PopupControl", "javafx.scene.control.SkinBase$StyleableProperties",
"javafx.scene.control.Labeled$StyleableProperties", "javafx.scene.control.SkinBase$StyleableProperties", "com.sun.javafx.tk.quantum.PrismImageLoader2$AsyncImageLoader",
"com.sun.javafx.tk.quantum.PrismImageLoader2", "com.sun.prism.PresentableState")
.map(access::findClassByName)
.filter(Objects::nonNull)
.forEach(RuntimeClassInitialization::delayClassInitialization);
}

private static Class<?> getJavaFXApplication(FeatureAccess access) {
return access.findClassByName("javafx.application.Application");
}

}

0 comments on commit ba952b1

Please sign in to comment.