jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Maven 2 & 3
  • MNG-1525

Allow environment variables to be referenced in pom.xml, settings.xml, etc.

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0.1
  • Component/s: None
  • Labels:
    None
  • Environment:
    Red Hat Linux, Java 5, Maven 2
  • Complexity:
    Intermediate

Description

Maven should allow environment variables to be referenced; similar to Java System properties. Ant allows this to be done using the following syntax:

<property environment="env"/>
${env.CATALINA_BASE}

where CATALINA_BASE has been defined like:

export CATALINA_BASE=$HOME/tomcat

In Maven, an example use for signing jars might be:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>${env.KEYSTORE_FILE}</keystore>
<storepass>${env.KEYSTORE_PASS}</storepass>
<alias>${env.KEYSTORE_ALIAS}</alias>
<jarPath>${project.build.directory}/${project.build.finalName}.jar</jarPath>
</configuration>
</plugin>

where KEYSTORE_FILE, KEYSTORE_PASS, and KEYSTORE_ALIAS are environment variables.

It would also be very useful to have environment variables available when defining filter properties files. For instance:

# application.properties
deploy.dir=${env.CATALINA_BASE}/webapps

Environment variables can be referenced in Java like:

Map<String, String> environmentVariables = java.lang.System.getenv();

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    MNG-1525-maven-project.patch
    25/Nov/05 2:11 AM
    2 kB
    Edwin Punzalan

Issue Links

relates to

Bug - A problem which impairs or prevents the functions of the product. MNG-3940 Interpolation of environment variables is not case-insensitive on Windows

  • Minor - Minor loss of function, or other problem where easy workaround is present.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Edwin Punzalan added a comment - 18/Nov/05 2:52 AM

Can you check if Runtime.exec( "set" ) will print the list of environment variables for your OS ? Thanks.

Show
Edwin Punzalan added a comment - 18/Nov/05 2:52 AM Can you check if Runtime.exec( "set" ) will print the list of environment variables for your OS ? Thanks.
Hide
Permalink
Richard Allen added a comment - 18/Nov/05 7:35 AM

No, Runtime.getRuntime().exec("set") does not work on my OS (Red Hat Linux). Java doesn't seem to be able to execute any of the commands that are built into the Bash shell. What would you need to do this for anyway?

Show
Richard Allen added a comment - 18/Nov/05 7:35 AM No, Runtime.getRuntime().exec("set") does not work on my OS (Red Hat Linux). Java doesn't seem to be able to execute any of the commands that are built into the Bash shell. What would you need to do this for anyway?
Hide
Permalink
Edwin Punzalan added a comment - 18/Nov/05 6:01 PM

You see, Maven's minimum JDK requirement is 1.4. And getEnv() in 1.4 is already deprecated.

Right now, I'm adding a method to retrieve the environment variables defined in a machine by executing "cmd /C set" for windows, or (since "set" is not working in your OS) "/usr/bin/printenv" for *NIX machines.

We're still open for suggesstions on how to do this, btw. _

Show
Edwin Punzalan added a comment - 18/Nov/05 6:01 PM You see, Maven's minimum JDK requirement is 1.4. And getEnv() in 1.4 is already deprecated. Right now, I'm adding a method to retrieve the environment variables defined in a machine by executing "cmd /C set" for windows, or (since "set" is not working in your OS) "/usr/bin/printenv" for *NIX machines. We're still open for suggesstions on how to do this, btw. _
Hide
Permalink
Brett Porter added a comment - 18/Nov/05 8:45 PM

Edwin, I think it is ok to use getenv() under 1.4. I'm not sure how well it is supported, but we can aim to replace it with the more robust commons-exec later.

Show
Brett Porter added a comment - 18/Nov/05 8:45 PM Edwin, I think it is ok to use getenv() under 1.4. I'm not sure how well it is supported, but we can aim to replace it with the more robust commons-exec later.
Hide
Permalink
Edwin Punzalan added a comment - 18/Nov/05 8:59 PM

Actually, the process I'm looking at is listing all the environment variables, saving it in a Properties object and then using it for interpolation... very much like the way we used it on System.getProperties(). This way, the method would only address machine specific issues which is not really too many since /usr/bin/printenv is common on *NIX.

getEnv() is usable if I am to read pom.xml and extract all ${env*} in it then add it for interpolation which is not really efficient. Also, not only do I have to read pom.xml but also settings.xml, etc.

Show
Edwin Punzalan added a comment - 18/Nov/05 8:59 PM Actually, the process I'm looking at is listing all the environment variables, saving it in a Properties object and then using it for interpolation... very much like the way we used it on System.getProperties(). This way, the method would only address machine specific issues which is not really too many since /usr/bin/printenv is common on *NIX. getEnv() is usable if I am to read pom.xml and extract all ${env*} in it then add it for interpolation which is not really efficient. Also, not only do I have to read pom.xml but also settings.xml, etc.
Hide
Permalink
Arik Kfir added a comment - 19/Nov/05 8:51 AM

Hi - "System.getenv()" is UNdeprecated under jdk1.5

Show
Arik Kfir added a comment - 19/Nov/05 8:51 AM Hi - "System.getenv()" is UNdeprecated under jdk1.5
Hide
Permalink
Richard Allen added a comment - 21/Nov/05 8:34 AM

I've had good success with having Ant recognize environment variables across three different platforms (Linux, Windows, and OS X) with both Java 1.4 and Java 5. Maybe you should look into how Ant reads environment variables. However, since getEnv() isn't deprecated in Java 5, Sun must plan on keeping it around, so I still think that is a viable option. I appreciate your work on this issue.

Show
Richard Allen added a comment - 21/Nov/05 8:34 AM I've had good success with having Ant recognize environment variables across three different platforms (Linux, Windows, and OS X) with both Java 1.4 and Java 5. Maybe you should look into how Ant reads environment variables. However, since getEnv() isn't deprecated in Java 5, Sun must plan on keeping it around, so I still think that is a viable option. I appreciate your work on this issue.
Hide
Permalink
Brett Porter added a comment - 21/Nov/05 2:36 PM

commons-exec that I mentioned earlier is derived from the Ant code. When released, we can use that, but getenv might be good enough for now.

Show
Brett Porter added a comment - 21/Nov/05 2:36 PM commons-exec that I mentioned earlier is derived from the Ant code. When released, we can use that, but getenv might be good enough for now.
Hide
Permalink
John Allen added a comment - 05/Dec/05 8:04 AM

I guess im going to have to wait for commons-exec as the only way i know of doing this robustly is via JNI (the codeset used by cmd.exe can be any old crap.)

Show
John Allen added a comment - 05/Dec/05 8:04 AM I guess im going to have to wait for commons-exec as the only way i know of doing this robustly is via JNI (the codeset used by cmd.exe can be any old crap.)
Hide
Permalink
John Casey added a comment - 06/Dec/05 10:28 AM

NOT applying this patch. I found a better solution that will factor the interpolation of the POM into a flexible utility in
plexus-utils, and will allow introduction of envar resolution to the POM. It will also make interpolating the settings.xml and profiles.xml using any of a number of expression resolvers (using envar resolution only for now).

BTW, I tried using System.getenv(..) in JDK1.4, and it fails with java.lang.Error and a deprecation message. So, I'm using Edwin's code to extract the envars into a Properties object. We can improve this later.

Show
John Casey added a comment - 06/Dec/05 10:28 AM NOT applying this patch. I found a better solution that will factor the interpolation of the POM into a flexible utility in plexus-utils, and will allow introduction of envar resolution to the POM. It will also make interpolating the settings.xml and profiles.xml using any of a number of expression resolvers (using envar resolution only for now). BTW, I tried using System.getenv(..) in JDK1.4, and it fails with java.lang.Error and a deprecation message. So, I'm using Edwin's code to extract the envars into a Properties object. We can improve this later.

People

  • Assignee:
    John Casey
    Reporter:
    Richard Allen
Vote (2)
Watch (0)

Dates

  • Created:
    11/Nov/05 1:23 PM
    Updated:
    23/Dec/08 11:55 AM
    Resolved:
    06/Dec/05 10:28 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.