ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xavier Hanin" <xavier.ha...@gmail.com>
Subject Re: svn commit: r610562 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/core/retrieve/ src/java/org/apache/ivy/core/settings/ test/java/org/apache/ivy/ant/
Date Thu, 10 Jan 2008 10:58:58 GMT
On Jan 9, 2008 10:03 PM, <maartenc@apache.org> wrote:

> Author: maartenc
> Date: Wed Jan  9 13:02:58 2008
> New Revision: 610562
>
> URL: http://svn.apache.org/viewvc?rev=610562&view=rev
> Log:
> NEW: Add support for importing environment variables (IVY-608)

[...]

> Modified:
> ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java
> URL:
> http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java?rev=610562&r1=610561&r2=610562&view=diff
>
> ==============================================================================
> ---
> ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java
> (original)
> +++
> ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java
> Wed Jan  9 13:02:58 2008
> @@ -25,8 +25,17 @@
>
>  public class IvyVariableContainerImpl implements IvyVariableContainer {
>
> -    private HashMap variables = new HashMap();
> +    private Map variables;
> +    private String envPrefix;
>
> +    public IvyVariableContainerImpl() {
> +        this.variables = new HashMap();
> +    }
> +
> +    public IvyVariableContainerImpl(Map variables) {
> +        this.variables = variables;
> +    }
> +
>     /*
>      * (non-Javadoc)
>      *
> @@ -40,21 +49,27 @@
>         } else {
>             Message.debug("'" + varName + "' already set: discarding '" +
> value + "'");
>         }
> -
> +    }
> +
> +    public void setEnvironmentPrefix(String prefix) {
> +        if ((prefix != null) && !prefix.endsWith(".")) {
> +            this.envPrefix = prefix + ".";
> +        } else {
> +            this.envPrefix = prefix;
> +        }
>     }
>
>     private String substitute(String value) {
> -        return IvyPatternHelper.substituteVariables(value,
> getVariables());
> +        return IvyPatternHelper.substituteVariables(value, this);
>     }
>
> -    /*
> -     * (non-Javadoc)
> -     *
> -     * @see
> org.apache.ivy.core.settings.IvyVariableContainer#getVariables()
> -     */
> -    public Map getVariables() {
> +    protected Map getVariables() {
>         return variables;
>     }
> +
> +    protected String getEnvironmentPrefix() {
> +        return envPrefix;
> +    }
>
>     /*
>      * (non-Javadoc)
> @@ -62,8 +77,14 @@
>      * @see org.apache.ivy.core.settings.IvyVariableContainer#getVariable(
> java.lang.String)
>      */
>     public String getVariable(String name) {
> -        String val = (String) variables.get(name);
> -        return val == null ? val : substitute(val);
> +        String val = null;
> +        if ((envPrefix != null) && name.startsWith(envPrefix)) {
> +            val = System.getenv(name.substring(envPrefix.length()));

I think System.getenv behavior is very jre dependent. Here is the
implementation in sun JDK 1.4.2_13:
    public static String getenv(String name) {
    throw new Error("getenv no longer supported, use properties and -D
instead: " + name);
    }

This won't really help the user :-) So maybe we could surround the call with
a try catch (catching Error or even Throwable, too bad they didn't use a
more specific throwable, we may catch OutOfMemoryError here :-( ) and
reporting the problem to the user in a more friendly way like "Impossible to
use Ivy environment prefix: System.getenv(String) doesn't seem to be
supported on your platform" and chaining the original Throwable.

Then in the documentation we could report that environmentPrefix is
supported only in Ant or with JRE supporting System.getenv(String) (i.e. >=
1.5.0 from what I know).

Xavier

-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message