tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1181898 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/ tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ tapestr...
Date Tue, 11 Oct 2011 17:17:59 GMT
Author: hlship
Date: Tue Oct 11 17:17:58 2011
New Revision: 1181898

URL: http://svn.apache.org/viewvc?rev=1181898&view=rev
Log:
TAP5-1688: Tapestry should expose environment variables as symbols

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/SystemEnvSymbolProvider.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/SystemEnvSymbolProviderTest.groovy
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java?rev=1181898&r1=1181897&r2=1181898&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryAppInitializer.java
Tue Oct 11 17:17:58 2011
@@ -184,7 +184,7 @@ public class TapestryAppInitializer
                 new SingleKeySymbolProvider(InternalSymbols.APP_PACKAGE_PATH, appPackage.replace('.',
'/')));
 
         ContributionDef symbolSourceContribution = new SyntheticSymbolSourceContributionDef("ServletContext",
-                appProvider, "before:ApplicationDefaults");
+                appProvider, "before:ApplicationDefaults", "after:EnvironmentVariables");
 
         ContributionDef appNameContribution = new SyntheticSymbolSourceContributionDef("AppName",
                 new SingleKeySymbolProvider(InternalSymbols.APP_NAME, appName), "before:ServletContext");
@@ -249,13 +249,17 @@ public class TapestryAppInitializer
                 registryCreatedTime - startTime,
                 toFinish - startTime);
 
+        String version = source.valueForSymbol(SymbolConstants.TAPESTRY_VERSION);
+        boolean productionMode = Boolean.parseBoolean(source.valueForSymbol(SymbolConstants.PRODUCTION_MODE));
+
 
         buffer.append("\n\n");
         buffer.append(" ______                  __             ____\n");
         buffer.append("/_  __/__ ____  ___ ___ / /_______ __  / __/\n");
         buffer.append(" / / / _ `/ _ \\/ -_|_-</ __/ __/ // / /__ \\ \n");
         buffer.append("/_/  \\_,_/ .__/\\__/___/\\__/_/  \\_, / /____/\n");
-        f.format("        /_/                   /___/  %s\n\n", source.valueForSymbol(SymbolConstants.TAPESTRY_VERSION));
+        f.format("        /_/                   /___/  %s%s\n\n",
+                version, productionMode ? "" : " (development mode)");
 
         logger.info(buffer.toString());
     }

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/SystemEnvSymbolProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/SystemEnvSymbolProvider.java?rev=1181898&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/SystemEnvSymbolProvider.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/SystemEnvSymbolProvider.java
Tue Oct 11 17:17:58 2011
@@ -0,0 +1,47 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.internal.services;
+
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.SymbolProvider;
+
+import java.util.Map;
+
+/**
+ * Provides <em>case insensitive</em> access to  environment variables. Environment
variable symbols
+ * are prefixed with "env.".
+ *
+ * @since 5.3
+ */
+public class SystemEnvSymbolProvider implements SymbolProvider
+{
+    private final Map<String, String> symbols = CollectionFactory.newCaseInsensitiveMap();
+
+    public synchronized String valueForSymbol(String symbolName)
+    {
+        if (symbols.isEmpty())
+        {
+            Map<String, String> env = System.getenv();
+
+            for (String key : env.keySet())
+            {
+                symbols.put("env." + key, env.get(key));
+            }
+        }
+
+
+        return symbols.get(symbolName);
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1181898&r1=1181897&r2=1181898&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
Tue Oct 11 17:17:58 2011
@@ -451,6 +451,18 @@ public final class TapestryIOCModule
         configuration.add(tuple);
     }
 
+    /**
+     * <dl>
+     * <dt>SystemProperties</dt>
+     * <dd>Exposes JVM System properties as symbols (currently case-sensitive)</dd>
+     * <dt>EnvironmentVariables</dt>
+     * <dd>Exposes environment variables as symbols (adding a "env." prefix)</dd>
+     * <dt>ApplicationDefaults</dt>
+     * <dd>Values contributed to @{@link SymbolProvider} @{@link ApplicationDefaults}</dd>
+     * <dt>FactoryDefaults</dt>
+     * <dd>Values contributed to @{@link SymbolProvider} @{@link FactoryDefaults}</dd>
+     * </dl>
+     */
     @Contribute(SymbolSource.class)
     public static void setupStandardSymbolProviders(OrderedConfiguration<SymbolProvider>
configuration,
                                                     @ApplicationDefaults
@@ -460,8 +472,9 @@ public final class TapestryIOCModule
                                                     SymbolProvider factoryDefaults)
     {
         configuration.add("SystemProperties", new SystemPropertiesSymbolProvider(), "before:*");
-        configuration.add("ApplicationDefaults", applicationDefaults, "after:SystemProperties");
-        configuration.add("FactoryDefaults", factoryDefaults, "after:ApplicationDefaults");
+        configuration.add("EnvironmentVariables", new SystemEnvSymbolProvider());
+        configuration.add("ApplicationDefaults", applicationDefaults);
+        configuration.add("FactoryDefaults", factoryDefaults);
     }
 
     public static ParallelExecutor buildDeferredExecution(@Symbol(IOCSymbols.THREAD_POOL_CORE_SIZE)

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/SystemEnvSymbolProviderTest.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/SystemEnvSymbolProviderTest.groovy?rev=1181898&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/SystemEnvSymbolProviderTest.groovy
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/groovy/org/apache/tapestry/ioc/services/SystemEnvSymbolProviderTest.groovy
Tue Oct 11 17:17:58 2011
@@ -0,0 +1,38 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry.ioc.services
+
+import org.apache.tapestry5.ioc.internal.services.SystemEnvSymbolProvider
+import org.apache.tapestry5.ioc.services.SymbolProvider
+import org.apache.tapestry5.ioc.test.IOCTestCase
+import org.testng.annotations.Test
+
+class SystemEnvSymbolProviderTest extends IOCTestCase
+{
+
+    SymbolProvider provider = new SystemEnvSymbolProvider()
+
+    @Test
+    void key_exists()
+    {
+        assert provider.valueForSymbol("env.home") == System.getenv("HOME")
+    }
+
+    @Test
+    void key_missing()
+    {
+        assert provider.valueForSymbol("env.does-not-exist") == null
+    }
+}



Mime
View raw message