Skip to content

Commit

Permalink
o.c.diirt: allow platform URI in diirt preferences
Browse files Browse the repository at this point in the history
This allows you to include diirt configuration inside a plugin,
in the same way as e.g. opibuilder preferences.

Since Diirt needs access to the configuration, the plugin needs
to specify "Eclipse-BundleShape: dir" so that the files are not
bundled into a jar.
  • Loading branch information
willrogers committed Oct 15, 2015
1 parent ee132e7 commit 75b865c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.osgi,
org.eclipse.core.runtime,
org.eclipse.ui,
org.csstudio.startup;bundle-version="3.2.1",
org.csstudio.diirt.util;bundle-version="1.0.0"
org.csstudio.diirt.util;bundle-version="1.0.0",
org.eclipse.core.filesystem;bundle-version="1.5.0"
Bundle-Vendor: Kunal Shroff <shroffk@bnl.gov>
Import-Package: org.csstudio.utility.product
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.csstudio.diirt.util.preferences;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

import org.csstudio.utility.product.IWorkbenchWindowAdvisorExtPoint;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
Expand All @@ -21,6 +25,7 @@
public class DiirtStartup implements IWorkbenchWindowAdvisorExtPoint {

private Logger log = Logger.getLogger(DiirtStartup.ID);
private static final String PLATFORM_URI_PREFIX = "platform:";

@Override
public void preWindowOpen() {
Expand All @@ -31,7 +36,19 @@ public void preWindowOpen() {

IPreferencesService prefs = Platform.getPreferencesService();
String diirtHome = prefs.getString("org.csstudio.diirt.util.preferences", "diirt.home", defaultDiirtConfig, null);
log.config("Setting Diirt configuration folder to :" + diirtHome);
// Allowing configuration to specify a location within a plugin.
if (diirtHome.startsWith(PLATFORM_URI_PREFIX)) {
try {
URL url = FileLocator.resolve(new URL(diirtHome));
IPath diirtHomeIpath = URIUtil.toPath(url.toURI());
if (diirtHomeIpath != null) {
diirtHome = diirtHomeIpath.toOSString();
}
} catch (MalformedURLException e) {
// leave diirtHome as is
}
}
log.config("Setting Diirt configuration folder to: " + diirtHome);
System.setProperty("diirt.home", diirtHome);
} catch (Exception e) {
log.severe(e.getMessage());
Expand Down

0 comments on commit 75b865c

Please sign in to comment.