-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicated dependencies causing module resolution failure; Fixes #…
- Loading branch information
1 parent
9499335
commit 291776a
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
.../src/neoforge/java/io/izzel/arclight/boot/neoforge/mod/ArclightJarContentsImplFilter.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,66 @@ | ||
package io.izzel.arclight.boot.neoforge.mod; | ||
|
||
import cpw.mods.jarhandling.impl.JarContentsImpl; | ||
import io.izzel.arclight.api.Unsafe; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Filter out packages already provided by Arclight. | ||
* For duplicate modules, the packages will be removed | ||
* before modules are removed. | ||
* For duplicate packages in non-duplicate library modules, | ||
* only the packages will be removed. | ||
* For duplicate packages in non-duplicate mod modules, | ||
* the packages won't be removed | ||
* Duplicated shaded mods are like modules, and are removed | ||
* later by JarInJarFilter. | ||
*/ | ||
public class ArclightJarContentsImplFilter { | ||
// Use unsafe to bypass JPMS accessibility check | ||
private static final MethodHandles.Lookup LOOKUP = Unsafe.lookup(); | ||
private static VarHandle PACKAGES; | ||
private static Set<String> serviceLayerPackages; | ||
private static final Logger LOGGER = LogManager.getLogger("Arclight"); | ||
|
||
static { | ||
try { | ||
PACKAGES = LOOKUP.findVarHandle(JarContentsImpl.class, "packages", Set.class); | ||
} catch (ReflectiveOperationException e) { | ||
LOGGER.error("Arclight failed to filter JarContents. This may cause dependency conflicts with some mods!", e); | ||
} | ||
serviceLayerPackages = ArclightJarContentsImplFilter.class | ||
.getModule() | ||
.getLayer() | ||
.modules() | ||
.stream() | ||
.flatMap(it -> it.getPackages().stream()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
/* | ||
* The result of getPackages() is cached | ||
* Through modifying the cache, we modify the result of getPackages() | ||
* Note: ModJarMetadata use getPackagesExcluding(String...), | ||
* which bypass the cache. This won't work for ModJarMetadata. | ||
*/ | ||
public static void filter(JarContentsImpl impl) { | ||
if (PACKAGES != null) { | ||
impl.getPackages(); | ||
Set<String> raw = (Set<String>)PACKAGES.get(impl); | ||
Set<String> result = raw.stream() | ||
.filter(ArclightJarContentsImplFilter::test) | ||
.collect(Collectors.toSet()); | ||
PACKAGES.set(impl, result); | ||
} | ||
} | ||
|
||
public static boolean test(String pkg) { | ||
return !serviceLayerPackages.contains(pkg); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
bootstrap/src/neoforge/java/io/izzel/arclight/boot/neoforge/mod/ArclightModFileReader.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,22 @@ | ||
package io.izzel.arclight.boot.neoforge.mod; | ||
|
||
import cpw.mods.jarhandling.JarContents; | ||
import cpw.mods.jarhandling.impl.JarContentsImpl; | ||
import net.neoforged.neoforgespi.locating.IModFile; | ||
import net.neoforged.neoforgespi.locating.IModFileReader; | ||
import net.neoforged.neoforgespi.locating.IOrderedProvider; | ||
import net.neoforged.neoforgespi.locating.ModFileDiscoveryAttributes; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ArclightModFileReader implements IModFileReader, IOrderedProvider { | ||
@Override | ||
public @Nullable IModFile read(JarContents jarContents, ModFileDiscoveryAttributes modFileDiscoveryAttributes) { | ||
ArclightJarContentsImplFilter.filter((JarContentsImpl) jarContents); | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return HIGHEST_SYSTEM_PRIORITY; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...rc/neoforge/resources/META-INF/services/net.neoforged.neoforgespi.locating.IModFileReader
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 @@ | ||
io.izzel.arclight.boot.neoforge.mod.ArclightModFileReader |