From f62a81d54d9f148051e5bf4b9bc9d3187c3c4ea0 Mon Sep 17 00:00:00 2001 From: Simon Taddiken Date: Wed, 31 May 2023 08:43:02 +0200 Subject: [PATCH] Make sure that `**` matches at least a single package part Fixes #76 --- RELEASE_NOTES.md | 8 ++++++-- readme/RELEASE_NOTES.md | 3 ++- .../enforcer/restrictimports/analyze/PackagePattern.java | 7 +++++++ .../restrictimports/analyze/PackagePatternTest.java | 8 ++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 27fe6274..63a5d358 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,7 +1,11 @@ [![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.2.1-SNAPSHOT&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.2.1-SNAPSHOT/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.2.1-SNAPSHOT&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.2.1-SNAPSHOT) -### Features -* [#60](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/60) Fall back to _line-by-line_ parsing if _full-compilation-unit_ parsing failed. +### Bug fixes +* [#73](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/73) Classloader issues while locating LanguageSupport instances +* [#76](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/76) `**` wildcard must match at least a single package part + +### Misc +* Updated various dependencies diff --git a/readme/RELEASE_NOTES.md b/readme/RELEASE_NOTES.md index 27dee52d..6993283c 100644 --- a/readme/RELEASE_NOTES.md +++ b/readme/RELEASE_NOTES.md @@ -1,7 +1,8 @@ [![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=${project.version}&color=blue)](https://search.maven.org/artifact/${project.groupId}/${project.artifactId}/${project.version}/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=${project.version}&color=orange)](http://www.javadoc.io/doc/${project.groupId}/${project.artifactId}/${project.version}) ### Bug fixes -* [#73](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/73) Classloader issues while locating LanguageSupport instances #73 +* [#73](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/73) Classloader issues while locating LanguageSupport instances +* [#76](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/76) `**` wildcard must match at least a single package part ### Misc * Updated various dependencies diff --git a/src/main/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePattern.java b/src/main/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePattern.java index a8e0c273..08d18c72 100644 --- a/src/main/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePattern.java +++ b/src/main/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePattern.java @@ -163,6 +163,13 @@ private static boolean matchesInternal(boolean matchIsStatic, String[] matchPart if ("**".equals(patternPart)) { if (patternIndex + 1 < patternParts.length) { + + // See #76 + // https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/76 + // ** is supposed to match at least one package. So we eagerly skip + // one package + matchIndex++; + final String nextPatternPart = patternParts[patternIndex + 1]; while (matchIndex < matchParts.length && !matchParts(nextPatternPart, matchParts[matchIndex])) { diff --git a/src/test/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePatternTest.java b/src/test/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePatternTest.java index 2ec684f9..452c732f 100644 --- a/src/test/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePatternTest.java +++ b/src/test/java/de/skuzzle/enforcer/restrictimports/analyze/PackagePatternTest.java @@ -9,6 +9,14 @@ public class PackagePatternTest { + @Test + void testMatchWildcardPrefix() { + // See #76 + // https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/76 + assertThat(PackagePattern.parse("**.com.google.common.annotations.VisibleForTesting") + .matches("com.couchbase.client.core.deps.com.google.common.annotations.VisibleForTesting")).isTrue(); + } + @Test void testMatchLiteralAsterisk() { final PackagePattern pattern = PackagePattern.parse("java.util.'*'");