Skip to content

Commit

Permalink
enh: Build on JDK 22
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Jun 11, 2024
1 parent 77c7c5f commit ed4695b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
matrix:
os: [ 'ubuntu-latest', 'windows-latest', 'macOS-latest' ]
jdk: [ 11, 17, 21 ]
jdk: [ 11, 17, 21, 22 ]
dist: [ 'temurin', 'adopt-openj9', 'zulu' ]
exclude:
# was already built
Expand All @@ -71,6 +71,9 @@ jobs:
# no OpenJ9 21
- dist: adopt-openj9
jdk: 21
# no OpenJ9 22
- dist: adopt-openj9
jdk: 22
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down
13 changes: 5 additions & 8 deletions tools/hasher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<exclusions>
<!-- BeanUtils is for ini config - this simple command line program
does not init a shiro environment, so we don't need it: -->
<exclusion>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- explicitly use the compile scopes for the algorithms, so we can access the parameter names. -->
<dependency>
Expand All @@ -71,6 +63,11 @@
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.shiro.tools.hasher;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -479,9 +480,8 @@ private static void printHelpAndExit(Options options, Exception e, boolean debug
private static char[] readPassword(boolean confirm) throws IOException {
java.io.Console console = System.console();
char[] first;
if (console != null) {
if (isTerminal(console)) {
first = console.readPassword("%s", "Password to hash: ");
//throw new IllegalStateException("java.io.Console is not available on the current JVM. Cannot read passwords.");
} else if (System.in != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String readLine = br.readLine();
Expand All @@ -495,6 +495,9 @@ private static char[] readPassword(boolean confirm) throws IOException {
throw new IllegalArgumentException("No password specified.");
}
if (confirm) {
if (!isTerminal(console)) {
throw new IllegalStateException("Cannot confirm password when console is not available.");
}
char[] second = console.readPassword("%s", "Password to hash (confirm): ");
if (!Arrays.equals(first, second)) {
String msg = "Password entries do not match.";
Expand All @@ -504,6 +507,15 @@ private static char[] readPassword(boolean confirm) throws IOException {
return first;
}

private static boolean isTerminal(java.io.Console console) throws IOException {
try {
// isTerminal is only available in Java 22 or later
return console != null && (Boolean) PropertyUtils.getProperty(console, "terminal");
} catch (ReflectiveOperationException e) {
return true;
}
}

private static File toFile(String path) {
String resolved = path;
if (path.startsWith("~/") || path.startsWith(("~\\"))) {
Expand Down

0 comments on commit ed4695b

Please sign in to comment.