From 849fdd5a63a4e1809a2bb5c4a6132a93e4a850ed Mon Sep 17 00:00:00 2001 From: footaku <18702821+footaku@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:20:55 +0900 Subject: [PATCH 1/3] Move setting file path to project root. --- README.md | 2 +- src/main/java/io/github/footaku/erai/Erai.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d04d03..65b1086 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ archUnit { ## Settings In The default settings, executes all rules. -If you only want to apply certain rules, create 'erai.yaml' in the classpath root. +If you only want to apply certain rules, create 'erai.yaml' in the project root. The configuration values are as follows. ```yaml # Presence of Nullability annotation diff --git a/src/main/java/io/github/footaku/erai/Erai.java b/src/main/java/io/github/footaku/erai/Erai.java index 5faa45c..221a76d 100644 --- a/src/main/java/io/github/footaku/erai/Erai.java +++ b/src/main/java/io/github/footaku/erai/Erai.java @@ -5,6 +5,7 @@ import io.github.footaku.erai.configuration.Nullability; import io.github.footaku.erai.configuration.Setting; +import java.nio.file.Path; import java.util.List; /** @@ -25,8 +26,9 @@ public static synchronized Setting getSetting() { if (setting == null) { var mapper = new ObjectMapper(new YAMLFactory()); try { - // TODO fallback erai.yml - setting = mapper.readValue(ClassLoader.getSystemResource("erai.yaml"), Setting.class); + // TODO fallback another yaml file name + var path = Path.of("erai.yaml"); + setting = mapper.readValue(path.toFile(), Setting.class); } catch (Exception e) { // TODO Logger setting = new Setting( From 8918bb1b2004d4d41fa5f612e66da8f0ea6526de Mon Sep 17 00:00:00 2001 From: footaku <18702821+footaku@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:21:08 +0900 Subject: [PATCH 2/3] Rename property. --- .../io/github/footaku/erai/configuration/Nullability.java | 8 ++++---- .../erai/rule/ShouldBeIndicateReturnValueNullability.java | 4 ++-- .../erai/ShouldBeIndicateReturnValueNullabilityTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/github/footaku/erai/configuration/Nullability.java b/src/main/java/io/github/footaku/erai/configuration/Nullability.java index 8566c4b..ef328fb 100644 --- a/src/main/java/io/github/footaku/erai/configuration/Nullability.java +++ b/src/main/java/io/github/footaku/erai/configuration/Nullability.java @@ -34,11 +34,11 @@ public List availableAnnotations() { * * @return enable */ - public List excludedClasses() { - if (Objects.isNull(returnValue.excludedClasses) || returnValue.excludedClasses.isEmpty()) { + public List excludeClasses() { + if (Objects.isNull(returnValue.excludeClasses) || returnValue.excludeClasses.isEmpty()) { return List.of(); } - return returnValue.excludedClasses; + return returnValue.excludeClasses; } /** @@ -46,7 +46,7 @@ public List excludedClasses() { */ public record ReturnValue( List availableAnnotations, - List excludedClasses + List excludeClasses ) { } } diff --git a/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java b/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java index 24924d5..b08fd6c 100644 --- a/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java +++ b/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java @@ -21,7 +21,7 @@ public class ShouldBeIndicateReturnValueNullability implements ArchRuleTest { private final List availableAnnotations = Erai.getSetting().nullability().availableAnnotations(); - private final List excludedClasses = Erai.getSetting().nullability().excludedClasses(); + private final List excludeClasses = Erai.getSetting().nullability().excludeClasses(); @Override public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection excludedPaths) { @@ -43,7 +43,7 @@ public void execute(String packagePath, ScopePathProvider scopePathProvider, Col new DescribedPredicate<>("is not excluded classes") { @Override public boolean test(JavaMethod javaMethod) { - return !excludedClasses.contains(javaMethod.getOwner().getName()); + return !excludeClasses.contains(javaMethod.getOwner().getName()); } }; diff --git a/src/test/java/io/github/footaku/erai/ShouldBeIndicateReturnValueNullabilityTest.java b/src/test/java/io/github/footaku/erai/ShouldBeIndicateReturnValueNullabilityTest.java index 0258623..b893058 100644 --- a/src/test/java/io/github/footaku/erai/ShouldBeIndicateReturnValueNullabilityTest.java +++ b/src/test/java/io/github/footaku/erai/ShouldBeIndicateReturnValueNullabilityTest.java @@ -22,7 +22,7 @@ public void defaultSettingTestShouldThrowViolations() { var th = Assertions.catchThrowable(() -> { var sut = new ShouldBeIndicateReturnValueNullability(); - addExcludedClasses(sut); + addexcludeClasses(sut); sut.execute(testTargetPath, new TestScopeProvider(), Collections.emptySet()); }); @@ -36,7 +36,7 @@ public void specifiedAnnotationTestShouldThrowViolations() { var th = Assertions.catchThrowable(() -> { var sut = new ShouldBeIndicateReturnValueNullability(); - addExcludedClasses(sut); + addexcludeClasses(sut); addAvailableAnnotations(sut); sut.execute(testTargetPath, new TestScopeProvider(), Collections.emptySet()); @@ -45,9 +45,9 @@ public void specifiedAnnotationTestShouldThrowViolations() { Assertions.assertThat(th).isInstanceOf(AssertionError.class).hasMessageContaining("was violated (10 times)"); } - private void addExcludedClasses(Object sut) { + private void addexcludeClasses(Object sut) { try { - var field = ShouldBeIndicateReturnValueNullability.class.getDeclaredField("excludedClasses"); + var field = ShouldBeIndicateReturnValueNullability.class.getDeclaredField("excludeClasses"); field.setAccessible(true); field.set(sut, List.of("com.example.footaku.NotInspectionClass")); } catch (Exception e) { From 0e9886c2a5d1d1e5a3e43c88fbd04af87f751ef5 Mon Sep 17 00:00:00 2001 From: footaku <18702821+footaku@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:21:31 +0900 Subject: [PATCH 3/3] Bump version. --- README.md | 2 +- build.gradle.kts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 65b1086..4f575a4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ plugins { dependencies { ... - archUnitExtraLib('io.github.footaku:erai:0.0.5') + archUnitExtraLib('io.github.footaku:erai:0.0.6') ... } diff --git a/build.gradle.kts b/build.gradle.kts index f8e63eb..aa7b882 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "io.github.footaku" -version = "0.0.5" +version = "0.0.6" repositories { mavenLocal() @@ -73,7 +73,7 @@ publishing { create("mavenJava") { groupId = "io.github.footaku" artifactId = "erai" - version = "0.0.5" + version = "0.0.6" pom { name.set("erai")