Skip to content

Commit db08f8a

Browse files
authored
modrinth: fix force include handling of default-excluded project (#623)
1 parent ef2c544 commit db08f8a

File tree

3 files changed

+80
-6
lines changed

3 files changed

+80
-6
lines changed

src/main/java/me/itzg/helpers/modrinth/FileInclusionCalculator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public static FileInclusionCalculator empty() {
4949
}
5050

5151
boolean includeModFile(ModpackIndex.ModpackFile modFile) {
52-
return (
52+
return shouldForceIncludeFile(modFile.getPath())
53+
|| (
5354
// env is optional
54-
modFile.getEnv() == null
55-
|| modFile.getEnv().get(Env.server) != EnvType.unsupported
56-
|| shouldForceIncludeFile(modFile.getPath())
57-
)
58-
&& !shouldExcludeFile(modFile.getPath());
55+
(modFile.getEnv() == null
56+
|| modFile.getEnv().get(Env.server) != EnvType.unsupported)
57+
&& !shouldExcludeFile(modFile.getPath())
58+
);
5959
}
6060

6161
private boolean shouldForceIncludeFile(String modPath) {

src/main/java/me/itzg/helpers/modrinth/ModrinthApiPackFetcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public Mono<FetchedPack> fetchModpack(ModrinthModpackManifest prevManifest) {
6161
modpackProjectRef, modLoaderType, gameVersion, defaultVersionType
6262
))))
6363
.filter(version -> needsInstall(prevManifest, project.getSlug(), version))
64+
.doOnNext(version -> log.info("Downloading modpack for {} {}", project.getTitle(), version.getName()))
6465
.flatMap(version ->
6566
apiClient.downloadMrPack(ModrinthApiClient.pickVersionFile(version))
6667
.map(mrPackFile -> new FetchedPack(
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.itzg.helpers.modrinth;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.Collections;
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
import me.itzg.helpers.curseforge.ExcludeIncludesContent.ExcludeIncludes;
9+
import me.itzg.helpers.modrinth.model.Env;
10+
import me.itzg.helpers.modrinth.model.EnvType;
11+
import me.itzg.helpers.modrinth.model.ModpackIndex.ModpackFile;
12+
import org.junit.jupiter.api.Test;
13+
14+
class FileInclusionCalculatorTest {
15+
16+
@Test
17+
void forceIncludeWhenExcludedServerFile() {
18+
final ExcludeIncludesContent globalContent = new ExcludeIncludesContent();
19+
globalContent.setGlobalExcludes(Collections.singleton("cloth-config"));
20+
21+
final FileInclusionCalculator calculator = new FileInclusionCalculator("modpack",
22+
null,
23+
Collections.singletonList("cloth"),
24+
globalContent
25+
);
26+
27+
final ModpackFile modFile = new ModpackFile()
28+
.setEnv(forServerAndClient())
29+
.setPath("mods/cloth-config-15.0.140-fabric.jar");
30+
31+
final boolean result = calculator.includeModFile(modFile);
32+
assertThat(result).isTrue();
33+
}
34+
35+
@Test
36+
void excludeForModpack() {
37+
final ExcludeIncludesContent globalContent = new ExcludeIncludesContent();
38+
globalContent.setGlobalExcludes(Collections.singleton("other"));
39+
final Map<String, ExcludeIncludes> modpacksGlobal = new HashMap<>();
40+
modpacksGlobal.put("modpackWithExcludes", new ExcludeIncludes().setExcludes(Collections.singleton("cloth-config")));
41+
globalContent.setModpacks(modpacksGlobal);
42+
43+
final ModpackFile modFile = new ModpackFile()
44+
.setEnv(forServerAndClient())
45+
.setPath("mods/cloth-config-15.0.140-fabric.jar");
46+
47+
{
48+
final FileInclusionCalculator calculator = new FileInclusionCalculator("modpack",
49+
null,
50+
null,
51+
globalContent
52+
);
53+
54+
assertThat(calculator.includeModFile(modFile)).isTrue();
55+
}
56+
{
57+
final FileInclusionCalculator calculator = new FileInclusionCalculator("modpackWithExcludes",
58+
null,
59+
null,
60+
globalContent
61+
);
62+
63+
assertThat(calculator.includeModFile(modFile)).isFalse();
64+
}
65+
}
66+
67+
private Map<Env, EnvType> forServerAndClient() {
68+
final Map<Env, EnvType> modEnvs = new HashMap<>();
69+
modEnvs.put(Env.client, EnvType.required);
70+
modEnvs.put(Env.server, EnvType.required);
71+
return modEnvs;
72+
}
73+
}

0 commit comments

Comments
 (0)