Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the actual system-packages from the JVM for Product/Site export #284

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/org.eclipse.pde.build/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.25.0,4.0.0)",
org.eclipse.equinox.p2.repository.tools;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
org.eclipse.equinox.p2.director.app;bundle-version="1.0.200",
org.eclipse.equinox.p2.publisher.eclipse;bundle-version="1.0.0",
org.eclipse.jdt.core;bundle-version="[3.28.0,4.0.0)"
org.eclipse.jdt.core;bundle-version="[3.28.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.19.700,4.0.0)"
Import-Package: org.eclipse.equinox.frameworkadmin;version="[2.0.0,3.0.0)",
org.eclipse.equinox.internal.p2.core.helpers,
org.eclipse.equinox.internal.p2.engine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package org.eclipse.pde.internal.build.site;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.osgi.service.resolver.*;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
Expand All @@ -32,7 +33,7 @@
// This class provides a higher level API on the state
public class PDEState implements IPDEBuildConstants, IBuildPropertiesConstants {
private static final String[] MANIFEST_ENTRIES = {Constants.BUNDLE_LOCALIZATION, Constants.BUNDLE_NAME, Constants.BUNDLE_VENDOR, ECLIPSE_BUNDLE_SHAPE, ECLIPSE_SOURCE_BUNDLE, ECLIPSE_SOURCE_REF};
private static int LAST_SUPPORTED_JDK = Integer.valueOf(JavaCore.latestSupportedJavaVersion());
private static final int LAST_SUPPORTED_JDK = Integer.parseInt(JavaCore.latestSupportedJavaVersion());
private StateObjectFactory factory;
protected State state;
private long id;
Expand Down Expand Up @@ -438,10 +439,8 @@ public void resolveState() {
String previousEE = eeJava9;
for (String execEnvID : eeJava10AndBeyond) {
prop = new Hashtable<>();
Properties javaProfilePropertiesForVMPackage = getJavaProfilePropertiesForVMPackage(execEnvID);
if (javaProfilePropertiesForVMPackage != null) {
systemPackages = javaProfilePropertiesForVMPackage.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
}
IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(execEnvID);
systemPackages = querySystemPackages(env);
String currentEE = previousEE + "," + execEnvID; //$NON-NLS-1$
if (systemPackages == null) {
previousEE = currentEE;
Expand All @@ -462,6 +461,53 @@ public void resolveState() {
}
}

public static String querySystemPackages(IExecutionEnvironment environment) {
// Copy of org.eclipse.pde.internal.core.TargetPlatformHelper.querySystemPackages()
IVMInstall vm = bestVmInstallFor(environment);
if (vm == null || !JavaRuntime.isModularJava(vm)) {
return null;
}
String release = environment.getProfileProperties().getProperty(JavaCore.COMPILER_COMPLIANCE);
try {
Collection<String> packages = new TreeSet<>();
String jrtPath = "lib/" + org.eclipse.jdt.internal.compiler.util.JRTUtil.JRT_FS_JAR; //$NON-NLS-1$
String path = new File(vm.getInstallLocation(), jrtPath).toString(); // $NON-NLS-1$
var jrt = org.eclipse.jdt.internal.core.builder.ClasspathLocation.forJrtSystem(path, null, null, release);
for (String moduleName : jrt.getModuleNames(null)) {
var module = jrt.getModule(moduleName);
if (module == null) {
continue;
}
for (var packageExport : module.exports()) {
if (!packageExport.isQualified()) {
packages.add(new String(packageExport.name()));
}
}
}
return String.join(",", packages); //$NON-NLS-1$
} catch (CoreException e) {
Platform.getLog(PDEState.class).log(Status.error("failed to read system packages for " + environment, e)); //$NON-NLS-1$
}
return null;
}

private static IVMInstall bestVmInstallFor(IExecutionEnvironment environment) {
IVMInstall defaultVM = environment.getDefaultVM();
if (defaultVM != null) {
return defaultVM;
}
IVMInstall[] compatible = environment.getCompatibleVMs();
if (compatible.length == 0) {
return null;
}
for (IVMInstall vm : compatible) {
if (environment.isStrictlyCompatible(vm)) {
return vm;
}
}
return compatible[0];
}

public State getState() {
return state;
}
Expand Down Expand Up @@ -735,43 +781,4 @@ public ProfileManager getProfileManager() {
}
return profileManager;
}

private static Properties getJavaProfilePropertiesForVMPackage(String ee) {
Bundle apitoolsBundle = Platform.getBundle("org.eclipse.pde.api.tools"); //$NON-NLS-1$
if (apitoolsBundle == null) {
return null;
}
URL systemPackageProfile = apitoolsBundle.getEntry("system_packages" + '/' + ee.replace('/', '_') + "-systempackages.profile"); //$NON-NLS-1$ //$NON-NLS-2$
if (systemPackageProfile != null) {
return getPropertiesFromURL(systemPackageProfile);

}
return null;
}

private static Properties getPropertiesFromURL(URL profileURL) {
InputStream is = null;
try {
profileURL = FileLocator.resolve(profileURL);
URLConnection openConnection = profileURL.openConnection();
openConnection.setUseCaches(false);
is = openConnection.getInputStream();
if (is != null) {
Properties profile = new Properties();
profile.load(is);
return profile;
}
} catch (IOException e) {
// nothing to do
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// nothing to do
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,7 @@ public static String querySystemPackages(IExecutionEnvironment environment) {
if (vm == null || !JavaRuntime.isModularJava(vm)) {
return null;
}

String release = null;
Map<String, String> complianceOptions = environment.getComplianceOptions();
if (complianceOptions != null) {
release = complianceOptions.get(JavaCore.COMPILER_COMPLIANCE);
}

String release = environment.getProfileProperties().getProperty(JavaCore.COMPILER_COMPLIANCE);
try {
Collection<String> packages = new TreeSet<>();
String jrtPath = "lib/" + org.eclipse.jdt.internal.compiler.util.JRTUtil.JRT_FS_JAR; //$NON-NLS-1$
Expand All @@ -440,12 +434,10 @@ private static IVMInstall bestVmInstallFor(IExecutionEnvironment environment) {
if (defaultVM != null) {
return defaultVM;
}

IVMInstall[] compatible = environment.getCompatibleVMs();
if (compatible.length == 0) {
return null;
}

for (IVMInstall vm : compatible) {
if (environment.isStrictlyCompatible(vm)) {
return vm;
Expand Down