Skip to content

Commit

Permalink
Fix path in getArchitectureFileContent
Browse files Browse the repository at this point in the history
  • Loading branch information
sarpsahinalp committed Aug 19, 2024
1 parent f788ba4 commit a76d913
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -55,7 +56,7 @@ public static Set<String> getForbiddenMethods(String key) {
* Get the content of a file from the architectural rules storage
*/
public static String getArchitectureRuleFileContent(String key) throws IOException {
return Files.readString(Path.of("src" + File.separator + "main" + File.separator + "resources" + File.separator + "archunit" + File.separator + "files" + File.separator + "java" + File.separator + "rules" + File.separator + "%s.txt".formatted(key)));
return Files.readString(Paths.get("src", "main", "resources", "archunit", "files", "java", "rules", "%s.txt".formatted(key)));
}

/**
Expand All @@ -81,6 +82,9 @@ public boolean test(JavaAccess<?> javaAccess) {
}
}));

/**
* This method checks if any class in the given package accesses the network.
*/
public static final ArchRule NO_CLASSES_SHOULD_ACCESS_NETWORK = ArchRuleDefinition.noClasses()
.should(new TransitivelyAccessesMethodsCondition(new DescribedPredicate<>("accesses network") {
private Set<String> forbiddenMethods;
Expand All @@ -101,6 +105,9 @@ public boolean test(JavaAccess<?> javaAccess) {
}
}));

/**
* This method checks if any class in the given package imports forbidden packages.
*/
public static final ArchRule NO_CLASSES_SHOULD_IMPORT_FORBIDDEN_PACKAGES = ArchRuleDefinition.noClasses()
.should()
.transitivelyDependOnClassesThat(new DescribedPredicate<>("imports package") {
Expand All @@ -111,6 +118,9 @@ public boolean test(JavaClass javaClass) {
}
});

/**
* This method checks if any class in the given package uses reflection.
*/
public static final ArchRule NO_CLASSES_SHOULD_USE_REFLECTION = ArchRuleDefinition.noClasses()
.should(new TransitivelyAccessesMethodsCondition(new DescribedPredicate<>("uses reflection") {
@Override
Expand All @@ -120,6 +130,9 @@ public boolean test(JavaAccess<?> javaAccess) {
}
}));

/**
* This method checks if any class in the given package uses the command line.
*/
public static final ArchRule NO_CLASSES_SHOULD_TERMINATE_JVM = ArchRuleDefinition.noClasses()
.should(new TransitivelyAccessesMethodsCondition((new DescribedPredicate<>("terminates JVM") {
private Set<String> forbiddenMethods;
Expand Down

0 comments on commit a76d913

Please sign in to comment.