Skip to content

Commit 88680c5

Browse files
committed
make rules a little more ideomatic and reduce redundant message strings by leveraging automatic message generation
1 parent 919fc34 commit 88680c5

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
insert_final_newline = true
8+
max_line_length = 120
9+
ij_continuation_indent_size = 8
10+
tab_width = 4
11+
trim_trailing_whitespace = true
12+
13+
[{*.kt,*.kts}]
14+
ij_kotlin_allow_trailing_comma = false
15+
ij_kotlin_allow_trailing_comma_on_call_site = false
16+
ij_kotlin_name_count_to_use_star_import_for_members = 20
17+
ij_kotlin_name_count_to_use_star_import = 20
18+
ij_kotlin_continuation_indent_size = 4
19+
ktlint_code_style=intellij_idea
20+
21+
[*.java]
22+
ij_java_names_count_to_use_import_on_demand = 20
23+
ij_java_class_count_to_use_import_on_demand = 20

archrules-gradle-plugin-development/src/archRules/java/com/netflix/nebula/archrules/gradleplugins/GradleTaskActionRule.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,32 @@ public class GradleTaskActionRule implements ArchRulesService {
2929
* cause runtime errors in Gradle 10+. Move Project access to configuration time
3030
* (constructor/initializer) and use task properties instead.
3131
*/
32-
public static final ArchRule taskActionShouldNotAccessProject = createTaskActionRule(
33-
notAccessProject(),
34-
"access the Project object",
35-
"Accessing Project in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
36-
"Move Project access to task configuration time and use task inputs/properties instead.",
37-
"task_project"
38-
);
32+
public static final ArchRule taskActionShouldNotAccessProject = ArchRuleDefinition.priority(Priority.MEDIUM)
33+
.methods()
34+
.that(areAnnotatedWithTaskAction())
35+
.should(notAccessProject())
36+
.allowEmptyShould(true)
37+
.because(
38+
"Accessing Project in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
39+
"Move Project access to task configuration time and use task inputs/properties instead. " +
40+
"See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#task_project"
41+
);
3942

4043
/**
4144
* Prevents {@code @TaskAction} methods from calling {@code getTaskDependencies()}.
4245
* <p>
4346
* Calling {@code getTaskDependencies()} in task actions breaks configuration cache and will
4447
* cause runtime errors in Gradle 10+. Task dependencies should be declared at configuration time.
4548
*/
46-
public static final ArchRule taskActionShouldNotCallGetTaskDependencies = createTaskActionRule(
47-
notCallGetTaskDependencies(),
48-
"call getTaskDependencies()",
49-
"Calling getTaskDependencies() in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
50-
"Declare task dependencies at configuration time instead.",
51-
"task_dependencies"
52-
);
53-
54-
private static ArchRule createTaskActionRule(ArchCondition<JavaMethod> condition, String actionDescription, String reason, String docAnchor) {
55-
return ArchRuleDefinition.priority(Priority.MEDIUM)
56-
.methods()
57-
.that(areAnnotatedWithTaskAction())
58-
.should(condition)
59-
.allowEmptyShould(true)
60-
.as("Methods annotated with @TaskAction should not " + actionDescription)
61-
.because(reason + " See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#" + docAnchor);
62-
}
49+
public static final ArchRule taskActionShouldNotCallGetTaskDependencies = ArchRuleDefinition.priority(Priority.MEDIUM)
50+
.methods()
51+
.that(areAnnotatedWithTaskAction())
52+
.should(notCallGetTaskDependencies())
53+
.because(
54+
"Calling getTaskDependencies() in @TaskAction methods breaks configuration cache and will be removed in Gradle 10. " +
55+
"Declare task dependencies at configuration time instead. " +
56+
"See https://docs.gradle.org/9.2.0/userguide/upgrading_version_7.html#task_dependencies"
57+
);
6358

6459
private static DescribedPredicate<JavaMethod> areAnnotatedWithTaskAction() {
6560
return new DescribedPredicate<JavaMethod>("are annotated with @TaskAction") {

0 commit comments

Comments
 (0)