Skip to content

Commit

Permalink
Added optional property to ignore folders for archunit tests #3453
Browse files Browse the repository at this point in the history
  • Loading branch information
lorriborri committed Nov 29, 2024
1 parent a0236d3 commit 452f4a9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,6 +14,8 @@ public class ArchUnitImportOptions {
return !location.contains("/test/"); // ignore any URI to sources that contains '/test/'
};

static List<ImportOption> 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/'
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mercedesbenz.com.sechub.archunit;

import java.util.*;

import com.tngtech.archunit.core.importer.ImportOption;

class ArchUnitRuntimeSupport {

public List<ImportOption> createImportOptionsIgnoreFolder() {
List<ImportOption> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -126,6 +129,7 @@ private JavaClasses ignoreTestGeneratedAndDeprecatedPackages() {
/* @formatter:off */
return new ClassFileImporter()
.withImportOption(ignoreAllTests)
.withImportOptions(ignoreFolders)
.withImportOption(ignoreSechubOpenAPIJava)
.withImportOption(ignoreNessusAdapter)
.withImportOption(ignoreNessusProduct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 452f4a9

Please sign in to comment.