Search in sources :

Example 26 with Location

use of org.eclipse.osgi.service.datalocation.Location in project MonjaDB by Kanatoko.

the class Activator method loadConfig.

//--------------------------------------------------------------------------------
public void loadConfig() throws IOException {
    Location location = Platform.getConfigurationLocation();
    if (location != null) {
        URL configURL = location.getURL();
        if (configURL != null && configURL.getProtocol().startsWith("file")) {
            File platformDir = new File(configURL.getFile(), Activator.PLUGIN_ID);
            MSystemUtil.createDir(platformDir.getAbsolutePath());
            String configFileName = platformDir.getAbsolutePath() + "/" + DEFAULT_CONFIG_FILE_NAME;
            loadConfig(configFileName);
        }
    } else {
        loadConfig("_dummy_not_exist_");
    }
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Example 27 with Location

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

the class SystemBundleTests method testSystemBundle07.

public void testSystemBundle07() {
    // test init twice
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle07_01");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    try {
        equinox.init();
    } catch (Exception e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    try {
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("SystemBundle context is null", systemContext);
    try {
        equinox.init();
    } catch (Exception e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    ServiceReference[] refs = null;
    try {
        // $NON-NLS-1$
        refs = systemContext.getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
    } catch (InvalidSyntaxException e) {
        // $NON-NLS-1$
        fail("Unexpected syntax error", e);
    }
    // $NON-NLS-1$
    assertNotNull("Configuration Location refs is null", refs);
    // $NON-NLS-1$
    assertEquals("config refs length is wrong", 1, refs.length);
    Location configLocation = (Location) systemContext.getService(refs[0]);
    URL configURL = configLocation.getURL();
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle07_01/"));
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) Equinox(org.eclipse.osgi.launch.Equinox) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Location(org.eclipse.osgi.service.datalocation.Location)

Example 28 with Location

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

the class SystemBundleTests method testSystemBundle01.

public void testSystemBundle01() {
    // simple test to create an embedded framework
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle01");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("SystemBundle context is null", systemContext);
    ServiceReference[] refs = null;
    try {
        // $NON-NLS-1$
        refs = systemContext.getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
    } catch (InvalidSyntaxException e) {
        // $NON-NLS-1$
        fail("Unexpected syntax error", e);
    }
    // $NON-NLS-1$
    assertNotNull("Configuration Location refs is null", refs);
    // $NON-NLS-1$
    assertEquals("config refs length is wrong", 1, refs.length);
    Location configLocation = (Location) systemContext.getService(refs[0]);
    URL configURL = configLocation.getURL();
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle01/"));
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) Equinox(org.eclipse.osgi.launch.Equinox) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Location(org.eclipse.osgi.service.datalocation.Location)

Example 29 with Location

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

the class BasicLocationTests method testUNC.

public void testUNC() throws Exception {
    if (!windows)
        return;
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "//server/share/a");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "//server/share/b");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "//server/share/c");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file://server/share/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        checkLocation(locations.get(Location.USER_FILTER), true, true, "file");
        checkLocation(locations.get(Location.INSTANCE_FILTER), true, true, "file");
        checkLocation(locations.get(Location.CONFIGURATION_FILTER), true, true, "file");
        checkLocation(locations.get(Location.INSTALL_FILTER), true, true, "file");
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 30 with Location

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

the class BasicLocationTests method testDebugLogOnGetURL.

public void testDebugLogOnGetURL() throws Exception {
    Properties debugOptions = new Properties();
    debugOptions.put("org.eclipse.osgi/debug/location", "true");
    File debugOptionsFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".options");
    debugOptions.store(new FileOutputStream(debugOptionsFile), getName());
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    fwkConfig.put(EquinoxConfiguration.PROP_DEBUG, debugOptionsFile.getAbsolutePath());
    fwkConfig.put("eclipse.consoleLog", "true");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        final List<LogEntry> logEntries = new ArrayList<LogEntry>();
        LogReaderService logReaderService = getLogReaderService(equinox);
        LogListener logListener = new SynchronousLogListener() {

            @Override
            public void logged(LogEntry entry) {
                logEntries.add(entry);
            }
        };
        logReaderService.addLogListener(logListener);
        Map<String, Location> locations = getLocations(equinox);
        Location userLocation = locations.get(Location.USER_FILTER);
        Location instanceLocation = locations.get(Location.INSTANCE_FILTER);
        assertNotNull("User locatoin is not null.", userLocation.getURL());
        assertNotNull("Instance location is not null.", instanceLocation.getURL());
        assertEquals("Wrong number of log entries", 2, logEntries.size());
    } finally {
        equinox.stop();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) Equinox(org.eclipse.osgi.launch.Equinox) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) 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