You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by dw...@apache.org on 2010/05/11 21:29:22 UTC
svn commit: r943239 - in /incubator/bval/trunk/bval-core: pom.xml
src/main/java/org/apache/bval/util/BeanValidationVersion.java
src/main/java/org/apache/bval/util/PrivilegedActions.java
Author: dwoods
Date: Tue May 11 19:29:21 2010
New Revision: 943239
URL: http://svn.apache.org/viewvc?rev=943239&view=rev
Log:
BVAL-40 Provide a way to display the Bean Validation version being used
Added:
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java (with props)
Modified:
incubator/bval/trunk/bval-core/pom.xml
incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
Modified: incubator/bval/trunk/bval-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/pom.xml?rev=943239&r1=943238&r2=943239&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/pom.xml (original)
+++ incubator/bval/trunk/bval-core/pom.xml Tue May 11 19:29:21 2010
@@ -97,6 +97,59 @@
</extensions>
<plugins>
+ <!--
+ get the svn revision number and project version
+ and set it in a properties file for later retrieval
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>set subversion revision</id>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <property name="tmpdir" value="${java.io.tmpdir}/bvalmvntmp" />
+ <condition property="outdir" value="${project.build.outputDirectory}">
+ <available type="dir" file="${project.build.outputDirectory}" />
+ </condition>
+ <property name="outdir" value="${tmpdir}" />
+ <property name="svnversion.executable" value="svnversion" />
+ <exec outputproperty="subversion.revision" failonerror="false" failifexecutionfails="false" executable="${svnversion.executable}">
+ <arg line="-c ${basedir}/.." />
+ </exec>
+ <property name="subversion.revision" value="unknown" />
+ <echo>Revision: ${subversion.revision}</echo>
+ <echo>Version: ${project.version}</echo>
+ <mkdir dir="${outdir}/META-INF" />
+ <echo file="${outdir}/META-INF/org.apache.bval.revision.properties">
+svn.revision=${subversion.revision}
+project.version=${project.version}
+ </echo>
+ <delete dir="${tmpdir}" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- create mainClass attribute -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.bval.util.BeanValidationVersion</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
+
Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java?rev=943239&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java Tue May 11 19:29:21 2010
@@ -0,0 +1,165 @@
+/*
+ * 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.bval.util;
+
+import java.io.File;
+import java.io.InputStream;
+import java.security.AccessController;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+/**
+ * This class contains version information for Bean Validation.
+ * It uses Ant's filter tokens to convert the template into a java
+ * file with current information.
+ */
+public class BeanValidationVersion {
+
+ public static final String PROJECT_NAME = "Apache Bean Validation";
+ public static final String PROJECT_ID;
+ public static final String VERSION_NUMBER;
+ public static final int MAJOR_RELEASE;
+ public static final int MINOR_RELEASE;
+ public static final int PATCH_RELEASE;
+ public static final String RELEASE_STATUS;
+ public static final String REVISION_NUMBER;
+
+ static {
+ Properties revisionProps = new Properties();
+ try {
+ InputStream in = BeanValidationVersion.class.getResourceAsStream
+ ("/META-INF/org.apache.bval.revision.properties");
+ if (in != null) {
+ try {
+ revisionProps.load(in);
+ } finally {
+ in.close();
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ String vers = revisionProps.getProperty("project.version");
+ if (vers == null || "".equals(vers.trim()))
+ vers = "0.0.0";
+ VERSION_NUMBER = vers;
+
+ StringTokenizer tok = new StringTokenizer(VERSION_NUMBER, ".-");
+ int major, minor, patch;
+ try {
+ major = tok.hasMoreTokens() ? Integer.parseInt(tok.nextToken()) : 0;
+ } catch (Exception e) {
+ major = 0;
+ }
+
+ try {
+ minor = tok.hasMoreTokens() ? Integer.parseInt(tok.nextToken()) : 0;
+ } catch (Exception e) {
+ minor = 0;
+ }
+
+ try {
+ patch = tok.hasMoreTokens() ? Integer.parseInt(tok.nextToken()) : 0;
+ } catch (Exception e) {
+ patch = 0;
+ }
+
+ String revision = revisionProps.getProperty("svn.revision");
+ if (revision == null || "".equals(revision.trim())) {
+ revision = "unknown";
+ } else {
+ tok = new StringTokenizer(revision, ":");
+ String strTok = null;
+ while (tok.hasMoreTokens()) {
+ try {
+ strTok = tok.nextToken();
+ } catch (Exception e) {
+ }
+ }
+ if (strTok != null)
+ revision = strTok;
+ }
+
+ MAJOR_RELEASE = major;
+ MINOR_RELEASE = minor;
+ PATCH_RELEASE = patch;
+ RELEASE_STATUS = tok.hasMoreTokens() ? tok.nextToken("!") : "";
+ REVISION_NUMBER = revision;
+ PROJECT_ID = PROJECT_NAME + " " + VERSION_NUMBER + "-r" + REVISION_NUMBER;
+ }
+
+ public static String getVersion() {
+ return VERSION_NUMBER;
+ }
+
+ public static String getRevision() {
+ return REVISION_NUMBER;
+ }
+
+ public static String getName() {
+ return PROJECT_NAME;
+ }
+
+ public static String getID() {
+ return PROJECT_ID;
+ }
+
+ public static void main(String [] args) {
+ System.out.println(new BeanValidationVersion().toString());
+ }
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder(80 * 40);
+ appendBanner(buf);
+ buf.append("\n");
+
+ appendProperty("os.name", buf).append("\n");
+ appendProperty("os.version", buf).append("\n");
+ appendProperty("os.arch", buf).append("\n\n");
+
+ appendProperty("java.version", buf).append("\n");
+ appendProperty("java.vendor", buf).append("\n\n");
+
+ buf.append("java.class.path:\n");
+ StringTokenizer tok = new StringTokenizer(
+ PrivilegedActions.getProperty("java.class.path"));
+ while (tok.hasMoreTokens()) {
+ buf.append("\t").append(tok.nextToken());
+ buf.append("\n");
+ }
+ buf.append("\n");
+
+ appendProperty("user.dir", buf).append("\n");
+ return buf.toString();
+ }
+
+ private void appendBanner(StringBuilder buf) {
+ buf.append("Project").append(": ").append(getName());
+ buf.append("\n");
+ buf.append("Version").append(": ").append(getVersion());
+ buf.append("\n");
+ buf.append("Revision").append(": ").append(getRevision());
+ buf.append("\n");
+ }
+
+ private StringBuilder appendProperty(String prop, StringBuilder buf) {
+ return buf.append(prop).append(": ").append(
+ PrivilegedActions.getProperty(prop));
+ }
+}
Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/BeanValidationVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java?rev=943239&r1=943238&r2=943239&view=diff
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java (original)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/PrivilegedActions.java Tue May 11 19:29:21 2010
@@ -27,6 +27,45 @@ import java.security.PrivilegedAction;
* Description: utility methods to perform actions with AccessController or without. <br/>
*/
public class PrivilegedActions {
+ private static String lineSeparator = null;
+ private static String pathSeparator = null;
+
+ /**
+ * Return the value of the "line.separator" system property.
+ *
+ * Requires security policy:
+ * 'permission java.util.PropertyPermission "read";'
+ */
+ public static final String getLineSeparator() {
+ if (lineSeparator == null) {
+ lineSeparator =
+ AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("line.separator");
+ }
+ });
+ }
+ return lineSeparator;
+ }
+
+ /**
+ * Return the value of the "path.separator" system property.
+ *
+ * Requires security policy:
+ * 'permission java.util.PropertyPermission "read";'
+ */
+ public static final String getPathSeparator() {
+ if (pathSeparator == null) {
+ pathSeparator =
+ AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("path.separator");
+ }
+ });
+ }
+ return pathSeparator;
+ }
+
/**
* create a new instance.
*
@@ -111,6 +150,16 @@ public class PrivilegedActions {
}
}
+ /**
+ * Return a PrivilegedAction object for clazz.getDeclaredMethod().invoke().
+ *
+ * Requires security policy
+ * 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
+ * 'permission java.lang.reflect.ReflectPermission "suppressAccessChecks";'
+ *
+ * @return Object
+ * @exception IllegalAccessException, InvocationTargetException
+ */
public static Object getAnnotationValue(final Annotation annotation, final String name)
throws IllegalAccessException, InvocationTargetException {
return run(new PrivilegedAction<Object>() {
@@ -132,6 +181,14 @@ public class PrivilegedActions {
});
}
+ /**
+ * Return a PrivilegeAction object for clazz.getClassloader().
+ *
+ * Requires security policy:
+ * 'permission java.lang.RuntimePermission "getClassLoader";'
+ *
+ * @return Classloader
+ */
public static ClassLoader getClassLoader(final Class<?> clazz) {
return run(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
@@ -143,4 +200,22 @@ public class PrivilegedActions {
}
});
}
+
+ /**
+ * Return a PrivilegeAction object for System.getProperty().
+ *
+ * Requires security policy:
+ * 'permission java.util.PropertyPermission "read";'
+ *
+ * @return String
+ */
+ public static final String getProperty(final String name) {
+ return AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty(name);
+ }
+ });
+ }
+
}
+