Skip to content

Commit

Permalink
Fix config cache errors (#132)
Browse files Browse the repository at this point in the history
* Fix config cache errors

* Fix failing functional tests
  • Loading branch information
Minecraftschurli committed Mar 18, 2024
1 parent 9b23c1e commit e1413ff
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.neoforged.gradle.dsl.common.runtime.tasks.RuntimeArguments;
import net.neoforged.gradle.dsl.common.runtime.tasks.RuntimeMultiArguments;
import net.neoforged.gradle.dsl.common.util.DistributionType;
import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -47,13 +46,10 @@ public DefaultRuntime() {
buildRuntimeArguments(result);
return result;
}));
getRuntimeData().convention(getSymbolicDataSources().map(dataSources -> {
final Directory unpackedMcpDirectory = getUnpackedMcpZipDirectory().get();
return dataSources.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
entry -> getProject().provider(() -> unpackedMcpDirectory.file(entry.getValue()).getAsFile())
));
}));
getRuntimeData().convention(getSymbolicDataSources().map(dataSources -> dataSources.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
entry -> getUnpackedMcpZipDirectory().map(unpackedMcpDirectory -> unpackedMcpDirectory.file(entry.getValue()).getAsFile())
))));

getOutputDirectory().finalizeValueOnRead();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.provider.Provider;

import java.io.File;

Expand Down Expand Up @@ -34,8 +33,4 @@ public static ResolvedArtifact resolveToolArtifact(final Project project, final
tool
).getResolvedConfiguration().getResolvedArtifacts().iterator().next();
}

public static Provider<File> resolveTool(final Project project, final Provider<String> tool) {
return tool.map(toolArtifactId -> resolveTool(project, toolArtifactId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,18 @@ private static Provider<RegularFile> maybeApplyParchment(NeoFormRuntimeSpecifica
return recompileInput;
}

// Provide the mappings via artifact
Provider<File> mappingFile = ToolUtilities.resolveTool(project, parchment.getParchmentArtifact());
Provider<File> toolExecutable = ToolUtilities.resolveTool(project, parchment.getToolArtifact());

TaskProvider<? extends Runtime> applyParchmentTask = project.getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "applyParchment"), Execute.class, task -> {
// Provide the mappings via artifact
File mappingFile = ToolUtilities.resolveTool(project, parchment.getParchmentArtifact().get());
File toolExecutable = ToolUtilities.resolveTool(project, parchment.getToolArtifact().get());

task.getInputs().file(mappingFile);
task.getInputs().file(recompileInput);
task.getInputs().file(listLibrariesOutput);
task.getExecutingJar().fileProvider(toolExecutable);
task.getExecutingJar().set(toolExecutable);
task.getProgramArguments().add(listLibrariesOutput.map(f -> "--libraries-list=" + f.getAsFile().getAbsolutePath()));
task.getProgramArguments().add("--enable-parchment");
task.getProgramArguments().add(mappingFile.map(f -> "--parchment-mappings=" + f.getAbsolutePath()));
task.getProgramArguments().add("--parchment-mappings=" + mappingFile.getAbsolutePath());
task.getProgramArguments().add("--in-format=archive");
task.getProgramArguments().add("--out-format=archive");
task.getProgramArguments().add(recompileInput.map(f -> f.getAsFile().getAbsolutePath()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.neoforged.gradle.neoform.runtime.tasks;

import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
Expand Down Expand Up @@ -50,7 +51,7 @@ public abstract class AbstractInjectSource {
public abstract void copyTo(ZipOutputStream out) throws IOException;

@Inject
protected abstract Project getProject();
protected abstract Logger getLogger();

protected final PatternSet createFilter() {
PatternSet filter = new PatternSet();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package net.neoforged.gradle.neoform.runtime.tasks;

import net.neoforged.gradle.util.ZipBuildingFileTreeVisitor;
import org.gradle.api.file.ArchiveOperations;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -29,15 +22,6 @@ public abstract class InjectFromDirectorySource extends AbstractInjectSource {
@PathSensitive(PathSensitivity.NONE)
public abstract DirectoryProperty getDirectory();

/**
* The object factory that can be used to manage the internal subsystems of a gradle model.
* Allows for the creation of for example file collections, trees and other components.
*
* @return The object factory.
*/
@Inject
public abstract ObjectFactory getObjectFactory();

@Override
public byte @Nullable [] tryReadFile(String path) throws IOException {
File packageInfoTemplateFile = getDirectory().file("package-info-template.java").get().getAsFile();
Expand All @@ -48,9 +32,8 @@ public abstract class InjectFromDirectorySource extends AbstractInjectSource {
}

@Override
public void copyTo(ZipOutputStream out) throws IOException {
final ConfigurableFileTree outputTree = getObjectFactory().fileTree();
FileTree source = outputTree.from(getDirectory()).matching(createFilter());
public void copyTo(ZipOutputStream out) {
FileTree source = getDirectory().getAsFileTree().matching(createFilter());
source.visit(new ZipBuildingFileTreeVisitor(out));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void copyTo(ZipOutputStream out) throws IOException {
throw e;
} else if (!entry.isDirectory()) {
// Warn on duplicate files, but ignore duplicate directories
getProject().getLogger().warn("Cannot inject duplicate file {}", entry.getName());
getLogger().warn("Cannot inject duplicate file {}", entry.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class FunctionalTests extends SimpleTestSpecification {
def "a mod with userdev as dependency can run the patch task for that dependency"() {
given:
settingsFile << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
rootProject.name = 'test-project'
"""
buildFile << """
plugins {
Expand Down Expand Up @@ -50,10 +50,10 @@ class FunctionalTests extends SimpleTestSpecification {
def "a mod with userdev as dependency and official mappings can compile through gradle"() {
given:
settingsFile << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
rootProject.name = 'test-project'
"""
buildFile << """
plugins {
Expand Down Expand Up @@ -92,10 +92,10 @@ class FunctionalTests extends SimpleTestSpecification {
def "the userdev runtime by default supports the build cache"() {
given:
settingsFile << """
rootProject.name = 'test-project'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}
rootProject.name = 'test-project'
"""
buildFile << """
plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ private static TaskProvider<? extends Runtime> maybeApplyParchment(VanillaRuntim
});
}

// Provide the mappings via artifact
Provider<File> mappingFile = ToolUtilities.resolveTool(project, parchment.getParchmentArtifact());
Provider<File> toolExecutable = ToolUtilities.resolveTool(project, parchment.getToolArtifact());

return project.getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "applyParchment"), Execute.class, task -> {
// Provide the mappings via artifact
File mappingFile = ToolUtilities.resolveTool(project, parchment.getParchmentArtifact().get());
File toolExecutable = ToolUtilities.resolveTool(project, parchment.getToolArtifact().get());

task.getInputs().file(mappingFile);
task.getInputs().file(inputProvidingTask.flatMap(WithOutput::getOutput));
task.getInputs().file(listLibrariesOutput);
task.getExecutingJar().fileProvider(toolExecutable);
task.getExecutingJar().set(toolExecutable);
task.getProgramArguments().add(listLibrariesOutput.map(f -> "--libraries-list=" + f.getAsFile().getAbsolutePath()));
task.getProgramArguments().add("--enable-parchment");
task.getProgramArguments().add(mappingFile.map(f -> "--parchment-mappings=" + f.getAbsolutePath()));
task.getProgramArguments().add("--parchment-mappings=" + mappingFile.getAbsolutePath());
task.getProgramArguments().add("--in-format=archive");
task.getProgramArguments().add("--out-format=archive");
task.getProgramArguments().add(inputProvidingTask.flatMap(WithOutput::getOutput).map(f -> f.getAsFile().getAbsolutePath()));
Expand Down

0 comments on commit e1413ff

Please sign in to comment.