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

Prototype plugin stubs generation #209 #232

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 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
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ include("sourcegen-generator-kotlin")
include("sourcegen-generator-bytecode")
include("sourcegen-bytecode-writer")
include("sourcegen-bom")
include("sourcegen-plugin-annotations")
include("sourcegen-plugin-generator")
andriy-dmytruk marked this conversation as resolved.
Show resolved Hide resolved

include("test-suite-java")
include("test-suite-bytecode")
//include("test-suite-groovy")
include("test-suite-kotlin")
include("test-suite-custom-annotations")
include("test-suite-custom-generators")
include("test-suite-plugin-common")
include("test-suite-plugin-gradle")
include("test-suite-plugin-maven")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ private CodeBlock renderStatement(@Nullable ObjectDef objectDef, MethodDef metho
);
}
if (statementDef instanceof StatementDef.Return aReturn) {
if (aReturn.expression() == null) {
return CodeBlock.of("return");
}
return CodeBlock.concat(
CodeBlock.of("return "),
renderExpression(objectDef, methodDef, aReturn.expression())
Expand Down
9 changes: 9 additions & 0 deletions sourcegen-plugin-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("io.micronaut.build.internal.sourcegen-module")
}

micronautBuild {
binaryCompatibility {
enabled.set(false)
andriy-dmytruk marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2017-2021 original authors
*
* 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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that triggers the generation of Gradle plugin and other types.
* Only single Gradle plugin should be generated. But a plugin may contain
* more than one task. Each task will have an corresponding extension method.
*
* @author Andriy Dmytruk
* @since 1.6.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
public @interface GenerateGradlePlugin {

/**
* The prefix to use for all names.
* For example if the prefix is {@code Test}, task will be generated as {@code TestTask}.
* The default is the annotated class name.
*
* @return The prefix
*/
String namePrefix() default "";

/**
* Configure gradle tasks that will be generated.
*
* @return gradle task configurations
*/
GenerateGradleTask[] tasks();

/**
* The types of classes to generate.
* By default, all are generated.
*
* @return The plugin types to generate.
*/
Type[] types() default {
Type.GRADLE_TASK, Type.GRADLE_EXTENSION, Type.GRADLE_SPECIFICATION, Type.GRADLE_PLUGIN
};

/**
* @return The gradle task group that will be set for all tasks
*/
String taskGroup() default "";

/**
* @return Whether to extend the micronaut plugin
*/
boolean micronautPlugin() default true;

/**
* The coordinate of dependency to add, like
* {@code io.micronaut.jsonschema:micronaut-jsonschema-generator}.
*
* @return The dependency
*/
String dependency() default "";

/**
* Enum defining the types that could be generated.
*/
enum Type {
GRADLE_TASK,
GRADLE_SPECIFICATION,
GRADLE_EXTENSION,
GRADLE_PLUGIN
}

@interface GenerateGradleTask {

/**
* @return The prefix to use for task name.
*/
String namePrefix();

/**
* @return The task configuration class name that has {@link PluginTask} annotation
*/
String source();

/**
* @return The name to use for the generated extension
*/
String extensionMethodName() default "";

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2017-2021 original authors
*
* 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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that triggers the generation of Maven Mojo.
* A plugin can include multiple Mojos.
*
* @author Andriy Dmytruk
* @since 1.6.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
@Repeatable(GenerateMavenMojo.List.class)
public @interface GenerateMavenMojo {

/**
* The prefix to use for the mojo name.
* For example if the prefix is {@code Test}, mojo will be generated as {@code TestMojo}.
* The default is the annotated class name.
*
* @return The prefix
*/
String namePrefix() default "";

/**
* @return The task configuration class name that has {@link PluginTask} annotation
*/
String source();

/**
* @return Whether to extend abstract micronaut mojo.
*/
boolean micronautPlugin() default true;

/**
* The property prefix to use for parameters generated in Maven Mojo.
*
* @see PluginTaskParameter#mavenProperty()
* @return The property prefix
*/
String mavenPropertyPrefix() default "";

/**
* A container for repeated MavenMojo.
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
@interface List {

/**
* @return Repeated annotations
*/
GenerateMavenMojo[] value();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2017-2021 original authors
*
* 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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that configures a plugin task.
* The annotation is used for generation of particular plugin implementations, like Maven
* Mojos or Gradle Tasks.
*
* @author Andriy Dmytruk
* @since 1.6.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
public @interface PluginTask {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2021 original authors
*
* 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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that configures the executable method to run for a plugin task.
* Should be inside a type annotated with {@link PluginTask}.
*
* @author Andriy Dmytruk
* @since 1.6.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.METHOD })
public @interface PluginTaskExecutable {

}
Loading
Loading