Skip to content

Commit

Permalink
Merge pull request #6 from footaku/repair-to-load-setting-file
Browse files Browse the repository at this point in the history
Repair to load setting file
  • Loading branch information
footaku authored Nov 9, 2023
2 parents 3c68474 + 0e9886c commit fb03c2a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
dependencies {
...
archUnitExtraLib('io.github.footaku:erai:0.0.5')
archUnitExtraLib('io.github.footaku:erai:0.0.6')
...
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "io.github.footaku"
version = "0.0.5"
version = "0.0.6"

repositories {
mavenLocal()
Expand Down Expand Up @@ -73,7 +73,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "io.github.footaku"
artifactId = "erai"
version = "0.0.5"
version = "0.0.6"

pom {
name.set("erai")
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/github/footaku/erai/Erai.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public List<String> availableAnnotations() {
*
* @return enable
*/
public List<String> excludedClasses() {
if (Objects.isNull(returnValue.excludedClasses) || returnValue.excludedClasses.isEmpty()) {
public List<String> excludeClasses() {
if (Objects.isNull(returnValue.excludeClasses) || returnValue.excludeClasses.isEmpty()) {
return List.of();
}
return returnValue.excludedClasses;
return returnValue.excludeClasses;
}

/**
* Return value settings.
*/
public record ReturnValue(
List<String> availableAnnotations,
List<String> excludedClasses
List<String> excludeClasses
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class ShouldBeIndicateReturnValueNullability implements ArchRuleTest {

private final List<String> availableAnnotations = Erai.getSetting().nullability().availableAnnotations();
private final List<String> excludedClasses = Erai.getSetting().nullability().excludedClasses();
private final List<String> excludeClasses = Erai.getSetting().nullability().excludeClasses();

@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {
Expand All @@ -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());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand All @@ -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());
Expand All @@ -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) {
Expand Down

0 comments on commit fb03c2a

Please sign in to comment.