Skip to content

Commit

Permalink
chore: Source Filter takes a list of artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Jan 15, 2025
1 parent e380975 commit a6ea26d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class LinkageChecker {
private final ImmutableList<ClassPathEntry> classPath;
private final SymbolReferences symbolReferences;
private final ClassReferenceGraph classReferenceGraph;
private final Artifact sourceFilter;
private final List<Artifact> sourceFilterList;
private final ExcludedErrors excludedErrors;

@VisibleForTesting
Expand All @@ -81,7 +81,7 @@ public static LinkageChecker create(List<ClassPathEntry> classPath) throws IOExc
public static LinkageChecker create(
List<ClassPathEntry> classPath,
Iterable<ClassPathEntry> entryPoints,
Artifact sourceFilter,
List<Artifact> sourceFilterList,
@Nullable Path exclusionFile)
throws IOException {
Preconditions.checkArgument(!classPath.isEmpty(), "The linkage classpath is empty.");
Expand All @@ -96,7 +96,7 @@ public static LinkageChecker create(
classPath,
symbolReferenceMaps,
classReferenceGraph,
sourceFilter,
sourceFilterList,
ExcludedErrors.create(exclusionFile));
}

Expand Down Expand Up @@ -147,13 +147,13 @@ private LinkageChecker(
List<ClassPathEntry> classPath,
SymbolReferences symbolReferenceMaps,
ClassReferenceGraph classReferenceGraph,
Artifact sourceFilter,
List<Artifact> sourceFilterList,
ExcludedErrors excludedErrors) {
this.classDumper = Preconditions.checkNotNull(classDumper);
this.classPath = ImmutableList.copyOf(classPath);
this.classReferenceGraph = Preconditions.checkNotNull(classReferenceGraph);
this.symbolReferences = Preconditions.checkNotNull(symbolReferenceMaps);
this.sourceFilter = sourceFilter;
this.sourceFilterList = sourceFilterList;
this.excludedErrors = Preconditions.checkNotNull(excludedErrors);
}

Expand All @@ -168,9 +168,10 @@ public ImmutableSet<LinkageProblem> findLinkageProblems() throws IOException {

// This sourceClassFile is a source of references to other symbols.
Set<ClassFile> classFiles = symbolReferences.getClassFiles();
if (sourceFilter != null) {
if (sourceFilterList != null) {
List<String> sourceFilterStringList = sourceFilterList.stream().map(Artifact::toString).collect(Collectors.toList());
classFiles = classFiles.stream()
.filter(x -> x.getClassPathEntry().getArtifact().toString().equals(sourceFilter.toString()))
.filter(x -> sourceFilterStringList.contains(x.getClassPathEntry().getArtifact().toString()))
.collect(Collectors.toSet());
}
for (ClassFile classFile : classFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -288,11 +289,13 @@ Path getOutputExclusionFile() {
return null;
}

Artifact getSourceFilterArtifact() {
List<Artifact> getSourceFilterArtifact() {
if (commandLine.hasOption("s")) {
String mavenCoordinatesOption = commandLine.getOptionValue('s');
return new DefaultArtifact(mavenCoordinatesOption);
String[] mavenCoordinatesOption = commandLine.getOptionValues("s");
return Arrays.stream(mavenCoordinatesOption)
.map(DefaultArtifact::new)
.collect(Collectors.toList());
}
return null;
return ImmutableList.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testExclusion()
classPathBuilder.resolve(ImmutableList.of(artifact), false, DependencyMediation.MAVEN);

LinkageChecker linkagechecker =
LinkageChecker.create(classPathResult.getClassPath(), ImmutableList.of(), exclusionFile);
LinkageChecker.create(classPathResult.getClassPath(), ImmutableList.of(), ImmutableList.of(), exclusionFile);

ImmutableSet<LinkageProblem> linkageProblems = linkagechecker.findLinkageProblems();
Truth.assertThat(linkageProblems).isEmpty();
Expand Down

0 comments on commit a6ea26d

Please sign in to comment.