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
Mitchell Skaggs 2021-05-22 17:29:02 -05:00 committed by GitHub
parent e955ebb8c5
commit 1f80e00e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 20 deletions

View File

@ -32,7 +32,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.google.gson.JsonObject;
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.DependencySet;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.artifacts.ResolvedDependency;
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());
// 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> jarTasks = dependencyProject.getTasksByName("jar", false);
for (Task task : remapJarTasks.isEmpty() ? jarTasks : remapJarTasks) {
if (task instanceof RemapJarTask remapJarTask) {
File file = remapJarTask.getArchiveFile().get().getAsFile();
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
} else if (task instanceof AbstractArchiveTask abstractArchiveTask) {
File file = abstractArchiveTask.getArchiveFile().get().getAsFile();
fileList.add(new DependencyInfo<>(projectDependency, new ProjectDependencyMetaExtractor(), file));
if (task instanceof AbstractArchiveTask abstractArchiveTask) {
fileList.add(new DependencyInfo<>(
projectDependency,
new ProjectDependencyMetaExtractor(),
abstractArchiveTask.getArchiveFile().get().getAsFile(),
abstractArchiveTask.getArchiveClassifier().getOrNull()
));
}
}
}
@ -133,14 +133,13 @@ public final class NestedDependencyProvider implements NestedJarProvider {
continue;
}
List<File> files = dependency
.getModuleArtifacts()
.stream()
.map(ResolvedArtifact::getFile)
.collect(Collectors.toList());
for (File file : files) {
fileList.add(new DependencyInfo<>(dependency, new ResolvedDependencyMetaExtractor(), file));
for (var artifact : dependency.getModuleArtifacts()) {
fileList.add(new DependencyInfo<>(
dependency,
new ResolvedDependencyMetaExtractor(),
artifact.getFile(),
artifact.getClassifier()
));
}
}
@ -195,7 +194,12 @@ public final class NestedDependencyProvider implements NestedJarProvider {
JsonObject jsonObject = new JsonObject();
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("name", metaExtractor.name(dependency));
@ -206,8 +210,8 @@ public final class NestedDependencyProvider implements NestedJarProvider {
return LoomGradlePlugin.GSON.toJson(jsonObject);
}
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file) {
public void validateInputs() {
private record DependencyInfo<D>(D dependency, DependencyMetaExtractor<D> metaExtractor, File file, @Nullable String classifier) {
void validateInputs() {
if (!file.exists()) {
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());
}
}
String getClassifierSuffix() {
if (classifier == null) {
return "";
} else {
return "_" + classifier;
}
}
}
private interface DependencyMetaExtractor<D> {