Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public static FileInclusionCalculator empty() {
}

boolean includeModFile(ModpackIndex.ModpackFile modFile) {
return (
return shouldForceIncludeFile(modFile.getPath())
|| (
// env is optional
modFile.getEnv() == null
|| modFile.getEnv().get(Env.server) != EnvType.unsupported
|| shouldForceIncludeFile(modFile.getPath())
)
&& !shouldExcludeFile(modFile.getPath());
(modFile.getEnv() == null
|| modFile.getEnv().get(Env.server) != EnvType.unsupported)
&& !shouldExcludeFile(modFile.getPath())
);
}

private boolean shouldForceIncludeFile(String modPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public Mono<FetchedPack> fetchModpack(ModrinthModpackManifest prevManifest) {
modpackProjectRef, modLoaderType, gameVersion, defaultVersionType
))))
.filter(version -> needsInstall(prevManifest, project.getSlug(), version))
.doOnNext(version -> log.info("Downloading modpack for {} {}", project.getTitle(), version.getName()))
.flatMap(version ->
apiClient.downloadMrPack(ModrinthApiClient.pickVersionFile(version))
.map(mrPackFile -> new FetchedPack(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package me.itzg.helpers.modrinth;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import me.itzg.helpers.curseforge.ExcludeIncludesContent.ExcludeIncludes;
import me.itzg.helpers.modrinth.model.Env;
import me.itzg.helpers.modrinth.model.EnvType;
import me.itzg.helpers.modrinth.model.ModpackIndex.ModpackFile;
import org.junit.jupiter.api.Test;

class FileInclusionCalculatorTest {

@Test
void forceIncludeWhenExcludedServerFile() {
final ExcludeIncludesContent globalContent = new ExcludeIncludesContent();
globalContent.setGlobalExcludes(Collections.singleton("cloth-config"));

final FileInclusionCalculator calculator = new FileInclusionCalculator("modpack",
null,
Collections.singletonList("cloth"),
globalContent
);

final ModpackFile modFile = new ModpackFile()
.setEnv(forServerAndClient())
.setPath("mods/cloth-config-15.0.140-fabric.jar");

final boolean result = calculator.includeModFile(modFile);
assertThat(result).isTrue();
}

@Test
void excludeForModpack() {
final ExcludeIncludesContent globalContent = new ExcludeIncludesContent();
globalContent.setGlobalExcludes(Collections.singleton("other"));
final Map<String, ExcludeIncludes> modpacksGlobal = new HashMap<>();
modpacksGlobal.put("modpackWithExcludes", new ExcludeIncludes().setExcludes(Collections.singleton("cloth-config")));
globalContent.setModpacks(modpacksGlobal);

final ModpackFile modFile = new ModpackFile()
.setEnv(forServerAndClient())
.setPath("mods/cloth-config-15.0.140-fabric.jar");

{
final FileInclusionCalculator calculator = new FileInclusionCalculator("modpack",
null,
null,
globalContent
);

assertThat(calculator.includeModFile(modFile)).isTrue();
}
{
final FileInclusionCalculator calculator = new FileInclusionCalculator("modpackWithExcludes",
null,
null,
globalContent
);

assertThat(calculator.includeModFile(modFile)).isFalse();
}
}

private Map<Env, EnvType> forServerAndClient() {
final Map<Env, EnvType> modEnvs = new HashMap<>();
modEnvs.put(Env.client, EnvType.required);
modEnvs.put(Env.server, EnvType.required);
return modEnvs;
}
}