Skip to content

Commit

Permalink
Migrate to Java 9. From now on, minimum Java 9 is minimum requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Sep 13, 2024
1 parent d283d20 commit 3e6db3c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 8
- name: Set up JDK 9
uses: actions/setup-java@v2
with:
java-version: '8'
java-version: '9'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ archivesBaseName = "kdbStudio"
version = "dz4.1"

compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
` sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
}

repositories {
Expand Down
44 changes: 10 additions & 34 deletions src/studio/core/Studio.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.PrintStream;
import java.lang.ref.Reference;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.util.List;
import java.util.*;

Expand Down Expand Up @@ -83,45 +82,22 @@ private static void registerForMacOSMenuJava8() throws Exception {
}

private static void registerForMacOSMenuJava9() throws Exception {
// Using reflection to be compilable on Java8

Class settingsClass = Class.forName("java.awt.desktop.PreferencesHandler");
Class quitClass = Class.forName("java.awt.desktop.QuitHandler");
Class aboutClass = Class.forName("java.awt.desktop.AboutHandler");

Object handler = Proxy.newProxyInstance(Studio.class.getClassLoader(), new Class[]{settingsClass, quitClass, aboutClass},
(o, method, objects) -> {
String name = method.getName();
if (name.equals("handlePreferences")) StudioWindow.settings();
else if (name.equals("handleAbout")) StudioWindow.about();
else if (name.equals("handleQuitRequestWith")) {
StudioWindow.quit();
try {
Class quiteResponseClass = Class.forName("java.awt.desktop.QuitResponse");
quiteResponseClass.getDeclaredMethod("cancelQuit").invoke(objects[1]);
} catch (Exception e) {
log.error("Error in cancelQuit()", e);
}
}
return null;
}
);

Class desktopClass = Class.forName("java.awt.Desktop");
Object desktop = desktopClass.getMethod("getDesktop").invoke(desktopClass);

desktopClass.getMethod("setPreferencesHandler", settingsClass).invoke(desktop, handler);
desktopClass.getMethod("setQuitHandler", quitClass).invoke(desktop, handler);
desktopClass.getMethod("setAboutHandler", aboutClass).invoke(desktop, handler);
Desktop desktop = Desktop.getDesktop();
desktop.setPreferencesHandler(e -> StudioWindow.settings());
desktop.setAboutHandler(e -> StudioWindow.about());
desktop.setQuitHandler( (e,response) -> {
StudioWindow.quit();
response.cancelQuit();
});
}

private static void registerForMacOSMenu() {
if (!Util.MAC_OS_X) return;

try {
if (Util.Java8Minus) registerForMacOSMenuJava8();
else registerForMacOSMenuJava9();

// if (Util.Java8Minus) registerForMacOSMenuJava8();
// else registerForMacOSMenuJava9();
registerForMacOSMenuJava9();
macOSSystemMenu = true;
} catch (Exception e) {
log.error("Failed to set MacOS handlers", e);
Expand Down
35 changes: 33 additions & 2 deletions test/kx/KServerMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import org.apache.logging.log4j.Logger;
import studio.kdb.K;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -27,7 +30,11 @@ public KServerMock() throws IOException {
}

public KServerMock(int port) throws IOException {
serverSocket = new ServerSocket(port);
this(ServerSocketFactory.getDefault(), port);
}

public KServerMock(ServerSocketFactory ssFactory, int port) throws IOException {
serverSocket = ssFactory.createServerSocket(port);
this.port = serverSocket.getLocalPort();
new Thread(this, "Server listen port " + port).start();
log.info("Server started on port {}", this.port);
Expand Down Expand Up @@ -170,7 +177,31 @@ public void shutdown() {
}
}

public static void main(String... args) throws IOException {
public static void main(String... args) throws IOException, NoSuchAlgorithmException {
new KServerMock(2345);

// SSLContext sslContext = SSLContext.getInstance("SSL"); //getDefault();

// new KServerMock(sslContext.getServerSocketFactory(), 2346);

new KServerMock(SSLServerSocketFactory.getDefault(), 2346);
//
// TrustManager allAcceptTrustManager = new X509TrustManager() {
// @Override
// public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// log.info("checkClientTrusted for authType {}; with chain length {}", authType, chain.length);
// }
//
// @Override
// public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// log.info("checkServerTrusted for authType {}; with chain length {}", authType, chain.length);
// }
//
// @Override
// public X509Certificate[] getAcceptedIssuers() {
// return null;
// }
// };

}
}

0 comments on commit 3e6db3c

Please sign in to comment.