diff --git a/build.gradle b/build.gradle index d4b1480..9cf883d 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ dependencies { } implementation ('org.jetbrains:intellij-fernflower:1.0.0.8') - implementation ('net.fabricmc:sponge-mixin:0.7.11.23') { + implementation ('net.fabricmc:sponge-mixin:0.7.11.27') { exclude module: 'launchwrapper' exclude module: 'guava' } diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index b51ea34..235c97c 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -34,6 +34,9 @@ import org.gradle.api.Project; import org.gradle.api.UnknownDomainObjectException; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.component.ComponentIdentifier; +import org.gradle.api.artifacts.component.ModuleComponentIdentifier; +import org.gradle.api.artifacts.result.ResolvedArtifactResult; import javax.annotation.Nullable; import java.io.File; @@ -135,11 +138,16 @@ public class LoomGradleExtension { } @Nullable - private Dependency findDependency(Collection configs, BiPredicate groupNameFilter) { - for (String s : configs) { - for (Dependency dependency : project.getConfigurations().getByName(s).getDependencies()) { - if (groupNameFilter.test(dependency.getGroup(), dependency.getName())) { - return dependency; + private ResolvedArtifactResult findDependency(Collection configs, BiPredicate groupNameFilter) { + for (Configuration config : configs) { + for (ResolvedArtifactResult artifact : config.getIncoming().getArtifacts().getArtifacts()) { + ComponentIdentifier artifactId = artifact.getId().getComponentIdentifier(); + if (artifactId instanceof ModuleComponentIdentifier) { + String group = ((ModuleComponentIdentifier) artifactId).getGroup(); + String name = ((ModuleComponentIdentifier) artifactId).getModule(); + if (groupNameFilter.test(group, name)) { + return artifact; + } } } } @@ -148,21 +156,13 @@ public class LoomGradleExtension { } @Nullable - private Dependency findBuildscriptDependency(BiPredicate groupNameFilter) { - for (Configuration config : project.getBuildscript().getConfigurations().getAsMap().values()) { - for (Dependency dependency : config.getDependencies()) { - if (groupNameFilter.test(dependency.getGroup(), dependency.getName())) { - return dependency; - } - } - } - - return null; + private ResolvedArtifactResult findBuildscriptDependency(BiPredicate groupNameFilter) { + return findDependency(project.getBuildscript().getConfigurations(), groupNameFilter); } @Nullable public String getLoomVersion() { - Dependency dependency = findBuildscriptDependency((group, name) -> { + ResolvedArtifactResult dependency = findBuildscriptDependency((group, name) -> { if (name.equalsIgnoreCase("fabric-loom")) { return group.equalsIgnoreCase("net.fabricmc"); } @@ -182,12 +182,12 @@ public class LoomGradleExtension { } } - return dependency != null ? dependency.getVersion() : null; + return dependency != null ? ((ModuleComponentIdentifier) dependency.getId().getComponentIdentifier()).getVersion() : null; } @Nullable - private Dependency getMixinDependency() { - return findDependency(Collections.singletonList("compile"), (group, name) -> { + private ResolvedArtifactResult getMixinDependency() { + return findDependency(Collections.singletonList(project.getConfigurations().getByName("compile")), (group, name) -> { if (name.equalsIgnoreCase("mixin") && group.equalsIgnoreCase("org.spongepowered")) { return true; } @@ -202,19 +202,17 @@ public class LoomGradleExtension { @Nullable public String getMixinVersion() { - Dependency dependency = getMixinDependency(); - if (dependency != null) { - return dependency.getVersion(); - } else { - return null; - } + ResolvedArtifactResult dependency = getMixinDependency(); + return dependency != null ? ((ModuleComponentIdentifier) dependency.getId().getComponentIdentifier()).getVersion() : null; } @Nullable public String getMixinJsonVersion() { - Dependency dependency = getMixinDependency(); + ResolvedArtifactResult artifactResult = getMixinDependency(); + + if (artifactResult != null) { + ModuleComponentIdentifier dependency = ((ModuleComponentIdentifier) artifactResult.getId().getComponentIdentifier()); - if (dependency != null) { if (dependency.getGroup().equalsIgnoreCase("net.fabricmc")) { if (Objects.requireNonNull(dependency.getVersion()).split("\\.").length >= 4) { return dependency.getVersion().substring(0, dependency.getVersion().lastIndexOf('.')) + "-SNAPSHOT"; diff --git a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java index bc53af8..a82734e 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java @@ -126,53 +126,16 @@ public abstract class DependencyProvider { // TODO: Can this be done with stable APIs only? @SuppressWarnings("UnstableApiUsage") - public Set resolve(String classifier) { - if (classifier.isEmpty()) { - return sourceConfiguration.files(dependency); - } else if ("sources".equals(classifier)) { - for (ResolvedArtifact rd : sourceConfiguration.getResolvedConfiguration().getResolvedArtifacts()) { - if (rd.getModuleVersion().getId().getGroup().equals(dependency.getGroup()) - && rd.getModuleVersion().getId().getName().equals(dependency.getName()) - && rd.getModuleVersion().getId().getVersion().equals(dependency.getVersion())) { - - ImmutableSet.Builder files = ImmutableSet.builder(); - - ArtifactResolutionQuery query = project.getDependencies().createArtifactResolutionQuery(); - query.forComponents(DefaultModuleComponentIdentifier.newId(rd.getModuleVersion().getId())); - //noinspection unchecked - query.withArtifacts(JvmLibrary.class, SourcesArtifact.class); - for (ComponentArtifactsResult cresult : query.execute().getResolvedComponents()) { - for (ArtifactResult result : cresult.getArtifacts(SourcesArtifact.class)) { - if (result instanceof ResolvedArtifactResult) { - files.add(((ResolvedArtifactResult) result).getFile()); - } - } - } - - return files.build(); - } - } - - return ImmutableSet.of(); - } else { - project.getLogger().warn("Unsupported classifier '" + classifier + "'"); - return ImmutableSet.of(); - } + public Set resolve() { + return sourceConfiguration.files(dependency); } public Optional resolveFile() { - return resolveFile(""); - } - - public Optional resolveFile(String classifier) { - Set files = resolve(classifier); + Set files = resolve(); if (files.isEmpty()) { return Optional.empty(); } else if (files.size() > 1) { StringBuilder builder = new StringBuilder(this.toString()); - if (!classifier.isEmpty()) { - builder.append(" [").append(classifier).append("]"); - } builder.append(" resolves to more than one file:"); for (File f : files) { builder.append("\n\t-").append(f.getAbsolutePath()); @@ -261,15 +224,6 @@ public abstract class DependencyProvider { } } - @Override - public Set resolve(String classifier) { - File file = classifierToFile.get(classifier); - if (file != null) return Collections.singleton(file); - - //Suppose we can always try the super resolving method, doubt it will do anything more though - return super.resolve(classifier); - } - @Override public String getResolvedVersion() { return version; diff --git a/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java b/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java index 346a154..e58cfa8 100644 --- a/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java +++ b/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java @@ -129,7 +129,7 @@ public class LoomDependencyManager { for (Dependency dependency : configuration.getDependencies()) { DependencyInfo info = DependencyInfo.create(project, dependency, configuration); - for (File input : info.resolve("")) { + for (File input : info.resolve()) { if (seenFiles.add(input)) { ModProcessor.readInstallerJson(input, project); if (extension.getInstallerJson() != null) {