Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add summaries and groups to Gradle tasks #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ private void configureJavaCodeGenTasks(NamedDomainObjectContainer<JavaCodeGenSpe
createModulesTask(JavaCodeGenTask.class, spec)
.configure(
task -> {
task.setDescription(TaskConstants.GENERATE_JAVA_DESCRIPTION);
task.setGroup(TaskConstants.TASK_GROUP_CODEGEN);
Comment on lines 171 to +175
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this is how I'm configuring description and group on these tasks.

configureCodeGenTask(task, spec);
task.getGenerateGetters().set(spec.getGenerateGetters());
task.getGenerateJavadoc().set(spec.getGenerateJavadoc());
Expand Down Expand Up @@ -200,6 +202,8 @@ private void configureKotlinCodeGenTasks(NamedDomainObjectContainer<KotlinCodeGe
createModulesTask(KotlinCodeGenTask.class, spec)
.configure(
task -> {
task.setDescription(TaskConstants.GENERATE_KOTLIN_DESCRIPTION);
task.setGroup(TaskConstants.TASK_GROUP_CODEGEN);
configureCodeGenTask(task, spec);
task.getGenerateKdoc().set(spec.getGenerateKdoc());
});
Expand Down Expand Up @@ -228,7 +232,12 @@ private void configurePkldocTasks(NamedDomainObjectContainer<PkldocSpec> specs)
.map(it -> it.dir("pkldoc").dir(spec.getName())));

createModulesTask(PkldocTask.class, spec)
.configure(task -> task.getOutputDir().set(spec.getOutputDir()));
.configure(
task -> {
task.setDescription(TaskConstants.GENERATE_PKLDOC_DESCRIPTION);
task.setGroup(TaskConstants.TASK_GROUP_DOCS);
task.getOutputDir().set(spec.getOutputDir());
});
});
}

Expand All @@ -242,6 +251,8 @@ private void configureTestTasks(NamedDomainObjectContainer<TestSpec> specs) {
var testTask = createModulesTask(TestTask.class, spec);
testTask.configure(
task -> {
task.setDescription(TaskConstants.GENERATE_PKLDOC_DESCRIPTION);
task.setGroup(TaskConstants.TASK_GROUP_DOCS);
task.getJunitReportsDir().set(spec.getJunitReportsDir());
task.getOverwrite().set(spec.getOverwrite());
});
Expand Down
38 changes: 38 additions & 0 deletions pkl-gradle/src/main/java/org/pkl/gradle/TaskConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.gradle;

/** Constant values used by tasks */
class TaskConstants {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is more conventional to put these constants directly to the plugin class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the category settings, which must be shared between plugins? I think there may be symbols for those somewhere in Gradle's API. I'll look for appropriate ones to use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's LifecycleBasePlugin which provides the base task names and groups.

Then there's JvmConstants, but this seems less appropriate for us.

I think it's fine to just have these as strings, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one plugin in the project, so there is nothing to share, or an I missing something?

Anyway, if you look at the built-in Gradle plugins, they always contain constants related to tasks configured by these plugins within the plugin class. If we ever decide to make new plugins, we can move these constants to the appropriate location at that time.

private TaskConstants() {
/* no construction */
}

/** Gradle task group declared for code-gen tasks. */
static final String TASK_GROUP_CODEGEN = "Code generation";

/** Gradle task group declared for documentation tasks. */
static final String TASK_GROUP_DOCS = "Documentation";
Comment on lines +25 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like these group names are generally lowercase single words.

Suggested change
static final String TASK_GROUP_CODEGEN = "Code generation";
/** Gradle task group declared for documentation tasks. */
static final String TASK_GROUP_DOCS = "Documentation";
static final String TASK_GROUP_CODEGEN = "codegen";
/** Gradle task group declared for documentation tasks. */
static final String TASK_GROUP_DOCS = "documentation";


/** Gradle task description for generating Java code from Pkl modules. */
static final String GENERATE_JAVA_DESCRIPTION = "Generate Java code from Pkl modules";

/** Gradle task description for generating Kotlin code from Pkl modules. */
static final String GENERATE_KOTLIN_DESCRIPTION = "Generate Kotlin code from Pkl modules";

/** Gradle task description for generating Pkldoc from Pkl modules. */
static final String GENERATE_PKLDOC_DESCRIPTION = "Generate Pkldoc from Pkl modules";
Comment on lines +24 to +37
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task constants that will show in ./gradlew tasks for a project with the Pkl Gradle Plugin added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think that if these strings are not reused anywhere, it might make sense to inline them to the specific task definitions within the plugin code. But I don't have a strong opinion on this.

}