Skip to content

Commit

Permalink
add priority
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 18, 2024
1 parent cb371cf commit 793b097
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/xyz/wagyourtail/jvmdg/ClassDowngrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,19 @@ public synchronized Map<Integer, VersionProvider> collectProviders() {
Map<Integer, VersionProvider> downgraders = new HashMap<>();
try {
for (VersionProvider provider : ServiceLoader.load(VersionProvider.class, classLoader)) {
downgraders.put(provider.inputVersion, provider);
if (downgraders.containsKey(provider.inputVersion)) {
VersionProvider prev = downgraders.get(provider.inputVersion);
if (prev.priotity < provider.priotity) {
downgraders.put(provider.inputVersion, provider);
} else if (prev.priotity == provider.priotity) {
logger.warn(
"Duplicate version providers with same priority for " + provider.inputVersion
+ " \"" + provider.getClass().getName() + "\" and \"" + prev.getClass().getName() + "\""
);
}
} else {
downgraders.put(provider.inputVersion, provider);
}
}
} catch (Throwable t) {
try {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/xyz/wagyourtail/jvmdg/version/VersionProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.wagyourtail.jvmdg.version;

import org.jetbrains.annotations.ApiStatus;
import org.objectweb.asm.*;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureWriter;
Expand Down Expand Up @@ -32,6 +33,8 @@ public abstract class VersionProvider {

public final Coverage coverage;

public final int priotity;

/**
* lateinit
* bound during ensureInit
Expand All @@ -41,10 +44,23 @@ public abstract class VersionProvider {

private volatile boolean initialized = false;

/**
* will be made package-private in a future release
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
protected VersionProvider(int inputVersion, int outputVersion) {
this.inputVersion = inputVersion;
this.outputVersion = outputVersion;
this.coverage = new Coverage(inputVersion, this);
this.priotity = 0;
}

protected VersionProvider(int inputVersion, int outputVersion, int priotity) {
this.inputVersion = inputVersion;
this.outputVersion = outputVersion;
this.coverage = new Coverage(inputVersion, this);
this.priotity = priotity;
}

public FullyQualifiedMemberNameAndDesc resolveStubTarget(Member member, Ref ref) {
Expand Down

0 comments on commit 793b097

Please sign in to comment.