Skip to content

Commit b525f34

Browse files
author
pavl-x86-machine
committed
PackageVariant: an early support API for automated usages
1 parent 6a5449c commit b525f34

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'Electrostatic-Sandbox' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package electrostatic4j.snaploader.platform.util;
34+
35+
/**
36+
* A namespace class exposing checks for the native window
37+
* currently in runtime; this could give some more insights
38+
* about the type of the framework the application is running
39+
* on.
40+
*
41+
* @author pavl_g.
42+
*/
43+
public final class PackageVariant {
44+
45+
private static final String FLUTTER_ACTIVITY_PATH = "io.flutter.embedding.android.FlutterActivity";
46+
private static final String JME_CONTEXT_PATH = "com.jme3.system.JmeContext";
47+
private static final String ANDROID_CONTEXT_PATH = "android.content.Context";
48+
private static final String JAVA_FX_CONTEXT_PATH = "javafx.application.Application";
49+
private static final String JAVA_AWT_CONTEXT_PATH = "java.awt.Frame";
50+
private static final String GWT_CONTEXT_PATH = "com.google.gwt.user.client.Window";
51+
52+
private PackageVariant() {
53+
}
54+
55+
public static boolean hasJavaFxWindow() {
56+
try {
57+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.JAVA_FX_CONTEXT_PATH) != null;
58+
} catch (ClassNotFoundException e) {
59+
return false;
60+
}
61+
}
62+
63+
public static boolean hasJavaAWTWindow() {
64+
try {
65+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.JAVA_AWT_CONTEXT_PATH) != null;
66+
} catch (ClassNotFoundException e) {
67+
return false;
68+
}
69+
}
70+
71+
public static boolean hasAndroidActivity() {
72+
try {
73+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.ANDROID_CONTEXT_PATH) != null;
74+
} catch (ClassNotFoundException e) {
75+
return false;
76+
}
77+
}
78+
79+
public static boolean hasGWTContext() {
80+
try {
81+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.GWT_CONTEXT_PATH) != null;
82+
} catch (ClassNotFoundException e) {
83+
return false;
84+
}
85+
}
86+
87+
public static boolean hasJmeContext() {
88+
try {
89+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.JME_CONTEXT_PATH) != null;
90+
} catch (ClassNotFoundException e) {
91+
return false;
92+
}
93+
}
94+
95+
public static boolean hasFlutterActivity() {
96+
try {
97+
return ClassLoader.getSystemClassLoader().loadClass(PackageVariant.FLUTTER_ACTIVITY_PATH) != null;
98+
} catch (ClassNotFoundException e) {
99+
return false;
100+
}
101+
}
102+
103+
public static boolean hasAndroidActivityOnly() {
104+
return hasAndroidActivity() && !hasFlutterActivity();
105+
}
106+
107+
public static boolean hasJmeAndroidContext() {
108+
return hasAndroidActivity() && hasJmeContext();
109+
}
110+
111+
public static boolean hasJmeFlutterContext() {
112+
return hasFlutterActivity() && hasJmeContext();
113+
}
114+
}

0 commit comments

Comments
 (0)