Skip to content

Commit

Permalink
Support jakarta.inject / jakarta.annotation in E4 as an alternative
Browse files Browse the repository at this point in the history
The javax.annotation / javax.inject are effectively deprecated as they
are now supersede by the jakarta.inject / jakarta.annotation 2.0 API.

This adds support for E4 to optionally process these annotations as well
so users can migrate their code away from the old namespace.

See eclipse-platform/eclipse.platform.ui#1129
  • Loading branch information
laeubi committed Sep 18, 2023
1 parent 13353c0 commit d9c8d1f
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 72 deletions.
6 changes: 3 additions & 3 deletions debug/org.eclipse.debug.ui.launchview/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.debug.ui.launchview;singleton:=true
Bundle-Version: 1.1.200.qualifier
Bundle-Version: 1.1.300.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
Expand All @@ -13,8 +13,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.e4.ui.di,
org.eclipse.e4.ui.services
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: javax.annotation;version="[1.0.0,2.0.0)",
javax.inject;version="[1.0.0,2.0.0)"
Import-Package: jakarta.annotation;version="[2.0.0,3.0.0)",
jakarta.inject;version="[2.0.0,3.0.0)"
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/org.eclipse.debug.ui.launchview.internal.model.LaunchViewModel.xml,
OSGI-INF/org.eclipse.debug.ui.launchview.internal.impl.DebugCoreProvider.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -61,6 +57,10 @@
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.inject.Inject;

public class LaunchViewImpl implements Supplier<Set<ILaunchObject>> {

private static final String CONTEXT_MENU_ID = "LaunchViewContextMenu"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.core.contexts
Bundle-Version: 1.12.300.qualifier
Bundle-Version: 1.12.400.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.e4.core.di
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: javax.inject;version="[1.0.0,2.0.0)",
Import-Package: jakarta.inject;version="[2.0.0,3.0.0)",
javax.inject;version="[1.0.0,2.0.0)",
org.osgi.framework;version="[1.5.0,2.0.0)",
org.osgi.service.event;version="[1.3.0,2.0.0)"
Export-Package: org.eclipse.e4.core.contexts;version="1.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Inject;
import javax.inject.Qualifier;

/**
* This annotation can be added to injectable fields ands methods
* to indicate that the injected value should come from the active context.
* This annotation can be added to injectable fields ands methods to indicate
* that the injected value should come from the active context.
*
* @see Inject
* @see javax.inject.Inject
* @see jakarta.inject.Inject
* @see IEclipseContext#activate
* @since 1.3
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Type;
import java.util.Objects;
import java.util.Stack;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.Active;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
Expand Down Expand Up @@ -189,8 +188,12 @@ else if (targetContext.containsKey(keys[i]))
}

private String getKey(IObjectDescriptor descriptor) {
if (descriptor.hasQualifier(Named.class)) {
Named namedAnnotation = descriptor.getQualifier(Named.class);
if (descriptor.hasQualifier(javax.inject.Named.class)) {
javax.inject.Named namedAnnotation = descriptor.getQualifier(javax.inject.Named.class);
return namedAnnotation.value();
}
if (descriptor.hasQualifier(jakarta.inject.Named.class)) {
jakarta.inject.Named namedAnnotation = descriptor.getQualifier(jakarta.inject.Named.class);
return namedAnnotation.value();
}
Type elementType = descriptor.getDesiredType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.e4.core.di.annotations
Bundle-Version: 1.8.100.qualifier
Bundle-Version: 1.8.200.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.e4.core.di.annotations;version="1.6.0"
Import-Package: javax.inject;version="[1.0.0,2.0.0)"
Import-Package: jakarta.inject;version="[2.0.0,3.0.0)",
javax.inject;version="[1.0.0,2.0.0)"
Bundle-Vendor: %Bundle-Vendor
Automatic-Module-Name: org.eclipse.e4.core.di.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
* Specifies that the target class can be created by an injector as needed.
* @since 1.3
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* This annotation can be applied to methods, fields, and parameters to mark
* them as optional for the dependency injection. Typically, if the injector is
Expand Down Expand Up @@ -53,7 +51,8 @@
*
* @since 1.3
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.e4.core.di.extensions;singleton:=true
Bundle-Version: 0.18.0.qualifier
Bundle-Version: 0.18.100.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.e4.core.di.extensions;version="0.16.0"
Bundle-Localization: fragment
Import-Package: javax.inject;version="[1.0.0,2.0.0)"
Import-Package: jakarta.inject;version="[2.0.0,3.0.0)",
javax.inject;version="[1.0.0,2.0.0)"
Automatic-Module-Name: org.eclipse.e4.core.di.extensions
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
* This annotation can be applied to arguments and fields that want to receive notifications on the
Expand All @@ -46,7 +45,8 @@
*
* @since 0.16
*/
@Qualifier
@jakarta.inject.Qualifier
@javax.inject.Qualifier
@Documented
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
* A method or field of type {@link org.osgi.framework.BundleContext} and
Expand Down Expand Up @@ -53,7 +52,8 @@
*
* @since 0.16
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
* @since 0.16
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

/**
* Annotation to use with DI to support dynamics and multiple services
*
* @since 0.16
*/
@Qualifier
@javax.inject.Qualifier
@jakarta.inject.Qualifier
@Documented
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
Expand Down
2 changes: 2 additions & 0 deletions runtime/bundles/org.eclipse.e4.core.di/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Export-Package: org.eclipse.e4.core.di;version="1.7.0",
Require-Bundle: org.eclipse.e4.core.di.annotations;bundle-version="[1.4.0,2.0.0)";visibility:=reexport
Import-Package: javax.annotation;version="[1.3.5,2.0.0)",
javax.inject;version="[1.0.0,2.0.0)",
jakarta.inject;version="[2,3)",
jakarta.annotation;version="[2,3)",
org.eclipse.osgi.framework.log;version="1.1.0",
org.osgi.framework;version="[1.8.0,2.0.0)",
org.osgi.util.tracker;version="[1.5.1,2.0.0)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.inject.Qualifier;

/**
* This interface describes objects created by the dependency injection.
Expand All @@ -24,7 +23,7 @@
* set of optional qualifiers.
* </p>
*
* @see Qualifier
* @see javax.inject.Qualifier
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
* @since 1.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*******************************************************************************/
package org.eclipse.e4.core.internal.di;

import jakarta.inject.Named;
import java.lang.reflect.Field;
import javax.inject.Named;
import org.eclipse.e4.core.di.IInjector;
import org.eclipse.e4.core.di.InjectionException;
import org.eclipse.e4.core.di.annotations.Optional;
Expand Down
Loading

0 comments on commit d9c8d1f

Please sign in to comment.