8

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.

Community
  • 1
  • 1
inger
  • 19,574
  • 9
  • 49
  • 54
  • +1 and I'm opening a bounty for this question. I really need to be able to specify a path relative to the installation directory, rather than the config area, for the eclipse.p2.data.area in my config.ini. If anyone can tell me how to do that, have 200 rep! – Tom Crockett Jun 07 '11 at 08:44
  • @pelotom, thanks for the boost - let's hope.. I actually am pretty convinced my question does not have a precise answer (it's unbelievable but the substitution seems hardcoded in the core).. However, since you seem to be more interested in a P2-specific property, it might be better supported, i.e. @config.dir does seem to be specially handled by P2 config processing-maybe that's not the only one. – inger Jun 08 '11 at 09:43

5 Answers5

3

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
Steven Darnell
  • 339
  • 1
  • 11
  • Works well with some variables e.g. `osgi.install.area`. Other variables like `osgi.configuration.area` are not resolved. – Tobber Sep 17 '15 at 13:11
2

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
Andrew
  • 13,757
  • 13
  • 66
  • 84
tkotisis
  • 3,442
  • 25
  • 30
  • I guess this will be helpful - trying it ASAP. Do you know if this support is recently added, would it work in 3.6.x? Last time I gave up and ended up with nasty absolute paths.. – inger Feb 15 '12 at 18:04
  • @inger Yes, it should work for 3.6, at least according to the [documentation](http://help.eclipse.org/helios/index.jsp) – tkotisis Feb 18 '12 at 09:52
1

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$                                                                                           
Chris Dolan
  • 8,905
  • 2
  • 35
  • 73
  • Thanks Chris -I found that same list (see my question). It seems pretty limited - so was wondering if I missed something (e.g system properties or sg like that). After debugging through the framework, there doesn't seem much hope. – inger Feb 10 '11 at 09:50
  • I also asked a similar question on the Equinox newsgroup http://www.eclipse.org/forums/index.php?t=msg&goto=653500&S=2de0a18be29a148e02639f3968181b8e#msg_653500 - awaiting answer. – inger Feb 10 '11 at 09:53
  • @inger: it seemed pretty clear from the source code that those are the only supported options. – Chris Dolan Feb 11 '11 at 00:33
  • Well, from looking only at LocationManager, yes it's kind of clear - I found it in a few minutes too. But that did not explain why @config.dir is supported then(as I said I assume now it's a special handling for P2, quite strange I think). I was just hoping this problem has been solved in some other way otherwise osgi.java.profile seems pretty useless for RCP development. It would have been great if the just hooked in ${system.properties} rather than stupid hard coded replacements. – inger Feb 11 '11 at 11:07
1

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.

Kane
  • 8,035
  • 7
  • 46
  • 75
  • Of course I can try a workaround where I create properties that Eclipse should have, but that would at least require an extra launcher script, extra hacks.. After this I'm still not sure I can reach to that property in config.ini, as part of other property definitions.. What I was really interested in if there was some Eclipse feature to do this which I missed. – inger Jun 08 '11 at 09:47
  • 1
    @inger, it's definitely a tricky of p2. You could find @config.dir is substituted by the value of framework property 'osgi.configuration.area' in runtime. See method org.eclipse.equinox.internal.p2.core.Activator.buildLocation(String, URI, boolean, boolean). The value of jvm's system property 'eclipse.p2.data.area' always is '@config.dir/../p2'. – Kane Jun 08 '11 at 15:01
1

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.

Michael Spector
  • 36,723
  • 6
  • 60
  • 88