Skip to content

Commit

Permalink
Add switch to disable/enable javax-annotation processing for E4-Injector
Browse files Browse the repository at this point in the history
The switch can be set via the VM property
'eclipse.e4.inject.javax.disabled'.
For now the default value is 'false', which enables processing of
'javax' annotations by default.

Users can specify the VM argument
'-Declipse.e4.inject.javax.disabled=true'
in order to test an application without processing of 'javax'
annotations now,
  • Loading branch information
HannesWell committed Nov 4, 2023
1 parent a1c46cd commit c61b9ee
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,33 @@ private static List<Class<?>> getAvailableClasses(Class<?> jakartaClass, Supplie

private static void loadJavaxClass(Runnable run) {
try {
run.run();
if (!javaxWarningPrinted) {
if (Boolean.parseBoolean(System.getProperty("eclipse.e4.inject.javax.warning", "true"))) { //$NON-NLS-1$//$NON-NLS-2$
@SuppressWarnings("nls")
String message = """
WARNING: Annotation classes from the 'javax.inject' or 'javax.annotation' package found.
It is recommended to migrate to the corresponding replacements in the jakarta namespace.
The Eclipse E4 Platform will remove support for those javax-annotations in a future release.
To suppress this warning set the VM property: -Declipse.e4.inject.javax.warning=false
""";
System.err.println(message);
if (!getSystemPropertyFlag("eclipse.e4.inject.javax.disabled", false)) { //$NON-NLS-1$
run.run();
if (!javaxWarningPrinted) {
if (getSystemPropertyFlag("eclipse.e4.inject.javax.warning", true)) { //$NON-NLS-1$
@SuppressWarnings("nls")
String message = """
WARNING: Annotation classes from the 'javax.inject' or 'javax.annotation' package found.
It is recommended to migrate to the corresponding replacements in the jakarta namespace.
The Eclipse E4 Platform will remove support for those javax-annotations in a future release.
To suppress this warning, set the VM property: -Declipse.e4.inject.javax.warning=false
To disable processing of 'javax' annotations entirely, set the VM property: -Declipse.e4.inject.javax.disabled=true
""";
System.err.println(message);
}
javaxWarningPrinted = true;
}
javaxWarningPrinted = true;
}
} catch (NoClassDefFoundError e) {
// Ignore exception: javax-annotation seems to be unavailable in the runtime
}
}

private static boolean getSystemPropertyFlag(String key, boolean defaultValue) {
String value = System.getProperty(key);
return value == null // assume "true" if value is empty (to allow -Dkey as shorthand for -Dkey=true)
? defaultValue
: (value.isEmpty() || Boolean.parseBoolean(value));
}

}

0 comments on commit c61b9ee

Please sign in to comment.