-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix annotations not applying properly to packages.
- Loading branch information
Showing
18 changed files
with
330 additions
and
97 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...ecraft-test/src/main/java/net/fabricmc/minecraft/test/server_only/TestMixinGuiHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ft/minecraft-test/src/main/java/net/fabricmc/minecraft/test/server_only/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @org.quiltmc.loader.api.minecraft.DedicatedServerOnly | ||
//@org.quiltmc.loader.api.minecraft.DedicatedServerOnly | ||
//@org.quiltmc.loader.api.Requires({"trinkets", "quilt_loader", "minecraft", "buildcraft"}) | ||
// Uncomment the above line to test out package based stripping. | ||
package net.fabricmc.minecraft.test.server_only; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/org/quiltmc/loader/impl/transformer/AbstractStripData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.quiltmc.loader.impl.transformer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
import org.quiltmc.loader.api.Requires; | ||
import org.quiltmc.loader.impl.util.QuiltLoaderInternal; | ||
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType; | ||
|
||
import net.fabricmc.api.EnvType; | ||
|
||
/** Contains string processing for both {@link PackageStrippingData} and {@link ClassStrippingData} */ | ||
@QuiltLoaderInternal(QuiltLoaderInternalType.NEW_INTERNAL) | ||
public abstract class AbstractStripData extends ClassVisitor { | ||
|
||
protected final EnvType envType; | ||
protected final Set<String> mods; | ||
|
||
protected final List<String> denyLoadReasons = new ArrayList<>(); | ||
|
||
protected AbstractStripData(int api, EnvType envType, Set<String> mods) { | ||
this(api, null, envType, mods); | ||
} | ||
|
||
protected AbstractStripData(int api, ClassVisitor classVisitor, EnvType envType, Set<String> mods) { | ||
super(api, classVisitor); | ||
this.envType = envType; | ||
this.mods = mods; | ||
} | ||
|
||
/** @return What this represents - generally "package" or "class". */ | ||
protected abstract String type(); | ||
|
||
public List<String> getDenyLoadReasons() { | ||
return Collections.unmodifiableList(denyLoadReasons); | ||
} | ||
|
||
public String summarizeDenyLoadReasons() { | ||
if (denyLoadReasons.isEmpty()) { | ||
return ""; | ||
} | ||
StringBuilder sb = new StringBuilder(); | ||
if (denyLoadReasons.size() == 1) { | ||
sb.append("because "); | ||
sb.append(denyLoadReasons.get(0)); | ||
} else { | ||
sb.append("because:"); | ||
for (String reason : denyLoadReasons) { | ||
sb.append("\n- "); | ||
sb.append(reason); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
/** Appends a client-only deny reason to {@link #denyLoadReasons}. */ | ||
protected void denyClientOnlyLoad() { | ||
denyLoadReasons.add("the " + type() + " is annotated with @ClientOnly but we're on the dedicated server"); | ||
} | ||
|
||
/** Appends a dedicated server only deny reason to {@link #denyLoadReasons}. */ | ||
protected void denyDediServerOnlyLoad() { | ||
denyLoadReasons.add("the " + type() + " is annotated with @DedicatedServerOnly but we're on the client"); | ||
} | ||
|
||
/** Checks to see if all mods given are in {@link #mods}, and appends a deny reason to {@link #denyLoadReasons} if | ||
* any are missing. Assumes the annotation is {@link Requires} in the error message */ | ||
protected void checkHasAllMods(List<String> requiredMods) { | ||
List<String> missingMods = new ArrayList<>(); | ||
for (String mod : requiredMods) { | ||
if (!mods.contains(mod)) { | ||
missingMods.add(mod); | ||
} | ||
} | ||
|
||
checkHasAllMods(requiredMods, missingMods); | ||
} | ||
|
||
/** Checks to see if the missing mods list is empty, and appends a deny reason to {@link #denyLoadReasons} if it is | ||
* not. Assumes the annotation is {@link Requires} in the error message */ | ||
protected void checkHasAllMods(List<String> requiredMods, List<String> missingMods) { | ||
if (!missingMods.isEmpty()) { | ||
StringBuilder all = new StringBuilder(); | ||
if (requiredMods.size() > 1) { | ||
all.append("{"); | ||
} | ||
|
||
for (String mod : requiredMods) { | ||
if (all.length() > 1) { | ||
all.append(", "); | ||
} | ||
all.append("\""); | ||
all.append(mod); | ||
all.append("\""); | ||
} | ||
|
||
if (requiredMods.size() > 1) { | ||
all.append("}"); | ||
} | ||
|
||
denyLoadReasons.add( | ||
"the " + type() + " is annotated with @Requires(" + all + ") but the mods " + missingMods | ||
+ " are not loaded!" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.