diff --git a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitImportOptions.java b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitImportOptions.java index 9e62666c42..ad5e4e8ba7 100644 --- a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitImportOptions.java +++ b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitImportOptions.java @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT package mercedesbenz.com.sechub.archunit; +import java.util.List; + import com.tngtech.archunit.core.importer.ImportOption; public class ArchUnitImportOptions { @@ -12,6 +14,8 @@ public class ArchUnitImportOptions { return !location.contains("/test/"); // ignore any URI to sources that contains '/test/' }; + static List ignoreFolders = new ArchUnitRuntimeSupport().createImportOptionsIgnoreFolder(); // ignore specific folders e.g. build folders + static ImportOption ignoreSechubOpenAPIJava = location -> { return !location.contains("/sechub-openapi-java/"); // ignore any URI to sources that contains '/sechub-openapi-java/' }; diff --git a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitRuntimeSupport.java b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitRuntimeSupport.java new file mode 100644 index 0000000000..de16e2d3f5 --- /dev/null +++ b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/ArchUnitRuntimeSupport.java @@ -0,0 +1,26 @@ +package mercedesbenz.com.sechub.archunit; + +import java.util.*; + +import com.tngtech.archunit.core.importer.ImportOption; + +class ArchUnitRuntimeSupport { + + public List createImportOptionsIgnoreFolder() { + List importOptions = new ArrayList<>(); + + // comma seperated list of folders to ignore e.g. build folders from different + // builds + String folderToIgnore = System.getProperty("sechub.archunit.ignoreFolders"); + if (folderToIgnore == null || folderToIgnore.isBlank()) { + return importOptions; + } + + String[] folders = folderToIgnore.split(","); + for (String folder : folders) { + importOptions.add(location -> !location.contains(folder)); + } + return importOptions; + } + +} \ No newline at end of file diff --git a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/CodingRulesTest.java b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/CodingRulesTest.java index 57c1272f0b..4e02386977 100644 --- a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/CodingRulesTest.java +++ b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/CodingRulesTest.java @@ -32,6 +32,7 @@ void classes_should_not_use_deprecated_members() { /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() .withImportOption(ignoreAllTests) + .withImportOptions(ignoreFolders) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreNessusAdapter) .withImportOption(ignoreNessusProduct) @@ -75,6 +76,7 @@ void test_classes_should_be_in_the_same_package_as_implementation() { /* prepare */ /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() + .withImportOptions(ignoreFolders) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreSechubApiJava) .withImportOption(ignoreDocGen) @@ -105,6 +107,7 @@ void classes_should_not_use_standard_streams() { /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() .withImportOption(ignoreAllTests) + .withImportOptions(ignoreFolders) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreIntegrationTest) .withImportOption(ignoreDocGen) @@ -126,6 +129,7 @@ private JavaClasses ignoreTestGeneratedAndDeprecatedPackages() { /* @formatter:off */ return new ClassFileImporter() .withImportOption(ignoreAllTests) + .withImportOptions(ignoreFolders) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreNessusAdapter) .withImportOption(ignoreNessusProduct) diff --git a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/DomainAccessRulesTest.java b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/DomainAccessRulesTest.java index 0e7c36aaec..b3e4666739 100644 --- a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/DomainAccessRulesTest.java +++ b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/DomainAccessRulesTest.java @@ -46,6 +46,7 @@ void no_class_in_one_domain_communicate_with_another_domain(String domainToTest) /* prepare */ /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() + .withImportOptions(ignoreFolders) .withImportOption(ignoreDevelopertools) .withImportOption(ignoreJarFiles) .importPath(SECHUB_ROOT_PATH); diff --git a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/NamingConventionTest.java b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/NamingConventionTest.java index d212d12372..6c372da8d3 100644 --- a/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/NamingConventionTest.java +++ b/sechub-archunit-test/src/test/java/mercedesbenz/com/sechub/archunit/NamingConventionTest.java @@ -19,6 +19,7 @@ void classes_in_test_packages_containing_test_or_assert_in_name() { /* prepare */ /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() + .withImportOptions(ignoreFolders) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreSechubTestframework) .withImportOption(ignoreSharedkernelTest) @@ -46,6 +47,7 @@ void service_annotated_classes_contain_service_or_executor_in_name() { /* prepare */ /* @formatter:off */ JavaClasses importedClasses = new ClassFileImporter() + .withImportOptions(ignoreFolders) .withImportOption(ignoreAllTests) .withImportOption(ignoreSechubOpenAPIJava) .withImportOption(ignoreJarFiles)