Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 562131
Collapse All | Expand All

(-)a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiBaseline.java (+65 lines)
Lines 17-22 Link Here
17
import java.io.File;
17
import java.io.File;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.io.InputStream;
19
import java.io.InputStream;
20
import java.lang.reflect.Method;
20
import java.net.URL;
21
import java.net.URL;
21
import java.net.URLConnection;
22
import java.net.URLConnection;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
Lines 79-84 Link Here
79
 */
80
 */
80
public class ApiBaseline extends ApiElement implements IApiBaseline, IVMInstallChangedListener {
81
public class ApiBaseline extends ApiElement implements IApiBaseline, IVMInstallChangedListener {
81
82
83
	private String fVMPackages = null;
82
	/**
84
	/**
83
	 * Empty array of component
85
	 * Empty array of component
84
	 */
86
	 */
Lines 293-298 Link Here
293
	}
295
	}
294
296
295
297
298
	@SuppressWarnings("unused")
299
	private String getVMPackages() {
300
		if (fVMPackages == null) {
301
			fVMPackages = calculateVMPackages();
302
		}
303
		return fVMPackages;
304
305
	}
306
307
	/*
308
	 * Copied from org.eclipse.osgi.storage.Storage.calculateVMPackages
309
	 */
310
311
	private String calculateVMPackages() {
312
		try {
313
			List<String> packages = new ArrayList<>();
314
			Class<?> moduleLayerClass = Class.forName("java.lang.ModuleLayer"); //$NON-NLS-1$
315
			Method boot = moduleLayerClass.getMethod("boot"); //$NON-NLS-1$
316
			Method modules = moduleLayerClass.getMethod("modules"); //$NON-NLS-1$
317
			Class<?> moduleClass = Class.forName("java.lang.Module"); //$NON-NLS-1$
318
			Method getDescriptor = moduleClass.getMethod("getDescriptor"); //$NON-NLS-1$
319
			Class<?> moduleDescriptorClass = Class.forName("java.lang.module.ModuleDescriptor"); //$NON-NLS-1$
320
			Method exports = moduleDescriptorClass.getMethod("exports"); //$NON-NLS-1$
321
			Class<?> exportsClass = Class.forName("java.lang.module.ModuleDescriptor$Exports"); //$NON-NLS-1$
322
			Method targets = exportsClass.getMethod("targets"); //$NON-NLS-1$
323
			Method source = exportsClass.getMethod("source"); //$NON-NLS-1$
324
325
			Object bootLayer = boot.invoke(null);
326
			Set<?> bootModules = (Set<?>) modules.invoke(bootLayer);
327
			for (Object m : bootModules) {
328
				Object descriptor = getDescriptor.invoke(m);
329
				for (Object export : (Set<?>) exports.invoke(descriptor)) {
330
					String pkg = (String) source.invoke(export);
331
					if (((Set<?>) targets.invoke(export)).isEmpty() && !pkg.startsWith("java.")) { //$NON-NLS-1$
332
						packages.add(pkg);
333
					}
334
				}
335
			}
336
			Collections.sort(packages);
337
			StringBuilder result = new StringBuilder();
338
			for (String pkg : packages) {
339
				if (result.length() != 0) {
340
					result.append(',').append(' ');
341
				}
342
				result.append(pkg);
343
			}
344
			return result.toString();
345
		} catch (Exception e) {
346
			// equinoxContainer.getLogServices().log(EquinoxContainer.NAME,
347
			// FrameworkLogEntry.ERROR, "Error determining system packages.",
348
			// e); //$NON-NLS-1$
349
			return null;
350
		}
351
	}
352
296
	/**
353
	/**
297
	 * Initializes this baseline from the given properties.
354
	 * Initializes this baseline from the given properties.
298
	 *
355
	 *
Lines 303-308 Link Here
303
	private void initialize(Properties profile, ExecutionEnvironmentDescription description) throws CoreException {
360
	private void initialize(Properties profile, ExecutionEnvironmentDescription description) throws CoreException {
304
		String value = profile.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
361
		String value = profile.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
305
		if (value == null) {
362
		if (value == null) {
363
364
			if (value == null) {
365
				// Java 10 onwards calculate this on runtime.
366
				// value = getVMPackages();
367
			}
306
			// In Java-10 and beyond, we take systempackages list from
368
			// In Java-10 and beyond, we take systempackages list from
307
			// org.eclipse.pde.api.tools\system_packages\JavaSE-x-systempackages.profile
369
			// org.eclipse.pde.api.tools\system_packages\JavaSE-x-systempackages.profile
308
			// They are calculated by launching eclipse in Java x and then using
370
			// They are calculated by launching eclipse in Java x and then using
Lines 317-322 Link Here
317
		if (value != null) {
379
		if (value != null) {
318
			systemPackages = value.split(","); //$NON-NLS-1$
380
			systemPackages = value.split(","); //$NON-NLS-1$
319
		}
381
		}
382
		for (String string : systemPackages) {
383
			System.out.println(string + " "); //$NON-NLS-1$
384
		}
320
		if (!(this instanceof WorkspaceBaseline)) {
385
		if (!(this instanceof WorkspaceBaseline)) {
321
			Dictionary<String, Object> dictionary = new Hashtable<>();
386
			Dictionary<String, Object> dictionary = new Hashtable<>();
322
			dictionary.put(Constants.FRAMEWORK_SYSTEMPACKAGES, value);
387
			dictionary.put(Constants.FRAMEWORK_SYSTEMPACKAGES, value);

Return to bug 562131