Skip to content

Commit

Permalink
Require JDK 11 and support JDK 21 at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 27, 2023
1 parent bd95366 commit a2ab047
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import java.io.*;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
Expand Down Expand Up @@ -187,12 +188,12 @@ public static SyntaxHighlighter build(String nanorcUrl) {
if (nanorcUrl.startsWith("classpath:")) {
inputStream = new Source.ResourceSource(nanorcUrl.substring(10), null).read();
} else {
inputStream = new Source.URLSource(new URL(nanorcUrl), null).read();
inputStream = new Source.URLSource(new URI(nanorcUrl).toURL(), null).read();
}
NanorcParser parser = new NanorcParser(inputStream, null, null);
parser.parse();
out.addRules(parser.getHighlightRules());
} catch (IOException e) {
} catch (IOException | URISyntaxException e) {
// ignore
}
return out;
Expand Down
12 changes: 9 additions & 3 deletions console/src/main/java/org/jline/console/SystemRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,21 @@ protected static Registeries getInstance() {
}

protected void addRegistry(SystemRegistry systemRegistry) {
systemRegisteries.put(Thread.currentThread().getId(), systemRegistry);
systemRegisteries.put(getThreadId(), systemRegistry);
}

protected SystemRegistry getSystemRegistry() {
return systemRegisteries.getOrDefault(Thread.currentThread().getId(), null);
return systemRegisteries.getOrDefault(getThreadId(), null);
}

protected void removeRegistry() {
systemRegisteries.remove(Thread.currentThread().getId());
systemRegisteries.remove(getThreadId());
}

// TODO: Thread.getId() should be replaced with Thread.threadId() when minimum is JDK >= 19
@SuppressWarnings("deprecation")
private static long getThreadId() {
return Thread.currentThread().getId();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ private Object doc(CommandInput input) {

private boolean urlExists(String weburl) {
try {
URL url = new URL(weburl);
URL url = URI.create(weburl).toURL();
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("HEAD");
return huc.getResponseCode() == HttpURLConnection.HTTP_OK;
Expand Down
172 changes: 86 additions & 86 deletions demo/jline-gogo.bat
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
@echo off

set DIRNAME=%~dp0%
set ROOTDIR=%DIRNAME%\..
set TARGETDIR=%DIRNAME%target

rem initialization
if not exist %TARGETDIR%\lib (
echo Build jline with maven before running the demo
goto END
)

goto :SETUP_CLASSPATH

:APPEND_TO_CLASSPATH
set filename=%~1
set cp=%cp%;%TARGETDIR%\lib\%filename%
goto :EOF

:SETUP_CLASSPATH
set cp=%TARGETDIR%\classes
rem JLINE
pushd %TARGETDIR%\lib
for %%G in (jline-*.jar) do call:APPEND_TO_CLASSPATH %%G
rem Gogo Runtime
for %%G in (org.apache.felix.gogo.runtime-*.jar) do call:APPEND_TO_CLASSPATH %%G
rem Gogo JLine
for %%G in (org.apache.felix.gogo.jline-*.jar) do call:APPEND_TO_CLASSPATH %%G

set "opts=%JLINE_OPTS%"
set "logconf=%DIRNAME%etc\logging.properties"
:RUN_LOOP
if "%1" == "jansi" goto :EXECUTE_JANSI
if "%1" == "jna" goto :EXECUTE_JNA
if "%1" == "ssh" goto :EXECUTE_SSH
if "%1" == "debug" goto :EXECUTE_DEBUG
if "%1" == "debugs" goto :EXECUTE_DEBUGS
if "%1" == "verbose" goto :EXECUTE_VERBOSE
if "%1" == "" goto :EXECUTE_MAIN
set "opts=%opts% %~1"
shift
goto :RUN_LOOP

:EXECUTE_JANSI
for %%G in (jansi-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_JNA
for %%G in (jna-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_SSH
for %%G in (sshd-common-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-core-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-scp-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-sftp-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (slf4j-api-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (slf4j-jdk14-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_DEBUG
set "opts=%opts% -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
shift
goto :RUN_LOOP

:EXECUTE_DEBUGS
set "opts=%opts% -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"
shift
goto :RUN_LOOP

:EXECUTE_VERBOSE
set "logconf=%DIRNAME%etc\logging-verbose.properties"
shift
goto :RUN_LOOP

:EXECUTE_MAIN
popd

rem Launch gogo shell
echo Launching Gogo JLine...
echo Classpath: %cp%
java -cp %cp% %opts% -Dgosh.home=%DIRNAME% -Djava.util.logging.config.file=%logconf% org.apache.felix.gogo.jline.Main

@echo off

set DIRNAME=%~dp0%
set ROOTDIR=%DIRNAME%\..
set TARGETDIR=%DIRNAME%target

rem initialization
if not exist %TARGETDIR%\lib (
echo Build jline with maven before running the demo
goto END
)

goto :SETUP_CLASSPATH

:APPEND_TO_CLASSPATH
set filename=%~1
set cp=%cp%;%TARGETDIR%\lib\%filename%
goto :EOF

:SETUP_CLASSPATH
set cp=%TARGETDIR%\classes
rem JLINE
pushd %TARGETDIR%\lib
for %%G in (jline-*.jar) do call:APPEND_TO_CLASSPATH %%G
rem Gogo Runtime
for %%G in (org.apache.felix.gogo.runtime-*.jar) do call:APPEND_TO_CLASSPATH %%G
rem Gogo JLine
for %%G in (org.apache.felix.gogo.jline-*.jar) do call:APPEND_TO_CLASSPATH %%G

set "opts=%JLINE_OPTS%"
set "logconf=%DIRNAME%etc\logging.properties"
:RUN_LOOP
if "%1" == "jansi" goto :EXECUTE_JANSI
if "%1" == "jna" goto :EXECUTE_JNA
if "%1" == "ssh" goto :EXECUTE_SSH
if "%1" == "debug" goto :EXECUTE_DEBUG
if "%1" == "debugs" goto :EXECUTE_DEBUGS
if "%1" == "verbose" goto :EXECUTE_VERBOSE
if "%1" == "" goto :EXECUTE_MAIN
set "opts=%opts% %~1"
shift
goto :RUN_LOOP

:EXECUTE_JANSI
for %%G in (jansi-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_JNA
for %%G in (jna-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_SSH
for %%G in (sshd-common-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-core-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-scp-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (sshd-sftp-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (slf4j-api-*.jar) do call:APPEND_TO_CLASSPATH %%G
for %%G in (slf4j-jdk14-*.jar) do call:APPEND_TO_CLASSPATH %%G
shift
goto :RUN_LOOP

:EXECUTE_DEBUG
set "opts=%opts% -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
shift
goto :RUN_LOOP

:EXECUTE_DEBUGS
set "opts=%opts% -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"
shift
goto :RUN_LOOP

:EXECUTE_VERBOSE
set "logconf=%DIRNAME%etc\logging-verbose.properties"
shift
goto :RUN_LOOP

:EXECUTE_MAIN
popd

rem Launch gogo shell
echo Launching Gogo JLine...
echo Classpath: %cp%
java -cp %cp% %opts% -Dgosh.home=%DIRNAME% -Djava.util.logging.config.file=%logconf% org.apache.felix.gogo.jline.Main

:END
2 changes: 1 addition & 1 deletion demo/src/main/java/org/apache/felix/gogo/jline/Posix.java
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ public int compare(String o1, String o2) {
protected Double getDouble(String s, int start, int end) {
Matcher m = fpPattern.matcher(s.substring(start, end));
m.find();
return new Double(s.substring(0, m.end(1)));
return Double.valueOf(s.substring(0, m.end(1)));
}

protected int compareRegion(
Expand Down
14 changes: 4 additions & 10 deletions native/src/main/java/org/jline/nativ/OSInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ public static boolean isAndroid() {

public static boolean isAlpine() {
try {
Process p = Runtime.getRuntime().exec("cat /etc/os-release | grep ^ID");
Process p = Runtime.getRuntime().exec(new String[] {"cat", "/etc/os-release", "|", "grep", "^ID"});
p.waitFor();

InputStream in = p.getInputStream();
try {
try (InputStream in = p.getInputStream()) {
return readFully(in).toLowerCase().contains("alpine");
} finally {
in.close();
}

} catch (Throwable e) {
Expand All @@ -135,14 +132,11 @@ public static boolean isAlpine() {

static String getHardwareName() {
try {
Process p = Runtime.getRuntime().exec("uname -m");
Process p = Runtime.getRuntime().exec(new String[] {"uname", "-m"});
p.waitFor();

InputStream in = p.getInputStream();
try {
try (InputStream in = p.getInputStream()) {
return readFully(in);
} finally {
in.close();
}
} catch (Throwable e) {
System.err.println("Error while running uname -m: " + e.getMessage());
Expand Down

0 comments on commit a2ab047

Please sign in to comment.