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

4.x: Mark inject processor as preview (warning when executed). #7590

Merged
merged 2 commits into from
Sep 15, 2023
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
3 changes: 3 additions & 0 deletions config/config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.helidon.common.features</groupId>
Expand Down
3 changes: 3 additions & 0 deletions config/tests/service-registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.helidon.inject</groupId>
Expand Down
1 change: 1 addition & 0 deletions examples/inject/basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<compilerArgs>
<arg>-Ainject.autoAddNonContractInterfaces=false</arg> <!-- this setting can be used to avoid the need for @Contract -->
<arg>-Ainject.debug=false</arg>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<annotationProcessorPaths>
Expand Down
3 changes: 3 additions & 0 deletions examples/inject/interceptors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<compilerArgs>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.helidon.inject</groupId>
Expand Down
1 change: 1 addition & 0 deletions examples/inject/providers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<compilerArgs>
<arg>-Ainject.autoAddNonContractInterfaces=true</arg> <!-- this setting can be used to avoid the need for @Contract -->
<arg>-Ainject.debug=false</arg>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;

import io.helidon.common.types.TypeName;
import io.helidon.inject.tools.Options;

/**
* Abstract base for all Helidon annotation processing.
*/
abstract class BaseAnnotationProcessor extends AbstractProcessor {
private static final AtomicBoolean LOGGED_WARNING = new AtomicBoolean();
private final System.Logger logger = System.getLogger(getClass().getName());

private ActiveProcessorUtils utils;
Expand All @@ -53,6 +57,15 @@ public SourceVersion getSupportedSourceVersion() {
public void init(ProcessingEnvironment processingEnv) {
this.utils = new ActiveProcessorUtils(this, processingEnv);
super.init(processingEnv);

if (!Options.isOptionEnabled(Options.TAG_ACCEPT_PREVIEW)
&& LOGGED_WARNING.compareAndSet(false, true)) {
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.WARNING,
"Helidon Inject is preview feature, and the API and SPI may be modified in a future"
+ " revision. It is considered a production feature."
+ " This warning can be disabled by compiler argument -Ainject.acceptPreview=true");
}
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions inject/tests/interception/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<compilerArgs>
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.helidon.inject</groupId>
Expand Down
14 changes: 7 additions & 7 deletions inject/tests/resources-inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
<artifactId>helidon-config-metadata</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.helidon.inject</groupId>
<artifactId>helidon-inject-processor</artifactId>
<scope>provided</scope> <!-- reactor dependency ordering only -->
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.inject</groupId>
<artifactId>helidon-inject-maven-plugin</artifactId>
Expand Down Expand Up @@ -104,6 +98,7 @@
<!-- <arg>-XprintProcessorInfo</arg>-->
<!-- <arg>-XprintRounds</arg>-->
<!-- <arg>-verbose</arg>-->
<arg>-Ainject.acceptPreview=true</arg>
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<annotationProcessorPaths>
Expand All @@ -130,7 +125,12 @@
</annotationProcessorPaths>
</configuration>
<dependencies>
<dependency>
<dependency>
<groupId>io.helidon.inject</groupId>
<artifactId>helidon-inject-processor</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.common.processor</groupId>
<artifactId>helidon-common-processor-helidon-copyright</artifactId>
<version>${helidon.version}</version>
Expand Down
26 changes: 15 additions & 11 deletions inject/tools/src/main/java/io/helidon/inject/tools/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import javax.annotation.processing.ProcessingEnvironment;
Expand All @@ -36,6 +37,10 @@ public class Options {
* Tag for putting Injection's annotation processing into debug mode.
*/
public static final String TAG_DEBUG = InjectionServices.TAG_DEBUG;
/**
* Tag to accept this is a preview feature (so no warning is printed).
*/
public static final String TAG_ACCEPT_PREVIEW = "inject.acceptPreview";
/**
* Treat all super types as a contract for a given service type being added.
*/
Expand Down Expand Up @@ -84,6 +89,7 @@ private Options() {
* @param processingEnv the processing env
*/
public static void init(ProcessingEnvironment processingEnv) {
Objects.requireNonNull(processingEnv);
if (OPTS.isEmpty()) {
OPTS.put(TAG_DEBUG,
String.valueOf(isOptionEnabled(TAG_DEBUG, processingEnv)));
Expand All @@ -105,6 +111,7 @@ public static void init(ProcessingEnvironment processingEnv) {
getOption(TAG_IGNORE_UNSUPPORTED_ANNOTATIONS, null, processingEnv));
OPTS.put(TAG_IGNORE_MODULE_USAGE,
getOption(TAG_IGNORE_MODULE_USAGE, null, processingEnv));
OPTS.put(TAG_ACCEPT_PREVIEW, getOption(TAG_ACCEPT_PREVIEW, null, processingEnv));
}
}

Expand Down Expand Up @@ -146,7 +153,7 @@ static List<String> getOptionStringList(String option) {
/**
* This only supports the subset of options that Injection cares about, and should not be generally used for options.
*
* @param option the key (assumed to be meaningful to this class)
* @param option the key (assumed to be meaningful to this class)
* @param defaultVal the default value used if the associated value is null.
* @return the option value
*/
Expand All @@ -158,11 +165,10 @@ private static String getOption(String option,

private static boolean isOptionEnabled(String option,
ProcessingEnvironment processingEnv) {
if (processingEnv != null) {
String val = processingEnv.getOptions().get(option);
if (val != null) {
return Boolean.parseBoolean(val);
}

String val = processingEnv.getOptions().get(option);
if (val != null) {
return Boolean.parseBoolean(val);
}

return getOption(option, "", processingEnv).equals("true");
Expand All @@ -171,11 +177,9 @@ private static boolean isOptionEnabled(String option,
private static String getOption(String option,
String defaultVal,
ProcessingEnvironment processingEnv) {
if (processingEnv != null) {
String val = processingEnv.getOptions().get(option);
if (val != null) {
return val;
}
String val = processingEnv.getOptions().get(option);
if (val != null) {
return val;
}

return defaultVal;
Expand Down