inger
inger

Reputation: 20194

Eclipse OSGI config: relative paths and/or @config.dir-like substitutions?

In my RCP app, I would like to point a property (osgi.java.profile) to a file, and would prefer using paths relative to my installation and config dir.

Is there a definitive spec on what kind of variables are supported in config.ini?


@config.dir seems to be supported, there are references in the builtin, and it's always mentioned as typical example (e.g this SO answer ) However, looking at docs like Eclipse help/Runtime Options, it mentions a few "symbolic locations" like @user.home; however that seems fairly limited and doesn't include @config.dir.

Have even dug into org.eclipse.osgi sources as well, and found no references to this (I did find LocationManager and its hard coded variable substitutions for @user.dir & co). Can I refer to arbitrary system properties there in some way?

Is this @config.dir a special case, only handled by P2? UPDATE: this seems to be the case.. looking at Eclipse SDK, About .. Configuration dialog shows @config.dir unresolved, probably taken literally by the Equinox..

Thanks for any hints.

Upvotes: 8

Views: 7289

Answers (5)

Steven Darnell
Steven Darnell

Reputation: 339

I'm late to the party, but hopefully this will help others in the future.

Starting with Eclipse 3.8/4.2 (June 2012), you can substitute Java properties and environment variables into your config.ini file (Eclipse Bug 241192). The Equinox launcher does not support substitution in the eclipse.ini launcher file. The syntax uses dollar signs ($VARIABLE$) to indicate variable substitution:

osgi.configuration.area=$APPDATA$/MyCompany/MyProgram/configuration
osgi.user.area=$APPDATA$/MyCompany/MyProgram/user
osgi.instance.area=$APPDATA$/MyCompany/MyProgram/instance

I imagine you could use something like this for your purposes:

osgi.java.profile=$osgi.install.area$/path/to/profile.txt

Upvotes: 3

tkotisis
tkotisis

Reputation: 3552

You can use a platform URL (Platform URI scheme) to achieve this, i.e.

osgi.java.profile = platform:/config/java_profile.txt

in config.ini, would point to the file java_profile.txt in the current configuration directory.

You might also use existing system properties in config.ini:

osgi.java.profile = ${osgi.configuration.area}/java_profile.txt

Upvotes: 2

Michael Spector
Michael Spector

Reputation: 37019

Look how osgi.java.profile is resolved in org.eclipse.osgi.framework.internal.core.Framework:

// check for the java profile property for a url
String propJavaProfile = FrameworkProperties.getProperty(Constants.OSGI_JAVA_PROFILE);
if (propJavaProfile != null)
    try {
        // we assume a URL
        url = new URL(propJavaProfile);
    } catch (MalformedURLException e1) {
        // try using a relative path in the system bundle
        url = findInSystemBundle(propJavaProfile);
    }

That means osgi.java.profile must point either to a fully qualified URL, or to a relative path in system bundle (org.eclipse.osgi). This makes impossible usage of installation directory relative path without patching Eclipse.

Upvotes: 1

Kane
Kane

Reputation: 8172

Why not use two system property variables?

One is named -Dmy.relativepath=filename, which is processed by your code of relative path of eclipse installation folder(workspace or anywhere), another is called -Dmy.path=absolutepath.

The system property is passed to the jvm, you need some tricky(translate the variable in runtime) in the native launcher(like eclipse.exe) if you wants to use variable in its value.

Upvotes: 1

Chris Dolan
Chris Dolan

Reputation: 8973

From org.eclipse.core.runtime.adaptor.LocationManager, here are the special tokens:

    // Data mode constants for user, configuration and data locations.                                                                                          
    private static final String NONE = "@none"; //$NON-NLS-1$                                                                                                   
    private static final String NO_DEFAULT = "@noDefault"; //$NON-NLS-1$                                                                                        
    private static final String USER_HOME = "@user.home"; //$NON-NLS-1$                                                                                         
    private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$                                                                                           

Upvotes: 1

Related Questions