use of org.eclipse.osgi.service.datalocation.Location in project bndtools by bndtools.
the class BundleUtils method getBundleLocation.
public static IPath getBundleLocation(BundleContext context, String symbolicName, VersionRange range) {
Location installLocation = Platform.getInstallLocation();
Location configLocation = Platform.getConfigurationLocation();
Bundle bundle = findBundle(context, symbolicName, range);
if (bundle == null)
return null;
String location = bundle.getLocation();
if (location.startsWith("file:")) {
//$NON-NLS-1$
location = location.substring(5);
} else if (location.startsWith("reference:file:")) {
//$NON-NLS-1$
location = location.substring(15);
}
IPath bundlePath = new Path(location);
if (bundlePath.isAbsolute())
return bundlePath;
// Try install location
if (installLocation != null) {
IPath installedBundlePath = new Path(installLocation.getURL().getFile()).append(bundlePath);
if (installedBundlePath.toFile().exists())
return installedBundlePath;
}
// Try config location
if (configLocation != null) {
IPath configuredBundlePath = new Path(configLocation.getURL().getFile()).append(bundlePath);
if (configuredBundlePath.toFile().exists())
return configuredBundlePath;
}
return null;
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class KNIMEApplication method writeWorkspaceVersion.
/**
* Write the version of the metadata into a known file overwriting any
* existing file contents. Writing the version file isn't really crucial, so
* the function is silent about failure
*/
private static void writeWorkspaceVersion() {
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null || instanceLoc.isReadOnly()) {
return;
}
File versionFile = getVersionFile(instanceLoc.getURL(), true);
if (versionFile == null) {
return;
}
OutputStream output = null;
try {
String versionLine = WORKSPACE_VERSION_KEY + '=' + WORKSPACE_VERSION_VALUE;
output = new FileOutputStream(versionFile);
// $NON-NLS-1$
output.write(versionLine.getBytes("UTF-8"));
} catch (IOException e) {
} finally {
try {
if (output != null) {
output.close();
}
} catch (IOException e) {
// do nothing
}
}
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class KNIMEConstants method assignUniqueID.
private static void assignUniqueID() {
Location configLocation = Platform.getConfigurationLocation();
if (configLocation != null) {
URL configURL = configLocation.getURL();
if (configURL != null) {
String path = configURL.getPath();
if (Platform.OS_WIN32.equals(Platform.getOS()) && path.matches("^/[a-zA-Z]:/.*")) {
// Windows path with drive letter => remove first slash
path = path.substring(1);
}
Path uniqueId = Paths.get(path, "org.knime.core", "knime-id");
if (!Files.exists(uniqueId)) {
try {
Files.createDirectories(uniqueId.getParent());
knimeID = "01-" + createUniqeID();
try (OutputStream os = Files.newOutputStream(uniqueId)) {
os.write(knimeID.toString().getBytes("UTF-8"));
} catch (IOException ex) {
NodeLogger.getLogger(KNIMEConstants.class).error("Could not write KNIME id to '" + uniqueId.toAbsolutePath() + "': " + ex.getMessage(), ex);
}
} catch (IOException ex) {
NodeLogger.getLogger(KNIMEConstants.class).error("Could not create configuration directory '" + uniqueId.getParent().toAbsolutePath() + "': " + ex.getMessage(), ex);
}
} else if (Files.isReadable(uniqueId)) {
try (InputStream is = Files.newInputStream(uniqueId)) {
byte[] buf = new byte[256];
int read = is.read(buf);
knimeID = new String(buf, 0, read, Charset.forName("UTF-8"));
} catch (IOException ex) {
NodeLogger.getLogger(KNIMEConstants.class).error("Could not read KNIME id from '" + uniqueId.toAbsolutePath() + "': " + ex.getMessage(), ex);
}
}
}
}
if (knimeID == null) {
knimeID = "00-" + createUniqeID();
}
}
use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.
the class EclipseUtil method checkSDK.
private static boolean checkSDK() {
Location installLocation = Platform.getInstallLocation();
if (installLocation == null) {
return true;
}
Location configurationLocation = Platform.getConfigurationLocation();
if (configurationLocation == null) {
return true;
}
return configurationLocation.getURL().getPath().contains("/.metadata/.plugins/org.eclipse.pde.core/");
}
use of org.eclipse.osgi.service.datalocation.Location in project rt.equinox.framework by eclipse.
the class BasicLocationTests method testCreateLocation04.
public void testCreateLocation04() {
Location configLocation = configLocationTracker.getService();
File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testCreateLocation04");
Location testLocation = configLocation.createLocation(null, null, true);
try {
testLocation.set(testLocationFile.toURL(), true);
testLocation.release();
fail("Should not be able to lock read-only location");
} catch (Throwable t) {
// expected
}
}
Aggregations