Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Oct 25, 2023
1 parent 289376e commit e16e31e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion java-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ operator fun JavaVersion.rangeTo(that: JavaVersion): Array<JavaVersion> {
return JavaVersion.values().copyOfRange(this.ordinal, that.ordinal + 1)
}

operator fun JavaVersion.minus(int: Int): JavaVersion {
return JavaVersion.values()[this.ordinal - int]
}

val fromVersion = JavaVersion.toVersion(project.properties["stubFromVersion"]!!)
val toVersion = JavaVersion.toVersion(project.properties["stubToVersion"]!!)

Expand All @@ -47,7 +51,7 @@ dependencies {

for (vers in fromVersion..toVersion) {
tasks.getByName("compileJava${vers.ordinal + 1}Java") {
(this as JavaCompile).configCompile(vers)
(this as JavaCompile).configCompile(vers - 1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ClassDowngradingAgent implements ClassFileTransformer {
public static final boolean DUMP_CLASSES = Boolean.parseBoolean(System.getProperty("jvmdg.dump", "true"));

static {
LOGGER.setLevel(Boolean.parseBoolean(System.getProperty("jvmdg.log", "true")) ? Level.ALL : Level.OFF);
LOGGER.setLevel(Boolean.parseBoolean(System.getProperty("jvmdg.log", "false")) ? Level.WARNING : Level.OFF);
}

static {
Expand Down Expand Up @@ -93,10 +93,10 @@ public byte[] transform(final ClassLoader loader, String className, Class<?> cla
int version = ((bytes[6] & 0xFF) << 8) | (bytes[7] & 0xFF);
if (version <= currentVersion) {
// already at or below the target version
// LOGGER.info("Ignoring " + className + " as it is already at or below the target version");
LOGGER.finer("Ignoring " + className + " as it is already at or below the target version");
return null;
}
LOGGER.info("Transforming " + className + " from " + version + " to " + currentVersion);
LOGGER.fine("Transforming " + className + " from " + version + " to " + currentVersion);
// if (loader instanceof DowngradingClassLoader) return bytes; // already handled
Map<String, byte[]> outputs = ClassDowngrader.currentVersionDowngrader.downgrade(new AtomicReference<>(className), bytes, new Function<String, byte[]>() {
@Override
Expand All @@ -110,10 +110,10 @@ public byte[] apply(String s) {
}
}
});
LOGGER.info("transform size: " + (outputs == null ? null : outputs.size()));
LOGGER.fine("transform size: " + (outputs == null ? null : outputs.size()));
if (outputs == null || outputs.isEmpty()) return bytes;
for (Map.Entry<String, byte[]> entry : outputs.entrySet()) {
LOGGER.info("Loading " + entry.getKey() + " into " + loader);
LOGGER.fine("Loading " + entry.getKey() + " into " + loader);
if (DUMP_CLASSES) {
ClassDowngrader.currentVersionDowngrader.writeBytesToDebug(entry.getKey(), entry.getValue());
}
Expand Down

0 comments on commit e16e31e

Please sign in to comment.