Skip to content

Commit b6a81a1

Browse files
Adding invertMarking flag to ModuleHasDependency to allow it to switch between marking files part of a module with a dependency (default / original behaviour / when flag is set to false or not provided) and marking files part of a module that doesn't have a dependency (when the flag is set to true)
1 parent 8b7a120 commit b6a81a1

File tree

2 files changed

+436
-2
lines changed

2 files changed

+436
-2
lines changed

src/main/java/org/openrewrite/java/dependencies/search/ModuleHasDependency.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public String getDescription() {
7373
@Nullable
7474
String version;
7575

76+
@Option(displayName = "Invert marking",
77+
description = "If `true`, will invert the check for whether to mark a file. Defaults to `false`.",
78+
required = false)
79+
@Nullable
80+
Boolean invertMarking;
81+
7682
@Override
7783
public Set<JavaProject> getInitialValue(ExecutionContext ctx) {
7884
return new HashSet<>();
@@ -110,8 +116,12 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
110116
return tree;
111117
}
112118
JavaProject jp = maybeJp.get();
113-
if (acc.contains(jp)) {
114-
return SearchResult.found(tree, "Module has dependency: " + groupIdPattern + ":" + artifactIdPattern + (version == null ? "" : ":" + version));
119+
boolean shouldInvert = invertMarking != null && invertMarking;
120+
String dependencyGav = groupIdPattern + ":" + artifactIdPattern + (version == null ? "" : ":" + version);
121+
if (shouldInvert && !acc.contains(jp)) {
122+
return SearchResult.found(tree, "Module does not have dependency: " + dependencyGav);
123+
} else if (!shouldInvert && acc.contains(jp)) {
124+
return SearchResult.found(tree, "Module has dependency: " + dependencyGav);
115125
}
116126
return tree;
117127
}

0 commit comments

Comments
 (0)