From c61b9ee9151f2b13e8269840db8094559da540bc Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 4 Nov 2023 18:11:15 +0100 Subject: [PATCH] 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, --- .../e4/core/internal/di/AnnotationLookup.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java b/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java index 767f6346dcd..d6793c24280 100644 --- a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java +++ b/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java @@ -163,23 +163,33 @@ private static List> 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)); + } + }