You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gareth Tilley <ga...@rmb.co.za> on 2006/11/09 11:08:35 UTC

Resource filtering using environment variables

Hi All,

    Gunther Popp-2 wrote:
    - All (platform-specific) Environment variables (Just add the prefix
    env. For example ${env.M2_HOME} returns the Maven2 installation path).

Has anyone actually been able to get this working? All of the filtering
works fine for me, but the environment variable stuff does not.  As a test I
have a properties file that contains:
${env.JAVA_HOME}
${user.home}
${pom.version}

After the process-resources phase (with filtering turn on in the pom), the
file looks like this:
${env.JAVA_HOME}
/home/build
1.2-SNAPSHOT

JAVA_HOME is definitely set, is there something I am doing wrong, or does
this just not work?

Regards
Gareth 
-- 
View this message in context: http://www.nabble.com/Resource-filtering-using-environment-variables-tf2600791s177.html#a7255537
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Resource filtering using environment variables

Posted by franz see <fr...@gmail.com>.
Good day,

If im not mistaken, Java (the programming language behind maven) does
differentiate the System and Environment Variables. Both are retrieved via
System.getProperties(). So as to which takes precedence over the other,
probably  depends on the JVM.

Anyway, if im not mistaken, the proper priority for maven-resources-plugin
(and maven-war-plugin) is as follows:

S/E < POM < CL < Filter

Meaning, Filter properties overrides all. Commandline properties (-D
<key>=<value>) overrides all but Filter Properties. POM properties overrides
only the System/Environment Properties. And System/Environment Properties
overrides nothing.

Note: though you will see something like:

reader = new InterpolationFilterReader( reader, new ReflectionProperties(
project, isPropertiesFile ), "${", "}" );

in ResourcesMojo, I don't think it actually works.

Cheers,
Franz


Minto.van.der.Sluis wrote:
> 
> 
> 
> Hi folks,
> 
> Not being sure how these properties are exactly used, I think you have
> to take good care of where you put that line. The order of importance
> need good consideration. Your situation results in:
> 
> 	- system properties
> 	- project properties
> 	- environment properties
> 
> In this situation project properties take precedent over environment
> properties. Is this the right behaviour? Like this you can put anything
> in your environment, but as long as it is in the project as well, the
> environment properties will not get used. IMO this is incorrect. I think
> the following order is better:
> 
> 	- system properties
> 	- environment properties
> 	- project properties
> 
> In this situation system properties (commandline) are most important. If
> properties can not be found in system properties, the environment
> properties will be checked. Project properties will only get used as a
> last resort. 
> 
> I can be wrong in my analysis, but I would like to stress that it
> probably is important where to put that line :)
> 
> Kind regard,
> 
> Minto van der Sluis
> 
> 
> 
> 
> -----Oorspronkelijk bericht-----
> Van: Haroon Rafique [mailto:haroon.rafique@utoronto.ca] 
> Verzonden: donderdag 9 november 2006 18:03
> Aan: Maven Users List
> Onderwerp: Re: Resource filtering using environment variables
> 
> On Today at 11:20am, HR=>Haroon Rafique <ha...@utoronto.ca>
> wrote:
> 
> HR> [..snip..]
> HR> 
> 
> Something like the following should work (not tested):
> 
> import org.codehaus.plexus.util.cli.CommandLineUtils;
> 
> 
> HR>         filterProperties = new Properties();
> HR>         
> HR>         // System properties
> HR>         filterProperties.putAll( System.getProperties() );
> HR>         
> HR>         // Project properties
> HR>         filterProperties.putAll( project.getProperties() );
> HR> 
> 
> follow the above two calls with:
> 
> 	// Environment variables
> 	filterProperties.putAll( CommandLineUtils.getSystemEnvVars() );
> 
> Anyone willing to give it a try?
> 
> Later,
> --
> Haroon Rafique
> <ha...@utoronto.ca>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 
> DISCLAIMER
> De informatie in deze e-mail is vertrouwelijk en uitsluitend bestemd voor
> de geadresseerde. Indien u niet de geadresseerde bent, wordt u er hierbij
> op gewezen, dat u geen recht heeft kennis te nemen van de rest van deze
> e-mail, deze te gebruiken, te kopieren of te verstrekken aan andere
> personen dan de geadresseerde. Indien u deze e-mail abusievelijk hebt
> ontvangen, brengt u dan alstublieft de afzender op de hoogte, waarbij u
> bij deze gevraagd wordt het originele bericht te vernietigen. Politie
> Amsterdam-Amstelland is niet verantwoordelijk voor de inhoud van deze
> e-mail en wijst iedere aansprakelijkheid af voor en/of in verband met alle
> gevolgen en/of schade van een onjuiste of onvolledige verzending ervan.
> Tenzij uitdrukkelijk het tegendeel blijkt, kunnen aan dit bericht geen
> rechten worden ontleend. Het gebruik van Internet e-mail brengt zekere
> risicos met zich. Daarom wordt iedere aansprakelijkheid voor het gebruik
> van dit medium door de Politie Amsterdam-Amstelland van de hand gewezen. 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Resource-filtering-using-environment-variables-tf2600791s177.html#a7275929
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Resource filtering using environment variables

Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 11:20am, HR=>Haroon Rafique <ha...@utoronto.ca> wrote:

HR> [..snip..]
HR> 

Something like the following should work (not tested):

import org.codehaus.plexus.util.cli.CommandLineUtils;


HR>         filterProperties = new Properties();
HR>         
HR>         // System properties
HR>         filterProperties.putAll( System.getProperties() );
HR>         
HR>         // Project properties
HR>         filterProperties.putAll( project.getProperties() );
HR> 

follow the above two calls with:

	// Environment variables
	filterProperties.putAll( CommandLineUtils.getSystemEnvVars() );

Anyone willing to give it a try?

Later,
--
Haroon Rafique
<ha...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Resource filtering using environment variables

Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 2:08am, GT=>Gareth Tilley <ga...@rmb.co.za> wrote:

GT> 
GT> Hi All,
GT> 
GT>     Gunther Popp-2 wrote:
GT>     - All (platform-specific) Environment variables (Just add the prefix
GT>     env. For example ${env.M2_HOME} returns the Maven2 installation path).
GT> 
GT> Has anyone actually been able to get this working? All of the filtering
GT> works fine for me, but the environment variable stuff does not.  As a test I
GT> have a properties file that contains:
GT> ${env.JAVA_HOME}
GT> ${user.home}
GT> ${pom.version}
GT> 
GT> After the process-resources phase (with filtering turn on in the pom), the
GT> file looks like this:
GT> ${env.JAVA_HOME}
GT> /home/build
GT> 1.2-SNAPSHOT
GT> 
GT> JAVA_HOME is definitely set, is there something I am doing wrong, or does
GT> this just not work?
GT> 
GT> Regards
GT> Gareth 
GT> 

Hi Gareth,

Environment variables tend to be second-class citizens in my experience. 
See my earlier post about profile activation based on environment 
variables:

http://www.nabble.com/profile-activation-based-on-environment-variables-t2585492s177.html

In addition, looking at the source for ResourcesMojo.java
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?revision=422969&view=markup
we see that there is no mention of environment variables during filtering 
(just system properties and project properties):

	filterProperties = new Properties();
        
        // System properties
        filterProperties.putAll( System.getProperties() );
        
        // Project properties
        filterProperties.putAll( project.getProperties() );

I am not familiar with the maven codebase at all, but I might try my luck 
with figuring this out (when I get some spare time).

Later,
--
Haroon Rafique
<ha...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org