Skip to content

Commit

Permalink
java 23 support, and fix java 7 break on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Sep 18, 2024
1 parent caf6d12 commit d526d54
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 16 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ in `build.gradle`:
```gradle
// add the plugin
plugins {
id 'xyz.wagyourtail.jvmdowngrader' version '1.0.0'
id 'xyz.wagyourtail.jvmdowngrader' version '$jvmdgVersion'
}
// optionally you can change some globals, here are their default values:
jvmdg.downgradeTo = JavaVersion.VERSION_1_8
jvmdg.apiJar = [this.getClass().getResourceAsStream("jvmdg/java-api-${version}.jar").writeToFile("build/jvmdg/java-api-${version}.jar")]
jvmdg.quiet = false
jvmdg.debug = false
jvmdg.logLevel = "INFO"
jvmdg.ignoreWarningsIn = [].toSet()
jvmdg.debugSkipStubs = [].toSet()
jvmdg.debugDumpClasses = false
jvmdg.shadePath = {
it.substringBefore(".").substringBeforeLast("-").replace(Regex("[.;\\[/]"), "-")
}
jvmdg.shadeInlining = true
jvmdg.multiReleaseOriginal = false
jvmdg.multiReleaseVersions = [].toSet()
```

You can see more of what these values mean by [checking the docs on the flags classes](gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags)

This will create a default downgrade task for `jar` (or `shadowJar` if present) called `downgradeJar` that will
downgrade the output to java 8 by default.
as well as a `shadeDowngradedApi` to then insert the required classes for not having a runtime dependency on the api
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ val mainVersion = project.properties["mainVersion"] as String
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(mainVersion.toInt()))
vendor.set(JvmVendorSpec.AZUL)
}
}

Expand Down
11 changes: 0 additions & 11 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ sourceSets.main {
java.srcDirs("src/utils/java")
kotlin.srcDirs("src/utils/kotlin")
}
//
//val utils by sourceSets.creating {
// compileClasspath += sourceSets["main"].compileClasspath
// runtimeClasspath += sourceSets["main"].runtimeClasspath
//
// sourceSets["main"].compileClasspath += this.output
// sourceSets["main"].runtimeClasspath += this.output
//
// sourceSets["test"].compileClasspath += this.output
// sourceSets["test"].runtimeClasspath += this.output
//}

val asmVersion: String = project.properties["asm_version"]?.toString() ?: run {
projectDir.parentFile.resolve("gradle.properties").inputStream().use {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface DowngradeFlags : TransformParameters {
*/
@get:Input
@get:Optional
@get:Deprecated(message = "use logLevel", replaceWith = ReplaceWith("logLevel = LogLevel.DEBUG"))
@get:Deprecated(message = "use logLevel", replaceWith = ReplaceWith("logLevel = LogLevel.FATAL"))
val quiet: Property<Boolean>

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ testVersion=21
testTargetVersion=8

stubFromVersion=8
stubToVersion=22
stubToVersion=23

maven_group=xyz.wagyourtail.jvmdowngrader
archives_base_name=jvmdowngrader
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package xyz.wagyourtail.jvmdg.j23.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.Console;
import java.io.PrintWriter;
import java.util.Locale;

public class J_I_Console {

@Stub
public Console format(Console console, Locale locale, String format, Object... args) {
PrintWriter pw = console.writer();
pw.format(locale, format, args);
pw.flush();
return console;
}

@Stub
public Console printf(Console console, Locale locale, String format, Object... args) {
PrintWriter pw = console.writer();
pw.printf(locale, format, args);
pw.flush();
return console;
}

@Stub
public String readLine(Console console, Locale locale, String format, Object... args) {
PrintWriter pw = console.writer();
pw.printf(locale, format, args);
pw.flush();
return console.readLine();
}

@Stub
public char[] readPassword(Console console, Locale locale, String format, Object... args) {
PrintWriter pw = console.writer();
pw.printf(locale, format, args);
pw.flush();
return console.readPassword();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package xyz.wagyourtail.jvmdg.j23.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

public class J_L_R_ExactConversionsSupport {

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToByteExact(double value) {
return value == (byte) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToCharExact(double value) {
return value == (char) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToFloatExact(double value) {
return value == (float) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToIntExact(double value) {
return value == (int) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToLongExact(double value) {
return value == (long) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isDoubleToShortExact(double value) {
return value == (short) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isFloatToByteExact(float value) {
return value == (byte) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isFloatToCharExact(float value) {
return value == (char) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isFloatToIntExact(float value) {
return value == (int) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isFloatToLongExact(float value) {
return value == (long) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isFloatToShortExact(float value) {
return value == (short) value && isNotNegativeZero(value);
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isIntToByteExact(int value) {
return value == (byte) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isIntToCharExact(int value) {
return value == (char) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isIntToFloatExact(int value) {
return value == (float) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isIntToShortExact(int value) {
return value == (short) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToByteExact(long value) {
return value == (byte) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToCharExact(long value) {
return value == (char) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToDoubleExact(long value) {
return value == (double) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToFloatExact(long value) {
return value == (float) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToIntExact(long value) {
return value == (int) value;
}

@Stub(ref = @Ref("java/lang/runtime/ExactConversionsSupport"))
public static boolean isLongToShortExact(long value) {
return value == (short) value;
}

private static boolean isNotNegativeZero(float value) {
return Float.floatToRawIntBits(value) != Integer.MIN_VALUE;
}

private static boolean isNotNegativeZero(double value) {
return Double.doubleToRawLongBits(value) != Long.MIN_VALUE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xyz.wagyourtail.jvmdg.j23.stub.java_base;

import xyz.wagyourtail.jvmdg.version.Stub;

import java.time.Duration;
import java.time.Instant;

public class J_T_Instant {

@Stub
public static Duration until(Instant instant, Instant endExclusive) {
return Duration.between(instant, endExclusive);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.wagyourtail.jvmdg.providers;

import org.objectweb.asm.Opcodes;
import xyz.wagyourtail.jvmdg.j23.stub.java_base.J_I_Console;
import xyz.wagyourtail.jvmdg.j23.stub.java_base.J_L_R_ExactConversionsSupport;
import xyz.wagyourtail.jvmdg.j23.stub.java_base.J_T_Instant;
import xyz.wagyourtail.jvmdg.version.VersionProvider;

public class Java23Downgrader extends VersionProvider {

public Java23Downgrader() {
super(Opcodes.V23, Opcodes.V22);
}

@Override
public void init() {
// -- java.base --
stub(J_I_Console.class);
stub(J_L_R_ExactConversionsSupport.class);
stub(J_T_Instant.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ xyz.wagyourtail.jvmdg.providers.Java19Downgrader
xyz.wagyourtail.jvmdg.providers.Java20Downgrader
xyz.wagyourtail.jvmdg.providers.Java21Downgrader
xyz.wagyourtail.jvmdg.providers.Java22Downgrader
xyz.wagyourtail.jvmdg.providers.Java23Downgrader
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.7.0")
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0")
}

include("gradle-plugin")
Expand All @@ -18,6 +18,5 @@ include("testing")
include("testing:downgrade")
include("testing:multi-version")


rootProject.name = "JvmDowngrader"

0 comments on commit d526d54

Please sign in to comment.