From 311e315fb2a8db984c6a89de7ecd4bae26af4f09 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Wed, 31 May 2023 07:10:31 +0000 Subject: [PATCH 1/4] Update for next development version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ac5cf142..1afcb9f8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.0 + 2.3.1-SNAPSHOT jar Restrict Imports Enforcer Rule Bans imports of specified classes/packages From 0596ad3200b194711705b222df859a1e81a22396 Mon Sep 17 00:00:00 2001 From: Simon Taddiken Date: Thu, 1 Jun 2023 10:44:49 +0200 Subject: [PATCH 2/4] Detect full qualified annotation uses Closes #79 --- README.md | 6 +++--- RELEASE_NOTES.md | 12 +++--------- readme/RELEASE_NOTES.md | 8 +------- .../parser/lang/JavaCompilationUnitParser.java | 9 +++++++++ .../parser/ImportStatementParserImplTest.java | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e82b0da9..67c0feee 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.0&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.0/jar) -[![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.0&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.0) +[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1-SNAPSHOT&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT/jar) +[![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1-SNAPSHOT&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT) [![Coverage Status](https://coveralls.io/repos/github/skuzzle/restrict-imports-enforcer-rule/badge.svg?branch=master)](https://coveralls.io/github/skuzzle/restrict-imports-enforcer-rule?branch=master) [![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS) @@ -26,7 +26,7 @@ information. de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.0 + 2.3.1-SNAPSHOT diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d3a50301..61f3d920 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,13 +1,7 @@ -[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.0&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.0/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.0&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.0) +[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1-SNAPSHOT&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1-SNAPSHOT&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT) ### 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 - - +* [#79](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/79) Recognize full qualified annotation use Maven Central coordinates for this release: @@ -15,6 +9,6 @@ Maven Central coordinates for this release: de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.0 + 2.3.1-SNAPSHOT ``` diff --git a/readme/RELEASE_NOTES.md b/readme/RELEASE_NOTES.md index 6993283c..db494c88 100644 --- a/readme/RELEASE_NOTES.md +++ b/readme/RELEASE_NOTES.md @@ -1,13 +1,7 @@ [![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 -* [#76](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/76) `**` wildcard must match at least a single package part - -### Misc -* Updated various dependencies - - +* [#79](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/79) Recognize full qualified annotation use Maven Central coordinates for this release: diff --git a/src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/JavaCompilationUnitParser.java b/src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/JavaCompilationUnitParser.java index 887a4c86..804e9bd1 100644 --- a/src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/JavaCompilationUnitParser.java +++ b/src/main/java/de/skuzzle/enforcer/restrictimports/parser/lang/JavaCompilationUnitParser.java @@ -16,6 +16,7 @@ import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.MarkerAnnotationExpr; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.nodeTypes.NodeWithType; import com.github.javaparser.ast.type.ClassOrInterfaceType; @@ -79,6 +80,14 @@ private Optional nodeToImportStatement(Node node) { return Optional.of(new ImportStatement(accessExpr.getScope() + "." + accessExpr.getName(), positionOf(node), ImportType.QUALIFIED_TYPE_USE)); + } else if (node instanceof MarkerAnnotationExpr) { + final MarkerAnnotationExpr expr = (MarkerAnnotationExpr) node; + final boolean isQualified = expr.getName().getQualifier().isPresent(); + + if (isQualified) { + return Optional.of( + new ImportStatement(expr.getNameAsString(), positionOf(node), ImportType.QUALIFIED_TYPE_USE)); + } } return Optional.empty(); diff --git a/src/test/java/de/skuzzle/enforcer/restrictimports/parser/ImportStatementParserImplTest.java b/src/test/java/de/skuzzle/enforcer/restrictimports/parser/ImportStatementParserImplTest.java index 9fcd5b3f..36fef57f 100644 --- a/src/test/java/de/skuzzle/enforcer/restrictimports/parser/ImportStatementParserImplTest.java +++ b/src/test/java/de/skuzzle/enforcer/restrictimports/parser/ImportStatementParserImplTest.java @@ -44,6 +44,24 @@ void testAnalyzeFallbackOnFailure(@TempDir Path tempDir) throws IOException { // fallback parsing also failed } + @Test + void testFullQualifiedAnnotationUsage(@TempDir Path tempDir) throws Exception { + final Path sourceFile = tempSourceFile(tempDir, "Filename.java", + "class Test {", + " @a.b.c.Annotation", + " @Override", + " String foo(int parameter) {", + " return null;", + " }", + "}"); + final boolean parseFullCompilationUnit = true; + final ImportStatementParser subject = ImportStatementParser.forCharset(StandardCharsets.UTF_8, + parseFullCompilationUnit); + final ParsedFile parsedFile = subject.parse(sourceFile); + assertThat(parsedFile.getImports()).containsOnly( + new ImportStatement("a.b.c.Annotation", 2, ImportType.QUALIFIED_TYPE_USE)); + } + @Test void testAnalyzeInlineFullQualifiedClassUsage(@TempDir Path tempDir) throws Exception { final Path sourceFile = tempSourceFile(tempDir, "Filename.java", From 1e0da88c309751aef1f6fc2ade6779306625ffb4 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Thu, 1 Jun 2023 09:19:32 +0000 Subject: [PATCH 3/4] Update versions for release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1afcb9f8..0bdce8e1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.1-SNAPSHOT + 2.3.1 jar Restrict Imports Enforcer Rule Bans imports of specified classes/packages From 886abf6dce98f9563d1cd6bb2d01c0642071f0fa Mon Sep 17 00:00:00 2001 From: Jenkins Date: Thu, 1 Jun 2023 09:21:48 +0000 Subject: [PATCH 4/4] Update README and RELEASE_NOTES --- README.md | 6 +++--- RELEASE_NOTES.md | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 67c0feee..95aed38d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1-SNAPSHOT&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT/jar) -[![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1-SNAPSHOT&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT) +[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1/jar) +[![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1) [![Coverage Status](https://coveralls.io/repos/github/skuzzle/restrict-imports-enforcer-rule/badge.svg?branch=master)](https://coveralls.io/github/skuzzle/restrict-imports-enforcer-rule?branch=master) [![Twitter Follow](https://img.shields.io/twitter/follow/skuzzleOSS.svg?style=social)](https://twitter.com/skuzzleOSS) @@ -26,7 +26,7 @@ information. de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.1-SNAPSHOT + 2.3.1 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 61f3d920..19d0827f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,4 @@ -[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1-SNAPSHOT&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1-SNAPSHOT&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1-SNAPSHOT) +[![Maven Central](https://img.shields.io/static/v1?label=MavenCentral&message=2.3.1&color=blue)](https://search.maven.org/artifact/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1/jar) [![JavaDoc](https://img.shields.io/static/v1?label=JavaDoc&message=2.3.1&color=orange)](http://www.javadoc.io/doc/de.skuzzle.enforcer/restrict-imports-enforcer-rule/2.3.1) ### Bug fixes * [#79](https://github.com/skuzzle/restrict-imports-enforcer-rule/issues/79) Recognize full qualified annotation use @@ -9,6 +9,6 @@ Maven Central coordinates for this release: de.skuzzle.enforcer restrict-imports-enforcer-rule - 2.3.1-SNAPSHOT + 2.3.1 ```