Author: nbelaevski
Date: 2010-06-01 16:36:23 -0400 (Tue, 01 Jun 2010)
New Revision: 17455
Modified:
root/core/trunk/impl/pom.xml
root/core/trunk/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
root/core/trunk/impl/src/main/java/org/richfaces/VersionBean.java
Log:
https://jira.jboss.org/browse/RFPL-609
Modified: root/core/trunk/impl/pom.xml
===================================================================
--- root/core/trunk/impl/pom.xml 2010-06-01 20:07:44 UTC (rev 17454)
+++ root/core/trunk/impl/pom.xml 2010-06-01 20:36:23 UTC (rev 17455)
@@ -151,6 +151,36 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>buildnumber-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <doCheck>false</doCheck>
+ <doUpdate>false</doUpdate>
+ <revisionOnScmFailure>unknown</revisionOnScmFailure>
+ <timestampFormat>{0,date,MM/dd/yyyy h:mm:ss a}</timestampFormat>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <SCM-Revision>${buildNumber}</SCM-Revision>
+ <SCM-Timestamp>${timestamp}</SCM-Timestamp>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
</plugins>
</build>
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2010-06-01 20:07:44
UTC (rev 17454)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2010-06-01 20:36:23
UTC (rev 17455)
@@ -21,18 +21,19 @@
package org.ajax4jsf.webapp;
+import java.io.Serializable;
+
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
import org.ajax4jsf.config.WebXMLParser;
import org.richfaces.VersionBean;
import org.richfaces.VersionBean.Version;
import org.richfaces.log.RichfacesLogger;
import org.slf4j.Logger;
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import java.io.Serializable;
-
/**
* Parse at startup application web.xml and store servlet and filter mappings.
* at runtime, used for convert resource key to uri, and vice versa.
@@ -58,7 +59,7 @@
static {
VersionBean versionBean = new VersionBean();
Version version = versionBean.getVersion();
- String suffix = "/" + version.getMajor() + "_" +
version.getMinor() + "_" + version.getRevision();
+ String suffix = "/" + version.getResourceVersion();
// that's to prevent static compile-time linkage to constant values
RESOURCE_URI_PREFIX_VERSIONED = RESOURCE_URI_PREFIX + suffix;
Modified: root/core/trunk/impl/src/main/java/org/richfaces/VersionBean.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/VersionBean.java 2010-06-01 20:07:44
UTC (rev 17454)
+++ root/core/trunk/impl/src/main/java/org/richfaces/VersionBean.java 2010-06-01 20:36:23
UTC (rev 17455)
@@ -21,83 +21,207 @@
package org.richfaces;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.CodeSource;
+import java.security.ProtectionDomain;
+import java.text.MessageFormat;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.richfaces.log.RichfacesLogger;
+
/**
* Vendor and version information for A4J project
*
* @author asmirnov(a)exadel.com (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class VersionBean {
- public static final int MAJOR_VERSION = 4;
- public static final int MINOR_VERSION = 0;
- public static final String PROJECT_NAME = "Jboss Richfaces";
-
+public final class VersionBean {
+
+ private static final org.slf4j.Logger LOGGER =
RichfacesLogger.APPLICATION.getLogger();
+
/**
- * Revision version, must be auto modified by CVS
- */
- public static final String REVISION = "0-SNAPSHOT";
-
- /**
- * $Revision$ $Date$";
- */
- public static final String SCM_REVISION =
- " SVN $Revision$ $Date$";
- public static final String VENDOR = "richfaces.org";
- public static final Version VERSION = new Version();
-
- public String getVendor() {
- return VENDOR;
- }
-
- public Version getVersion() {
- return VERSION;
- }
-
- public String getProjectName() {
- return PROJECT_NAME;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
-
- // TODO Auto-generated method stub
- return getProjectName() + " by " + getVendor() + ", version "
+ getVersion().toString();
- }
-
- /**
* Class for incapsulate version info.
*
* @author asmirnov(a)exadel.com (latest modification by $Author$)
* @version $Revision$ $Date$
*/
public static class Version {
- public static final String VERSION_INFO = "v." + MAJOR_VERSION +
'.' + MINOR_VERSION + '.' + REVISION
- + SCM_REVISION;
- public static final String RESOURCE_VERSION_INFO = MAJOR_VERSION + "_"
+ MINOR_VERSION + "_" + REVISION;
+
+ private static final String UNKNOWN = "";
+
+ private String implementationVendor = UNKNOWN;
- public int getMajor() {
- return MAJOR_VERSION;
+ //TODO nick - default value for manifest file absense - review
+ private String implementationVersion = "4.0.0-SNAPSHOT";
+
+ private String implementationTitle = UNKNOWN;
+
+ private String scmRevision = UNKNOWN;
+
+ private String scmTimestamp = UNKNOWN;
+
+ private String fullVersionString = UNKNOWN;
+
+ private String resourceVersion = UNKNOWN;
+
+ private boolean containsDataFromManifest = false;
+
+ public Version() {
+ initialize();
}
+
+ private String getAttributeValueOrDefault(Attributes attributes, String name) {
+ String value = attributes.getValue(name);
+ if (value == null) {
+ value = UNKNOWN;
+ }
+
+ return value;
+ }
+
+ private void initialize() {
+ Manifest manifest = null;
+ try {
+ manifest = readManifest();
+ } catch (Exception e) {
+ LOGGER.error(MessageFormat.format("Error reading project metadata:
{0}", e.getMessage()), e);
+ }
+
+ if (manifest != null) {
+ initializePropertiesFromManifest(manifest);
+ initializeDerivativeProperties();
+ }
+ }
- public int getMinor() {
- return MINOR_VERSION;
+ private void initializePropertiesFromManifest(Manifest manifest) {
+ containsDataFromManifest = true;
+
+ Attributes attributes = manifest.getMainAttributes();
+ implementationVendor = getAttributeValueOrDefault(attributes,
"Implementation-Vendor");
+ implementationVersion = getAttributeValueOrDefault(attributes,
"Implementation-Version");
+ implementationTitle = getAttributeValueOrDefault(attributes,
"Implementation-Title");
+ scmRevision = getAttributeValueOrDefault(attributes,
"SCM-Revision");
+ scmTimestamp = getAttributeValueOrDefault(attributes,
"SCM-Timestamp");
}
+ private void initializeDerivativeProperties() {
+ fullVersionString = MessageFormat.format("v.{0} SVN r.{1}",
implementationVersion, scmRevision);
+ resourceVersion = implementationVersion.replace('.', '_') +
"_" + scmRevision;
+ }
+
+ private Manifest readManifest() {
+ ProtectionDomain domain = VersionBean.class.getProtectionDomain();
+ if (domain != null) {
+ CodeSource codeSource = domain.getCodeSource();
+ if (codeSource != null) {
+ URL url = codeSource.getLocation();
+ if (url != null) {
+ JarInputStream jis = null;
+ try {
+ URLConnection urlConnection = url.openConnection();
+ urlConnection.setUseCaches(false);
+
+ if (urlConnection instanceof JarURLConnection) {
+ JarURLConnection jarUrlConnection = (JarURLConnection)
urlConnection;
+ return jarUrlConnection.getManifest();
+ } else {
+ jis = new
JarInputStream(urlConnection.getInputStream());
+ return jis.getManifest();
+ }
+ } catch (IOException e) {
+ LOGGER.error(MessageFormat.format("Error reading
META-INF/MANIFEST.MF file: {0}", e.getMessage()), e);
+ } finally {
+ if (jis != null) {
+ try {
+ jis.close();
+ } catch (IOException e) {
+ LOGGER.error(MessageFormat.format("Error closing
stream: {0}", e.getMessage()), e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ boolean containsDataFromManifest() {
+ return containsDataFromManifest;
+ }
+
public String getRevision() {
- return REVISION;
+ return scmRevision;
}
+ public String getVersion() {
+ return fullVersionString;
+ }
+
public String getResourceVersion() {
- return RESOURCE_VERSION_INFO;
+ return resourceVersion;
}
+ public String getImplementationTitle() {
+ return implementationTitle;
+ }
+
+ public String getImplementationVendor() {
+ return implementationVendor;
+ }
+
+ public String getImplementationVersion() {
+ return implementationVersion;
+ }
+
+ public String getScmRevision() {
+ return scmRevision;
+ }
+
+ public String getScmTimestamp() {
+ return scmTimestamp;
+ }
+
@Override
public String toString() {
- return VERSION_INFO;
+ return getVersion();
}
}
+
+ public static final Version VERSION = new Version();
+
+ public String getVendor() {
+ return VERSION.getImplementationVendor();
+ }
+
+ public String getTitle() {
+ return VERSION.getImplementationTitle();
+ }
+
+ public String getRevision() {
+ return VERSION.getScmRevision();
+ }
+
+ public String getTimestamp() {
+ return VERSION.getScmTimestamp();
+ }
+
+ public Version getVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public String toString() {
+ if (VERSION.containsDataFromManifest()) {
+ return getTitle() + " by " + getVendor() + ", version " +
VERSION.toString();
+ } else {
+ return VERSION.toString();
+ }
+ }
+
}