fix #85, remove parts of deprecated code, update Mixin

dev/0.11
Adrian Siekierka 2019-04-27 22:31:50 +02:00
parent 2b4d9fd3bc
commit 17b8aa7a70
4 changed files with 30 additions and 78 deletions

View File

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

View File

@ -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<String> configs, BiPredicate<String, String> 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<Configuration> configs, BiPredicate<String, String> 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<String, String> 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<String, String> 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";

View File

@ -126,53 +126,16 @@ public abstract class DependencyProvider {
// TODO: Can this be done with stable APIs only?
@SuppressWarnings("UnstableApiUsage")
public Set<File> 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<File> 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<File> resolve() {
return sourceConfiguration.files(dependency);
}
public Optional<File> resolveFile() {
return resolveFile("");
}
public Optional<File> resolveFile(String classifier) {
Set<File> files = resolve(classifier);
Set<File> 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<File> 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;

View File

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