You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/04/19 22:42:05 UTC

svn commit: r649848 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/corelib/pages/ main/java/org/apache/tapestry/internal/ main/resources/org/apache/tapestry/corelib/pages/ site/apt/

Author: hlship
Date: Sat Apr 19 13:42:04 2008
New Revision: 649848

URL: http://svn.apache.org/viewvc?rev=649848&view=rev
Log:
TAPESTRY-2231: Make Tapestry release number visible as a symbol ("tapestry.version")

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/ExceptionReport.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/ExceptionReport.tml
    tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java?rev=649848&r1=649847&r2=649848&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryConstants.java Sat Apr 19 13:42:04 2008
@@ -138,6 +138,12 @@
     public static final String FILE_CHECK_UPDATE_TIMEOUT_SYMBOL = "tapestry.file-check-update-timeout";
 
     /**
+     * The version number of the core Tapestry framework, or UNKNOWN if the version number is not available (which
+     * should only occur when developing Tapestry).
+     */
+    public static final String TAPESTRY_VERSION_SYMBOL = "tapestry.version";
+
+    /**
      * The page field persistence strategy that stores data in the session until the next request.
      */
     public static final String FLASH_PERSISTENCE_STRATEGY = "flash";

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/ExceptionReport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/ExceptionReport.java?rev=649848&r1=649847&r2=649848&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/ExceptionReport.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/ExceptionReport.java Sat Apr 19 13:42:04 2008
@@ -19,20 +19,24 @@
 import org.apache.tapestry.annotations.Property;
 import org.apache.tapestry.ioc.annotations.Inject;
 import org.apache.tapestry.ioc.annotations.Symbol;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.apache.tapestry.services.ExceptionReporter;
 import org.apache.tapestry.services.Request;
 import org.apache.tapestry.services.Session;
 
+import java.util.List;
+
 /**
  * Responsible for reporting runtime exceptions. This page is quite verbose and is usually overridden in a production
- * application. When {@link org.apache.tapestry.TapestryConstants#PRODUCTION_MODE_SYMBOL} is "true", it is very
- * abbreviated.
+ * application. When {@link TapestryConstants#PRODUCTION_MODE_SYMBOL} is "true", it is very abbreviated.
  *
  * @see org.apache.tapestry.corelib.components.ExceptionDisplay
  */
 @ContentType("text/html")
 public class ExceptionReport implements ExceptionReporter
 {
+    private static final String PATH_SEPARATOR_PROPERTY = "path.separator";
+
     @Property
     private String _attributeName;
 
@@ -42,12 +46,21 @@
 
     @Inject
     @Symbol(TapestryConstants.PRODUCTION_MODE_SYMBOL)
-    @Property
+    @Property(write = false)
     private boolean _productionMode;
 
-    @Property
+    @Inject
+    @Symbol(TapestryConstants.TAPESTRY_VERSION_SYMBOL)
+    @Property(write = false)
+    private String _tapestryVersion;
+
+    @Property(write = false)
     private Throwable _rootException;
 
+    @Property
+    private String _propertyName;
+    private final String _pathSeparator = System.getProperty(PATH_SEPARATOR_PROPERTY);
+
     public void reportException(Throwable exception)
     {
         _rootException = exception;
@@ -67,4 +80,32 @@
     {
         return getSession().getAttribute(_attributeName);
     }
+
+    /**
+     * Returns a <em>sorted</em> list of system property names.
+     */
+    public List<String> getSystemProperties()
+    {
+        return InternalUtils.sortedKeys(System.getProperties());
+    }
+
+    public String getPropertyValue()
+    {
+        return System.getProperty(_propertyName);
+    }
+
+    public boolean isSimpleProperty()
+    {
+        if (_propertyName.equals(PATH_SEPARATOR_PROPERTY)) return true;
+
+        return !getPropertyValue().contains(_pathSeparator);
+    }
+
+    public String[] getComplexPropertyValue()
+    {
+        // Neither : nor ; is a regexp character.
+
+        return getPropertyValue().split(_pathSeparator);
+    }
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java?rev=649848&r1=649847&r2=649848&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java Sat Apr 19 13:42:04 2008
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry.internal;
 
+import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.ioc.IOCUtilities;
 import org.apache.tapestry.ioc.Registry;
 import org.apache.tapestry.ioc.RegistryBuilder;
@@ -24,6 +25,11 @@
 import org.apache.tapestry.services.Alias;
 import org.apache.tapestry.services.TapestryModule;
 
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
 /**
  * This class is used to build the {@link Registry}. The Registry contains {@link org.apache.tapestry.ioc.services.TapestryIOCModule}
  * and {@link TapestryModule}, any modules identified by {@link #addModules(Class[])} )}, plus the application module.
@@ -136,7 +142,13 @@
                                                                                                _appName),
                                                                                        "before:ServletContext");
 
-        _builder.add(new SyntheticModuleDef(symbolSourceContribution, aliasModeContribution, appNameContribution));
+        ContributionDef versionContribution = new SyntheticSymbolSourceContributionDef("TapestryVersion",
+                                                                                       new SingleKeySymbolProvider(
+                                                                                               TapestryConstants.TAPESTRY_VERSION_SYMBOL,
+                                                                                               readTapestryVersionNumber()));
+
+        _builder.add(new SyntheticModuleDef(symbolSourceContribution, aliasModeContribution, appNameContribution,
+                                            versionContribution));
     }
 
     public Registry getRegistry()
@@ -160,5 +172,41 @@
     public long getStartTime()
     {
         return _startTime;
+    }
+
+    private String readTapestryVersionNumber()
+    {
+        String result = "UNKNOWN";
+
+        InputStream stream = getClass().getResourceAsStream(
+                "META-INF/maven/org.apache.tapestry/tapestry-core/pom.properties");
+
+
+        if (stream != null)
+        {
+            Properties properties = new Properties();
+
+
+            try
+            {
+                stream = new BufferedInputStream(stream);
+
+                properties.load(stream);
+            }
+            catch (IOException ex)
+            {
+                // Just ignore it.
+            }
+
+            String version = properties.getProperty("version");
+
+            // Since the file, if it exists, is created by Maven and will have the key, I can't see
+            // how version would EVER be null, unless there's a problem reading the properties.
+
+            if (version != null) result = version;
+        }
+
+        return result;
+
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/ExceptionReport.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/ExceptionReport.tml?rev=649848&r1=649847&r2=649848&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/ExceptionReport.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/corelib/pages/ExceptionReport.tml Sat Apr 19 13:42:04 2008
@@ -11,6 +11,13 @@
                 <t:exceptiondisplay exception="rootException"/>
 
                 <div class="t-env-data">
+
+                    <h2>Tapestry Framework</h2>
+                    <dl>
+                        <dt>Version</dt>
+                        <dd>${tapestryVersion}</dd>
+                    </dl>
+
                     <h2>Request</h2>
                     <t:renderobject object="request"/>
 
@@ -25,6 +32,26 @@
                             </t:loop>
                         </dl>
                     </t:if>
+
+                    <h2>System Properties</h2>
+                    <dl>
+                        <t:loop source="systemProperties" value="propertyName">
+                            <dt>${propertyName}</dt>
+                            <dd>
+                                <t:if test="simpleProperty">
+                                    ${propertyValue}
+                                    <t:parameter name="else">
+                                        <ul>
+                                            <li t:type="loop" source="complexPropertyValue" value="var:path">
+                                                ${var:path}
+                                            </li>
+                                        </ul>
+                                    </t:parameter>
+                                </t:if>
+                            </dd>
+                        </t:loop>
+                    </dl>
+
                 </div>
             </t:parameter>
         </t:if>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt?rev=649848&r1=649847&r2=649848&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/index.apt Sat Apr 19 13:42:04 2008
@@ -10,6 +10,9 @@
 
 New And Of Note
 
+  * The Exception Report page now identifies the version of the Tapestry framework, and lists
+    out System properties (including the Java classpath).
+
   * The {{{ref/org/apache/tapestry/corelib/components/Grid.html}Grid}} component can now update itself in place,
     using Ajax, when paging or sorting links are clicked.