[webbeans-commits] Webbeans SVN: r1688 - in ri/trunk/jboss-tck-runner/src: main/java/org/jboss/webbeans/tck/integration/jbossas/util and 3 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Feb 24 15:47:29 EST 2009
Author: pete.muir at jboss.org
Date: 2009-02-24 15:47:28 -0500 (Tue, 24 Feb 2009)
New Revision: 1688
Added:
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterator.java
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/ResourceLoadingException.java
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/SimpleResourceLoader.java
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/Strings.java
ri/trunk/jboss-tck-runner/src/test/resources/debug/
ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/
ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/web-beans-tck.properties
Modified:
ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java
Log:
Add suitable config for running tests incontainer from an IDE
Modified: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java 2009-02-24 19:59:44 UTC (rev 1687)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/AbstractContainersImpl.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -2,7 +2,6 @@
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
@@ -16,6 +15,7 @@
import org.jboss.jsr299.tck.api.Configurable;
import org.jboss.jsr299.tck.api.Configuration;
import org.jboss.jsr299.tck.spi.Containers;
+import org.jboss.webbeans.tck.integration.jbossas.util.DeploymentProperties;
/**
*
@@ -36,12 +36,19 @@
private static Logger log = Logger.getLogger(AbstractContainersImpl.class);
+ private final DeploymentProperties properties;
+
private Configuration configuration;
protected String jbossHome;
private String jbossHttpUrl;
private boolean jbossWasStarted;
private long bootTimeout;
private String javaOpts;
+
+ public AbstractContainersImpl()
+ {
+ this.properties = new DeploymentProperties();
+ }
protected static void copy(InputStream inputStream, File file) throws IOException
{
@@ -94,9 +101,10 @@
public void setup() throws IOException
{
- if (System.getProperty(JBOSS_AS_DIR_PROPERTY_NAME) != null)
+ String jbossAsPath = properties.getStringValue(JBOSS_AS_DIR_PROPERTY_NAME, "../jboss-as", false);
+ if (jbossAsPath != null)
{
- File jbossAsDir = new File(System.getProperty(JBOSS_AS_DIR_PROPERTY_NAME));
+ File jbossAsDir = new File(jbossAsPath);
if (jbossAsDir.isDirectory())
{
File buildProperties = new File(jbossAsDir, "build.properties");
@@ -111,27 +119,15 @@
}
}
}
- jbossHome = System.getProperty(JBOSS_HOME_PROPERTY_NAME);
- javaOpts = System.getProperty(JAVA_OPTS_PROPERTY_NAME);
- if (javaOpts == null)
- {
- javaOpts = "";
- }
+ jbossHome = properties.getStringValue(JBOSS_HOME_PROPERTY_NAME, null, true);
+ javaOpts = properties.getStringValue(JAVA_OPTS_PROPERTY_NAME, "", false);
javaOpts = javaOpts + JAVA_OPTS;
- if (jbossHome == null)
+ File jbossHomeFile = new File(jbossHome);
+ jbossHome = jbossHomeFile.getPath();
+ log.info("Using JBoss instance in " + jbossHome + " at URL " + configuration.getHost());
+ this.bootTimeout = properties.getLongValue(JBOSS_BOOT_TIMEOUT_PROPERTY_NAME, 240000, false);
+ if (properties.getBooleanValue(FORCE_RESTART_PROPERTY_NAME, false, false))
{
- throw new IllegalArgumentException("-D" + JBOSS_HOME_PROPERTY_NAME + " must be set");
- }
- else
- {
- jbossHome = System.getProperty(JBOSS_HOME_PROPERTY_NAME);
- File jbossHomeFile = new File(jbossHome);
- jbossHome = jbossHomeFile.getPath();
- log.info("Using JBoss instance in " + jbossHome + " at URL " + configuration.getHost());
- }
- this.bootTimeout = Long.getLong(JBOSS_BOOT_TIMEOUT_PROPERTY_NAME, 240000);
- if (Boolean.getBoolean(FORCE_RESTART_PROPERTY_NAME))
- {
if (isJBossUp())
{
log.info("Shutting down JBoss instance as in force-restart mode");
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,233 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+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;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Utility class to load deployment properties
+ *
+ * @author Pete Muir
+ */
+public class DeploymentProperties
+{
+ // The resource bundle used to control Web Beans RI deployment
+ public static final String RESOURCE_BUNDLE = "META-INF/web-beans-tck.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 DeploymentProperties()
+ {
+ 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)
+ {
+ 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 long getLongValue(String propertyName, long _default, boolean required)
+ {
+ return Long.valueOf(getStringValue(propertyName, Long.toString(_default), required)).longValue();
+ }
+
+ 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
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,37 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An Enumeration -> Iteratble 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
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterator.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterator.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterator.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,55 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+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
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/ResourceLoadingException.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/ResourceLoadingException.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/ResourceLoadingException.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,54 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+import javax.inject.ExecutionException;
+
+/**
+ * Exception thrown when errors occur while loading resource
+ *
+ * @author Pete Muir
+ *
+ */
+class ResourceLoadingException extends ExecutionException
+{
+ 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
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/ResourceLoadingException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/SimpleResourceLoader.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/SimpleResourceLoader.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/SimpleResourceLoader.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,43 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+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
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/SimpleResourceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/Strings.java
===================================================================
--- ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/Strings.java (rev 0)
+++ ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/Strings.java 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,30 @@
+package org.jboss.webbeans.tck.integration.jbossas.util;
+
+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;
+ }
+}
Property changes on: ri/trunk/jboss-tck-runner/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/Strings.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/web-beans-tck.properties
===================================================================
--- ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/web-beans-tck.properties (rev 0)
+++ ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/web-beans-tck.properties 2009-02-24 20:47:28 UTC (rev 1688)
@@ -0,0 +1,5 @@
+org.jboss.jsr299.tck.standalone=false
+jboss-as.dir=/Users/pmuir/workspace/webbeans/jboss-as
+jboss.force.restart=false
+org.jboss.jsr299.tck.libraryDirectory=/Users/pmuir/workspace/webbeans/jboss-tck-runner/target/dependency/lib
+org.jboss.jsr299.tck.runIntegrationTests=true
\ No newline at end of file
Property changes on: ri/trunk/jboss-tck-runner/src/test/resources/debug/META-INF/web-beans-tck.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list