Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Gradle configuration cache support #867

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@

import net.minecraftforge.gradle.common.util.Utils;

import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;

import com.google.common.collect.ImmutableMap;

import javax.inject.Inject;
import java.util.List;

public abstract class ApplyBinPatches extends JarExec {
public ApplyBinPatches() {
getTool().set(Utils.BINPATCHER);
getArgs().addAll("--clean", "{clean}", "--output", "{output}", "--apply", "{patch}");

getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.jar")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.jar")));
}

@Override
Expand All @@ -45,6 +48,9 @@ protected List<String> filterArgs(List<String> args) {
"{patch}", getPatch().get().getAsFile()), null);
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFile
public abstract RegularFileProperty getClean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

import org.apache.commons.io.IOUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -42,7 +44,7 @@ public abstract class ApplyMappings extends DefaultTask {
private boolean lambdas = true;

public ApplyMappings() {
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.zip")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.zip")));
}

@TaskAction
Expand All @@ -69,6 +71,9 @@ public void apply() throws IOException {
}
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFile
public abstract RegularFileProperty getInput();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraftforge.gradle.common.util.Utils;

import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
Expand All @@ -31,6 +32,8 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;

import javax.inject.Inject;
import java.util.List;

public abstract class ApplyRangeMap extends JarExec {
Expand All @@ -43,7 +46,7 @@ public ApplyRangeMap() {
"--output", "{output}", "--keepImports", "{keepImports}");
setMinimumRuntimeJavaVersion(11);

getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.zip")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.zip")));
}

@Override
Expand All @@ -61,6 +64,9 @@ protected List<String> filterArgs(List<String> args) {
);
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFiles
public abstract ConfigurableFileCollection getSrgFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package net.minecraftforge.gradle.common.tasks;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
Expand All @@ -29,6 +30,8 @@
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;
import com.google.common.hash.HashingInputStream;

import javax.inject.Inject;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
Expand All @@ -44,7 +47,7 @@ public abstract class ArchiveChecksum extends DefaultTask {
//TODO: Filters of some kind?

public ArchiveChecksum() {
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.sha256")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.sha256")));
}

@TaskAction
Expand All @@ -71,6 +74,9 @@ public void run() throws IOException {
}
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFile
public abstract RegularFileProperty getInput();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
Expand All @@ -49,6 +51,7 @@

public abstract class DownloadAssets extends DefaultTask {
public DownloadAssets() {
notCompatibleWithConfigurationCache("MAD");
getAssetRepository().convention("https://resources.download.minecraft.net/");
getConcurrentDownloads().convention(8);
}
Expand All @@ -73,20 +76,20 @@ public void run() throws IOException, InterruptedException {
try {
File localFile = FileUtils.getFile(assetsPath + File.separator + asset.getPath());
if (localFile.exists()) {
getProject().getLogger().lifecycle("Copying local object: " + asset.getPath() + " Asset: " + key);
getLogger().lifecycle("Copying local object: " + asset.getPath() + " Asset: " + key);
FileUtils.copyFile(localFile, target);
} else {
getProject().getLogger().lifecycle("Downloading: " + url + " Asset: " + key);
getLogger().lifecycle("Downloading: " + url + " Asset: " + key);
FileUtils.copyURLToFile(url, target, 10_000, 5_000);
}
if (!HashFunction.SHA1.hash(target).equals(asset.hash)) {
failedDownloads.add(key);
Utils.delete(target);
getProject().getLogger().error("{} Hash failed.", key);
getLogger().error("{} Hash failed.", key);
}
} catch (IOException e) {
failedDownloads.add(key);
getProject().getLogger().error("{} Failed.", key);
getLogger().error("{} Failed.", key);
e.printStackTrace();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
Expand All @@ -33,6 +34,8 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -44,8 +47,8 @@ public abstract class DownloadMCMeta extends DefaultTask {
private static final Gson GSON = new GsonBuilder().create();

public DownloadMCMeta() {
getManifest().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(s -> s.file("manifest.json")));
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(s -> s.file("version.json")));
getManifest().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(s -> s.file("manifest.json")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(s -> s.file("version.json")));
}

@TaskAction
Expand All @@ -60,6 +63,9 @@ public void downloadMCMeta() throws IOException {
}
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@Input
public abstract Property<String> getMCVersion();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@

import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;

Expand All @@ -40,11 +43,12 @@ public abstract class DownloadMavenArtifact extends DefaultTask {
private boolean changing = false;

public DownloadMavenArtifact() {
notCompatibleWithConfigurationCache("MAD");
// We need to always ask, in case the file on the remote maven/local fake repo has changed.
getOutputs().upToDateWhen(task -> false);

this.artifact = getProject().getObjects().property(Artifact.class);
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName())
this.artifact = getProjectObjects().property(Artifact.class);
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName())
.zip(getArtifact(), (d, a) -> d.file("output." + a.getExtension())));
}

Expand Down Expand Up @@ -85,4 +89,10 @@ public void run() throws IOException {
if (!output.getParentFile().exists()) output.getParentFile().mkdirs();
FileUtils.copyFile(out, output);
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@Inject
protected abstract ObjectFactory getProjectObjects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package net.minecraftforge.gradle.common.tasks;

import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.InputFile;
Expand All @@ -28,12 +29,14 @@
import org.gradle.api.tasks.OutputFile;

import com.google.common.collect.ImmutableMap;

import javax.inject.Inject;
import java.io.File;
import java.util.List;

public abstract class DynamicJarExec extends JarExec {
public DynamicJarExec() {
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.jar")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.jar")));
}

@Override
Expand All @@ -46,6 +49,9 @@ protected List<String> filterArgs(List<String> args) {
return replaceArgs(args, replace.build(), null);
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFiles
@Optional
public abstract MapProperty<String, File> getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import net.minecraftforge.gradle.common.util.Utils;

import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.InputFile;
Expand All @@ -30,6 +31,7 @@

import com.google.common.collect.ImmutableMap;

import javax.inject.Inject;
import java.io.File;
import java.util.List;

Expand All @@ -38,7 +40,7 @@ public ExtractInheritance() {
getTool().set(Utils.INSTALLERTOOLS);
getArgs().addAll("--task", "extract_inheritance", "--input", "{input}", "--output", "{output}");

getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.json")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.json")));
}

@Override
Expand All @@ -53,6 +55,8 @@ protected List<String> filterArgs(List<String> args) {
return newArgs;
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@InputFile
public abstract RegularFileProperty getInput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.apache.commons.io.IOUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.Project;
Expand All @@ -36,6 +37,7 @@
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -47,7 +49,7 @@ public abstract class ExtractMCPData extends DefaultTask {
private boolean allowEmpty = false;

public ExtractMCPData() {
getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.srg")));
getOutput().convention(getProjectLayout().getBuildDirectory().dir(getName()).map(s -> s.file("output.srg")));
getKey().convention("mappings");
}

Expand Down Expand Up @@ -109,6 +111,9 @@ private void error(String message) throws IOException {
outputFile.createNewFile();
}

@Inject
protected abstract ProjectLayout getProjectLayout();

@Input
public abstract Property<String> getKey();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import java.io.IOException;

public abstract class ExtractNatives extends DefaultTask {

public ExtractNatives() {
notCompatibleWithConfigurationCache("Utils needing getProject()");
}

@TaskAction
public void run() throws IOException {
VersionJson json = Utils.loadJson(getMeta().get().getAsFile(), VersionJson.class);
Expand Down
Loading