Skip to content

Commit

Permalink
Prepare for migration to javax.inject/annotation provided by Jakarta
Browse files Browse the repository at this point in the history
Use Import-Package in all wizards/templates and tests instead of relying
on the name of the bundle that provides the javax.inject/annotation
packages.

Part of eclipse-platform/eclipse.platform.releng.aggregator#1056
  • Loading branch information
HannesWell committed May 4, 2023
1 parent 4621352 commit 8410aad
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 23 deletions.
1 change: 1 addition & 0 deletions ui/org.eclipse.pde.ui.templates/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Export-Package: org.eclipse.pde.internal.ui.templates;x-internal:=true,
org.eclipse.pde.internal.ui.templates.ide;x-internal:=true,
org.eclipse.pde.internal.ui.templates.osgi;x-internal:=true,
org.eclipse.pde.internal.ui.templates.rcp;x-internal:=true
Import-Package: javax.annotation;version="[1.3.0,2.0.0)"
Require-Bundle: org.eclipse.ui;bundle-version="[3.3.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)",
org.eclipse.pde.ui;bundle-version="[3.3.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
public class E4ApplicationNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"0.0.0\""); //$NON-NLS-1$
"javax.annotation;version=\"[1.2.0,2.0.0)\"", //$NON-NLS-1$
"javax.inject;version=\"[1.0.0,2.0.0)\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class E4ApplicationTemplate extends PDETemplateSection {
private static final String EMPTY_E4_MODEL_FILE = "bin" + File.separator + E4_MODEL_FILE; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.core.runtime", //$NON-NLS-1$
"org.eclipse.swt", //$NON-NLS-1$
"org.eclipse.e4.ui.model.workbench", //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
public class E4HandlerNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"1.2.0\""); //$NON-NLS-1$
"javax.annotation;version=\"[1.2.0,2.0.0)\"", //$NON-NLS-1$
"javax.inject;version=\"[1.0.0,2.0.0)\"", //$NON-NLS-1$
"org.osgi.framework;version=\"[1.10.0,2.0.0)\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class E4HandlerTemplate extends PDETemplateSection {
static final String E4_FRAGMENT_FILE = "fragment.e4xmi"; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.osgi", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.services", //$NON-NLS-1$
"org.eclipse.e4.core.di.annotations"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
public class E4ToolbarContributionNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"1.2.0\""); //$NON-NLS-1$
"javax.annotation;version=\"[1.2.0,2.0.0)\"", //$NON-NLS-1$
"javax.inject;version=\"[1.0.0,2.0.0)\"", //$NON-NLS-1$
"org.osgi.framework;version=\"[1.10.0,2.0.0)\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class E4ToolbarContributionTemplate extends PDETemplateSection {
static final String E4_FRAGMENT_FILE = "fragment.e4xmi"; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.osgi", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.services", //$NON-NLS-1$
"org.eclipse.e4.core.di.annotations"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
public class E4ViewNewWizard extends AbstractE4NewPluginTemplateWizard {

private static final List<String> PACKAGE_IMPORTS = List.of( //
"javax.annotation;version=\"1.2.0\""); //$NON-NLS-1$
"javax.annotation;version=\"[1.2.0,2.0.0)\"", //$NON-NLS-1$
"javax.inject;version=\"[1.0.0,2.0.0)\"", //$NON-NLS-1$
"org.osgi.framework;version=\"[1.10.0,2.0.0)\""); //$NON-NLS-1$

@Override
public void init(IFieldData data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class E4ViewTemplate extends PDETemplateSection {
static final String E4_FRAGMENT_FILE = "fragment.e4xmi"; //$NON-NLS-1$

private static final List<String> REQUIRED_BUNDLES = List.of(//
"javax.inject", //$NON-NLS-1$
"org.eclipse.osgi", //$NON-NLS-1$
"org.eclipse.jface", //$NON-NLS-1$
"org.eclipse.e4.ui.model.workbench", //$NON-NLS-1$
"org.eclipse.e4.ui.di", //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String getUsedExtensionPoint() {
protected void updateModel(IProgressMonitor monitor) throws CoreException {

IBundle bundle = ((IBundlePluginModelBase) model).getBundleModel().getBundle();
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject"); //$NON-NLS-1$
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject;version=\"[1.0.0,2.0.0)\""); //$NON-NLS-1$

IPluginBase plugin = model.getPluginBase();
IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String getUsedExtensionPoint() {
protected void updateModel(IProgressMonitor monitor) throws CoreException {

IBundle bundle = ((IBundlePluginModelBase) model).getBundleModel().getBundle();
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject"); //$NON-NLS-1$
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject;version=\"[1.0.0,2.0.0)\""); //$NON-NLS-1$

IPluginBase plugin = model.getPluginBase();
IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void updateModel(IProgressMonitor monitor) throws CoreException {
createProductExtension();

IBundle bundle = ((IBundlePluginModelBase) model).getBundleModel().getBundle();
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject"); //$NON-NLS-1$
bundle.setHeader(Constants.IMPORT_PACKAGE, "javax.inject;version=\"[1.0.0,2.0.0)\""); //$NON-NLS-1$
}

private void createApplicationExtension() throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<plugin id="$pluginId$"/>
<plugin id="com.sun.jna"/>
<plugin id="com.sun.jna.platform"/>
<plugin id="javax.annotation"/>
<plugin id="javax.inject"/>
<plugin id="org.apache.batik.constants"/>
<plugin id="org.apache.batik.css"/>
<plugin id="org.apache.batik.i18n"/>
Expand Down
3 changes: 2 additions & 1 deletion ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Require-Bundle: org.junit,
org.eclipse.equinox.simpleconfigurator.manipulator;bundle-version="2.1.300",
org.eclipse.platform,
org.eclipse.ui.ide.application
Import-Package: org.assertj.core.api;version="3.14.0",
Import-Package: javax.annotation;version="[1.3.0,2.0.0)",
org.assertj.core.api;version="3.14.0",
org.assertj.core.presentation;version="3.21.0",
org.eclipse.pde.internal.build,
org.junit.jupiter.api.function;version="5.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.*;
import org.junit.rules.TestRule;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

public class ClasspathResolutionTest {

Expand All @@ -43,6 +44,14 @@ public class ClasspathResolutionTest {
@Rule
public final TestRule deleteCreatedTestProjectsAfter = ProjectUtils.DELETE_CREATED_WORKSPACE_PROJECTS_AFTER;

private static String javaxAnnotationProviderBSN;

@BeforeClass
public static void getJavaxAnnotationProviderBSN() {
Bundle bundle = FrameworkUtil.getBundle(javax.annotation.PostConstruct.class);
javaxAnnotationProviderBSN = bundle.getSymbolicName();
}

@Test
public void testImportSystemPackageDoesntAddExtraBundleJava11() throws Exception {
loadTargetPlatform("org.w3c.dom.events");
Expand Down Expand Up @@ -73,30 +82,30 @@ public void testImportSystemPackageDoesntAddExtraBundleJava11() throws Exception

@Test
public void testImportExternalPreviouslySystemPackageAddsExtraBundle() throws Exception {
loadTargetPlatform("javax.annotation");
loadTargetPlatform(javaxAnnotationProviderBSN);
IProject project = ProjectUtils.importTestProject("tests/projects/demoMissedExternalPackage");
// In Java 11, javax.annotation is not present, so the bundle *must* be
// part of classpath
List<String> classpathEntries = getRequiredPluginContainerEntries(project);
assertThat(classpathEntries).anyMatch(filename -> filename.contains("javax.annotation"));
assertThat(classpathEntries).anyMatch(filename -> filename.contains(javaxAnnotationProviderBSN));
}

@Test
public void testImportExternalPreviouslySystemPackageAddsExtraBundle_missingBREE() throws Exception {
loadTargetPlatform("javax.annotation");
loadTargetPlatform(javaxAnnotationProviderBSN);
IProject project = ProjectUtils.importTestProject("tests/projects/demoMissedExternalPackageNoBREE");

IExecutionEnvironment java11 = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("JavaSE-11");
assertThat(JavaRuntime.getVMInstall(JavaCore.create(project))).isIn(Arrays.asList(java11.getCompatibleVMs()));
// In Java 11, javax.annotation is not present, so the bundle *must* be
// part of classpath, even if no BREE is specified
List<String> classpathEntries = getRequiredPluginContainerEntries(project);
assertThat(classpathEntries).anyMatch(filename -> filename.contains("javax.annotation"));
assertThat(classpathEntries).anyMatch(filename -> filename.contains(javaxAnnotationProviderBSN));
}

@Test
public void testImportSystemPackageDoesntAddExtraBundleJava8() throws Exception {
loadTargetPlatform("javax.annotation");
loadTargetPlatform(javaxAnnotationProviderBSN);
IProject project = ProjectUtils.importTestProject("tests/projects/demoMissedSystemPackageJava8");
// In Java 8, javax.annotation is present, so the bundle must *NOT* be
// part of classpath
Expand All @@ -106,7 +115,7 @@ public void testImportSystemPackageDoesntAddExtraBundleJava8() throws Exception

@Test
public void testImportSystemPackageDoesntAddExtraBundleJava8_osgiEERequirement() throws Exception {
loadTargetPlatform("javax.annotation");
loadTargetPlatform(javaxAnnotationProviderBSN);
IProject project = ProjectUtils.importTestProject("tests/projects/demoMissedSystemPackageJava8OsgiEERequirement");
// bundle is build with java 11, but declares java 8 requirement via
// Require-Capability
Expand Down

0 comments on commit 8410aad

Please sign in to comment.