Move remapped mods into a full local maven repo (#300)
parent
3ab757363c
commit
78c934aed5
|
@ -207,9 +207,9 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
|
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
|
||||||
});
|
});
|
||||||
|
|
||||||
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
|
project1.getRepositories().maven(mavenArtifactRepository -> {
|
||||||
flatDirectoryArtifactRepository.dir(extension.getRemappedModCache());
|
mavenArtifactRepository.setUrl(extension.getRemappedModCache());
|
||||||
flatDirectoryArtifactRepository.setName("UserLocalRemappedMods");
|
mavenArtifactRepository.setName("UserLocalRemappedMods");
|
||||||
});
|
});
|
||||||
|
|
||||||
project1.getRepositories().maven(mavenArtifactRepository -> {
|
project1.getRepositories().maven(mavenArtifactRepository -> {
|
||||||
|
|
|
@ -28,16 +28,19 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
|
|
||||||
import net.fabricmc.loom.util.ModProcessor;
|
import net.fabricmc.loom.util.ModProcessor;
|
||||||
|
|
||||||
public class ModDependencyInfo {
|
public class ModDependencyInfo {
|
||||||
public final String group;
|
private final String group;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String version;
|
public final String version;
|
||||||
public final String classifier;
|
public final String classifier;
|
||||||
|
@ -61,15 +64,39 @@ public class ModDependencyInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRemappedNotation() {
|
public String getRemappedNotation() {
|
||||||
return String.format("%s:%s:%s@%s%s", group, name, version, remapData.mappingsSuffix, classifier);
|
if (classifier == null || classifier.isEmpty()) {
|
||||||
|
return String.format("%s:%s:%s", getGroup(), name, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRemappedFilename() {
|
return String.format("%s:%s:%s:%s", getGroup(), name, version, classifier);
|
||||||
return String.format("%s-%s@%s", name, version, remapData.mappingsSuffix + classifier.replace(':', '-'));
|
}
|
||||||
|
|
||||||
|
private String getRemappedFilename() {
|
||||||
|
if (classifier == null || classifier.isEmpty()) {
|
||||||
|
return String.format("%s-%s", name, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("%s-%s@%s", name, version, classifier.replace(':', '-'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getRemappedDir() {
|
||||||
|
return new File(remapData.modStore, String.format("%s/%s/%s", getGroup().replace(".", "/"), name, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getRemappedOutput() {
|
public File getRemappedOutput() {
|
||||||
return new File(remapData.modStore, getRemappedFilename() + ".jar");
|
return new File(getRemappedDir(), getRemappedFilename() + ".jar");
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getRemappedPom() {
|
||||||
|
return new File(getRemappedOutput().getAbsolutePath().replace(".jar", ".pom"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getGroup() {
|
||||||
|
return getMappingsPrefix(remapData.mappingsSuffix) + "." + group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMappingsPrefix(String mappings) {
|
||||||
|
return mappings.replace(".", "_").replace("-", "_").replace("+", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getInputFile() {
|
public File getInputFile() {
|
||||||
|
@ -77,11 +104,31 @@ public class ModDependencyInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresRemapping() {
|
public boolean requiresRemapping() {
|
||||||
return !getRemappedOutput().exists() || inputFile.lastModified() <= 0 || inputFile.lastModified() > getRemappedOutput().lastModified() || forceRemap;
|
return !getRemappedOutput().exists() || inputFile.lastModified() <= 0 || inputFile.lastModified() > getRemappedOutput().lastModified() || forceRemap || !getRemappedPom().exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finaliseRemapping() {
|
public void finaliseRemapping() {
|
||||||
getRemappedOutput().setLastModified(inputFile.lastModified());
|
getRemappedOutput().setLastModified(inputFile.lastModified());
|
||||||
|
savePom();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void savePom() {
|
||||||
|
try {
|
||||||
|
String pomTemplate;
|
||||||
|
|
||||||
|
try (InputStream input = ModDependencyInfo.class.getClassLoader().getResourceAsStream("mod_compile_template.pom")) {
|
||||||
|
pomTemplate = IOUtils.toString(input, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
pomTemplate = pomTemplate
|
||||||
|
.replace("%GROUP%", getGroup())
|
||||||
|
.replace("%NAME%", name)
|
||||||
|
.replace("%VERSION%", version);
|
||||||
|
|
||||||
|
FileUtils.writeStringToFile(getRemappedPom(), pomTemplate, StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to write mod pom", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forceRemap() {
|
public void forceRemap() {
|
||||||
|
|
|
@ -331,4 +331,8 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
|
|
||||||
return intermediaryTiny;
|
return intermediaryTiny;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMappingsKey() {
|
||||||
|
return mappingsName + "." + minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class LoomDependencyManager {
|
||||||
|
|
||||||
private final List<DependencyProvider> dependencyProviderList = new ArrayList<>();
|
private final List<DependencyProvider> dependencyProviderList = new ArrayList<>();
|
||||||
|
|
||||||
public void addProvider(DependencyProvider provider) {
|
public <T extends DependencyProvider> T addProvider(T provider) {
|
||||||
if (dependencyProviderList.contains(provider)) {
|
if (dependencyProviderList.contains(provider)) {
|
||||||
throw new RuntimeException("Provider is already registered");
|
throw new RuntimeException("Provider is already registered");
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ public class LoomDependencyManager {
|
||||||
|
|
||||||
provider.register(this);
|
provider.register(this);
|
||||||
dependencyProviderList.add(provider);
|
dependencyProviderList.add(provider);
|
||||||
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getProvider(Class<T> clazz) {
|
public <T> T getProvider(Class<T> clazz) {
|
||||||
|
@ -132,7 +133,7 @@ public class LoomDependencyManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
|
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
|
||||||
String mappingsKey = mappingsProvider.mappingsName + "." + mappingsProvider.minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsProvider.mappingsVersion;
|
String mappingsKey = mappingsProvider.getMappingsKey();
|
||||||
|
|
||||||
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
|
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class ModCompileRemapper {
|
||||||
project.getLogger().info(":providing " + remappedLog);
|
project.getLogger().info(":providing " + remappedLog);
|
||||||
|
|
||||||
if (sources != null) {
|
if (sources != null) {
|
||||||
scheduleSourcesRemapping(project, sourceRemapper, info.sourcesFile, info.getRemappedNotation(), info.getRemappedFilename(), modStore);
|
scheduleSourcesRemapping(project, sourceRemapper, info.sourcesFile, info.getRemappedNotation(), info.getRemappedOutput(), modStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,10 +156,10 @@ public class ModCompileRemapper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleSourcesRemapping(Project project, SourceRemapper sourceRemapper, File sources, String remappedLog, String remappedFilename, File modStore) {
|
private static void scheduleSourcesRemapping(Project project, SourceRemapper sourceRemapper, File sources, String remappedLog, File remappedJar, File modStore) {
|
||||||
project.getLogger().debug(":providing " + remappedLog + " sources");
|
project.getLogger().debug(":providing " + remappedLog + " sources");
|
||||||
|
|
||||||
File remappedSources = new File(modStore, remappedFilename + "-sources.jar");
|
File remappedSources = new File(remappedJar.getAbsolutePath().replace(".jar", "-sources.jar"));
|
||||||
boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
|
boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
|
||||||
|
|
||||||
if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified() || refreshDeps) {
|
if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified() || refreshDeps) {
|
||||||
|
|
|
@ -196,6 +196,8 @@ public class ModProcessor {
|
||||||
if (accessWidener != null) {
|
if (accessWidener != null) {
|
||||||
ZipUtil.replaceEntry(info.getRemappedOutput(), info.getAccessWidener(), accessWidener);
|
ZipUtil.replaceEntry(info.getRemappedOutput(), info.getAccessWidener(), accessWidener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info.finaliseRemapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>%GROUP%</groupId>
|
||||||
|
<artifactId>%NAME%</artifactId>
|
||||||
|
<version>%VERSION%</version>
|
||||||
|
</project>
|
Loading…
Reference in New Issue