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

Ignore the generated optional sources during problem checker #1443

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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 @@ -39,6 +39,7 @@

import java.io.*;
import java.util.*;
import java.util.stream.Stream;

/**
* The abstract superclass of Java builders.
Expand Down Expand Up @@ -86,13 +87,23 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor, ICompi
public final static Integer P_NORMAL = Integer.valueOf(IMarker.PRIORITY_NORMAL);
public final static Integer P_LOW = Integer.valueOf(IMarker.PRIORITY_LOW);
private CompilationGroup compilationGroup;
/**
* A flag to control whether to ignore the optional sources during build.
*/
public static boolean IGNORE_OPTIONAL_SOURCES = true;

protected AbstractImageBuilder(JavaBuilder javaBuilder, boolean buildStarting, State newState, CompilationGroup compilationGroup) {
// local copies
this.javaBuilder = javaBuilder;
this.compilationGroup = compilationGroup;
this.nameEnvironment = compilationGroup == CompilationGroup.TEST ? javaBuilder.testNameEnvironment : javaBuilder.nameEnvironment;
this.sourceLocations = this.nameEnvironment.sourceLocations;
if (IGNORE_OPTIONAL_SOURCES && this.nameEnvironment.sourceLocations != null) {
this.sourceLocations = Stream.of(this.nameEnvironment.sourceLocations)
.filter(sourceLocation -> !sourceLocation.isOptional)
.toArray(ClasspathMultiDirectory[]::new);
} else {
this.sourceLocations = this.nameEnvironment.sourceLocations;
}
this.notifier = javaBuilder.notifier;
this.keepStoringProblemMarkers = true; // may get disabled when missing classfiles are encountered

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer out
char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems, IPath externalAnnotationPath) {
return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns, ignoreOptionalProblems, externalAnnotationPath);
}
static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder,
char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems, IPath externalAnnotationPath, boolean isOptional) {
return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns, ignoreOptionalProblems, externalAnnotationPath, isOptional);
}
public static ClasspathLocation forBinaryFolder(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet, IPath externalAnnotationPath, boolean autoModule) {
return new ClasspathDirectory(binaryFolder, isOutputFolder, accessRuleSet, externalAnnotationPath, autoModule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ClasspathMultiDirectory extends ClasspathDirectory {
public char[][] exclusionPatterns; // used by builders when walking source folders
boolean hasIndependentOutputFolder; // if output folder is not equal to any of the source folders
public boolean ignoreOptionalProblems;
public boolean isOptional = false;

ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns,
boolean ignoreOptionalProblems, IPath externalAnnotationPath) {
Expand All @@ -52,6 +53,12 @@ public class ClasspathMultiDirectory extends ClasspathDirectory {
this.exclusionPatterns = null;
}

ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns,
boolean ignoreOptionalProblems, IPath externalAnnotationPath, boolean isOptional) {
this(sourceFolder, binaryFolder, inclusionPatterns, exclusionPatterns, ignoreOptionalProblems, externalAnnotationPath);
this.isOptional = isOptional;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.*;
import org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdateKind;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
Expand Down Expand Up @@ -179,13 +178,15 @@ private void computeClasspathLocations(
}
bLocation.patchModuleName = patchedModuleName;
} else {
boolean isOptional = "true".equals(ClasspathEntry.getExtraAttribute(entry, "optional"));
ClasspathLocation sourceLocation = ClasspathLocation.forSourceFolder(
(IContainer) target,
outputFolder,
entry.fullInclusionPatternChars(),
entry.fullExclusionPatternChars(),
entry.ignoreOptionalProblems(),
externalAnnotationPath);
externalAnnotationPath,
isOptional);
if (patchedModule != null) {
ModuleEntryProcessor.combinePatchIntoModuleEntry(sourceLocation, patchedModule, moduleEntries);
}
Expand Down