Add classifier to "fake" mods' id if they have a classifier specified (#394)
* Remove unused codepath (`RemapJarTask` is an `AbstractArchiveTask`)
* Remove incorrect comment
Comment originally added in 02e9616622
* Add classifier to `DependencyInfo`
* Add classifier to generated mod ID
* Clean up code structure from review
Co-authored-by: haykam821 <haykam821@users.noreply.github.com>
* Inline `file` local variable
Co-authored-by: haykam821 <haykam821@users.noreply.github.com>
Co-authored-by: haykam821 <haykam821@users.noreply.github.com>
dev/0.11
parent
e955ebb8c5
commit
1f80e00e88
|
@ -32,7 +32,8 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -42,7 +43,6 @@ import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.Dependency;
|
import org.gradle.api.artifacts.Dependency;
|
||||||
import org.gradle.api.artifacts.DependencySet;
|
import org.gradle.api.artifacts.DependencySet;
|
||||||
import org.gradle.api.artifacts.ProjectDependency;
|
import org.gradle.api.artifacts.ProjectDependency;
|
||||||
import org.gradle.api.artifacts.ResolvedArtifact;
|
|
||||||
import org.gradle.api.artifacts.ResolvedConfiguration;
|
import org.gradle.api.artifacts.ResolvedConfiguration;
|
||||||
import org.gradle.api.artifacts.ResolvedDependency;
|
import org.gradle.api.artifacts.ResolvedDependency;
|
||||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||||
|
@ -103,17 +103,17 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||||
|
|
||||||
visited.add(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion());
|
visited.add(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion());
|
||||||
|
|
||||||
// TODO change this to allow just normal jar tasks, so a project can have a none loom sub project
|
|
||||||
Collection<Task> remapJarTasks = dependencyProject.getTasksByName("remapJar", false);
|
Collection<Task> remapJarTasks = dependencyProject.getTasksByName("remapJar", false);
|
||||||
Collection<Task> jarTasks = dependencyProject.getTasksByName("jar", false);
|
Collection<Task> jarTasks = dependencyProject.getTasksByName("jar", false);
|
||||||
|
|
||||||
for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) {
|
for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) {
|
||||||
if (task instanceof RemapJarTask remapJarTask) {
|
if (task instanceof AbstractArchiveTask abstractArchiveTask) {
|
||||||
File file = remapJarTask.getArchiveFile().get().getAsFile();
|
fileList.add(new DependencyInfo<>(
|
||||||
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
|
projectDependency,
|
||||||
} else if (task instanceof AbstractArchiveTask abstractArchiveTask) {
|
new ProjectDependencyMetaExtractor(),
|
||||||
File file = abstractArchiveTask.getArchiveFile().get().getAsFile();
|
abstractArchiveTask.getArchiveFile().get().getAsFile(),
|
||||||
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
|
abstractArchiveTask.getArchiveClassifier().getOrNull()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,13 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = dependency
|
for (var artifact : dependency.getModuleArtifacts()) {
|
||||||
.getModuleArtifacts()
|
fileList.add(new DependencyInfo<>(
|
||||||
.stream()
|
dependency,
|
||||||
.map(ResolvedArtifact::getFile)
|
new ResolvedDependencyMetaExtractor(),
|
||||||
.collect(Collectors.toList());
|
artifact.getFile(),
|
||||||
|
artifact.getClassifier()
|
||||||
for (File file : files) {
|
));
|
||||||
fileList.add(new DependencyInfo<>(dependency, new ResolvedDependencyMetaExtractor(), file));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +194,12 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||||
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("schemaVersion", 1);
|
jsonObject.addProperty("schemaVersion", 1);
|
||||||
jsonObject.addProperty("id", (metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency)).replaceAll("\\.", "_").toLowerCase(Locale.ENGLISH));
|
|
||||||
|
jsonObject.addProperty("id",
|
||||||
|
(metaExtractor.group(dependency) + "_" + metaExtractor.name(dependency) + info.getClassifierSuffix())
|
||||||
|
.replaceAll("\\.", "_")
|
||||||
|
.toLowerCase(Locale.ENGLISH)
|
||||||
|
);
|
||||||
jsonObject.addProperty("version", metaExtractor.version(dependency));
|
jsonObject.addProperty("version", metaExtractor.version(dependency));
|
||||||
jsonObject.addProperty("name", metaExtractor.name(dependency));
|
jsonObject.addProperty("name", metaExtractor.name(dependency));
|
||||||
|
|
||||||
|
@ -206,8 +210,8 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||||
return LoomGradlePlugin.GSON.toJson(jsonObject);
|
return LoomGradlePlugin.GSON.toJson(jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file) {
|
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file, @Nullable String classifier) {
|
||||||
public void validateInputs() {
|
void validateInputs() {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new RuntimeException("Failed to include nested jars, as it could not be found @ " + file.getAbsolutePath());
|
throw new RuntimeException("Failed to include nested jars, as it could not be found @ " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
@ -216,6 +220,14 @@ public final class NestedDependencyProvider implements NestedJarProvider {
|
||||||
throw new RuntimeException("Failed to include nested jars, as file was not a jar: " + file.getAbsolutePath());
|
throw new RuntimeException("Failed to include nested jars, as file was not a jar: " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getClassifierSuffix() {
|
||||||
|
if (classifier == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return "_" + classifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface DependencyMetaExtractor<D> {
|
private interface DependencyMetaExtractor<D> {
|
||||||
|
|
Loading…
Reference in New Issue