add support for expanding system properties as well as environment properties in bld files FELIX-1499


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@805507 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java b/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
index 05aaf5c..9b1a445 100644
--- a/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
+++ b/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
@@ -611,18 +611,6 @@
     {
         HashMap<String, Properties> map = new HashMap<String, Properties>();
 
-        final Map<String, String> env = System.getenv();
-        final Properties props = new Properties();
-        try
-        {
-            // supports ${.} and ${..} expansions
-            props.setProperty( ".", resolve( "." ).getCanonicalPath() );
-            props.setProperty( "..", resolve( ".." ).getCanonicalPath() );
-        }
-        catch ( IOException e )
-        {
-        }
-
         for ( String name : config.getList( null, BldConfig.C_REPOSITORIES ) )
         {
             Properties repo = config.getProps( null, name );
@@ -632,13 +620,7 @@
                 String key = ( String ) k;
                 String value = repo.getProperty( key );
 
-                String expand = BldUtil.expand( value, new Properties()
-                {
-                    public String getProperty( String name )
-                    {
-                        return props.getProperty( name, env.get( name ) );
-                    }
-                } );
+                String expand = BldUtil.expand( value, new BldProperties(this));
 
                 if ( !value.equals( expand ) )
                 {
diff --git a/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java b/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java
new file mode 100644
index 0000000..49149cd
--- /dev/null
+++ b/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.config;
+
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+
+public class BldProperties extends Properties
+{
+    private static final long serialVersionUID = 1L;
+    private static final Map<String, String> env = System.getenv();
+    private static final Properties sys = System.getProperties();
+
+    private final BldProject project;
+    private String dot;
+    private String dotdot;
+
+    private static final BldProperties global = new BldProperties();
+
+
+    private BldProperties()
+    {
+        this.project = null;
+    }
+
+
+    BldProperties( BldProject project ) throws NullPointerException
+    {
+        if ( project == null )
+        {
+            throw new NullPointerException();
+        }
+        this.project = project;
+    }
+
+
+    public String getProperty( String key, String defaultValue )
+    {
+        if ( project != null )
+        {
+            try
+            {
+                if ( ".".equals( key ) )
+                {
+                    if ( dot == null )
+                    {
+                        dot = project.resolve( "." ).getCanonicalPath();
+                    }
+                    return dot;
+                }
+                else if ( "..".equals( key ) )
+                {
+                    if ( dotdot == null )
+                    {
+                        dotdot = project.resolve( ".." ).getCanonicalPath();
+                    }
+                    return dotdot;
+                }
+            }
+            catch ( IOException e )
+            {
+                throw new IllegalStateException( e );
+            }
+        }
+
+        String val = sys.getProperty( key, env.get( key ) );
+
+        if ( val == null )
+        {
+            val = defaultValue;
+        }
+
+        return val;
+    }
+
+
+    public String getProperty( String key )
+    {
+        return getProperty( key, null );
+    }
+
+
+    public static Properties global()
+    {
+        return global;
+    }
+}
diff --git a/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java b/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java
index fd02745..bfedb8a 100644
--- a/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java
+++ b/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java
@@ -167,15 +167,6 @@
 
     public static String expand( String s )
     {
-        final Map<String, String> env = System.getenv();
-
-        return expand( s, new Properties()
-        {
-            public String getProperty( String name )
-            {
-                return System.getProperty( name, env.get( name ) );
-            }
-        } );
-    }
-
+        return expand( s, BldProperties.global() );
+    }    
 }