Search in sources :

Example 41 with Location

use of org.eclipse.osgi.service.datalocation.Location in project rt.equinox.framework by eclipse.

the class EclipseStarter method getInitialBundles.

private static InitialBundle[] getInitialBundles(String[] installEntries) {
    searchCandidates.clear();
    List<InitialBundle> result = new ArrayList<>(installEntries.length);
    int defaultStartLevel = Integer.parseInt(getProperty(PROP_BUNDLES_STARTLEVEL, DEFAULT_BUNDLES_STARTLEVEL));
    String syspath = getSysPath();
    // should canonicalize the syspath.
    try {
        syspath = new File(syspath).getCanonicalPath();
    } catch (IOException ioe) {
    // do nothing
    }
    Collection<ServiceReference<Location>> installLocRef;
    try {
        installLocRef = context.getServiceReferences(Location.class, Location.INSTALL_FILTER);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    Location installLocation = installLocRef == null ? null : context.getService(installLocRef.iterator().next());
    if (installLocation == null) {
        throw new IllegalStateException(Msg.EclipseStarter_InstallLocation);
    }
    for (int i = 0; i < installEntries.length; i++) {
        String name = installEntries[i];
        int level = defaultStartLevel;
        boolean start = false;
        int index = name.lastIndexOf('@');
        if (index >= 0) {
            // $NON-NLS-1$
            String[] attributes = getArrayFromList(name.substring(index + 1, name.length()), ":");
            for (int j = 0; j < attributes.length; j++) {
                String attribute = attributes[j];
                if (// $NON-NLS-1$
                attribute.equals("start"))
                    start = true;
                else {
                    try {
                        level = Integer.parseInt(attribute);
                    } catch (NumberFormatException e) {
                        // bug 188089
                        index = name.length();
                        continue;
                    }
                }
            }
            name = name.substring(0, index);
        }
        try {
            URL location = searchForBundle(name, syspath);
            if (location == null) {
                FrameworkLogEntry entry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, NLS.bind(Msg.ECLIPSE_STARTUP_BUNDLE_NOT_FOUND, installEntries[i]), 0, null, null);
                log.log(entry);
                // skip this entry
                continue;
            }
            location = makeRelative(installLocation.getURL(), location);
            String locationString = INITIAL_LOCATION + location.toExternalForm();
            result.add(new InitialBundle(locationString, location, level, start));
        } catch (IOException e) {
            log.log(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null));
        }
    }
    return result.toArray(new InitialBundle[result.size()]);
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) Location(org.eclipse.osgi.service.datalocation.Location)

Example 42 with Location

use of org.eclipse.osgi.service.datalocation.Location in project rt.equinox.framework by eclipse.

the class SystemBundleActivator method registerLocations.

private void registerLocations(BundleContext bc, EquinoxLocations equinoxLocations) {
    Dictionary<String, Object> locationProperties = new Hashtable<>(1);
    Location location = equinoxLocations.getUserLocation();
    if (location != null) {
        // $NON-NLS-1$
        locationProperties.put("type", EquinoxLocations.PROP_USER_AREA);
        register(bc, Location.class, location, locationProperties);
    }
    location = equinoxLocations.getInstanceLocation();
    if (location != null) {
        // $NON-NLS-1$
        locationProperties.put("type", EquinoxLocations.PROP_INSTANCE_AREA);
        register(bc, Location.class, location, locationProperties);
    }
    location = equinoxLocations.getConfigurationLocation();
    if (location != null) {
        // $NON-NLS-1$
        locationProperties.put("type", EquinoxLocations.PROP_CONFIG_AREA);
        register(bc, Location.class, location, locationProperties);
    }
    location = equinoxLocations.getInstallLocation();
    if (location != null) {
        // $NON-NLS-1$
        locationProperties.put("type", EquinoxLocations.PROP_INSTALL_AREA);
        register(bc, Location.class, location, locationProperties);
    }
    location = equinoxLocations.getEclipseHomeLocation();
    if (location != null) {
        // $NON-NLS-1$
        locationProperties.put("type", EquinoxLocations.PROP_HOME_LOCATION_AREA);
        register(bc, Location.class, location, locationProperties);
    }
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

Location (org.eclipse.osgi.service.datalocation.Location)42 File (java.io.File)14 URL (java.net.URL)13 IOException (java.io.IOException)12 Equinox (org.eclipse.osgi.launch.Equinox)10 MalformedURLException (java.net.MalformedURLException)9 FileNotFoundException (java.io.FileNotFoundException)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 ServiceReference (org.osgi.framework.ServiceReference)4 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 BundleException (org.osgi.framework.BundleException)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2