Skip to content

Commit 312651a

Browse files
committed
Add switch to disable/enable javax-annotation processing for E4-Injector
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,
1 parent a1c46cd commit 312651a

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,33 @@ private static List<Class<?>> getAvailableClasses(Class<?> jakartaClass, Supplie
163163

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

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

0 commit comments

Comments
 (0)