diff options
author | Hannes Wellmann | 2021-11-27 13:40:24 +0000 |
---|---|---|
committer | Hannes Wellmann | 2021-12-07 22:45:58 +0000 |
commit | 0e25c9c81ddbda7f332080076b8f28629480b02d (patch) | |
tree | 972c5a99d16226b3e9bfe19a718d3db5793fd5d9 | |
parent | 68fa0c03747cf77307616b0fc644757a81e39578 (diff) | |
download | rt.equinox.framework-Y20220106-0600.tar.gz rt.equinox.framework-Y20220106-0600.tar.xz rt.equinox.framework-Y20220106-0600.zip |
Bug 577497 - Support version-specific entries in dev-classPath fileY20220110-0600Y20220109-0600Y20220108-0600Y20220107-0600Y20220106-0600Y20220105-0600Y20220104-0600Y20220103-0600Y20220102-0600Y20220101-0600Y20211231-0600Y20211230-0600Y20211229-0600Y20211228-0600Y20211227-0600Y20211224-0600Y20211223-0600Y20211222-1030Y20211222-0840Y20211222-0830Y20211222-0600Y20211221-0600Y20211220-0600Y20211219-0600Y20211218-0600Y20211217-0600Y20211216-0600Y20211215-1140Y20211215-0600Y20211214-0600Y20211213-0600Y20211212-0600Y20211211-0600Y20211210-0600Y20211210-0210S4_23_0_M1I20220110-0550I20220110-0310I20220109-1800I20220108-1800I20220107-1800I20220106-0000I20220105-1800I20220105-0600I20220104-1800I20220104-0940I20220104-0600I20220103-1800I20220103-0600I20220102-1800I20220102-0600I20220101-1800I20220101-1140I20220101-0600I20211231-1800I20211230-1800I20211229-1800I20211228-1800I20211227-1800I20211226-1800I20211225-1800I20211224-1800I20211223-1800I20211222-1800I20211221-1800I20211221-0620I20211220-1820I20211219-1800I20211218-1800I20211218-0200I20211218-0140I20211217-1800I20211216-1800I20211215-1800I20211214-1800I20211213-1800I20211213-0440I20211212-1800I20211211-1800I20211210-1800I20211210-1050I20211210-0600I20211209-1800I20211208-1800I20211207-1800
Change-Id: Ic1ce5b73b0e044315a15f300c50db90842413787
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/188210
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
3 files changed, 27 insertions, 50 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index 9f181d11b..00a8670d7 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2020 IBM Corporation and others. + * Copyright (c) 2003, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hannes Wellmann - Bug 577497 - Support version-specific entries in dev-classPath file *******************************************************************************/ package org.eclipse.osgi.internal.framework; @@ -40,7 +41,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; import java.util.LinkedHashMap; @@ -68,6 +68,7 @@ import org.eclipse.osgi.service.environment.EnvironmentInfo; import org.eclipse.osgi.util.ManifestElement; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Version; +import org.osgi.framework.wiring.BundleRevision; /** * Internal class. @@ -96,6 +97,8 @@ public class EquinoxConfiguration implements EnvironmentInfo { public static final String VARIABLE_DELIM_STRING = "$"; //$NON-NLS-1$ public static final char VARIABLE_DELIM_CHAR = '$'; + private static final String DEV_FILE_ENTRY_VERSION_SEPARATOR = ";"; //$NON-NLS-1$ + private final ConfigValues configValues; private final Debug debug; @@ -113,7 +116,7 @@ public class EquinoxConfiguration implements EnvironmentInfo { private final File devLocation; private final Object devMonitor = new Object(); private String[] devDefaultClasspath; - private Dictionary<String, String> devProperties = null; + private Map<String, String> devProperties = null; // timestamp for the dev.properties file private long devLastModified = 0; @@ -882,25 +885,21 @@ public class EquinoxConfiguration implements EnvironmentInfo { * Updates the dev classpath if the file containing the entries have changed */ private void updateDevProperties() { - if (devLocation == null) - return; - synchronized (devMonitor) { - if (devLocation.lastModified() == devLastModified) - return; - + if (devLocation != null && devLocation.lastModified() != devLastModified) { try { loadDevProperties(new FileInputStream(devLocation)); - } catch (FileNotFoundException e) { - return; + devLastModified = devLocation.lastModified(); + } catch (FileNotFoundException e) { // ignore and try again next time } - devLastModified = devLocation.lastModified(); } } - private static String[] getDevClassPath(String id, Dictionary<String, String> properties, String[] defaultClasspath) { + private static String[] getDevClassPath(BundleRevision bundle, Map<String, String> properties, String[] defaultClasspath) { String[] result = null; + String id = bundle.getSymbolicName(); if (id != null && properties != null) { - String entry = properties.get(id); + String idVersion = id + DEV_FILE_ENTRY_VERSION_SEPARATOR + bundle.getVersion(); + String entry = properties.getOrDefault(idVersion, properties.get(id)); // prefer idVersion value if (entry != null) result = getArrayFromList(entry); } @@ -911,28 +910,14 @@ public class EquinoxConfiguration implements EnvironmentInfo { /** * Returns a list of classpath elements for the specified bundle symbolic name. - * @param id a bundle symbolic name to get the development classpath for - * @param properties a Dictionary of properties to use or <code>null</code> if - * the default develoment classpath properties should be used + * @param bundle a bundle revision to get the development classpath for * @return a list of development classpath elements */ - public String[] getDevClassPath(String id, Dictionary<String, String> properties) { - if (properties == null) { - synchronized (devMonitor) { - updateDevProperties(); - return getDevClassPath(id, devProperties, devDefaultClasspath); - } + public String[] getDevClassPath(BundleRevision bundle) { + synchronized (devMonitor) { + updateDevProperties(); + return getDevClassPath(bundle, devProperties, devDefaultClasspath); } - return getDevClassPath(id, properties, getArrayFromList(properties.get("*"))); //$NON-NLS-1$ - } - - /** - * Returns a list of classpath elements for the specified bundle symbolic name. - * @param id a bundle symbolic name to get the development classpath for - * @return a list of development classpath elements - */ - public String[] getDevClassPath(String id) { - return getDevClassPath(id, null); } private static String[] getArrayFromList(String prop) { @@ -944,24 +929,16 @@ public class EquinoxConfiguration implements EnvironmentInfo { */ private void loadDevProperties(InputStream input) { Properties props = new Properties(); - try { - props.load(input); + try (InputStream inputStream = input) { + props.load(inputStream); } catch (IOException e) { exceptions.put(e, FrameworkLogEntry.ERROR); - } finally { - if (input != null) - try { - input.close(); - } catch (IOException e) { - // tried our best - } } - @SuppressWarnings({"unchecked", "rawtypes"}) - Dictionary<String, String> result = (Dictionary) props; + @SuppressWarnings({ "unchecked", "rawtypes" }) + Map<String, String> result = (Map) props; synchronized (devMonitor) { devProperties = result; - if (devProperties != null) - devDefaultClasspath = getArrayFromList(devProperties.get("*")); //$NON-NLS-1$ + devDefaultClasspath = getArrayFromList(devProperties.get("*")); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hooks/DevClassLoadingHook.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hooks/DevClassLoadingHook.java index ca9a3e64b..c707e4c76 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hooks/DevClassLoadingHook.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hooks/DevClassLoadingHook.java @@ -49,11 +49,11 @@ public class DevClassLoadingHook extends ClassLoaderHook implements KeyedElement return false; } // first check that we are in devmode for this sourcedata - String[] devClassPaths = !configuration.inDevelopmentMode() ? null : configuration.getDevClassPath(sourceGeneration.getRevision().getSymbolicName()); + String[] devClassPaths = !configuration.inDevelopmentMode() ? null : configuration.getDevClassPath(sourceGeneration.getRevision()); if (devClassPaths == null || devClassPaths.length == 0) return false; // not in dev mode return // check that dev classpath entries have not already been added; we mark this in the first entry below - if (cpEntries.size() > 0 && cpEntries.get(0).getUserObject(KEY) != null) + if (!cpEntries.isEmpty() && cpEntries.get(0).getUserObject(KEY) != null) return false; // this source has already had its dev classpath entries added. // get the specified classpath from the Bundle-ClassPath header to check for dups @@ -105,7 +105,7 @@ public class DevClassLoadingHook extends ClassLoaderHook implements KeyedElement } // mark the first entry of the list. // This way we can quickly tell that dev classpath entries have been added to the list - if (result && cpEntries.size() > 0) + if (result && !cpEntries.isEmpty()) cpEntries.get(0).addUserObject(this); return result; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java index 52a4854eb..34e7e1c9f 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java @@ -194,7 +194,7 @@ public class FrameworkExtensionInstaller { if (configuration.inDevelopmentMode()) { // must create a copy because paths could be unmodifiable paths = new ArrayList<>(paths); - String[] devPaths = configuration.getDevClassPath(revision.getSymbolicName()); + String[] devPaths = configuration.getDevClassPath(revision); Collections.addAll(paths, devPaths); } List<File> results = new ArrayList<>(paths.size()); |