Skip to content

Commit

Permalink
Fix an issue with how additional classpath inputs of the recompile ta…
Browse files Browse the repository at this point in the history
…sk are not being deleted.
  • Loading branch information
marchermans committed Jan 18, 2025
1 parent 702a6a9 commit 4cc8e2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.neoforged.gradle.neoform.util.NeoFormRuntimeUtils;
import net.neoforged.gradle.util.TransformerUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.taskdefs.Unpack;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand Down Expand Up @@ -439,16 +440,18 @@ protected void bakeDefinition(NeoFormRuntimeDefinition definition) {
extractionSource.flatMap(WithOutput::getOutput)
.map(sourceJar -> task.getArchiveOperations().zipTree(sourceJar).matching(sp -> sp.include("**/*.java")).getAsFileTree())
);
task.getInput().from(
definition.getAdditionalCompileSources()
);
});
unpackSources.configure(neoFormRuntimeTask -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, neoFormRuntimeTask));

final TaskProvider<UnpackZip> unpackAdditionalSources = spec.getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "unzipAdditionalSources"), UnpackZip.class, task -> {
task.getInput().from(definition.getAdditionalCompileSources());
});
unpackAdditionalSources.configure(neoFormRuntimeTask -> configureMcpRuntimeTaskWithDefaults(spec, neoFormDirectory, symbolicDataSources, neoFormRuntimeTask));

final TaskProvider<RecompileSourceJar> recompileTask = spec.getProject()
.getTasks().register(CommonRuntimeUtils.buildTaskName(spec, "recompile"), RecompileSourceJar.class, task -> {
task.setSource(unpackSources.flatMap(UnpackZip::getUnpackingTarget));
task.getAdditionalInputFiles().from(definition.getAdditionalCompileSources());
task.getAdditionalInputFileRoot().set(unpackAdditionalSources.flatMap(UnpackZip::getUnpackingTarget));
task.getCompileClasspath().setFrom(recompileDependencies);
task.getStepName().set("recompile");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import net.neoforged.gradle.dsl.common.runtime.tasks.RuntimeMultiArguments;
import org.gradle.api.GradleException;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.file.FileVisitor;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Property;
Expand Down Expand Up @@ -82,6 +85,7 @@ public RecompileSourceJar() {
getOptions().setFork(true);
getOptions().setIncremental(true);
getOptions().getIncrementalAfterFailure().set(true);
getOptions().setSourcepath(getProject().files(getAdditionalInputFileRoot()));
}

@Override
Expand Down Expand Up @@ -133,7 +137,7 @@ public Property<JavaLanguageVersion> getJavaVersion() {

@InputFiles
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getAdditionalInputFiles();
public abstract DirectoryProperty getAdditionalInputFileRoot();

@Override
protected void compile(InputChanges inputs) {
Expand All @@ -155,28 +159,25 @@ protected void compile(InputChanges inputs) {

private void doCachedCompile(InputChanges inputs) {
super.compile(inputs);
final FileTree output = this.getDestinationDirectory().getAsFileTree();

final FileTree outputTree = getDestinationDirectory().get().getAsFileTree();
outputTree.matching(pattern -> pattern.include(fileTreeElement -> {
final String relativePath = fileTreeElement.getRelativePath().getPathString();
if (!relativePath.endsWith(".class")) {
return false;
}
output.visit(details -> {
if (details.isDirectory())
return;

final String relativePath = details.getRelativePath().getPathString();
final String sourceFilePath;
if (!relativePath.contains("$")) {
sourceFilePath = relativePath.substring(0, relativePath.length() - ".class".length()) + ".java";
} else {
sourceFilePath = relativePath.substring(0, relativePath.indexOf('$')) + ".java";
}

return !getAdditionalInputFiles()
.getAsFileTree()
.matching(sp1 -> sp1.include(sourceFilePath))
.getFiles().isEmpty();
})).forEach(file -> {
getLogger().debug("Removing additional source file: {}", file);
file.delete();
if (!getAdditionalInputFileRoot().getAsFileTree().matching(pattern -> pattern.include(sourceFilePath))
.isEmpty()) {
getLogger().debug("Deleting additional input file.");
details.getFile().delete();
}
});
}
}

0 comments on commit 4cc8e2b

Please sign in to comment.