Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Chandra2021-05-31 09:49:21 +0000
committerAndrey Loskutov2021-06-10 16:30:36 +0000
commitfe498f234da05bcca171b34b06a61a61dfd97a0a (patch)
tree35972a6f476d90c270fba84a156d4c4a8d1b14ec
parent98d469780f13dbfdc31c1bf653cd549da8cf2dca (diff)
downloadrt.equinox.p2-fe498f234da05bcca171b34b06a61a61dfd97a0a.tar.gz
rt.equinox.p2-fe498f234da05bcca171b34b06a61a61dfd97a0a.tar.xz
rt.equinox.p2-fe498f234da05bcca171b34b06a61a61dfd97a0a.zip
Bug 572099 - testBug242346 fail since I20210316-1800
- Switched default profile used by JREAction to Java 11. - If no JRE profile given, JREAction generates a temporary profile based on default profile version and containing packages observed by the currently running JVM. - Updated JREActionTest to Java 11 expectations: 228 system packages and 23 capabilities Change-Id: Iaa8cbd62b8d70576ee55ade49e9a416799dfed5d Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com> Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/181182 Tested-by: Equinox Bot <equinox-bot@eclipse.org> Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java141
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java7
3 files changed, 144 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
index 55bf28314..714b41c86 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/actions/JREAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2018 Code 9 and others.
+ * Copyright (c) 2008, 2021 Code 9 and others.
*
* This
* program and the accompanying materials are made available under the terms of
@@ -17,7 +17,10 @@
package org.eclipse.equinox.p2.publisher.actions;
import java.io.*;
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleDescriptor.Exports;
import java.net.URL;
+import java.nio.file.Files;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
@@ -38,8 +41,8 @@ import org.osgi.framework.*;
public class JREAction extends AbstractPublisherAction {
private static final String DEFAULT_JRE_NAME = "a.jre"; //$NON-NLS-1$
- private static final Version DEFAULT_JRE_VERSION = Version.parseVersion("9.0"); //$NON-NLS-1$
- private static final String DEFAULT_PROFILE = "JavaSE-9"; //$NON-NLS-1$
+ private static final Version DEFAULT_JRE_VERSION = Version.parseVersion("11.0"); //$NON-NLS-1$
+ private static final String DEFAULT_PROFILE = "JavaSE-11"; //$NON-NLS-1$
private static final String PROFILE_LOCATION = "jre.action.profile.location"; //$NON-NLS-1$
private static final String PROFILE_NAME = "osgi.java.profile.name"; //$NON-NLS-1$
private static final String PROFILE_TARGET_VERSION = "org.eclipse.jdt.core.compiler.codegen.targetPlatform"; //$NON-NLS-1$
@@ -297,8 +300,22 @@ public class JREAction extends AbstractPublisherAction {
}
private void initialize(IPublisherInfo publisherInfo) {
+ File runtimeProfile = null;
this.info = publisherInfo;
-
+ if (jreLocation == null && environment == null) {
+ // create a runtime profile
+ StringBuilder buffer = createDefaultProfileFromRunningJvm();
+ try {
+ File tempDirectory = Files.createTempDirectory("JREAction").toFile(); //$NON-NLS-1$
+ runtimeProfile = new File(tempDirectory, DEFAULT_PROFILE + ".profile"); //$NON-NLS-1$
+ try (FileWriter writer = new FileWriter(runtimeProfile)) {
+ writer.write(buffer.toString());
+ }
+ jreLocation = runtimeProfile;
+ } catch (IOException e) {
+ // ignore
+ }
+ }
if (jreLocation != null) {
File javaProfile = null;
@@ -322,6 +339,122 @@ public class JREAction extends AbstractPublisherAction {
URL profileURL = getResouceFromSystemBundle(profileFile);
profileProperties = loadProfile(profileURL);
}
+ if (runtimeProfile != null) {
+ runtimeProfile.delete();
+ runtimeProfile.getParentFile().delete();
+ }
+ }
+
+ /*
+ * Copied from org.eclipse.osgi.storage.Storage.calculateVMPackages and adopted
+ * to Java 11
+ */
+ private String calculateVMPackages() {
+ try {
+ List<String> packages = new ArrayList<>();
+ ModuleLayer bootLayer = ModuleLayer.boot();
+ Set<Module> bootModules = bootLayer.modules();
+ for (Module m : bootModules) {
+ ModuleDescriptor descriptor = m.getDescriptor();
+ if (descriptor.isAutomatic()) {
+ /*
+ * Automatic modules are supposed to export all their packages. However,
+ * java.lang.module.ModuleDescriptor::exports returns an empty set for them. Add
+ * all their packages (as returned by
+ * java.lang.module.ModuleDescriptor::packages) to the list of VM supplied
+ * packages.
+ */
+ packages.addAll(descriptor.packages());
+ } else {
+ for (Exports export : descriptor.exports()) {
+ String pkg = export.source();
+ if (!export.isQualified()) {
+ packages.add(pkg);
+ }
+ }
+ }
+ }
+ Collections.sort(packages);
+ StringBuilder result = new StringBuilder();
+ for (String pkg : packages) {
+ if (result.length() != 0) {
+ result.append(',').append(' ');
+ }
+ result.append(pkg);
+ }
+ return result.toString();
+ } catch (Exception e) {
+
+ return null;
+ }
+ }
+
+ /**
+ * Creates default profile with minumum version as stated by
+ * {@link #DEFAULT_PROFILE} and adds packages observed on currently used JVM.
+ *
+ * @return generated profile content
+ */
+ @SuppressWarnings("nls")
+ private StringBuilder createDefaultProfileFromRunningJvm() {
+ StringBuilder buffer = new StringBuilder();
+ final String NEWLINE = System.lineSeparator();
+ // add systempackages
+ buffer.append("org.osgi.framework.system.packages = \\");
+ buffer.append(NEWLINE);
+ buffer.append(' ');
+ String calculateVMPackages = calculateVMPackages();
+ if (calculateVMPackages != null) {
+ String[] pack;
+ pack = calculateVMPackages.split(",");
+ for (int i = 0; i < pack.length; i++) {
+ buffer.append(pack[i]);
+ if (i != pack.length - 1) {
+ buffer.append(',');
+ buffer.append("\\");
+ }
+ buffer.append(NEWLINE);
+ }
+ }
+ // add EE
+ buffer.append("org.osgi.framework.executionenvironment = \\\n" + " OSGi/Minimum-1.0,\\\n"
+ + " OSGi/Minimum-1.1,\\\n" + " OSGi/Minimum-1.2,\\\n" + " JavaSE/compact1-1.8,\\\n"
+ + " JavaSE/compact2-1.8,\\\n" + " JavaSE/compact3-1.8,\\\n" + " JRE-1.1,\\\n" + " J2SE-1.2,\\\n"
+ + " J2SE-1.3,\\\n" + " J2SE-1.4,\\\n" + " J2SE-1.5,\\\n" + " JavaSE-1.6,\\\n" + " JavaSE-1.7,\\\n"
+ + " JavaSE-1.8,\\\n");
+ String version = DEFAULT_PROFILE.substring(DEFAULT_PROFILE.indexOf('-') + 1);
+ int ver = Integer.parseInt(version);
+ for (int i = 9; i < ver; i++) {
+ buffer.append(" JavaSE-" + String.valueOf(i) + ",\\\n");
+ }
+ buffer.append(" JavaSE-" + String.valueOf(ver));
+ buffer.append(NEWLINE);
+
+ // add capabilities
+ StringBuilder versionList = new StringBuilder();
+ versionList.append("1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8");
+ for (int i = 9; i <= ver; i++) {
+ versionList.append(", " + String.valueOf(i) + ".0");
+ }
+ buffer.append("org.osgi.framework.system.capabilities = \\\n"
+ + " osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0, 1.1, 1.2\",\\\n"
+ + " osgi.ee; osgi.ee=\"JRE\"; version:List<Version>=\"1.0, 1.1\",\\\n"
+ + " osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"" + versionList.toString() + "\",\\\n"
+ + " osgi.ee; osgi.ee=\"JavaSE/compact1\"; version:List<Version>=\"1.8," + String.valueOf(ver)
+ + ".0\",\\\n" + " osgi.ee; osgi.ee=\"JavaSE/compact2\"; version:List<Version>=\"1.8,"
+ + String.valueOf(ver) + ".0\",\\\n"
+ + " osgi.ee; osgi.ee=\"JavaSE/compact3\"; version:List<Version>=\"1.8," + String.valueOf(ver) + ".0\"");
+ buffer.append(NEWLINE);
+
+ // add profile name and compiler options
+ buffer.append("osgi.java.profile.name = " + DEFAULT_PROFILE + "\n" + "org.eclipse.jdt.core.compiler.compliance="
+ + String.valueOf(ver) + "\n" + "org.eclipse.jdt.core.compiler.source=" + String.valueOf(ver) + "\n"
+ + "org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\n"
+ + "org.eclipse.jdt.core.compiler.codegen.targetPlatform=" + String.valueOf(ver) + "\n"
+ + "org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\n"
+ + "org.eclipse.jdt.core.compiler.problem.enumIdentifier=error");
+ buffer.append(NEWLINE);
+ return buffer;
}
private static URL getResouceFromSystemBundle(String entry) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
index 9d02fddf8..9d7df8723 100644
--- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
@@ -54,7 +54,8 @@ Require-Bundle: org.eclipse.equinox.frameworkadmin,
org.eclipse.equinox.p2.publisher.eclipse;bundle-version="1.0.0",
org.eclipse.equinox.p2.operations;bundle-version="2.1.0",
org.eclipse.equinox.p2.ui.sdk.scheduler,
- org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.3.0,2.0.0)"
+ org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.3.0,2.0.0)",
+ org.hamcrest.library;bundle-version="1.3.0"
Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository
Bundle-RequiredExecutionEnvironment: JavaSE-11
Eclipse-BundleShape: dir
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
index 088b3bd9c..0382ee4f2 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/JREActionTest.java
@@ -20,11 +20,13 @@ import static org.easymock.EasyMock.expect;
import static org.eclipse.equinox.p2.tests.publisher.actions.StatusMatchers.errorStatus;
import static org.eclipse.equinox.p2.tests.publisher.actions.StatusMatchers.okStatus;
import static org.eclipse.equinox.p2.tests.publisher.actions.StatusMatchers.statusWithMessageWhich;
+import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -134,7 +136,7 @@ public class JREActionTest extends ActionTest {
performAction(new JREAction((String) null));
// these assertions need to be changed each time the default java profile, hardcoded in o.e.e.p2.publisher.actions.JREAction, is changed;
- verifyMetadataIU("a.jre.javase", 226, 21, Version.parseVersion("9.0.0"));
+ verifyMetadataIU("a.jre.javase", 228, 23, Version.parseVersion("11.0.0"));
// verifyConfigIU(DEFAULT_JRE_NAME, DEFAULT_JRE_VERSION); // TODO config IU is not needed!?
}
@@ -204,7 +206,8 @@ public class JREActionTest extends ActionTest {
// check provided capabilities
Collection<IProvidedCapability> fooProvidedCapabilities = foo.getProvidedCapabilities();
- assertThat(fooProvidedCapabilities.size(), is(1 + expectedProvidedPackages + expectedProvidedEEs));
+ int expected = expectedProvidedPackages + expectedProvidedEEs;
+ assertThat(fooProvidedCapabilities.size(), anyOf(is(expected), greaterThan(expected)));
}
private void verifyConfigIU(String id, Version jreVersion) {

Back to the top