Supply the configuration to the run Exec directly (#232)

* Supply the configuration to the run Exec directly

This allows the implicit task dependencies from project() dependencies
to flow into the run tasks.

* Make unmappedMods a CFC to track task information

Deprecates the old methods, and they should probably be removed with
0.5.
dev/0.11
Octavia Togami 2020-06-29 07:25:05 -07:00 committed by GitHub
parent 2d7421d4ed
commit 886d77ce0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 37 deletions

View File

@ -49,12 +49,14 @@ import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.plugins.ide.idea.model.IdeaModel; import org.gradle.plugins.ide.idea.model.IdeaModel;
import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.providers.LaunchProvider;
import net.fabricmc.loom.providers.MappingsCache;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.MappingsCache;
import net.fabricmc.loom.task.RemapJarTask; import net.fabricmc.loom.task.RemapJarTask;
import net.fabricmc.loom.task.RemapSourcesJarTask; import net.fabricmc.loom.task.RemapSourcesJarTask;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.FabricApiExtension;
import net.fabricmc.loom.util.GroovyXmlUtil; import net.fabricmc.loom.util.GroovyXmlUtil;
import net.fabricmc.loom.util.LoomDependencyManager; import net.fabricmc.loom.util.LoomDependencyManager;
import net.fabricmc.loom.util.NestedJars; import net.fabricmc.loom.util.NestedJars;
@ -63,8 +65,6 @@ import net.fabricmc.loom.util.SetupIntelijRunConfigs;
import net.fabricmc.loom.util.mixin.JavaApInvoker; import net.fabricmc.loom.util.mixin.JavaApInvoker;
import net.fabricmc.loom.util.mixin.KaptApInvoker; import net.fabricmc.loom.util.mixin.KaptApInvoker;
import net.fabricmc.loom.util.mixin.ScalaApInvoker; import net.fabricmc.loom.util.mixin.ScalaApInvoker;
import net.fabricmc.loom.util.FabricApiExtension;
import net.fabricmc.loom.util.DownloadUtil;
public class AbstractPlugin implements Plugin<Project> { public class AbstractPlugin implements Plugin<Project> {
protected Project project; protected Project project;
@ -247,7 +247,7 @@ public class AbstractPlugin implements Plugin<Project> {
remapJarTask.getInput().set(jarTask.getArchivePath()); remapJarTask.getInput().set(jarTask.getArchivePath());
} }
extension.addUnmappedMod(jarTask.getArchivePath().toPath()); extension.getUnmappedModCollection().from(jarTask);
remapJarTask.getAddNestedDependencies().set(true); remapJarTask.getAddNestedDependencies().set(true);
remapJarTask.getRemapAccessWidener().set(true); remapJarTask.getRemapAccessWidener().set(true);
@ -282,7 +282,7 @@ public class AbstractPlugin implements Plugin<Project> {
} }
} else { } else {
AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar"); AbstractArchiveTask jarTask = (AbstractArchiveTask) project1.getTasks().getByName("jar");
extension.addUnmappedMod(jarTask.getArchivePath().toPath()); extension.getUnmappedModCollection().from(jarTask);
} }
project.getLogger().lifecycle("Configuring compiler arguments for Java"); project.getLogger().lifecycle("Configuring compiler arguments for Java");

View File

@ -28,12 +28,12 @@ import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -43,6 +43,7 @@ import org.cadixdev.mercury.Mercury;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.BasePluginConvention; import org.gradle.api.plugins.BasePluginConvention;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
@ -62,12 +63,12 @@ public class LoomGradleExtension {
public File accessWidener = null; public File accessWidener = null;
public Function<String, Object> intermediaryUrl = mcVer -> "https://maven.fabricmc.net/net/fabricmc/intermediary/" + mcVer + "/intermediary-" + mcVer + "-v2.jar"; public Function<String, Object> intermediaryUrl = mcVer -> "https://maven.fabricmc.net/net/fabricmc/intermediary/" + mcVer + "/intermediary-" + mcVer + "-v2.jar";
private List<Path> unmappedModsBuilt = new ArrayList<>(); private final ConfigurableFileCollection unmappedMods;
final List<LoomDecompiler> decompilers = new ArrayList<>(); final List<LoomDecompiler> decompilers = new ArrayList<>();
//Not to be set in the build.gradle //Not to be set in the build.gradle
private Project project; private final Project project;
private LoomDependencyManager dependencyManager; private LoomDependencyManager dependencyManager;
private JarProcessorManager jarProcessorManager; private JarProcessorManager jarProcessorManager;
private JsonObject installerJson; private JsonObject installerJson;
@ -92,14 +93,30 @@ public class LoomGradleExtension {
public LoomGradleExtension(Project project) { public LoomGradleExtension(Project project) {
this.project = project; this.project = project;
this.unmappedMods = project.files();
} }
/**
* @see ConfigurableFileCollection#from(Object...)
* @deprecated use {@link #getUnmappedModCollection()}{@code .from()} instead
*/
@Deprecated
public void addUnmappedMod(Path file) { public void addUnmappedMod(Path file) {
unmappedModsBuilt.add(file); getUnmappedModCollection().from(file);
} }
/**
* @deprecated use {@link #getUnmappedModCollection()} instead
*/
@Deprecated
public List<Path> getUnmappedMods() { public List<Path> getUnmappedMods() {
return Collections.unmodifiableList(unmappedModsBuilt); return unmappedMods.getFiles().stream()
.map(File::toPath)
.collect(Collectors.toList());
}
public ConfigurableFileCollection getUnmappedModCollection() {
return unmappedMods;
} }
public void setInstallerJson(JsonObject object) { public void setInstallerJson(JsonObject object) {

View File

@ -116,13 +116,12 @@ public class LoomGradlePlugin extends AbstractPlugin {
tasks.register("runClient", RunClientTask.class, t -> { tasks.register("runClient", RunClientTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft client."); t.setDescription("Starts a development version of the Minecraft client.");
t.dependsOn("jar", "downloadAssets"); t.dependsOn("downloadAssets");
t.setGroup("fabric"); t.setGroup("fabric");
}); });
tasks.register("runServer", RunServerTask.class, t -> { tasks.register("runServer", RunServerTask.class, t -> {
t.setDescription("Starts a development version of the Minecraft server."); t.setDescription("Starts a development version of the Minecraft server.");
t.dependsOn("jar");
t.setGroup("fabric"); t.setGroup("fabric");
}); });

View File

@ -25,8 +25,6 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -37,8 +35,6 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.util.MinecraftVersionInfo;
import net.fabricmc.loom.util.RunConfig; import net.fabricmc.loom.util.RunConfig;
public abstract class AbstractRunTask extends JavaExec { public abstract class AbstractRunTask extends JavaExec {
@ -49,6 +45,9 @@ public abstract class AbstractRunTask extends JavaExec {
super(); super();
setGroup("fabric"); setGroup("fabric");
this.configProvider = config; this.configProvider = config;
classpath(getProject().getConfigurations().getByName("runtimeClasspath"));
classpath(this.getProject().getExtensions().getByType(LoomGradleExtension.class).getUnmappedModCollection());
} }
@Override @Override
@ -57,23 +56,6 @@ public abstract class AbstractRunTask extends JavaExec {
config = configProvider.apply(getProject()); config = configProvider.apply(getProject());
} }
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().getVersionInfo();
MappingsProvider mappingsProvider = extension.getMappingsProvider();
List<String> libs = new ArrayList<>();
for (File file : getProject().getConfigurations().getByName("runtimeClasspath").getFiles()) {
libs.add(file.getAbsolutePath());
}
for (Path file : extension.getUnmappedMods()) {
if (Files.isRegularFile(file)) {
libs.add(file.toFile().getAbsolutePath());
}
}
classpath(libs);
List<String> argsSplit = new ArrayList<>(); List<String> argsSplit = new ArrayList<>();
String[] args = config.programArgs.split(" "); String[] args = config.programArgs.split(" ");
int partPos = -1; int partPos = -1;
@ -103,6 +85,7 @@ public abstract class AbstractRunTask extends JavaExec {
} }
args(argsSplit); args(argsSplit);
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
setWorkingDir(new File(getProject().getRootDir(), extension.runDir)); setWorkingDir(new File(getProject().getRootDir(), extension.runDir));
super.exec(); super.exec();
@ -136,7 +119,6 @@ public abstract class AbstractRunTask extends JavaExec {
config = configProvider.apply(getProject()); config = configProvider.apply(getProject());
} }
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
List<String> superArgs = super.getJvmArgs(); List<String> superArgs = super.getJvmArgs();
List<String> args = new ArrayList<>(superArgs != null ? superArgs : Collections.emptyList()); List<String> args = new ArrayList<>(superArgs != null ? superArgs : Collections.emptyList());
args.addAll(Arrays.asList(config.vmArgs.split(" "))); args.addAll(Arrays.asList(config.vmArgs.split(" ")));

View File

@ -165,9 +165,11 @@ public class SourceRemapper {
Mercury mercury = extension.getOrCreateSrcMercuryCache(toNamed ? 1 : 0, () -> { Mercury mercury = extension.getOrCreateSrcMercuryCache(toNamed ? 1 : 0, () -> {
Mercury m = createMercuryWithClassPath(project, toNamed); Mercury m = createMercuryWithClassPath(project, toNamed);
for (Path file : extension.getUnmappedMods()) { for (File file : extension.getUnmappedModCollection()) {
if (Files.isRegularFile(file)) { Path path = file.toPath();
m.getClassPath().add(file);
if (Files.isRegularFile(path)) {
m.getClassPath().add(path);
} }
} }