CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-flink--flink-architecture-tests-base

Base library for Apache Flink architecture tests that provides common ArchUnit extensions and utilities for validating architectural constraints in both production and test code

Pending
Overview
Eval results
Files

import-control.mddocs/

Import Control

ImportOption implementations for controlling which classes are analyzed during ArchUnit import. These options provide essential filtering capabilities for Maven projects and mixed Java/Scala codebases, helping manage memory consumption and focus analysis on relevant code.

Capabilities

Maven Project Filtering

Only imports class files from Maven main classes target directory, excluding test classes and other build artifacts.

/**
 * ImportOption that only includes class files from Maven main classes target directory
 * Pattern: .*/target/classes/.*
 */
public static final class MavenMainClassesOnly implements ImportOption {
    public boolean includes(Location location);
}

Usage Example:

import org.apache.flink.architecture.common.ImportOptions;
import com.tngtech.archunit.core.importer.ClassFileImporter;

// Import only main classes, excluding tests
JavaClasses mainClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.MavenMainClassesOnly())
    .importPackages("org.apache.flink");

// Apply architecture rules only to production code
ArchRule productionCodeRule = classes()
    .that().areNotEnums()
    .should().notAccessClassesThat().haveSimpleNameContaining("Test");

productionCodeRule.check(mainClasses);

Scala Code Exclusion

Excludes Scala classes on a best-effort basis, since ArchUnit doesn't fully support Scala analysis.

/**
 * ImportOption that excludes Scala classes to avoid ArchUnit compatibility issues
 * Pattern: .*/scala/.* (excluded)
 * Note: This is best-effort; use SourcePredicates.areJavaClasses() in rules as well
 */
public static final class ExcludeScalaImportOption implements ImportOption {
    public boolean includes(Location location);
}

Usage Example:

import org.apache.flink.architecture.common.ImportOptions;
import org.apache.flink.architecture.common.GivenJavaClasses;

// Exclude Scala classes during import
JavaClasses javaOnlyClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .importPackages("org.apache.flink");

// Use Java-only rule definitions for additional safety
ArchRule javaOnlyRule = GivenJavaClasses.javaClassesThat()
    .arePublic()
    .should().onlyDependOnClassesThat().areNotAnnotatedWith(Deprecated.class);

javaOnlyRule.check(javaOnlyClasses);

Shaded Dependency Exclusion

Excludes shaded (relocated) dependencies to avoid analyzing external code and reduce memory consumption.

/**
 * ImportOption that excludes shaded dependencies and relocated packages
 * Pattern: .*/shaded/.* (excluded)
 * Essential for memory consumption control when analyzing large projects
 */
public static final class ExcludeShadedImportOption implements ImportOption {
    public boolean includes(Location location);
}

Usage Example:

import org.apache.flink.architecture.common.ImportOptions;

// Exclude shaded dependencies to focus on core code
JavaClasses coreClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeShadedImportOption())
    .importPackages("org.apache.flink");

// Validate that core code doesn't directly access shaded packages
ArchRule noShadedAccessRule = classes()
    .should().onlyAccessClassesThat()
    .haveFullyQualifiedName(not(containsString(".shaded.")));

noShadedAccessRule.check(coreClasses);

Combined Import Strategies

Production Java Code Only

Combines all import options for the cleanest analysis focused on production Java code.

import org.apache.flink.architecture.common.ImportOptions;

JavaClasses productionJavaClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.MavenMainClassesOnly())
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .withImportOption(new ImportOptions.ExcludeShadedImportOption())
    .importPackages("org.apache.flink");

Memory-Optimized Import

For large codebases where memory consumption is a concern.

// Import strategy for large projects
JavaClasses optimizedClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeShadedImportOption()) // Critical for memory
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())  // Avoid analysis issues
    .withImportOption(location -> !location.contains("test"))        // Custom test exclusion
    .importPackagesOf(MyMainClass.class); // Import specific package tree

Module-Specific Analysis

Target specific modules while excluding irrelevant code.

// Analyze only streaming API module
JavaClasses streamingClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.MavenMainClassesOnly())
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .withImportOption(location -> location.contains("streaming"))
    .importPackages("org.apache.flink.streaming");

// Apply streaming-specific rules
ArchRule streamingRule = classes()
    .that().haveSimpleNameEndingWith("Stream")
    .should().implement("org.apache.flink.streaming.api.DataStream");

Performance Considerations

Memory Usage

// High memory usage - imports everything
JavaClasses allClasses = new ClassFileImporter()
    .importPackages("org.apache.flink"); // May cause OutOfMemoryError

// Optimized memory usage
JavaClasses optimizedClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeShadedImportOption()) // Biggest impact
    .withImportOption(new ImportOptions.MavenMainClassesOnly())      // Reduces test noise
    .importPackages("org.apache.flink.streaming.api");               // Specific package

Analysis Scope

// Broad analysis - slower but comprehensive
JavaClasses broadAnalysis = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .importPackages("org.apache.flink");

// Focused analysis - faster and more targeted
JavaClasses focusedAnalysis = new ClassFileImporter()
    .withImportOption(new ImportOptions.MavenMainClassesOnly())
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .withImportOption(new ImportOptions.ExcludeShadedImportOption())
    .importPackagesOf(SpecificModuleClass.class);

Integration with Other Components

Working with GivenJavaClasses

import org.apache.flink.architecture.common.ImportOptions;
import org.apache.flink.architecture.common.GivenJavaClasses;

// Import with filtering
JavaClasses filteredClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .importPackages("org.apache.flink");

// Apply Java-only rules for additional safety
ArchRule javaClassRule = GivenJavaClasses.javaClassesThat()
    .arePublic()
    .should().notHaveSimpleNameContaining("Scala");

javaClassRule.check(filteredClasses);

Custom Import Options

// Create custom import option
ImportOption customOption = location -> 
    !location.contains("deprecated") && 
    !location.contains("experimental");

JavaClasses customFilteredClasses = new ClassFileImporter()
    .withImportOption(new ImportOptions.MavenMainClassesOnly())
    .withImportOption(new ImportOptions.ExcludeScalaImportOption())
    .withImportOption(customOption)
    .importPackages("org.apache.flink");

Design Principles

  • Memory Efficiency: Designed to reduce memory consumption when analyzing large codebases
  • Best-Effort Filtering: Scala exclusion is best-effort; additional filtering in rules is recommended
  • Composability: Multiple import options can be combined for precise control
  • Maven Integration: Specifically designed for Maven project structures and conventions
  • Performance Optimization: Essential for making architectural analysis feasible on large projects

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-flink--flink-architecture-tests-base

docs

field-analysis.md

general-predicates.md

import-control.md

index.md

java-only-rules.md

method-validation.md

source-predicates.md

tile.json