Skip to content

Commit

Permalink
[Feature]: Adapt to dynamically configurable tools (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Nov 3, 2024
1 parent 173aeb9 commit 134aa03
Show file tree
Hide file tree
Showing 20 changed files with 732 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ private void configureToolsDefaults() {
tools.getDevLogin().convention(
getStringProperty("tools.devLogin", DEVLOGIN_TOOL_ARTIFACT)
);
tools.getBinaryPatcher().convention(
getStringProperty("tools.binaryPatcher", BINPARCHER_TOOL_ARTIFACT)
);
tools.getAccessTransformer().convention(
getStringProperty("tools.accessTransformer", ACCESSTRANSFORMER_TOOL_ARTIFACT)
);
tools.getAutoRenamingTool().convention(
getStringProperty("tools.autoRenamingTool", FART_TOOL_ARTIFACT)
);
tools.getInstallerTools().convention(
getStringProperty("tools.installerTools", INSTALLERTOOLS_TOOL_ARTIFACT)
);
tools.getJarSplitter().convention(
getStringProperty("tools.jarSplitter", JARSPLITTER_TOOL_ARTIFACT)
);

RenderDocTools renderDocTools = tools.getRenderDoc();
renderDocTools.getRenderDocPath().convention(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.neoforged.gradle.common.runtime.tasks.DefaultExecute;
import net.neoforged.gradle.common.util.ToolUtilities;
import net.neoforged.gradle.dsl.common.extensions.MinecraftArtifactCache;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Tools;
import net.neoforged.gradle.dsl.common.tasks.WithOutput;
import net.neoforged.gradle.dsl.common.util.Constants;
import net.neoforged.gradle.dsl.common.util.DistributionType;
Expand All @@ -24,7 +25,7 @@ public abstract class ApplyOfficialMappingsToCompiledJar extends DefaultExecute
public ApplyOfficialMappingsToCompiledJar() {
super();

getExecutingJar().set(ToolUtilities.resolveTool(getProject(), Constants.FART));
getExecutingJar().fileProvider(ToolUtilities.resolveTool(getProject(), Tools::getAutoRenamingTool));
getProgramArguments().set(getShouldReverseMappings().map(shouldReverse -> {
final List<String> result = Lists.newArrayList(RenameConstants.DEFAULT_PROGRAMM_ARGS);
if (shouldReverse) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.collect.Lists;
import net.neoforged.gradle.common.util.ToolUtilities;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Tools;
import net.neoforged.gradle.dsl.common.util.Constants;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
Expand All @@ -22,7 +24,7 @@ public BinaryAccessTransformer() {

setDescription("Runs the access transformer on the decompiled sources.");

getExecutingJar().set(ToolUtilities.resolveTool(getProject(), Constants.ACCESSTRANSFORMER));
getExecutingJar().fileProvider(ToolUtilities.resolveTool(getProject(), Tools::getAccessTransformer));
getRuntimeProgramArguments().convention(
getInputFile().map(inputFile -> {
final List<String> args = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package net.neoforged.gradle.common.util;

import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Tools;
import net.neoforged.gradle.util.ModuleDependencyUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.dsl.Dependencies;
import org.gradle.api.artifacts.dsl.DependencyCollector;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Provider;

import java.io.File;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

public class ToolUtilities {
Expand All @@ -14,6 +26,32 @@ private ToolUtilities() {
throw new IllegalStateException("Tried to create utility class!");
}

public static Provider<File> resolveTool(final Project project, final Function<Tools, Provider<String>> tool) {
return resolveTool(
project,
tool.apply(
project.getExtensions().getByType(Subsystems.class).getTools()
)
);
}

public static Provider<File> resolveTool(final Project project, final Provider<String> tool) {
//We use an anonymous dependency collector here so that we can convert the tool coordinate
//to a file outside the scope of the provider itself.
//If we were to use the provider directly, for example via map, the lambda would need to capture
//the project that converts the string to a dependency.
//This breaks the configuration cache as Projects can not be serialized.
final DependencyCollector collector = project.getObjects().dependencyCollector();
collector.add(tool.map(project.getDependencies()::create));
final Configuration config = ConfigurationUtils.temporaryUnhandledConfiguration(
project.getConfigurations(),
"Tool"
);
config.fromDependencyCollector(collector);
return config.getIncoming().getArtifacts().getResolvedArtifacts().map(a -> a.iterator().next())
.map(ResolvedArtifactResult::getFile);
}

public static File resolveTool(final Project project, final String tool) {
return resolveTool(() -> ConfigurationUtils.temporaryUnhandledConfiguration(
project.getConfigurations(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,58 @@ interface Tools extends ConfigurableDSLElement<Tools> {
*/
@Nested
RenderDocTools getRenderDoc();

/**
* Artifact coordinates for the binary patcher.
* Used by dynamic projects to create and use binary patches.
*/
@Input
@Optional
@DSLProperty
Property<String> getBinaryPatcher();

/**
* Artifact coordinates for the binary access transformer tool.
* Used by the vanilla subsystem to apply access transformers to binary classes.
*/
@Input
@Optional
@DSLProperty
Property<String> getAccessTransformer();

/**
* Artifact coordinates for the AutoRenamingTool.
* Used by different subsystems to rename classes in jars.
*/
@Input
@Optional
@DSLProperty
Property<String> getAutoRenamingTool();

/**
* Artifact coordinates for the NeoGradle decompiler.
* Used by the vanilla subsystem to decompile the game.
*/
@Input
@Optional
@DSLProperty
Property<String> getDecompiler();

/**
* Artifact coordinates for the installer tools.
* Used by the platform to configure different tooling in production and userdev.
*/
@Input
@Optional
@DSLProperty
Property<String> getInstallerTools();

/**
* Artifact coordinates for the jar splitter.
* Used by the platform to split jars into smaller jars.
*/
@Input
@Optional
@DSLProperty
Property<String> getJarSplitter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,18 @@ import groovy.transform.CompileStatic

@CompileStatic
class Constants {

public static final String BINPATCHER_VERSION = "1.1.1";
public static final String BINPATCHER_VERSION_INTERPOLATION = "net.minecraftforge:binarypatcher:%s:fatjar";
public static final String BINPATCHER = String.format(BINPATCHER_VERSION_INTERPOLATION, BINPATCHER_VERSION);
public static final String ACCESSTRANSFORMER_VERSION = "10.0.+";
public static final String ACCESSTRANSFORMER_VERSION_INTERPOLATION = "net.neoforged.accesstransformers:at-cli:%s:fatjar";
public static final String ACCESSTRANSFORMER = String.format(ACCESSTRANSFORMER_VERSION_INTERPOLATION, ACCESSTRANSFORMER_VERSION);
public static final String SPECIALSOURCE = "net.md-5:SpecialSource:1.11.0:shaded";
public static final String FART_VERSION = "2.0.3";
public static final String FART_ARTIFACT_INTERPOLATION = "net.neoforged:AutoRenamingTool:%s:all";
public static final String FART = String.format(FART_ARTIFACT_INTERPOLATION, FART_VERSION);
public static final String INSTALLERTOOLS_VERSION = '2.1.2'
public static final String INSTALLERTOOLS = "net.neoforged.installertools:installertools:${INSTALLERTOOLS_VERSION}"
public static final String JARSPLITTER = "net.neoforged.installertools:jarsplitter:${INSTALLERTOOLS_VERSION}"
public static final String BINARYPATCHER = "net.neoforged.installertools:binarypatcher:${INSTALLERTOOLS_VERSION}"

public static final String VINEFLOWER_VERSION = "1.9.3";
public static final String VINEFLOWER_ARTIFACT_INTERPOLATION = "org.vineflower:vineflower:%s";
public static final String VINEFLOWER = String.format(VINEFLOWER_ARTIFACT_INTERPOLATION, VINEFLOWER_VERSION);

public static final String DEFAULT_PARCHMENT_GROUP = "org.parchmentmc.data"
public static final String DEFAULT_PARCHMENT_ARTIFACT_PREFIX = "parchment-"
public static final String DEFAULT_PARCHMENT_MAVEN_URL = "https://maven.parchmentmc.org/"
public static final String JST_TOOL_ARTIFACT = "net.neoforged.jst:jst-cli-bundle:1.0.67"
public static final String DEVLOGIN_TOOL_ARTIFACT = "net.covers1624:DevLogin:0.1.0.4"
public static final String RENDERNURSE_TOOL_ARTIFACT = "net.neoforged:render-nurse:0.0.12";
public static final String DEVLOGIN_MAIN_CLASS = "net.covers1624.devlogin.DevLogin"
public static final String BINPARCHER_TOOL_ARTIFACT = "net.neoforged.installertools:binarypatcher:2.1.7:fatjar"
public static final String ACCESSTRANSFORMER_TOOL_ARTIFACT = "net.neoforged.accesstransformers:at-cli:11.0.1:fatjar"
public static final String FART_TOOL_ARTIFACT = "net.neoforged:AutoRenamingTool:2.0.4:all"
public static final String INSTALLERTOOLS_TOOL_ARTIFACT = "net.neoforged.installertools:installertools:2.1.7"
public static final String JARSPLITTER_TOOL_ARTIFACT = "net.neoforged.installertools:jarsplitter:2.1.7"

public static final String DEFAULT_RECOMPILER_MAX_MEMORY = "1g"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.neoforged.gradle.dsl.platform.extensions

import net.neoforged.gradle.dsl.platform.model.Library
import org.gradle.api.provider.Provider

/**
* Defines a manager for libraries.
*/
interface LibraryManager {

/**
* Gets the classpath of a library.
*
* @param library The library to get the classpath of.
* @return The classpath of the library.
*/
Provider<Set<String>> getClasspathOf(Provider<String> library);

/**
* Gets the libraries that a library depends on.
*
* @param library The library to get the dependencies of.
* @return The dependencies of the library.
*/
Provider<Set<Library>> getLibrariesOf(Provider<String> library);

/**
* Gets the classpath of a library.
*
* @param library The library to get the classpath of.
* @return The classpath of the library.
*/
Provider<Set<String>> getClasspathOf(String library);

/**
* Gets the libraries that a library depends on.
*
* @param library The library to get the dependencies of.
* @return The dependencies of the library.
*/
Provider<Set<Library>> getLibrariesOf(String library);
}
Loading

0 comments on commit 134aa03

Please sign in to comment.