Search in sources :

Example 16 with Location

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

the class BasicLocationTests method testNone.

public void testNone() throws Exception {
    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, "@none");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@none");
    // TODO framework does not handle no config area well
    // fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@none");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        assertNull("User location should be null", locations.get(Location.USER_FILTER));
        assertNull("Instance location should be null", locations.get(Location.INSTANCE_FILTER));
    // TODO assertNull("Configuration location should be null", locations.get(Location.CONFIGURATION_FILTER));
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 17 with Location

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

the class BasicLocationTests method testCreateLocation03.

public void testCreateLocation03() {
    Location configLocation = configLocationTracker.getService();
    File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testCreateLocation03");
    Location testLocation = configLocation.createLocation(null, null, false);
    try {
        testLocation.set(testLocationFile.toURL(), true);
    } catch (Throwable t) {
        fail("Failed to set location", t);
    }
    try {
        assertTrue("Could not lock location", testLocation.isLocked());
    } catch (IOException e) {
        fail("Failed to lock location", e);
    }
    testLocation.release();
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Example 18 with Location

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

the class BasicLocationTests method testNoDefault.

public void testNoDefault() throws Exception {
    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(EquinoxLocations.PROP_INSTANCE_AREA, "@noDefault");
    fwkConfig.put(EquinoxLocations.PROP_USER_AREA, "@noDefault");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        Map<String, Location> locations = getLocations(equinox);
        Location userLocation = locations.get(Location.USER_FILTER);
        Location instanceLocation = locations.get(Location.INSTANCE_FILTER);
        assertNull("User locatoin is not null.", userLocation.getURL());
        assertNull("Instance location is not null.", instanceLocation.getURL());
    } finally {
        equinox.stop();
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Location(org.eclipse.osgi.service.datalocation.Location)

Example 19 with Location

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

the class LocationAreaSessionTest method doLock.

static void doLock(String testLocationDir, boolean release, boolean succeed) {
    if (testLocationDir == null)
        fail("The testLocationDir is not set");
    ServiceReference[] refs = null;
    try {
        refs = OSGiTestsActivator.getContext().getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
    } catch (InvalidSyntaxException e) {
        fail("failed to create filter", e);
    }
    // this is test code so we are not very careful; just assume there is at lease one service.  Do not copy and paste this code!!!
    Location configLocation = (Location) OSGiTestsActivator.getContext().getService(refs[0]);
    Location testLocation = null;
    try {
        testLocation = configLocation.createLocation(null, new File(testLocationDir).toURL(), false);
        testLocation.setURL(testLocation.getDefault(), false);
        // try locking location
        if (succeed ? testLocation.isLocked() : !testLocation.isLocked())
            fail("location should " + (succeed ? "not " : "") + "be locked");
        if (succeed ? !testLocation.lock() : testLocation.lock())
            fail((succeed ? "Could not" : "Could") + " lock location");
        if (!testLocation.isLocked())
            fail("location should be locked");
    } catch (MalformedURLException e) {
        fail("failed to create the location URL", e);
    } catch (IOException e) {
        fail("failed to lock with IOExcetpion", e);
    } finally {
        if (release && testLocation != null)
            testLocation.release();
        if (!release)
            lockedTestLocation = testLocation;
        OSGiTestsActivator.getContext().ungetService(refs[0]);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference) Location(org.eclipse.osgi.service.datalocation.Location)

Example 20 with Location

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

the class SystemBundleTests method testSystemBundle08.

public void testSystemBundle08() {
    // create/start/stop/start/stop test
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_1");
    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());
    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());
    // $NON-NLS-1$
    config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_2");
    configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    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());
    ServiceReference[] refs = null;
    try {
        // $NON-NLS-1$
        refs = equinox.getBundleContext().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) equinox.getBundleContext().getService(refs[0]);
    URL configURL = configLocation.getURL();
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle08_2/"));
    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) 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