Skip to content

Commit

Permalink
java "5" support
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Oct 31, 2024
1 parent a22e388 commit fecdf7d
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

version=1.2.1
version=1.3.0

asm_version=9.7.1

Expand All @@ -12,7 +12,7 @@ testVersion=21
# because java 7 support is in beta*
testTargetVersion=8

stubFromVersion=8
stubFromVersion=7
stubToVersion=23

maven_group=xyz.wagyourtail.jvmdowngrader
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package xyz.wagyourtail.jvmdg.j7.stub;

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

import java.util.*;

public class J_L_Throwable {
private static final Map<Throwable, List<Throwable>> suppressed = Collections.synchronizedMap(new WeakHashMap<Throwable, List<Throwable>>());
private static final Throwable[] empty = new Throwable[0];

@Stub
public static void addSuppressed(Throwable self, Throwable other) {
if (!suppressed.containsKey(self)) {
synchronized (suppressed) {
if (!suppressed.containsKey(self)) {
suppressed.put(self, new ArrayList<Throwable>());
}
}
}
suppressed.get(self).add(other);
}

@Stub
public static Throwable[] getSuppressed(Throwable self) {
if (!suppressed.containsKey(self)) {
synchronized (suppressed) {
if (!suppressed.containsKey(self)) {
return empty;
}
}
}
return suppressed.get(self).toArray(empty);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import xyz.wagyourtail.jvmdg.util.Function;
import xyz.wagyourtail.jvmdg.version.VersionProvider;

import java.io.IOException;
import java.util.*;

public class Java11Downgrader extends VersionProvider {
Expand Down Expand Up @@ -115,7 +116,7 @@ public void init() {
}

@Override
public ClassNode otherTransforms(ClassNode clazz, Set<ClassNode> extra, Function<String, ClassNode> getReadOnly) {
public ClassNode otherTransforms(ClassNode clazz, Set<ClassNode> extra, Function<String, ClassNode> getReadOnly) throws IOException {
super.otherTransforms(clazz);
if (clazz.name.equals("module-info")) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import xyz.wagyourtail.jvmdg.util.Function;
import xyz.wagyourtail.jvmdg.version.VersionProvider;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void init() {
}

@Override
public ClassNode otherTransforms(ClassNode clazz, Set<ClassNode> extra, Function<String, ClassNode> getReadOnly) {
public ClassNode otherTransforms(ClassNode clazz, Set<ClassNode> extra, Function<String, ClassNode> getReadOnly) throws IOException {
super.otherTransforms(clazz, extra, getReadOnly);
fixHandleAccessNests(clazz, getReadOnly);
return clazz;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package xyz.wagyourtail.jvmdg.providers;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import xyz.wagyourtail.jvmdg.ClassDowngrader;
import xyz.wagyourtail.jvmdg.version.VersionProvider;

import java.io.IOException;
import java.util.Iterator;

public class Java6Downgrader extends VersionProvider {

public Java6Downgrader() {
super(Opcodes.V1_6, Opcodes.V1_5, 0);
}

@Override
public void ensureInit(ClassDowngrader downgrader) {
if (!isInitialized()) {
downgrader.logger.warn("Java 6 -> 5 Stubs are VERY incomplete!");
}
super.ensureInit(downgrader);
}

@Override
public void init() {

}

@Override
public ClassNode otherTransforms(ClassNode clazz) throws IOException {
for (MethodNode method : clazz.methods) {
if (method.instructions != null) {
Iterator<AbstractInsnNode> it = method.instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode insn = it.next();
if (insn.getType() == AbstractInsnNode.FRAME) {
it.remove();
}
}
}
}
return super.otherTransforms(clazz);
}

}
Loading

0 comments on commit fecdf7d

Please sign in to comment.