Skip to content

Commit

Permalink
Remove a bunch of internal gradle api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Mar 24, 2024
1 parent 51e86d6 commit 386e5bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ArchiveOperations;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
Expand Down Expand Up @@ -63,7 +63,7 @@ public abstract class BinaryPatchJarTask extends DefaultTask implements IJarTran
public abstract ConfigurableFileTree getExtraResourcesTree();

@Inject
protected abstract FileOperations getFileOperations();
protected abstract ArchiveOperations getArchiveOperations();

@Override
public MessageDigestConsumer hashInputs() {
Expand Down Expand Up @@ -124,7 +124,7 @@ public void patchJar() throws IOException {
}
// Copy extra classes
{
final FileTree tree = getFileOperations().zipTree(getExtraClassesJar().getAsFile().get());
final FileTree tree = getArchiveOperations().zipTree(getExtraClassesJar().getAsFile().get());
tree.visit(fvd -> {
if (fvd.isDirectory()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.CacheableTask;
Expand Down Expand Up @@ -50,9 +49,6 @@ public abstract class InjectTagsTask extends DefaultTask {
@Input
public abstract Property<Boolean> getCleanOutputDir();

@Inject
protected abstract FileOperations getFileOperations();

@Inject
public InjectTagsTask() {
getCleanOutputDir().convention(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ArchiveOperations;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -60,7 +61,10 @@ public abstract class PatchSourcesTask extends DefaultTask implements IJarTransf
public abstract Property<Integer> getPathComponentsToStrip();

@Inject
public abstract FileOperations getFileOperations();
public abstract ObjectFactory getObjects();

@Inject
public abstract ArchiveOperations getArchiveOperations();

@Override
public MessageDigestConsumer hashInputs() {
Expand Down Expand Up @@ -128,11 +132,11 @@ private void patchFiles() throws IOException, PatchException {
for (File patchSpec : getPatches()) {
final FileCollection patchFiles;
if (patchSpec.isDirectory()) {
patchFiles = getFileOperations().fileTree(patchSpec);
patchFiles = getObjects().fileTree().from(patchSpec);
} else if (patchSpec.getName().endsWith(".zip") || patchSpec.getName().endsWith(".jar")) {
patchFiles = getFileOperations().zipTree(patchSpec);
patchFiles = getArchiveOperations().zipTree(patchSpec);
} else {
patchFiles = getFileOperations().immutableFiles(patchSpec);
patchFiles = getObjects().fileCollection().from(patchSpec);
}
for (File patchFile : patchFiles) {
logStream.printf("Applying patch %s from bundle %s%n", patchFile.getPath(), patchSpec.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Arrays;

import org.apache.commons.lang3.SystemUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand All @@ -20,7 +21,6 @@
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.os.OperatingSystem;

public abstract class ExtractNativesTask extends DefaultTask {

Expand All @@ -34,12 +34,11 @@ public abstract class ExtractNativesTask extends DefaultTask {
public void configureMe(Project project, File targetDirectory, Configuration lwjglConfiguration,
Configuration vanillaMcConfiguration) {
this.getNatives().from(project.provider(() -> {
final OperatingSystem os = OperatingSystem.current();
final String twitchNatives;
final String lwjglNatives = (String) project.getExtensions().getByName("lwjglNatives");
if (os.isWindows()) {
if (SystemUtils.IS_OS_WINDOWS) {
twitchNatives = "natives-windows-64";
} else if (os.isMacOsX()) {
} else if (SystemUtils.IS_OS_MAC) {
twitchNatives = "natives-osx";
} else {
twitchNatives = "natives-linux"; // don't actually exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ComponentMetadataSupplier;
Expand All @@ -25,7 +26,6 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.internal.os.OperatingSystem;

import com.gtnewhorizons.retrofuturagradle.Constants;
import com.gtnewhorizons.retrofuturagradle.IMinecraftyExtension;
Expand Down Expand Up @@ -389,27 +389,26 @@ private void applyMcDependencies() {
content.excludeGroup("cpw.mods");
});

final OperatingSystem os = OperatingSystem.current();
final String osArch = System.getProperty("os.arch");
final String lwjgl2Natives;
if (os.isWindows()) {
if (SystemUtils.IS_OS_WINDOWS) {
lwjgl2Natives = "natives-windows";
} else if (os.isMacOsX()) {
} else if (SystemUtils.IS_OS_MAC) {
lwjgl2Natives = (osArch.startsWith("aarch64")) ? "natives-osx-arm64" : "natives-osx";
} else {
lwjgl2Natives = "natives-linux";
}

final String lwjgl3Natives;
if (os.isMacOsX()) {
if (SystemUtils.IS_OS_MAC) {
lwjgl3Natives = (osArch.startsWith("aarch64")) ? "natives-macos-arm64" : "natives-macos";
} else if (os.isWindows()) {
} else if (SystemUtils.IS_OS_WINDOWS) {
if (osArch.contains("64")) {
lwjgl3Natives = osArch.startsWith("aarch64") ? "natives-windows-arm64" : "natives-windows";
} else {
lwjgl3Natives = "natives-windows-x86";
}
} else if (os.isLinux() || os.isUnix()) {
} else if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
if (osArch.startsWith("arm") || osArch.startsWith("aarch64")) {
lwjgl3Natives = (osArch.contains("64") || osArch.startsWith("armv8")) ? "natives-linux-arm64"
: "natives-linux-arm32";
Expand Down Expand Up @@ -498,11 +497,11 @@ private void applyMcDependencies() {
deps.add(VANILLA_MC_CFG, "org.apache.logging.log4j:log4j-api:2.17.1");
deps.add(VANILLA_MC_CFG, "org.apache.logging.log4j:log4j-core:2.17.1");
deps.add(VANILLA_MC_CFG, "com.mojang:text2speech:1.10.3");
if (os.isWindows()) {
if (SystemUtils.IS_OS_WINDOWS) {
deps.add(VANILLA_MC_CFG, "com.mojang:text2speech:1.10.3:natives-windows");
} else if (os.isLinux()) {
} else if (SystemUtils.IS_OS_LINUX) {
deps.add(VANILLA_MC_CFG, "com.mojang:text2speech:1.10.3:natives-linux");
} else if (os.isMacOsX()) {
} else if (SystemUtils.IS_OS_MAC) {
deps.add(VANILLA_MC_CFG, "ca.weblite:java-objc-bridge:1.0.0");
}
}
Expand Down Expand Up @@ -540,7 +539,7 @@ private void applyMcDependencies() {

if (mcMinor <= 8) {
deps.add(VANILLA_MC_CFG, "tv.twitch:twitch:5.16");
if (os.isWindows()) {
if (SystemUtils.IS_OS_WINDOWS) {
deps.add(VANILLA_MC_CFG, "tv.twitch:twitch-platform:5.16:natives-windows-64");
deps.add(VANILLA_MC_CFG, "tv.twitch:twitch-external-platform:4.5:natives-windows-64");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -63,9 +62,6 @@ public abstract class DeobfuscateFileTaskBase extends DefaultTask {
@Option(option = "output", description = "Where to save the deobfuscated version")
public abstract RegularFileProperty getOutputFile();

@Inject
protected abstract FileOperations getFileOperations();

@Inject
protected abstract ObjectFactory getObjectFactory();

Expand Down

0 comments on commit 386e5bd

Please sign in to comment.