Skip to content

Commit 3c03470

Browse files
committed
Refactor OOM detection in DecompilerExecute; introduce OOMDetectorStream and update error handling
1 parent 1cadf69 commit 3c03470

3 files changed

Lines changed: 34 additions & 41 deletions

File tree

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/DecompilerExecute.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.gradle.api.GradleException;
66
import org.gradle.api.problems.Problems;
77
import org.gradle.api.tasks.CacheableTask;
8+
import org.gradle.api.tasks.Internal;
89

910
import javax.inject.Inject;
1011
import java.io.ByteArrayOutputStream;
@@ -22,10 +23,16 @@ public OutputStream createErrorOutputStream()
2223
{
2324
return new BifurcatingOutputStream(
2425
super.createErrorOutputStream(),
25-
this.detector
26+
new OOMDetectorStream(this.detector)
2627
);
2728
}
2829

30+
@Internal
31+
public OOMDetector getDetector()
32+
{
33+
return detector;
34+
}
35+
2936
@Override
3037
public void doExecute() throws Exception
3138
{
@@ -41,7 +48,7 @@ public void doExecute() throws Exception
4148

4249
private void detectError(boolean throwError)
4350
{
44-
if (detector.failed()) {
51+
if (getDetector().failed()) {
4552
//We failed, so we can access the project now, to get the reporter
4653
//We should not need to care about the config cache here,
4754
getProject().getExtensions().getByType(IProblemReporter.class)
@@ -59,35 +66,47 @@ private void detectError(boolean throwError)
5966
}
6067
}
6168

62-
private static final class OOMDetector extends OutputStream {
63-
private final ByteArrayOutputStream collectionDelegate = new ByteArrayOutputStream();
69+
public static final class OOMDetector {
6470
private final StringBuilder resultBuilder = new StringBuilder();
6571

6672
private OOMDetector() {
6773
}
6874

75+
private void addLog(String log) {
76+
resultBuilder.append(log);
77+
}
78+
79+
public boolean failed() {
80+
return this.resultBuilder.toString().contains("java.lang.OutOfMemoryError");
81+
}
82+
}
83+
84+
public static final class OOMDetectorStream extends OutputStream {
85+
private final OOMDetector detector;
86+
private final ByteArrayOutputStream collectionDelegate = new ByteArrayOutputStream();
87+
88+
public OOMDetectorStream(final OOMDetector detector) {this.detector = detector;}
89+
6990
@Override
70-
public void write(final int b)
91+
public void write(final int b) throws IOException
7192
{
72-
this.collectionDelegate.write(b);
93+
collectionDelegate.write(b);
7394
}
7495

7596
@Override
7697
public void flush() throws IOException
7798
{
78-
this.collectionDelegate.flush();
99+
super.flush();
100+
collectionDelegate.flush();
79101
}
80102

81103
@Override
82104
public void close() throws IOException
83105
{
84-
this.collectionDelegate.close();
106+
super.close();
107+
collectionDelegate.close();
85108

86-
this.resultBuilder.append(this.collectionDelegate);
87-
}
88-
89-
public boolean failed() {
90-
return this.resultBuilder.toString().contains("java.lang.OutOfMemoryError");
109+
this.detector.addLog(collectionDelegate.toString());
91110
}
92111
}
93112
}

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/RecompileSourceJar.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public abstract class RecompileSourceJar extends JavaCompile implements Runtime
4646
public RecompileSourceJar() {
4747
super();
4848

49-
//We use a custom instance here that marks the sourcepath as an incremental field, allowing us to provide the compiler
50-
//with all required elements directly while keeping incremental compile support for II.
51-
ReflectionUtils.setFinalFieldUncheckedWithAlternatives(this, getObjectFactory().newInstance(RecompileOptions.class), "compileOptions", "__options__");
52-
5349
arguments = getObjectFactory().newInstance(RuntimeArgumentsImpl.class, getProviderFactory());
5450
multiArguments = getObjectFactory().newInstance(RuntimeMultiArgumentsImpl.class, getProviderFactory());
5551

@@ -90,8 +86,8 @@ public RecompileSourceJar() {
9086
getOptions().setWarnings(false);
9187
getOptions().setVerbose(false);
9288
getOptions().setDeprecation(false);
93-
getOptions().setIncremental(true);
94-
getOptions().getIncrementalAfterFailure().set(true);
89+
getOptions().setIncremental(false);
90+
getOptions().getIncrementalAfterFailure().set(false);
9591

9692
setSource(getCompileFileRoot());
9793

@@ -230,25 +226,4 @@ public Provider<FileTree> getOutputAsTree()
230226
{
231227
return getOutput().map(it -> getArchiveOperations().zipTree(it));
232228
}
233-
234-
public static abstract class RecompileOptions extends CompileOptions {
235-
236-
@Inject
237-
public RecompileOptions(final ObjectFactory objectFactory)
238-
{
239-
super(objectFactory);
240-
}
241-
242-
@Incremental
243-
@Optional
244-
@IgnoreEmptyDirectories
245-
@PathSensitive(PathSensitivity.RELATIVE)
246-
@InputFiles
247-
@ToBeReplacedByLazyProperty
248-
@Override
249-
public @Nullable FileCollection getSourcepath()
250-
{
251-
return super.getSourcepath();
252-
}
253-
}
254229
}

userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/ConfigurationCacheTests.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class ConfigurationCacheTests extends BuilderBasedTestSpecification {
3030
it.withGlobalCacheDirectory(tempDir)
3131
it.enableLocalBuildCache()
3232
it.enableConfigurationCache()
33-
it.enableBuildScan()
3433
})
3534

3635
when:

0 commit comments

Comments
 (0)