[hibernate-commits] Hibernate SVN: r15981 - in validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck: config and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 17 02:55:44 EST 2009


Author: shane.bryzak at jboss.com
Date: 2009-02-17 02:55:44 -0500 (Tue, 17 Feb 2009)
New Revision: 15981

Added:
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterable.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterator.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/ResourceLoadingException.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/RuntimeProperties.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/SimpleResourceLoader.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/Strings.java
Modified:
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
Log:
support for fisheye and svn urls

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterable.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterable.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterable.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,37 @@
+package org.hibernate.tck.config;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An Enumeration -> Iterable adaptor
+ *  
+ * @author Pete Muir
+ * @see org.jboss.webbeans.util.EnumerationIterator
+ */
+class EnumerationIterable<T> implements Iterable<T>
+{
+   // The enumeration-iteartor
+   private EnumerationIterator<T> iterator;
+   
+   /**
+    * Constructor
+    * 
+    * @param enumeration The enumeration
+    */
+   public EnumerationIterable(Enumeration<T> enumeration)
+   {
+      this.iterator = new EnumerationIterator<T>(enumeration);
+   }
+   
+   /**
+    * Gets an iterator
+    * 
+    * @return The iterator
+    */
+   public Iterator<T> iterator()
+   {
+      return iterator;
+   }
+   
+}
\ No newline at end of file

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterator.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterator.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/EnumerationIterator.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,55 @@
+package org.hibernate.tck.config;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An enumeration -> iterator adapter
+ *  
+ * @author Pete Muir
+ */
+ at SuppressWarnings("unchecked")
+class EnumerationIterator<T> implements Iterator<T>
+{
+   // The enumeration
+   private Enumeration e;
+
+   /**
+    * Constructor
+    * 
+    * @param e The enumeration
+    */
+   public EnumerationIterator(Enumeration e)
+   {
+      this.e = e;
+   }
+
+   /**
+    * Indicates if there are more items to iterate
+    * 
+    * @return True if more, false otherwise
+    */
+   public boolean hasNext()
+   {
+      return e.hasMoreElements();
+   }
+
+   /**
+    * Gets the next item
+    * 
+    * @return The next items
+    */
+   public T next()
+   {
+      return (T) e.nextElement();
+   }
+
+   /**
+    * Removes an item. Not supported
+    */
+   public void remove()
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+}
\ No newline at end of file

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/ResourceLoadingException.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/ResourceLoadingException.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/ResourceLoadingException.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,52 @@
+package org.hibernate.tck.config;
+
+/**
+ * Exception thrown when errors occur while loading resource
+ * 
+ * @author Pete Muir
+ *
+ */
+class ResourceLoadingException extends RuntimeException
+{
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * Constructor
+    */
+   public ResourceLoadingException()
+   {
+      super();
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param message The message
+    * @param throwable The exception
+    */
+   public ResourceLoadingException(String message, Throwable throwable)
+   {
+      super(message, throwable);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param message The message
+    */
+   public ResourceLoadingException(String message)
+   {
+      super(message);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param throwable The exception
+    */
+   public ResourceLoadingException(Throwable throwable)
+   {
+      super(throwable);
+   }
+   
+}
\ No newline at end of file

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/RuntimeProperties.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/RuntimeProperties.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/RuntimeProperties.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,232 @@
+package org.hibernate.tck.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * Utility class to load deployment properties
+ * 
+ * @author Pete Muir
+ */
+public class RuntimeProperties
+{
+   // The resource bundle used to control tck unit runtime properties
+   public static final String RESOURCE_BUNDLE = "META-INF/tck-unit.properties";
+   
+   //private static final Logger log = Logger.getLogger(DeploymentProperties.class);
+   
+   // The class to work from
+   private SimpleResourceLoader resourceLoader;
+
+   /**
+    * Constructor
+    * 
+    * @param classLoader The classloader to work on
+    */
+   public RuntimeProperties()
+   {
+      this.resourceLoader = new SimpleResourceLoader();
+   }
+
+   /**
+    * Get a list of possible values for a given key.
+    * 
+    * First, System properties are tried, followed by the specified resource
+    * bundle (first in classpath only).
+    * 
+    * @param key The key to search for
+    * @return A list of possible values. An empty list is returned if there are
+    *         no matches.
+    */
+   public List<String> getPropertyValues(String key)
+   {
+      List<String> values = new ArrayList<String>();
+      addPropertiesFromSystem(key, values);
+      addPropertiesFromResourceBundle(key, values);
+      return values;
+   }
+
+   /**
+    * Adds matches from system properties
+    * 
+    * @param key The key to match
+    * @param values The currently found values
+    */
+   private void addPropertiesFromSystem(String key, List<String> values)
+   {
+      addProperty(key, System.getProperty(key), values);
+   }
+
+   /**
+    * Adds matches from detected resource bundles
+    * 
+    * @param key The key to match
+    * @param values The currently found values
+    */
+   private void addPropertiesFromResourceBundle(String key, List<String> values)
+   {
+      try
+      {
+         for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE))
+         {
+            Properties properties = new Properties();
+            InputStream propertyStream = url.openStream();
+            try
+            {
+               properties.load(propertyStream);
+               addProperty(key, properties.getProperty(key), values);
+            }
+            finally
+            {
+               if (propertyStream != null)
+               {
+                  propertyStream.close();
+               }
+            }
+         }
+      }
+      catch (IOException e)
+      {
+         // No - op, file is optional
+      }
+   }
+
+   /**
+    * Add the property to the set of properties only if it hasn't already been
+    * added
+    * 
+    * @param key The key searched for
+    * @param value The value of the property
+    * @param values The currently found values
+    */
+   private void addProperty(String key, String value, List<String> values)
+   {
+      if (value != null)
+      {
+         //String[] properties = Strings.split(value, "[^\\]:");
+         //for (String property : properties)
+         //{
+            //values.add(property);
+         //}
+         values.add(value);
+
+      }
+   }
+   
+   /**
+    * Gets the possible implementation class for a given property for which the
+    * values are classanames
+    * 
+    * @param deploymentProperties The deployment properties object to use
+    * @param resourceLoader The resource laoder to use to attempt
+    * @param propertyName The name of the property to load
+    * @return A set of classes specified
+    */
+   @SuppressWarnings("unchecked")
+   public <T> Set<Class<T>> getClasses(String propertyName, Class<T> expectedType)
+   {
+      Set<Class<T>> classes = new HashSet<Class<T>>();
+      for (String className : getPropertyValues(propertyName))
+      {
+         try
+         {
+            classes.add((Class<T>) resourceLoader.classForName(className));
+         }
+         catch (ResourceLoadingException e)
+         {
+            //log.debug("Unable to load class " + className + " for property " + propertyName, e);
+         }
+      }
+      return classes;
+   }
+   
+   public <T> Class<T> getClassValue(String propertyName, Class<T> expectedType, boolean required)
+   {
+      Set<Class<T>> classes = getClasses(propertyName, expectedType);
+      if (classes.size() == 0)
+      {
+         if (required)
+         {
+            throw new IllegalArgumentException("Cannot find any implementations of " + expectedType.getSimpleName() + ", check that " + propertyName + " is specified");
+         }
+         else
+         {
+            return null;
+         }
+      }
+      else if (classes.size() > 1)
+      {
+         throw new IllegalArgumentException("More than one implementation of " + expectedType.getSimpleName() + " specified by " + propertyName + ", not sure which one to use!");
+      }
+      else
+      {
+         return classes.iterator().next(); 
+      }
+   }
+   
+   public <T> T getInstanceValue(String propertyName, Class<T> expectedType, boolean required)
+   {
+      Class<T> clazz = getClassValue(propertyName, expectedType, required);
+      if (clazz != null)
+      {
+         try
+         {
+            return clazz.newInstance();
+         }
+         catch (InstantiationException e)
+         {
+            throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e);
+         }
+         catch (IllegalAccessException e)
+         {
+            throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e);
+         }
+      }
+      else
+      {
+         return null;
+      }
+   }
+   
+   public boolean getBooleanValue(String propertyName, boolean _default, boolean required)
+   {
+      return Boolean.valueOf(getStringValue(propertyName, _default ? "true" : "false", required));
+   }
+   
+   public int getIntValue(String propertyName, int _default, boolean required)
+   {
+      return Integer.valueOf(getStringValue(propertyName, Integer.toString(_default), required)).intValue();
+   }
+   
+   public String getStringValue(String propertyName, String _default, boolean required)
+   {
+      List<String> values = getPropertyValues(propertyName);
+      
+      if (values.size() == 0)
+      {
+         if (required)
+         {
+            throw new IllegalArgumentException("Cannot find required property " + propertyName + ", check that it is specified");
+         }
+         else
+         {
+            return _default;
+         }
+      }
+      else if (values.size() > 1)
+      {
+         throw new IllegalArgumentException("More than one value given for " + propertyName + ", not sure which one to use!");
+      }
+      else
+      {
+         return values.iterator().next();
+      }
+   }
+
+}
\ No newline at end of file

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/SimpleResourceLoader.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/SimpleResourceLoader.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/SimpleResourceLoader.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,43 @@
+package org.hibernate.tck.config;
+
+import java.io.IOException;
+import java.net.URL;
+
+class SimpleResourceLoader
+{
+   
+   public Class<?> classForName(String name)
+   {
+      
+      try
+      {
+         return Class.forName(name);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+      catch (NoClassDefFoundError e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+   }
+   
+   public URL getResource(String name)
+   {
+      return getClass().getResource(name);
+   }
+   
+   public Iterable<URL> getResources(String name)
+   {
+      try
+      {
+         return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+      }
+      catch (IOException e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+   }
+   
+}
\ No newline at end of file

Added: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/Strings.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/Strings.java	                        (rev 0)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/config/Strings.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -0,0 +1,30 @@
+package org.hibernate.tck.config;
+
+import java.util.StringTokenizer;
+
+public class Strings
+{
+   static String[] split(String strings, String delims)
+   {
+      if (strings == null)
+      {
+         return new String[0];
+      }
+      else
+      {
+         StringTokenizer tokens = new StringTokenizer(strings, delims);
+         String[] result = new String[tokens.countTokens()];
+         int i = 0;
+         while (tokens.hasMoreTokens())
+         {
+            result[i++] = tokens.nextToken();
+         }
+         return result;
+      }
+   }
+   
+   public static boolean isEmpty(String string)
+   {
+      return string == null || string.length() == 0;
+   }
+}

Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java	2009-02-17 06:20:23 UTC (rev 15980)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -106,7 +106,7 @@
         if (baseDirName == null) {
             baseDirName = getCurrentWorkingDirectory() + "target";
            System.out.println(
-                    "No output directory specided using " + baseDirName + " instead."
+                    "No output directory specified, using " + baseDirName + " instead."
             );
         }
         else
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java	2009-02-17 06:20:23 UTC (rev 15980)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java	2009-02-17 07:55:44 UTC (rev 15981)
@@ -9,18 +9,31 @@
 import java.util.List;
 import java.util.Map;
 
+import org.hibernate.tck.config.RuntimeProperties;
+
 /**
  * Generates the TCK spec coverage report
  *
  * @author Shane Bryzak
  */
 public class CoverageReport {
+   
+   public static final String FISHEYE_BASE_URL_PROPERTY = "fisheye_base_url";
+   
+   public static final String SVN_BASE_URL_PROPERTY = "svn_base_url";
+   
     /*
     * References to the spec assertions made by the tck tests
     */
     private final Map<String, List<SpecReference>> references;
 
     private AuditParser auditParser;
+    
+    private RuntimeProperties properties;
+    
+    private String fisheyeBaseUrl = null;
+    
+    private String svnBaseUrl = null;
 
     public CoverageReport(List<SpecReference> references, AuditParser auditParser) {
         this.references = new HashMap<String, List<SpecReference>>();
@@ -34,6 +47,29 @@
         }
 
         this.auditParser = auditParser;
+        
+        this.properties = new RuntimeProperties();
+        
+        try
+        {
+           fisheyeBaseUrl = this.properties.getStringValue(FISHEYE_BASE_URL_PROPERTY, null, false);
+           
+           if (!fisheyeBaseUrl.endsWith("/"))
+           {
+              fisheyeBaseUrl = fisheyeBaseUrl + "/";
+           }
+           
+           svnBaseUrl = this.properties.getStringValue(SVN_BASE_URL_PROPERTY, null, false);
+           
+           if (!svnBaseUrl.endsWith("/"))
+           {
+              svnBaseUrl = svnBaseUrl + "/";
+           }
+        }
+        catch (Exception ex)
+        {
+           // swallow
+        }        
     }
 
     public void generate(OutputStream out) throws IOException {
@@ -62,6 +98,14 @@
         sb.append("    width: 50px;\n");
         sb.append("    margin-top: 0px;\n");
         sb.append("    height: 100%; }\n");
+        sb.append("   a.external, a.external:visited, a.external:hover {\n");
+        sb.append("    color: #0000ff;\n");
+        sb.append("    font-size: 9px;\n");
+        sb.append("    font-style: normal;\n");
+        sb.append("    padding-left: 2px;\n");
+        sb.append("    margin-left: 6px;\n");
+        sb.append("    margin-right: 6px;\n");
+        sb.append("    padding-right: 2px; }\n");       
         sb.append("  .results {\n");
         sb.append("    margin-left: 50px; }\n");
         sb.append("  .description {\n");
@@ -106,6 +150,8 @@
 
     private void writeCoverage(OutputStream out) throws IOException {
        
+        out.write("<h3>Coverage Detail</h3>\n".getBytes());
+       
         for (String sectionId : auditParser.getSectionIds()) {
 
             List<AuditAssertion> sectionAssertions = auditParser.getAssertionsForSection(sectionId);
@@ -153,6 +199,34 @@
                             sb.append(".");
                             sb.append(ref.getMethodName());
                             sb.append("()");
+                            
+                            if (fisheyeBaseUrl != null)
+                            {                               
+                               sb.append("<a class=\"external\" target=\"_blank\" href=\"");
+                               sb.append(fisheyeBaseUrl);
+                               sb.append(currentPackageName.replace('.', '/'));
+                               sb.append("/");
+                               sb.append(ref.getClassName());
+                               sb.append(".java");
+                               sb.append("\">fisheye</a>");
+                            }
+                            
+                            if (svnBaseUrl != null)
+                            {
+                               if (fisheyeBaseUrl != null)
+                               {
+                                  sb.append("|");                                  
+                               }
+                               
+                               sb.append("<a class=\"external\" target=\"_blank\" href=\"");
+                               sb.append(svnBaseUrl);
+                               sb.append(currentPackageName.replace('.', '/'));
+                               sb.append("/");
+                               sb.append(ref.getClassName());
+                               sb.append(".java");
+                               sb.append("\">svn</a>");                               
+                            }
+                            
                             sb.append("</div>\n");
                         }
                     }




More information about the hibernate-commits mailing list