Skip to content

Commit 0731665

Browse files
committed
Fix exclude globstar module matching
1 parent 2bef25d commit 0731665

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/commands/manifest/scripts/maven-extension/src/main/java/tech/coana/socket/SocketSupport.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ public static List<PathMatcher> parseExcludeMatchers(String csv) {
108108

109109
/**
110110
* NIO glob requires a slash-adjacent {@code **} to consume at least one path segment, but the
111-
* CLI's micromatch lets it match zero ({@code **}{@code /x} matches root-level {@code x}). Emit
112-
* every variant with {@code **}{@code /} occurrences dropped so both semantics hold.
111+
* CLI's micromatch lets it match zero ({@code **}{@code /x} matches root-level {@code x};
112+
* {@code x/**} matches {@code x}). Emit every variant with those zero-depth {@code **}
113+
* occurrences dropped so both semantics hold.
113114
*/
114115
private static Set<String> zeroDepthVariants(String glob) {
115116
Set<String> out = new LinkedHashSet<>();
@@ -118,6 +119,10 @@ private static Set<String> zeroDepthVariants(String glob) {
118119
while (!work.isEmpty()) {
119120
String cur = work.poll();
120121
if (!out.add(cur)) continue;
122+
if (cur.endsWith("/**")) {
123+
String collapsed = cur.substring(0, cur.length() - 3);
124+
if (!collapsed.isEmpty()) work.add(collapsed);
125+
}
121126
int idx = cur.indexOf("**/");
122127
while (idx >= 0) {
123128
if (idx == 0 || cur.charAt(idx - 1) == '/') {

src/commands/manifest/scripts/socket-facts.init.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ gradle.ext.socketProp = { proj, name -> proj.hasProperty(name) ? proj.property(n
1717
// Standard glob semantics (anchored to the scan root, matching the CLI flag): `x` is root-level, `**/x`
1818
// matches at any depth. Mirrors the sbt/maven producers.
1919
// NIO glob requires a slash-adjacent `**` to consume at least one path segment, but the CLI's
20-
// micromatch lets it match zero (`**/x` matches root-level `x`). Emit every variant with `**/`
21-
// occurrences dropped so both semantics hold.
20+
// micromatch lets it match zero (`**/x` matches root-level `x`; `x/**` matches `x`). Emit every
21+
// variant with those zero-depth `**` occurrences dropped so both semantics hold.
2222
gradle.ext.socketZeroDepthVariants = { String glob ->
2323
def out = new LinkedHashSet()
2424
def work = new ArrayDeque()
2525
work.add(glob)
2626
while (!work.isEmpty()) {
2727
def cur = work.poll()
2828
if (!out.add(cur)) { continue }
29+
if (cur.endsWith('/**')) {
30+
def collapsed = cur.substring(0, cur.length() - 3)
31+
if (!collapsed.isEmpty()) { work.add(collapsed) }
32+
}
2933
int idx = cur.indexOf('**/')
3034
while (idx >= 0) {
3135
if (idx == 0 || cur[idx - 1] == '/') {

src/commands/manifest/scripts/socket-facts.plugin.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,18 @@ object SocketFactsPlugin extends AutoPlugin {
414414
}
415415

416416
// NIO glob requires a slash-adjacent `**` to consume at least one path segment, but the CLI's
417-
// micromatch lets it match zero (`**/x` matches root-level `x`). Emit every variant with `**/`
418-
// occurrences dropped so both semantics hold.
417+
// micromatch lets it match zero (`**/x` matches root-level `x`; `x/**` matches `x`). Emit every
418+
// variant with those zero-depth `**` occurrences dropped so both semantics hold.
419419
private def zeroDepthVariants(glob: String): Seq[String] = {
420420
val out = mutable.LinkedHashSet[String]()
421421
val work = mutable.Queue(glob)
422422
while (work.nonEmpty) {
423423
val cur = work.dequeue()
424424
if (out.add(cur)) {
425+
if (cur.endsWith("/**")) {
426+
val collapsed = cur.substring(0, cur.length - 3)
427+
if (collapsed.nonEmpty) work.enqueue(collapsed)
428+
}
425429
var idx = cur.indexOf("**/")
426430
while (idx >= 0) {
427431
if (idx == 0 || cur.charAt(idx - 1) == '/') {

0 commit comments

Comments
 (0)