Move remapped mods into a full local maven repo (#300)

dev/0.11
modmuss50 2020-12-21 19:33:23 +00:00 committed by GitHub
parent 3ab757363c
commit 78c934aed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 14 deletions

View File

@ -207,9 +207,9 @@ public class AbstractPlugin implements Plugin<Project> {
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
});
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
flatDirectoryArtifactRepository.dir(extension.getRemappedModCache());
flatDirectoryArtifactRepository.setName("UserLocalRemappedMods");
project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setUrl(extension.getRemappedModCache());
mavenArtifactRepository.setName("UserLocalRemappedMods");
});
project1.getRepositories().maven(mavenArtifactRepository -> {

View File

@ -28,16 +28,19 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.gradle.api.artifacts.Configuration;
import net.fabricmc.loom.util.ModProcessor;
public class ModDependencyInfo {
public final String group;
private final String group;
public final String name;
public final String version;
public final String classifier;
@ -61,15 +64,39 @@ public class ModDependencyInfo {
}
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);
}
return String.format("%s:%s:%s:%s", getGroup(), name, version, classifier);
}
public String getRemappedFilename() {
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() {
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() {
@ -77,11 +104,31 @@ public class ModDependencyInfo {
}
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() {
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() {

View File

@ -331,4 +331,8 @@ public class MappingsProvider extends DependencyProvider {
return intermediaryTiny;
}
public String getMappingsKey() {
return mappingsName + "." + minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsVersion;
}
}

View File

@ -54,7 +54,7 @@ public class LoomDependencyManager {
private final List<DependencyProvider> dependencyProviderList = new ArrayList<>();
public void addProvider(DependencyProvider provider) {
public <T extends DependencyProvider> T addProvider(T provider) {
if (dependencyProviderList.contains(provider)) {
throw new RuntimeException("Provider is already registered");
}
@ -65,6 +65,7 @@ public class LoomDependencyManager {
provider.register(this);
dependencyProviderList.add(provider);
return provider;
}
public <T> T getProvider(Class<T> clazz) {
@ -132,7 +133,7 @@ public class LoomDependencyManager {
}
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);

View File

@ -92,7 +92,7 @@ public class ModCompileRemapper {
project.getLogger().info(":providing " + remappedLog);
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;
}
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");
File remappedSources = new File(modStore, remappedFilename + "-sources.jar");
File remappedSources = new File(remappedJar.getAbsolutePath().replace(".jar", "-sources.jar"));
boolean refreshDeps = project.getGradle().getStartParameter().isRefreshDependencies();
if (!remappedSources.exists() || sources.lastModified() <= 0 || sources.lastModified() > remappedSources.lastModified() || refreshDeps) {

View File

@ -196,6 +196,8 @@ public class ModProcessor {
if (accessWidener != null) {
ZipUtil.replaceEntry(info.getRemappedOutput(), info.getAccessWidener(), accessWidener);
}
info.finaliseRemapping();
}
}

View File

@ -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>