Author: hlship
Date: Tue Apr 22 10:08:30 2008
New Revision: 650576
URL: http://svn.apache.org/viewvc?rev=650576&view=rev
Log:
TAPESTRY-2368: The value for the Tapestry version number symbol is not
initialized correctly and is always "UNKNOWN"
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/noversion.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/version.properties
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryUtils.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/TapestryAppInitializer.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/TapestryUtilsTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryUtils.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryUtils.java?rev=650576&r1=650575&r2=650576&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryUtils.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryUtils.java
Tue Apr 22 10:08:30 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -16,8 +16,12 @@
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Collections;
import java.util.List;
+import java.util.Properties;
/**
* Utilities often needed when building Tapestry applications.
@@ -103,5 +107,51 @@
}
return builder.toString();
+ }
+
+ /**
+ * Reads a version number from a properties file on the classpath. These
files are generally created by Maven. For
+ * example, tapestry-core's properties file is
<code>META-INF/maven/org.apache.tapestry/tapestry-core/pom.properties</code>.
+ * The Maven generated properties files include the artifact id and group
id as well as the version.
+ * <p/>
+ * The resource is located using the Thread's context class loader.
+ *
+ * @param resourcePath the complete path to the resource, including a
leading slash.
+ * @return the version number read from the properties file, or "UNKNOWN"
if the version number is not present or
+ * the file can not be opened
+ */
+ public static String readVersionNumber(String resourcePath)
+ {
+ String result = "UNKNOWN";
+
+ InputStream stream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
+ resourcePath);
+
+
+ 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/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=650576&r1=650575&r2=650576&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
Tue Apr 22 10:08:30 2008
@@ -14,7 +14,6 @@
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;
@@ -25,11 +24,6 @@
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 [EMAIL PROTECTED] Registry}. The Registry
contains [EMAIL PROTECTED] org.apache.tapestry.ioc.services.TapestryIOCModule}
* and [EMAIL PROTECTED] TapestryModule}, any modules identified by [EMAIL
PROTECTED] #addModules(Class[])} )}, plus the application module.
@@ -142,13 +136,7 @@
_appName),
"before:ServletContext");
- ContributionDef versionContribution = new
SyntheticSymbolSourceContributionDef("TapestryVersion",
-
new SingleKeySymbolProvider(
-
TapestryConstants.TAPESTRY_VERSION_SYMBOL,
-
readTapestryVersionNumber()));
-
- _builder.add(new SyntheticModuleDef(symbolSourceContribution,
aliasModeContribution, appNameContribution,
- versionContribution));
+ _builder.add(new SyntheticModuleDef(symbolSourceContribution,
aliasModeContribution, appNameContribution));
}
public Registry getRegistry()
@@ -172,41 +160,5 @@
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/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=650576&r1=650575&r2=650576&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
Tue Apr 22 10:08:30 2008
@@ -1779,6 +1779,10 @@
// This should be overridden for particular applications.
configuration.add(TapestryConstants.SUPPORTED_LOCALES_SYMBOL,
"en,it,zh_CN");
+ configuration.add(TapestryConstants.TAPESTRY_VERSION_SYMBOL,
+ TapestryUtils.readVersionNumber(
+
"META-INF/maven/org.apache.tapestry/tapestry-core/pom.properties"));
+
configuration.add("tapestry.default-cookie-max-age", "7 d");
configuration.add("tapestry.start-page-name", "start");
@@ -1864,8 +1868,8 @@
initializer.initializeApplication(context);
-// We don't care about the result, but this forces a load of the service
-// at application startup, rather than on first request.
+ // We don't care about the result, but this forces a load of
the service
+ // at application startup, rather than on first request.
componentClassResolver.isPageName("ForceLoadAtStartup");
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/TapestryUtilsTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/TapestryUtilsTest.java?rev=650576&r1=650575&r2=650576&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/TapestryUtilsTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/TapestryUtilsTest.java
Tue Apr 22 10:08:30 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -34,9 +34,9 @@
{
return new Object[][]
{
- {"Suzy said: \"It's not the proper time\".",
- "'Suzy said: \\\"It\\'s not the proper time\\\".'"},
- {"regexp: \\d{4}", "'regexp: \\\\d{4}'"},
+ { "Suzy said: \"It's not the proper time\".",
+ "'Suzy said: \\\"It\\'s not the proper
time\\\".'" },
+ { "regexp: \\d{4}", "'regexp: \\\\d{4}'" },
};
}
@@ -60,10 +60,29 @@
{
return new Object[][]
{
- {new String[0], ""},
- {new String[]
- {"fred"}, "fred"},
- {new String[]
- {"fred", "barney", "wilma"}, "barney fred
wilma"}};
+ { new String[0], "" },
+ { new String[]
+ { "fred" }, "fred" },
+ { new String[]
+ { "fred", "barney", "wilma" }, "barney fred
wilma" } };
}
+
+ @Test
+ public void read_version_number_missing()
+ {
+
assertEquals(TapestryUtils.readVersionNumber("no-such-file.properties"),
"UNKNOWN");
+ }
+
+ @Test
+ public void read_version_number()
+ {
+
assertEquals(TapestryUtils.readVersionNumber("org/apache/tapestry/version.properties"),
"1.2.3.4");
+ }
+
+ @Test
+ public void read_version_number_no_version_key()
+ {
+
assertEquals(TapestryUtils.readVersionNumber("org/apache/tapestry/noversion.properties"),
"UNKNOWN");
+ }
+
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/noversion.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/noversion.properties?rev=650576&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/noversion.properties
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/noversion.properties
Tue Apr 22 10:08:30 2008
@@ -0,0 +1 @@
+no-version-specified=here
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/version.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/version.properties?rev=650576&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/version.properties
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/version.properties
Tue Apr 22 10:08:30 2008
@@ -0,0 +1 @@
+version=1.2.3.4