Bug 102239 - [launcher] Environment variable substitution in <launcher>.ini/eclipse.ini
Summary: [launcher] Environment variable substitution in <launcher>.ini/eclipse.ini
Status: REOPENED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Launcher (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement with 32 votes (vote)
Target Milestone: ---   Edit
Assignee: Sravan Kumar Lakkimsetti CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 94087 215020 224091 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-29 20:24 EDT by Ian Graham CLA
Modified: 2021-03-18 02:52 EDT (History)
38 users (show)

See Also:


Attachments
Patch to LocationManager adding support for environment variables (2.84 KB, text/plain)
2009-08-12 06:27 EDT, Romain Castell CLA
no flags Details
Patch to eclipseConfig.c to dereference environment variables (3.54 KB, application/octet-stream)
2010-03-23 10:23 EDT, Romain Castell CLA
no flags Details
Eclipse patch (2.77 KB, patch)
2010-03-23 13:27 EDT, Andrew Niefer CLA
no flags Details | Diff
Patch for Luna. Uses $VARIABLE$ syntax. (2.95 KB, patch)
2014-07-19 21:06 EDT, Predrag Stanar CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Graham CLA 2005-06-29 20:24:33 EDT
It'd be very helpful if the launcher would support the insertion of environment 
variables in the <launcher>.ini.  Whatever form might make sense(e.g. @ENV, %
ENV%, ${ENV}, ${env_var:ENV})

e.g. something like

-vm
${MYRCPAPP_VM}
-mx${MYRCPAPP_HEAPSIZE}
Comment 1 Pascal Rapicault CLA 2006-03-23 15:44:32 EST
The launcher is written in C. The code is in the platform-launcher project.
Comment 2 Pascal Rapicault CLA 2006-03-29 15:16:31 EST
*** Bug 94087 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Niefer CLA 2008-01-15 11:06:26 EST
*** Bug 215020 has been marked as a duplicate of this bug. ***
Comment 4 Thomas Watson CLA 2008-03-26 10:06:40 EDT
*** Bug 224091 has been marked as a duplicate of this bug. ***
Comment 5 Romain Castell CLA 2009-08-12 06:26:31 EDT
Hi there,

I'm attaching a patch to org.eclipse.core.runtime.adaptor.LocationManager (from plug-in org.eclipse.osgi) adding support for @env.ANY_ENV_VAR syntax.

This works for location specified both on the command line or in the eclipse.ini file. For instance, 

  -vmargs
  -Dosgi.instance.area.default=@env.HOMEDRIVE\@env.HOMEPATH\workspace

provides a more user-friendly default location for the workspace in our deployment environment on Windows.

This is not entirely foolproof: @env{ANY_ENV_VAR} would be a much better syntax but I wanted to stay close to the @user.home/@user.dir ones. Something to build on anyway (hopefully)

I've been missing and worked around this feature for a while now. just by looking at the number of duplicates, I can see I'm not the only one.

Hope this helps.

Comment 6 Romain Castell CLA 2009-08-12 06:27:43 EDT
Created attachment 144200 [details]
Patch to LocationManager adding support for environment variables
Comment 7 Andrew Niefer CLA 2009-08-12 09:59:34 EDT
If this is expected to work for all properties, in particular, the various osgi.configuration.*, osgi.install.area, osgi.framework*, and some others, then this would also need to be handled in org.eclipse.equinox.launcher's Main.

As well, the original comment #0, wants this on any argument including the vm, vmargs etc, in which case this would need to happen in the native code.
Comment 8 Romain Castell CLA 2009-08-12 10:08:48 EDT
Personnaly, I miss environment variables most for user-specific settings (I feel the JVM location and associated options are more machine-specific and can therefore be sorted on installation) although extending this to all command line arguments would be nice.
Comment 9 Andrew Niefer CLA 2009-08-12 10:26:16 EDT
Also, the patch does not compile for me because it uses methods/classes not in the OSGi/Minimum-1.2 execution environment.

To see this yourself, go to your Preferences -> Java -> Installed JREs -> Add -> Execution Environment Description
Point at org.eclipse.osgi/osgi/OSGi_Minimum-12.ee.
Click ok, then go back to Installed JREs -> Execution Environments in the preference tree, select OSGi/Minimum-1.2 and check the jre you just added.

You then may need to right click on the osgi project and do PDE Tools -> update class path.
Comment 10 Romain Castell CLA 2009-08-12 10:58:57 EDT
Fair enough. The same code without regex support is going to be horrible and error-prone. Let's forget it then...
Comment 11 Romain Castell CLA 2010-03-23 10:22:43 EDT
Hi eclipse.org,

I got sufficiently annoyed by this bug that I actually resolved myself to write a fix for it in C, as requested. It hurt... Anyway, attached is a patch to eclipeConfig.c to dereference environment variables in the form of ${var}

I have tested this on Windows (32-bit) and Linux (64-bit) and the code looks sufficiently bland to make me believe it should compile on most platforms.

I left test-code in the patch to show the cases this patch covers to help reviewers spot shortcomings. Of course this should not remain where it is now.

Hope this helps,

  Romain
Comment 12 Romain Castell CLA 2010-03-23 10:23:31 EDT
Created attachment 162768 [details]
Patch to eclipseConfig.c to dereference environment variables
Comment 13 Andrew Niefer CLA 2010-03-23 13:27:34 EDT
Created attachment 162794 [details]
Eclipse patch

Here is a eclipse workspace patch of the same code with the string stuff changed to the macros (_TCHAR, _tcsstr, _tcscat, etc).

I haven't tried running it.  First comment is that we don't rescan the replaced string.  Do we want to support something like this:

USER = person
ROOT = ${USER}/eclipse

${ROOT}/workspace -> ${USER}/eclipse/workspace -> person/eclipse/workspace
Comment 14 Andrew Niefer CLA 2010-05-05 11:04:02 EDT
Hi Romain, thanks for the patch, this was discussed on the Equinox call during M7 but I forgot to make a note here.  It was decided to wait until 3.7 before releasing it.  We are now into the first release candidates for 3.6 and want to avoid making changes to the launcher if possible.
Comment 15 Romain Castell CLA 2010-05-05 11:55:39 EDT
Thanks for the update. For the benefit of anyone waiting on this and not requiring environment variables dereferencing for the JVM location, there is a simple way to implement this in Java alone: write the code in Java and have the native launcher calling out to your class using the -startup option. Once all the environment variables expanded, call out to org.eclipse.equinox.launcher.Main located in plugins/org.eclipse.equinox.launcher_w.x.y.z.jar

I'm sure there are disadvantages in doing it this way (and also benefits, for one can do more arguments/pre-startup processing without going back to C), but I thought I'd mention it as a possible workaround.
Comment 16 Martin Oberhuber CLA 2010-05-06 09:15:20 EDT
See also bug 215689 for setting / unsetting environment variables in the Launcher, which seems to be related.

One extra feature I'd like to see with this is a fallback for cases where an environment variable is not set. For instance:

-vm ${WIND_HOME:-../../..}/jre/bin/client/jvm.dll}
Comment 17 Thomas Watson CLA 2011-04-20 11:50:33 EDT
Not going to happen for 3.7.
Comment 18 Thomas Watson CLA 2011-06-08 11:30:51 EDT
Move all 3.8 bugs to Juno.
Comment 19 Romain Castell CLA 2011-06-08 11:51:40 EDT
Hi all,

Can I politely ask what is happening to this bug and the proposed patch? I feel the patch fulfils the requirement (to resolve environment variables in launcher ini file)

Of course it could be better, as others suggested, but how about addressing improvements in an iterative fashion rather that waiting - possibly forever - on the perfect solution?

Thanks,

  Romain
Comment 20 Thomas Watson CLA 2012-04-30 11:32:28 EDT
Not going to make Juno.
Comment 21 Erik Englund CLA 2014-04-22 14:44:41 EDT
This bugs seems to have died even though there is a possible patch.  I like the env option but I would also like a variable that points to where the eclipse executable resides,  ie the ECLIPSE_HOME.  This is important in order to pass java system properties to the jvm that point to locations relative to ECLIPSE_HOME.  I tried doing this in the config.ini using the platform url form but these settings much we resolved before the JVM starts and passed in as VM args.
Comment 22 Thomas Watson CLA 2014-05-20 14:48:18 EDT
(In reply to Erik Englund from comment #21)
> This bugs seems to have died even though there is a possible patch.  I like
> the env option but I would also like a variable that points to where the
> eclipse executable resides,  ie the ECLIPSE_HOME.  This is important in
> order to pass java system properties to the jvm that point to locations
> relative to ECLIPSE_HOME.  I tried doing this in the config.ini using the
> platform url form but these settings much we resolved before the JVM starts
> and passed in as VM args.

Yes, this bug seems to have died.  I will move it to Mars, but I think we likely need a new patch to be done against the latest code.  There were also several open questions about the solution.
Comment 23 Steven Darnell CLA 2014-05-20 18:13:05 EDT
Bug 241192 added support for environment variables and Java properties in config.ini since 3.8/4.2. The decided upon syntax was $VARIABLE$, rather than ${VARIABLE} syntax. I recommend that any further work should be consistent with the already released implementation in config.ini.
Comment 24 Thomas Watson CLA 2014-05-21 08:21:30 EDT
(In reply to Steven Darnell from comment #23)
> Bug 241192 added support for environment variables and Java properties in
> config.ini since 3.8/4.2. The decided upon syntax was $VARIABLE$, rather
> than ${VARIABLE} syntax. I recommend that any further work should be
> consistent with the already released implementation in config.ini.

Good point Steven.  I agree we should be consistent here for the syntax.
Comment 25 Predrag Stanar CLA 2014-07-19 21:06:09 EDT
Created attachment 245215 [details]
Patch for Luna. Uses $VARIABLE$ syntax.

To keep this going and, hopefully, see it one day resolved I'm attaching patch based off of Andrew Niefer's work that works with Luna (R4.4). It conforms with $VARIABLE$ syntax.
Comment 26 Daniel Raap CLA 2016-10-27 07:26:52 EDT
Two years later, still no support for this 11 years old request, althought multiple patches were offered m(
Comment 27 rgra Missing name CLA 2018-11-30 05:37:18 EST
Why is this not considered for being merged?
Is nobody maintaining the code to be able to merge this?

On Windows Terminal Server environments it is needed to be able to resolve ENV Variables when launching the product to be able to have some directories in other folders than support by the @variable's.
Comment 28 Alexander Kurtakov CLA 2018-11-30 05:54:49 EST
(In reply to Rabea Gransberger from comment #27)
> Why is this not considered for being merged?
> Is nobody maintaining the code to be able to merge this?

Sorry about that. I try to keep track of patches in gerrit but this one is not there. If someone puts it there we will try merging it for 4.11.

> 
> On Windows Terminal Server environments it is needed to be able to resolve
> ENV Variables when launching the product to be able to have some directories
> in other folders than support by the @variable's.
Comment 29 rgra Missing name CLA 2018-11-30 06:14:50 EST
@Predrag / @Andrew / @Romain: I know this is a lot of work to get into this again, but I and other would really appreciate if you'd take the time to get this into Gerrit :)
Comment 30 Predrag Stanar CLA 2018-11-30 13:47:41 EST
It has been 6 years since I made change to that code, and over 4 since the patch I posted. I cloned equinox repository today, installed Windows Server 2003 SP1 SDK and compiled and tested it again.

I can make another git patch against current master, but I'm not committer and can't push it to Gerrit.
Comment 31 Andrey Loskutov CLA 2018-11-30 14:07:04 EST
(In reply to Predrag Stanar from comment #30)
> It has been 6 years since I made change to that code, and over 4 since the
> patch I posted. I cloned equinox repository today, installed Windows Server
> 2003 SP1 SDK and compiled and tested it again.
> 
> I can make another git patch against current master, but I'm not committer
> and can't push it to Gerrit.

Everyone can push to Gerrit, but only committers can merge.
Comment 32 Eclipse Genie CLA 2018-11-30 15:21:41 EST
New Gerrit change created: https://git.eclipse.org/r/133322
Comment 33 johannes schmieder CLA 2019-04-09 09:55:52 EDT
(In reply to Alexander Kurtakov from comment #28)
> (In reply to Rabea Gransberger from comment #27)
> > Why is this not considered for being merged?
> > Is nobody maintaining the code to be able to merge this?
> 
> Sorry about that. I try to keep track of patches in gerrit but this one is
> not there. If someone puts it there we will try merging it for 4.11.
> 
> > 
> > On Windows Terminal Server environments it is needed to be able to resolve
> > ENV Variables when launching the product to be able to have some directories
> > in other folders than support by the @variable's.

Patch seems to be in gerrit now. So, maybe this bug can soon be solved.
Comment 34 Andrew Thomas CLA 2019-11-06 13:02:41 EST
I want to specify where to write crash files.

That would best be done with the VM arg -XX:ErrorFile, specifying an existing, writable directory that may differ by operating system and user.

That in turn would best be done by using an environment variable in the <launcher>.ini file. 

Can this issue be addressed?
Comment 35 Andrey Loskutov CLA 2019-11-06 16:53:35 EST
(In reply to Andrew Thomas from comment #34)
> Can this issue be addressed?

Sure. https://wiki.eclipse.org/Platform/How_to_Contribute
Comment 36 Andrey Loskutov CLA 2019-11-06 16:55:06 EST
(In reply to Andrey Loskutov from comment #35)
> (In reply to Andrew Thomas from comment #34)
> > Can this issue be addressed?
> 
> Sure. https://wiki.eclipse.org/Platform/How_to_Contribute

(In reply to Eclipse Genie from comment #32)
> New Gerrit change created: https://git.eclipse.org/r/133322

This patch needs a qualified reviewer.
Comment 37 Sravan Kumar Lakkimsetti CLA 2019-11-07 01:23:16 EST
(In reply to Andrey Loskutov from comment #36)
> (In reply to Andrey Loskutov from comment #35)
> > (In reply to Andrew Thomas from comment #34)
> > > Can this issue be addressed?
> > 
> > Sure. https://wiki.eclipse.org/Platform/How_to_Contribute
> 
> (In reply to Eclipse Genie from comment #32)
> > New Gerrit change created: https://git.eclipse.org/r/133322
> 
> This patch needs a qualified reviewer.

I will review by this end of this week
Comment 38 Andrey Loskutov CLA 2019-12-06 10:15:24 EST
Sravan, may I put this on your plan for 4.15?
Comment 39 Sravan Kumar Lakkimsetti CLA 2019-12-09 01:45:18 EST
(In reply to Andrey Loskutov from comment #38)
> Sravan, may I put this on your plan for 4.15?

Sure. I should be able to complete this by M1
Comment 40 Andrey Loskutov CLA 2020-01-16 08:34:16 EST
(In reply to Sravan Kumar Lakkimsetti from comment #39)
> (In reply to Andrey Loskutov from comment #38)
> > Sravan, may I put this on your plan for 4.15?
> 
> Sure. I should be able to complete this by M1

Sravan, may be something for M3?
Comment 41 Alexander Kurtakov CLA 2020-02-17 03:49:51 EST
Move to 4.16 M1
Comment 42 Thomas Watson CLA 2020-04-06 08:42:23 EDT
Where are we at for this one?  Likely not to make M1?
Comment 43 Sravan Kumar Lakkimsetti CLA 2020-04-06 09:43:42 EDT
Moving to M3. I could not find time to work on this due to JIPP migration work
Comment 44 Alexander Kurtakov CLA 2020-05-15 12:44:50 EDT
Remove target milestone as it's clearly not a topic for 4.16.
Comment 45 Udo Walker CLA 2020-06-08 04:50:48 EDT
Will this be part of 4.17?
Comment 46 Sravan Kumar Lakkimsetti CLA 2020-06-08 05:01:30 EDT
(In reply to Udo Walker from comment #45)
> Will this be part of 4.17?

I will review this tomorrow. There some firefights going on today.
Comment 48 Sravan Kumar Lakkimsetti CLA 2020-06-08 07:34:38 EDT
(In reply to Udo Walker from comment #45)
> Will this be part of 4.17?

Please test this in tomorrows I build I20200608-1800
Comment 49 Sravan Kumar Lakkimsetti CLA 2020-06-29 07:42:26 EDT
Merged to master and rebuilt the launchers
Comment 50 Eclipse Genie CLA 2020-12-23 03:22:32 EST
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/174076
Comment 51 Sravan Kumar Lakkimsetti CLA 2020-12-23 03:23:51 EST
Reverting this fix as this caused regression bug 569885
Comment 53 Christoph Laeubrich CLA 2020-12-23 08:08:57 EST
Is there any option to fix/adjust the patch?

I think ${env_var:ENV} syntax would be much better as it will work inside eclipse also that way when used in a product config while the $ENV$ syntax will only work in exported product but not in the IDE, beside it might be easier/more reliable to find the bounds.