Search in sources :

Example 31 with Location

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

the class BasicLocationTests method testUserHome.

public void testUserHome() 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, "@user.home");
    fwkConfig.put(EquinoxLocations.PROP_INSTANCE_AREA, "@user.home");
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA, "@user.home");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/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 32 with Location

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

the class BasicLocationTests method testCreateLocation01.

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

Example 33 with Location

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

the class BasicLocationTests method testSetLocationWithEmptyLockFile.

public void testSetLocationWithEmptyLockFile() {
    Location configLocation = configLocationTracker.getService();
    // $NON-NLS-1$
    File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testSetLocationWithEmptyLockFile");
    Location testLocation = configLocation.createLocation(null, null, false);
    try {
        // $NON-NLS-1$
        testLocation.set(testLocationFile.toURL(), true, "");
        // Make sure it has created the default lock file
        // $NON-NLS-1$
        File lockFile = new File(testLocationFile, ".metadata/.lock");
        // $NON-NLS-1$
        assertTrue("Lock file does not exist!", lockFile.exists());
    } catch (Throwable t) {
        // $NON-NLS-1$
        fail("Failed to set location", t);
    }
    try {
        // $NON-NLS-1$
        assertTrue("Could not lock location", testLocation.isLocked());
    } catch (IOException e) {
        // $NON-NLS-1$
        fail("Failed to lock location", e);
    }
    testLocation.release();
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Example 34 with Location

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

the class BasicLocationTests method testSetLocationWithRelLockFile.

public void testSetLocationWithRelLockFile() {
    Location configLocation = configLocationTracker.getService();
    // $NON-NLS-1$
    File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testSetLocationWithRelLockFile");
    Location testLocation = configLocation.createLocation(null, null, false);
    try {
        // $NON-NLS-1$
        testLocation.set(testLocationFile.toURL(), true, ".mocklock");
        // $NON-NLS-1$
        File lockFile = new File(testLocationFile, ".mocklock");
        // $NON-NLS-1$
        assertTrue("Lock file does not exist!", lockFile.exists());
    } catch (Throwable t) {
        // $NON-NLS-1$
        fail("Failed to set location", t);
    }
    try {
        // $NON-NLS-1$
        assertTrue("Could not lock location", testLocation.isLocked());
    } catch (IOException e) {
        // $NON-NLS-1$
        fail("Failed to lock location", e);
    }
    testLocation.release();
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Example 35 with Location

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

the class BasicLocationTests method testSetLocationWithAbsLockFile.

public void testSetLocationWithAbsLockFile() {
    Location configLocation = configLocationTracker.getService();
    // $NON-NLS-1$
    File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testSetLocationWithAbsLockFile");
    // $NON-NLS-1$
    File testLocationLockFile = OSGiTestsActivator.getContext().getDataFile("testLocations/mock.lock");
    assertTrue(testLocationLockFile.isAbsolute());
    Location testLocation = configLocation.createLocation(null, null, false);
    try {
        testLocation.set(testLocationFile.toURL(), true, testLocationLockFile.getAbsolutePath());
        // $NON-NLS-1$
        assertTrue("The lock file should be present!", testLocationLockFile.exists());
    } catch (Throwable t) {
        // $NON-NLS-1$
        fail("Failed to set location", t);
    }
    try {
        // $NON-NLS-1$
        assertTrue("Could not lock location", testLocation.isLocked());
    } catch (IOException e) {
        // $NON-NLS-1$
        fail("Failed to lock location", e);
    }
    testLocation.release();
    // $NON-NLS-1$
    assertTrue("The lock file could not be removed!", testLocationLockFile.delete());
}
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