Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion archrules-common/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is expected to be part of source control.
ch.qos.logback:logback-classic:1.5.20=testCompileClasspath,testRuntimeClasspath
ch.qos.logback:logback-core:1.5.20=testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-archrules-core:0.15.1=testCompileClasspath,testRuntimeClasspath
com.netflix.nebula:nebula-archrules-core:0.15.2=testCompileClasspath,testRuntimeClasspath
com.tngtech.archunit:archunit:1.4.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.17.7=testCompileClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.tngtech.archunit.base.DescribedPredicate;
import org.jspecify.annotations.NullMarked;

import java.util.Arrays;
import java.util.stream.StreamSupport;

import static com.tngtech.archunit.core.domain.JavaClass.Predicates.assignableTo;
import static com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith;
import static com.tngtech.archunit.core.domain.properties.HasType.Predicates.rawType;

@NullMarked
public class CanBeAnnotated {
Expand All @@ -26,5 +31,29 @@ public static DescribedPredicate<com.tngtech.archunit.core.domain.properties.Can
return annotatedWith(JavaAnnotation.Predicates.deprecatedForRemoval())
.as("deprecated for removal");
}

/**
* Creates a predicate matching elements annotated with any of the given annotations.
*/
public static DescribedPredicate<com.tngtech.archunit.core.domain.properties.CanBeAnnotated> annotatedWithAny(
String... annotationTypes) {
return Arrays.stream(annotationTypes)
.map(com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates::annotatedWith)
.reduce((a, b) -> a.or(b))
.orElseGet(() -> annotatedWith(rawType(assignableTo(Object.class))))
.as("annotated with any [%s]", String.join(", ", annotationTypes));
}

/**
* Creates a predicate matching elements annotated with any of the given annotations.
*/
public static DescribedPredicate<com.tngtech.archunit.core.domain.properties.CanBeAnnotated> annotatedWithAny(
Iterable<String> annotationTypes) {
return StreamSupport.stream(annotationTypes.spliterator(), false)
.map(com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates::annotatedWith)
.reduce((a, b) -> a.or(b))
.orElseGet(() -> annotatedWith(rawType(assignableTo(Object.class))))
.as("annotated with any [%s]", String.join(", ", annotationTypes));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class JavaBeanGetterPredicate extends DescribedPredicate<JavaMethod> {

JavaBeanGetterPredicate() {
super("getter");
super("a getter");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;

import static com.netflix.nebula.archrules.common.CanBeAnnotated.Predicates.annotatedWithAny;
import static com.netflix.nebula.archrules.common.Util.scanClass;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -16,21 +17,43 @@ public void test_javaDeprecatedClass() {
@Test
public void test_javaDeprecatedForRemovalClass() {
assertThat(CanBeAnnotated.Predicates.deprecatedForRemoval().test(scanClass(Usage.class))).isFalse();
assertThat(CanBeAnnotated.Predicates.deprecatedForRemoval().getDescription()).isEqualTo("deprecated for removal");
assertThat(CanBeAnnotated.Predicates.deprecatedForRemoval().getDescription())
.isEqualTo("deprecated for removal");
}

@Test
public void test_annotatedWithAny() {
final var rule = annotatedWithAny(SomeAnnotation.class.getName(), AnotherAnnotation.class.getName());
assertThat(rule.test(scanClass(Annotated1.class))).isTrue();
assertThat(rule.test(scanClass(Annotated2.class))).isTrue();
assertThat(rule.test(scanClass(Usage.class))).isFalse();
assertThat(rule.getDescription()).startsWith("annotated with any [");
}

@Deprecated
static class JavaDeprecatedClass {

}

@Deprecated(forRemoval = true)
static class JavaDeprecatedForRemovalClass {

}

static class Usage {
JavaDeprecatedClass aField;
JavaDeprecatedForRemovalClass deprecatedForRemoval;
}

@SomeAnnotation
static class Annotated1 {
}

@AnotherAnnotation
static class Annotated2 {
}

@interface SomeAnnotation {
}

@interface AnotherAnnotation {
}
}
4 changes: 2 additions & 2 deletions archrules-gradle-plugin-development/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ com.netflix.nebula:archrules-joda:0.9.0=archRules,archRulesArchRulesRuntime,arch
com.netflix.nebula:archrules-nullability:0.9.0=archRules,archRulesArchRulesRuntime,archRulesTestArchRulesRuntime,mainArchRulesRuntime,testArchRulesRuntime
com.netflix.nebula:archrules-security:0.9.0=archRules,archRulesArchRulesRuntime,archRulesTestArchRulesRuntime,mainArchRulesRuntime,testArchRulesRuntime
com.netflix.nebula:archrules-testing-frameworks:0.9.0=archRules,archRulesArchRulesRuntime,archRulesTestArchRulesRuntime,mainArchRulesRuntime,testArchRulesRuntime
com.netflix.nebula:nebula-archrules-core:0.15.1=archRulesArchRulesRuntime,archRulesCompileClasspath,archRulesJsonReportingResolved,archRulesRuntimeClasspath,archRulesTestArchRulesRuntime,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
com.netflix.nebula:nebula-archrules-core:0.15.2=archRulesArchRulesRuntime,archRulesCompileClasspath,archRulesJsonReportingResolved,archRulesRuntimeClasspath,archRulesTestArchRulesRuntime,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
com.netflix.nebula:nebula-archrules-core:0.8.0=archRules,mainArchRulesRuntime,testArchRulesRuntime
com.netflix.nebula:nebula-archrules-gradle-plugin:0.15.1=archRulesJsonReportingResolved
com.netflix.nebula:nebula-archrules-gradle-plugin:0.15.2=archRulesJsonReportingResolved
com.tngtech.archunit:archunit:1.4.1=archRules,archRulesArchRulesRuntime,archRulesCompileClasspath,archRulesJsonReportingResolved,archRulesRuntimeClasspath,archRulesTestArchRulesRuntime,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath,mainArchRulesRuntime,testArchRulesRuntime
net.bytebuddy:byte-buddy:1.17.7=archRulesTestArchRulesRuntime,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
org.assertj:assertj-core:3.27.6=archRulesTestArchRulesRuntime,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GradleInternalApiRule {
* and may change or be removed between versions without notice. Use only public
* Gradle APIs to ensure compatibility across Gradle versions.
*/
public static final ArchRule PLUGIN_INTERNAL = ArchRuleDefinition.priority(Priority.MEDIUM)
public static final ArchRule PLUGIN_INTERNAL = ArchRuleDefinition.priority(Priority.LOW)
.noClasses()
.that().implement("org.gradle.api.Plugin")
.should().dependOnClassesThat(internalGradleClass)
Expand All @@ -43,7 +43,7 @@ public class GradleInternalApiRule {
* and may change or be removed between versions without notice. Use only public
* Gradle APIs to ensure compatibility across Gradle versions.
*/
public static final ArchRule TASK_INTERNAL = ArchRuleDefinition.priority(Priority.MEDIUM)
public static final ArchRule TASK_INTERNAL = ArchRuleDefinition.priority(Priority.LOW)
.noClasses()
.that().areAssignableTo("org.gradle.api.Task")
.and().areNotInterfaces()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskCacheabilityRule.METHODS_PATH_SENSITIVITY;
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskContainerApiRule.USE_CONFIGURE_EACH_INSTEAD_OF_ALL;
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskContainerApiRule.USE_NAMED_INSTEAD_OF_GET_BY_NAME;
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskInputOutputRule.INPUTS_OUTPUTS;
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskProviderApiRule.ABSTRACT_GETTERS;
import static com.netflix.nebula.archrules.gradleplugins.GradleTaskProviderApiRule.PROVIDER_PROPERTIES;

@NullMarked
@SuppressWarnings("unused")
public class GradlePluginBestPractices implements ArchRulesService {
@Override
public Map<String, ArchRule> getRules() {
Map<String, ArchRule> rules = new HashMap<>();
rules.put("provider properties", PROVIDER_PROPERTIES);
rules.put("abstract getters", ABSTRACT_GETTERS);
rules.put("Task input/output file should be regular", TaskRegularFilePropertyRule.RULE);
rules.put("abstract getters", TaskAbstractGetterRule.RULE);
rules.put("Task declares inputs and/or outputs", TaskHasInputOutputRule.RULE);
rules.put("Task input/output should not be fields", TaskInputOutputFieldRule.RULE);
rules.put("Task input/output should use Provider API", GradleTaskRules.PROVIDER_PROPERTIES);
rules.put("task project access", taskActionShouldNotAccessProject);
rules.put("task dependencies", taskActionShouldNotCallGetTaskDependencies);
rules.put("lazy task registration", LAZY_TASK_CREATION);
Expand All @@ -50,7 +50,6 @@ public Map<String, ArchRule> getRules() {
rules.put("Plugin should inject ProviderFactory", USE_INJECTED_PROVIDER_FACTORY);
rules.put("Extension fields use Provider API", EXTENSION_FIELDS_USE_PROVIDER_API);
rules.put("Extension abstract getters", EXTENSION_ABSTRACT_GETTERS);
rules.put("Task declares inputs and/or outputs", INPUTS_OUTPUTS);
rules.put("Cacheable Task input field path sensitivity", FIELDS_PATH_SENSITIVITY);
rules.put("Cacheable Task input method path sensitivity", METHODS_PATH_SENSITIVITY);
rules.put("Apply plugins by ID", APPLY_BY_ID);
Expand Down
Loading
Loading