On Jan 10, 2008 12:14 PM, Maarten Coene <[EMAIL PROTECTED]> wrote:

> Strange,
> I tested it with a sun jdk 1.4.2 (I can't check the patch level from here)
> and it was working ok, so I assumed it would work for all sun 1.4.2 VM's
> :-(

Strange indeed. To be honest I haven't tested it at all, just navigate in
the source from eclipse. But I assume the sources packaged with the jdk are
actually the good sources. BTW since the implementation is most probably OS
dependent, I should add that the source I quote is from sun jdk for windows.
Maybe you ran your test on a different platform?

Xavier


>
> Maarten
>
> ----- Original Message ----
> From: Xavier Hanin <[EMAIL PROTECTED]>
> To: dev@ant.apache.org
> Sent: Thursday, January 10, 2008 11:58:58 AM
> 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/
>
>
> On Jan 9, 2008 10:03 PM, <[EMAIL PROTECTED]> 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/
>
>
>
>
>
>
>  
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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

Reply via email to