com.tngtech.archunit.core.importer.ImportOption Java Examples

The following examples show how to use com.tngtech.archunit.core.importer.ImportOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Modules.java    From moduliths with Apache License 2.0 6 votes vote down vote up
private Modules(ModulithMetadata metadata, Collection<String> packages, DescribedPredicate<JavaClass> ignored,
		boolean useFullyQualifiedModuleNames) {

	this.metadata = metadata;

	List<String> toImport = new ArrayList<>(packages);
	toImport.addAll(FRAMEWORK_PACKAGES);

	this.allClasses = new ClassFileImporter() //
			.withImportOption(new ImportOption.DoNotIncludeTests()) //
			.importPackages(toImport) //
			.that(not(ignored));

	Classes classes = Classes.of(allClasses);

	this.modules = packages.stream() //
			.flatMap(it -> getSubpackages(classes, it)) //
			.map(it -> new Module(it, useFullyQualifiedModuleNames)) //
			.collect(toMap(Module::getName, Function.identity()));

	this.rootPackages = packages.stream() //
			.map(it -> JavaPackage.of(classes, it).toSingle()) //
			.collect(Collectors.toList());

	this.sharedModules = Collections.emptySet();
}
 
Example #2
Source File: ArchTest.java    From jhipster-online with Apache License 2.0 6 votes vote down vote up
@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {

    JavaClasses importedClasses = new ClassFileImporter()
        .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
        .importPackages("io.github.jhipster.online");

    noClasses()
        .that()
            .resideInAnyPackage("io.github.jhipster.online.service..")
        .or()
            .resideInAnyPackage("io.github.jhipster.online.repository..")
        .should().dependOnClassesThat()
            .resideInAnyPackage("..io.github.jhipster.online.web..")
    .because("Services and repositories should not depend on web layer")
    .check(importedClasses);
}
 
Example #3
Source File: ArchTest.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {

    JavaClasses importedClasses = new ClassFileImporter()
        .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
        .importPackages("io.github.jhipster.registry");

    noClasses()
        .that()
            .resideInAnyPackage("io.github.jhipster.registry.service..")
        .or()
            .resideInAnyPackage("io.github.jhipster.registry.repository..")
        .should().dependOnClassesThat()
            .resideInAnyPackage("..io.github.jhipster.registry.web..")
    .because("Services and repositories should not depend on web layer")
    .check(importedClasses);
}
 
Example #4
Source File: ArchitectureTest.java    From archunit-examples with MIT License 5 votes vote down vote up
@BeforeClass
public static void setUp() {
  classes = new ClassFileImporter()
    .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
    .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES)
    .importPackages("com.company.app");
}
 
Example #5
Source File: SecurityTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private ImportOptions onlyAppAndRuntime() {
    return new ImportOptions().with(new ImportOption() {
        @Override
        public boolean includes(Location location) {
            return location.contains("archunit")
                    || location.contains("/rt.jar")
                    || location.contains("java.base");
        }
    });
}
 
Example #6
Source File: ClassCache.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private synchronized void initialize() {
    if (javaClasses == null) {
        ImportOptions importOptions = new ImportOptions();
        for (Class<? extends ImportOption> optionClass : importOptionTypes) {
            importOptions = importOptions.with(newInstanceOf(optionClass));
        }
        javaClasses = cacheClassFileImporter.importClasses(importOptions, locations);
    }
}
 
Example #7
Source File: SecurityTest.java    From ArchUnit-Examples with Apache License 2.0 5 votes vote down vote up
private ImportOptions onlyAppAndRuntime() {
    return new ImportOptions().with(new ImportOption() {
        @Override
        public boolean includes(Location location) {
            return location.contains("archunit")
                    || location.contains("/rt.jar")
                    || location.contains("java.base");
        }
    });
}
 
Example #8
Source File: ArchitectureTest.java    From ddd-architecture-samples with MIT License 4 votes vote down vote up
@BeforeAll
static void init() {
    classes = new ClassFileImporter()
            .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
            .importPackages("study.huhao.demo");
}
 
Example #9
Source File: ArchUnitTestDescriptor.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends ImportOption>[] getImportOptions() {
    return analyzeClasses.importOptions();
}
 
Example #10
Source File: ArchUnitRunner.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends ImportOption>[] getImportOptions() {
    return analyzeClasses.importOptions();
}
 
Example #11
Source File: ClassCache.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private LazyJavaClasses(Set<Location> locations, Set<Class<? extends ImportOption>> importOptionTypes) {
    this.locations = locations;
    this.importOptionTypes = importOptionTypes;
}
 
Example #12
Source File: ClassCache.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private LocationsKey(Class<? extends ImportOption>[] importOptionTypes, Set<Location> locations) {
    this.importOptionTypes = ImmutableSet.copyOf(importOptionTypes);
    this.locations = locations;
}
 
Example #13
Source File: ClassCache.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private All(Class<? extends ImportOption>[] importOptions) {
    this.importOptions = importOptions;
}
 
Example #14
Source File: TestAnalysisRequest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends ImportOption>[] getImportOptions() {
    return importOptions;
}
 
Example #15
Source File: TestAnalysisRequest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
final TestAnalysisRequest withImportOptions(Class<? extends ImportOption>... importOptions) {
    this.importOptions = importOptions;
    return this;
}
 
Example #16
Source File: ClassAnalysisRequest.java    From ArchUnit with Apache License 2.0 votes vote down vote up
Class<? extends ImportOption>[] getImportOptions();