mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Add @Generated annotation to generated Java types (#1075)
JaCoCo automatically excludes methods and classes annotated with @Generated from the coverage reports. This is very important to us as generated code should not normally be included in the coverage report. We want to measure the coverage of the code that we actually wrote and maintain, not the code that was automatically generated by tools. By introducing a property generatedAnnotation (default value false) one could enable writing @Generated on Java types to be generated. Co-authored-by: Nullpointer <mike.schulze@tealium.com>
This commit is contained in:
@@ -190,6 +190,7 @@ public class PklPlugin implements Plugin<Project> {
|
||||
configureBaseSpec(spec);
|
||||
configureCodeGenSpec(spec);
|
||||
|
||||
spec.getAddGeneratedAnnotation().convention(false);
|
||||
spec.getGenerateGetters().convention(false);
|
||||
spec.getGenerateJavadoc().convention(false);
|
||||
// Not using `convention()` so that users can disable generation of
|
||||
@@ -206,6 +207,7 @@ public class PklPlugin implements Plugin<Project> {
|
||||
.configure(
|
||||
task -> {
|
||||
configureCodeGenTask(task, spec);
|
||||
task.getGeneratedAnnotation().set(spec.getAddGeneratedAnnotation());
|
||||
task.getGenerateGetters().set(spec.getGenerateGetters());
|
||||
task.getGenerateJavadoc().set(spec.getGenerateJavadoc());
|
||||
task.getParamsAnnotation().set(spec.getParamsAnnotation());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 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.
|
||||
@@ -24,6 +24,8 @@ import org.gradle.api.tasks.SourceSet;
|
||||
public interface CodeGenSpec extends ModulesSpec {
|
||||
DirectoryProperty getOutputDir();
|
||||
|
||||
Property<Boolean> getAddGeneratedAnnotation();
|
||||
|
||||
Property<SourceSet> getSourceSet();
|
||||
|
||||
Property<String> getIndent();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 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.
|
||||
@@ -19,12 +19,17 @@ import org.gradle.api.file.DirectoryProperty;
|
||||
import org.gradle.api.provider.MapProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.Optional;
|
||||
import org.gradle.api.tasks.OutputDirectory;
|
||||
|
||||
public abstract class CodeGenTask extends ModulesTask {
|
||||
@OutputDirectory
|
||||
public abstract DirectoryProperty getOutputDir();
|
||||
|
||||
@Input
|
||||
@Optional
|
||||
public abstract Property<Boolean> getGeneratedAnnotation();
|
||||
|
||||
@Input
|
||||
public abstract Property<String> getIndent();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 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.
|
||||
@@ -47,6 +47,7 @@ public abstract class JavaCodeGenTask extends CodeGenTask {
|
||||
getCliBaseOptions(),
|
||||
getProject().file(getOutputDir()).toPath(),
|
||||
getIndent().get(),
|
||||
getGeneratedAnnotation().get(),
|
||||
getGenerateGetters().get(),
|
||||
getGenerateJavadoc().get(),
|
||||
getGenerateSpringBootConfig().get(),
|
||||
|
||||
Reference in New Issue
Block a user