felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r805507 - in /felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config: BldProject.java BldProperties.java BldUtil.java
Date Tue, 18 Aug 2009 17:31:56 GMT
Author: dsavage
Date: Tue Aug 18 17:31:55 2009
New Revision: 805507

URL: http://svn.apache.org/viewvc?rev=805507&view=rev
Log:
add support for expanding system properties as well as environment properties in bld files
FELIX-1499

Added:
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java
Modified:
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java?rev=805507&r1=805506&r2=805507&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProject.java Tue Aug
18 17:31:55 2009
@@ -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 ) )
                 {

Added: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java?rev=805507&view=auto
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java (added)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldProperties.java Tue
Aug 18 17:31:55 2009
@@ -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;
+    }
+}

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java?rev=805507&r1=805506&r2=805507&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java (original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/config/BldUtil.java Tue Aug 18
17:31:55 2009
@@ -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() );
+    }    
 }



Mime
View raw message