add minVersion filling support - fix #34

dev/0.11
asie 2018-12-15 14:33:25 +01:00
parent fe194ea64d
commit 83d6a2da42
5 changed files with 33 additions and 6 deletions

View File

@ -41,7 +41,7 @@ dependencies {
// implementation ('org.benf:cfr:0.136')
implementation ('org.jetbrains:intellij-fernflower:1.0.0.2')
implementation ('net.fabricmc:sponge-mixin:0.7.11.4') {
implementation ('net.fabricmc:sponge-mixin:0.7.11.10') {
exclude module: 'launchwrapper'
exclude module: 'guava'
}

View File

@ -29,11 +29,14 @@ import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.util.LoomDependencyManager;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class LoomGradleExtension {
public String runDir = "run";
@ -74,6 +77,24 @@ public class LoomGradleExtension {
return projectCache;
}
@Nullable
public String getMixinVersion() {
for (Dependency dependency : project.getConfigurations().getByName("compile").getDependencies()) {
if (dependency.getName().equalsIgnoreCase("mixin") && dependency.getGroup().equals("org.spongepowered")) {
return dependency.getVersion();
}
if (dependency.getName().equals("sponge-mixin") && dependency.getGroup().equals("net.fabricmc")) {
if (Objects.requireNonNull(dependency.getVersion()).split("\\.").length >= 4) {
return dependency.getVersion().substring(0, dependency.getVersion().lastIndexOf('.')) + "-SNAPSHOT";
}
return dependency.getVersion();
}
}
return null;
}
public LoomDependencyManager getDependencyManager() {
return dependencyManager;
}

View File

@ -66,7 +66,7 @@ public class LoomDependencyManager {
}
for(String config : targetConfigs){
Configuration configuration = project.getConfigurations().getByName(config);
configuration.getDependencies().stream().forEach(dependency -> {
configuration.getDependencies().forEach(dependency -> {
for(DependencyProvider provider : dependencyProviderList){
if(provider.getTargetConfig().equals(config)){
DependencyProvider.DependencyInfo info = new DependencyProvider.DependencyInfo(dependency, configuration);

View File

@ -50,7 +50,7 @@ public final class MixinRefmapHelper {
private MixinRefmapHelper() {
}
public static boolean addRefmapName(String filename, File output) {
public static boolean addRefmapName(String filename, String mixinVersion, File output) {
Set<String> mixinFilenames = findMixins(output, true);
if (mixinFilenames.size() > 0) {
@ -61,7 +61,12 @@ public final class MixinRefmapHelper {
@Override
protected String transform(ZipEntry zipEntry, String input) throws IOException {
JsonObject json = GSON.fromJson(input, JsonObject.class);
json.addProperty("refmap", filename);
if (!json.has("refmap")) {
json.addProperty("refmap", filename);
}
if (!json.has("minVersion") && mixinVersion != null) {
json.addProperty("minVersion", mixinVersion);
}
return GSON.toJson(json);
}
})).toArray(ZipEntryTransformerEntry[]::new)
@ -82,7 +87,7 @@ public final class MixinRefmapHelper {
try {
JsonObject json = GSON.fromJson(inputStreamReader, JsonObject.class);
if (json != null && json.has("mixins") && json.get("mixins").isJsonArray()) {
if (!onlyWithoutRefmap || !json.has("refmap")) {
if (!onlyWithoutRefmap || !json.has("refmap") || !json.has("minVersion")) {
mixinFilename.add(entry.getName());
}
}

View File

@ -31,6 +31,7 @@ import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import java.io.File;
import java.nio.file.Path;
@ -100,7 +101,7 @@ public class ModRemapper {
}
if (extension.refmapName != null && extension.refmapName.length() > 0) {
if (MixinRefmapHelper.addRefmapName(extension.refmapName, modJarOutput)) {
if (MixinRefmapHelper.addRefmapName(extension.refmapName, extension.getMixinVersion(), modJarOutput)) {
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
}
}