/** * Removes path information from the given string containing one or more comma separated osgi * bundles. Replaces escaped '\:' with ':'. Removes, reference, platform and file prefixes. * Removes any other path information converting the location or the last segment to a bundle id. * * @param osgiBundles list of bundles to strip path information from (commma separated) * @return list of bundles with path information stripped */ public static String stripPathInformation(String osgiBundles) { StringBuffer result = new StringBuffer(); StringTokenizer tokenizer = new StringTokenizer(osgiBundles, ","); // $NON-NLS-1$ while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); token = token.replaceAll("\\\\:|/:", ":"); // $NON-NLS-1$ //$NON-NLS-2$ // read up until the first @, if there int atIndex = token.indexOf('@'); String bundle = atIndex > 0 ? token.substring(0, atIndex) : token; bundle = bundle.trim(); // strip [reference:][platform:][file:] prefixes if any if (bundle.startsWith(REFERENCE_PREFIX) && bundle.length() > REFERENCE_PREFIX.length()) bundle = bundle.substring(REFERENCE_PREFIX.length()); if (bundle.startsWith(PLATFORM_PREFIX) && bundle.length() > PLATFORM_PREFIX.length()) bundle = bundle.substring(PLATFORM_PREFIX.length()); if (bundle.startsWith(FILE_URL_PREFIX) && bundle.length() > FILE_URL_PREFIX.length()) bundle = bundle.substring(FILE_URL_PREFIX.length()); // if the path is relative, the last segment is the bundle symbolic name // Otherwise, we need to retrieve the bundle symbolic name ourselves IPath path = new Path(bundle); String id = null; if (path.isAbsolute()) { id = getSymbolicName(bundle); } if (id == null) { id = path.lastSegment(); } if (id != null) { int underscoreIndex = id.indexOf('_'); if (underscoreIndex >= 0) { id = id.substring(0, underscoreIndex); } if (id.endsWith(JAR_EXTENSION)) { id = id.substring(0, id.length() - 4); } } if (result.length() > 0) result.append(","); // $NON-NLS-1$ result.append(id != null ? id : bundle); if (atIndex > -1) result.append(token.substring(atIndex).trim()); } return result.toString(); }
/** Create the default set of framework (launch) properties. */ protected void initProperties(FrameworkContext fwCtx) { setPropertyIfNotSet(Constants.FRAMEWORK_BOOTDELEGATION, ""); setPropertyIfNotSet(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_BOOT); setPropertyIfNotSet(Constants.FRAMEWORK_EXECPERMISSION, ""); if (!props.containsKey(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)) { StringBuffer ee = new StringBuffer(); // Always allow ee minimum ee.append("OSGi/Minimum-1.0"); ee.append(",OSGi/Minimum-1.1"); ee.append(",OSGi/Minimum-1.2"); // Set up the default ExecutionEnvironment if (1 == javaVersionMajor) { for (int i = javaVersionMinor; i > 1; i--) { ee.append((i > 5) ? ",JavaSE-1." : ",J2SE-1."); ee.append(i); } } props.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, ee.toString()); } setPropertyIfNotSet(Constants.FRAMEWORK_LANGUAGE, Locale.getDefault().getLanguage()); setPropertyIfNotSet(Constants.FRAMEWORK_LIBRARY_EXTENSIONS, ""); setPropertyIfNotSet( Constants.FRAMEWORK_OS_NAME, Alias.unifyOsName(System.getProperty("os.name"))); if (!props.containsKey(Constants.FRAMEWORK_OS_VERSION)) { String ver = System.getProperty("os.version"); int maj = 0; int min = 0; int mic = 0; String qual = null; if (ver != null) { // Convert os.version to a reasonable default try { StringTokenizer st = new StringTokenizer(ver.trim(), "."); maj = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) { qual = st.nextToken(); min = Integer.parseInt(qual); qual = null; if (st.hasMoreTokens()) { qual = st.nextToken(); mic = Integer.parseInt(qual); qual = null; if (st.hasMoreTokens()) { qual = st.nextToken(); } } } } catch (Exception ignore) { } } Version osVersion; try { osVersion = new Version(maj, min, mic, qual); } catch (IllegalArgumentException skip) { osVersion = new Version(maj, min, mic, null); } props.put(Constants.FRAMEWORK_OS_VERSION, osVersion.toString()); } setPropertyIfNotSet( Constants.FRAMEWORK_PROCESSOR, Alias.unifyProcessor(System.getProperty("os.arch"))); setPropertyIfNotSet(Constants.FRAMEWORK_SECURITY, ""); setPropertyIfNotSet(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "1"); setPropertyIfNotSet(Constants.FRAMEWORK_STORAGE, "fwdir"); setPropertyIfNotSet(Constants.FRAMEWORK_STORAGE_CLEAN, ""); // NYI, fill this with values setPropertyIfNotSet(Constants.FRAMEWORK_SYSTEMPACKAGES, ""); setPropertyIfNotSet(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, ""); setPropertyIfNotSet(Constants.FRAMEWORK_TRUST_REPOSITORIES, ""); // NYI setPropertyIfNotSet(Constants.FRAMEWORK_WINDOWSYSTEM, ""); // Impl. constants props.put(Constants.FRAMEWORK_VERSION, FrameworkContext.SPEC_VERSION); props.put(Constants.FRAMEWORK_VENDOR, "Knopflerfish"); props.put(Constants.SUPPORTS_FRAMEWORK_REQUIREBUNDLE, TRUE); props.put(Constants.SUPPORTS_FRAMEWORK_FRAGMENT, TRUE); // Only first framework support framework extension // NYI! Improve this in the future props.put( Constants.SUPPORTS_FRAMEWORK_EXTENSION, getClass().getClassLoader() instanceof URLClassLoader && fwCtx.id == 0 ? TRUE : FALSE); // Only first framework can support bootclasspath extension // NYI! Improve this in the future setPropertyIfNotSet(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION, FALSE); if (getBooleanProperty(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION) && !(getClass().getClassLoader() instanceof URLClassLoader && fwCtx.id == 1)) { props.put(Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION, FALSE); } }