Skip to content

Commit

Permalink
fix PlantUmlArchCondition.Configuration not accessible warning
Browse files Browse the repository at this point in the history
On the contrary to the Java compiler the Kotlin compiler emits a warning that `PlantUmlArchCondition.Configuration` as the parameter type of `PlantUmlArchCondition.adhereToPlantUmlDiagram()` is not accessible (because it is package private). Since in the end the pattern used here is a little inconsistent to other places anyway we change this now to be a publicly accessible class. The current construct was a little strange, either it needs to be a generic interface, freely extensible, but then there does not seem to be a reason to hide it from the user. Or we want to limit the possibilities, but then we might as well use a concrete class. As an additional benefit (since we will break the API anyway with release 1.0) we can now define the factory methods directly on the parameter type removing one indirection.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Jun 19, 2022
1 parent 38ff639 commit e1680a5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_PACKAGE_NAME;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.equivalentTo;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.adhereToPlantUmlDiagram;

@Category(Example.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_PACKAGE_NAME;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.equivalentTo;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.adhereToPlantUmlDiagram;

@ArchTag("example")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_PACKAGE_NAME;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.equivalentTo;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.adhereToPlantUmlDiagram;

@Category(Example.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Function;

import com.google.common.base.Joiner;
import com.google.common.collect.FluentIterable;
Expand Down Expand Up @@ -71,9 +72,9 @@
* Which dependencies should be considered by the rule can be configured via {@link Configuration}.
* Candidates are
* <ul>
* <li>{@link Configurations#consideringAllDependencies()}</li>
* <li>{@link Configurations#consideringOnlyDependenciesInDiagram()}</li>
* <li>{@link Configurations#consideringOnlyDependenciesInAnyPackage(String, String...)}</li>
* <li>{@link Configuration#consideringAllDependencies()}</li>
* <li>{@link Configuration#consideringOnlyDependenciesInDiagram()}</li>
* <li>{@link Configuration#consideringOnlyDependenciesInAnyPackage(String, String...)}</li>
* </ul>
* <br>
* A PlantUML diagram used with ArchUnit must abide by a certain set of rules:
Expand Down Expand Up @@ -210,16 +211,32 @@ private static URL toUrl(Path path) {
}
}

public static final class Configurations {
private Configurations() {
/**
* Used to specify which dependencies should be checked by the condition. Possible options are:
* <ul>
* <li>{@link #consideringAllDependencies()}</li>
* <li>{@link #consideringOnlyDependenciesInDiagram()}</li>
* <li>{@link #consideringOnlyDependenciesInAnyPackage(String, String...)}</li>
* </ul>
*/
@PublicAPI(usage = ACCESS)
public static final class Configuration {
private final Function<JavaClassDiagramAssociation, DescribedPredicate<Dependency>> createIgnorePredicate;

private Configuration(Function<JavaClassDiagramAssociation, DescribedPredicate<Dependency>> createIgnorePredicate) {
this.createIgnorePredicate = createIgnorePredicate;
}

DescribedPredicate<Dependency> asIgnorePredicate(JavaClassDiagramAssociation javaClassDiagramAssociation) {
return createIgnorePredicate.apply(javaClassDiagramAssociation);
}

/**
* Considers all dependencies of every imported class, including basic Java classes like {@link Object}
*/
@PublicAPI(usage = ACCESS)
public static Configuration consideringAllDependencies() {
return javaClassDiagramAssociation -> DescribedPredicate.<Dependency>alwaysFalse().as("");
return new Configuration(javaClassDiagramAssociation -> DescribedPredicate.<Dependency>alwaysFalse().as(""));
}

/**
Expand All @@ -229,7 +246,7 @@ public static Configuration consideringAllDependencies() {
*/
@PublicAPI(usage = ACCESS)
public static Configuration consideringOnlyDependenciesInDiagram() {
return NotContainedInDiagramPredicate::new;
return new Configuration(NotContainedInDiagramPredicate::new);
}

/**
Expand All @@ -243,7 +260,7 @@ public static Configuration consideringOnlyDependenciesInAnyPackage(String packa
.append(furtherPackageIdentifiers)
.toList();

return javaClassDiagramAssociation -> new NotContainedInPackagesPredicate(packageIdentifiers);
return new Configuration(javaClassDiagramAssociation -> new NotContainedInPackagesPredicate(packageIdentifiers));
}

private static class NotContainedInDiagramPredicate extends DescribedPredicate<Dependency> {
Expand Down Expand Up @@ -274,16 +291,4 @@ public boolean test(Dependency input) {
}
}
}

/**
* Used to specify which dependencies should be checked by the condition. Compare concrete instances:
* <ul>
* <li>{@link Configurations#consideringAllDependencies()}</li>
* <li>{@link Configurations#consideringOnlyDependenciesInDiagram()}</li>
* <li>{@link Configurations#consideringOnlyDependenciesInAnyPackage(String, String...)}</li>
* </ul>
*/
interface Configuration {
DescribedPredicate<Dependency> asIgnorePredicate(JavaClassDiagramAssociation javaClassDiagramAssociation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import static com.tngtech.archunit.core.domain.TestUtils.importClasses;
import static com.tngtech.archunit.lang.ArchRule.Assertions.assertNoViolation;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configurations.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringAllDependencies;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInAnyPackage;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.Configuration.consideringOnlyDependenciesInDiagram;
import static com.tngtech.archunit.library.plantuml.PlantUmlArchCondition.adhereToPlantUmlDiagram;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down

0 comments on commit e1680a5

Please sign in to comment.