You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/08/12 17:23:08 UTC
svn commit: r232310 [72/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateConfiguration.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateConfiguration.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateConfiguration.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateConfiguration.java Fri Aug 12 08:12:28 2005
@@ -1,263 +1,263 @@
-package org.apache.beehive.test.tools.tch.extension.update;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.PropertyNames;
-import org.apache.beehive.test.tools.tch.util.GeneralUtil;
-import org.apache.beehive.test.tools.tch.util.ValueHandler;
-import org.apache.beehive.test.tools.tch.util.xml.DomUtils;
-import org.apache.beehive.test.tools.tch.util.xml.DynamicPropNodeVisitor;
-import org.apache.beehive.test.tools.tch.util.xml.NestedXMLProcessingException;
-import org.apache.beehive.test.tools.tch.util.xml.NestedXMLProcessingRuntimeException;
-
-/**
- * In memory representation of xml configuration file
- *
- */
-/* package */
-class UpdateConfiguration
-{
- private static final String CONF_FILE =
- AntProperties.getHomeDir() + "/" + "tch-update-conf.xml";
-
- // some listener xml element names
- public static final String LISTENER_ROOT_ELEMENT_NAME = "update-listener",
- LISTENER_ELEMENT_NAME = "listener",
- LISTENER_CONF_ELEMENT_NAME = "configuration",
- LISTENER_NAME_ATTR = "name",
- LISTENER_CLASS_ATTR = "classname",
- LISTENER_EXEC_TASK_ATTR = "exectask";
-
- // some updatable entity xml element names
- public static final String UPDATABLE_ROOT_ELEMENT_NAME = "updatable-entity",
- UPDATABLE_ENTITY_ELEMENT_NAME = "entity",
- UPDATABLE_NAME_ATTR = "name",
- UPDATABLE_PROP_ATTR = "property-name";
-
- // default listener key
- public static final String DEFAULT_LISTENER_KEY = "_default_listener";
-
- // Maps exectask name (String) to ListenerEntry
- // if no mapping for particular exectask, get default one using
- // DEFAULT_LISTENER_KEY
- private Map listenerMap = new HashMap();
-
- // also store collection of all available listeners
- // for easy access
- // (intances of UpdateListener)
- private Collection allListeners = new HashSet();
-
- // Maps prop name (String) to UpdatableEntityEntry
- private Map updatableEntityMap = new HashMap();
-
- public void load()
- {
- Document root = loadRoot();
- resolveTchHome(root);
- populateUpdateListeners(root);
- populateUpdateEntites(root);
- }
-
- public Map getUpdatableEntities()
- {
- return Collections.unmodifiableMap(updatableEntityMap);
- }
-
- public TestUpdateListener getListener(String execTaskName)
- {
- ListenerEntry entry = (ListenerEntry)listenerMap.get(execTaskName);
- if (entry == null)
- entry = (ListenerEntry)listenerMap.get(DEFAULT_LISTENER_KEY);
- return entry.getListener();
- }
-
- public Collection getAllListeners()
- {
- return Collections.unmodifiableCollection(allListeners);
- }
-
- private void populateUpdateListeners(Document root)
- {
- Element listenerRoot =
- (Element)root.getElementsByTagName(LISTENER_ROOT_ELEMENT_NAME).item(0);
- NodeList listeners =
- listenerRoot.getElementsByTagName(LISTENER_ELEMENT_NAME);
- for (int i = 0; i < listeners.getLength(); i++)
- {
- Element listenerNode = (Element)listeners.item(i);
- String name = listenerNode.getAttribute(LISTENER_NAME_ATTR);
- // try to load listener class
- Class clazz = null;
- try
- {
- clazz = Class.forName(listenerNode.getAttribute(LISTENER_CLASS_ATTR));
- }
- catch (ClassNotFoundException ex)
- {
- throw new NestedXMLProcessingRuntimeException(ex);
- }
- registerListener(
- GeneralUtil.emptyStringOrNullToNull(
- listenerNode.getAttribute(LISTENER_EXEC_TASK_ATTR)),
- new ListenerEntry(name, clazz, listenerNode));
- }
- }
-
- private void populateUpdateEntites(Document root)
- {
- Element updatableRoot =
- (Element)root.getElementsByTagName(UPDATABLE_ROOT_ELEMENT_NAME).item(0);
- NodeList updatableEntities =
- updatableRoot.getElementsByTagName(UPDATABLE_ENTITY_ELEMENT_NAME);
- for (int i = 0; i < updatableEntities.getLength(); i++)
- {
- Element entityNode = (Element)updatableEntities.item(i);
- String name = entityNode.getAttribute(UPDATABLE_NAME_ATTR);
- String propName =
- AntProperties.appendTch(
- entityNode.getAttribute(UPDATABLE_PROP_ATTR));
- UpdatableEntityEntry entry = new UpdatableEntityEntry(name, propName);
- registerUpdatableEntity(entry);
- }
- }
-
- private Document loadRoot()
- {
- try
- {
- return DomUtils.instantiateDom(new File(CONF_FILE));
- }
- catch (NestedXMLProcessingException ex)
- {
- // parsing error
- throw new NestedXMLProcessingRuntimeException(ex);
- }
- }
-
- private void registerListener(String execTaskKey, ListenerEntry entry)
- {
- String key = DEFAULT_LISTENER_KEY;
- if (execTaskKey != null)
- key = execTaskKey;
- listenerMap.put(key, entry);
-
- // also store all listeners in a Collection
- allListeners.add(entry.getListener());
- }
-
- private void registerUpdatableEntity(UpdatableEntityEntry entry)
- {
- updatableEntityMap.put(entry.getPropName(), entry);
- }
-
- // we try to resolve tch home in the conf file
- // we don't support other props at this point
- private void resolveTchHome(Document root)
- {
- Map props = new HashMap(1);
- props.put(
- PropertyNames.TCH_PREFIX + PropertyNames.TCH_HOME_PROPERTY,
- AntProperties.getHomeDir());
- // using '%' for consistency
- DomUtils.visitDom(
- root,
- new DynamicPropNodeVisitor(new ValueHandler(props, '%')));
- }
-
- public String toString()
- {
- return "Listeners: "
- + listenerMap.toString()
- + " updatable entites: "
- + updatableEntityMap.toString();
- }
-
- static class UpdatableEntityEntry
- {
- private String name = null;
- private String propName = null;
-
- UpdatableEntityEntry(String inName, String inPropName)
- {
- name = inName;
- propName = inPropName;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getPropName()
- {
- return propName;
- }
-
- public String toString()
- {
- return name + " " + propName;
- }
- }
-
- static class ListenerEntry
- {
- private String name = null;
- private TestUpdateListener listener = null;
-
- // an update listener may have additional configuration
- private Node configuration = null;
-
- ListenerEntry(String inName, Class inClazz, Element inListenerNode)
- {
- name = inName;
-
- // extract optional nested configuration
- NodeList children =
- inListenerNode.getElementsByTagName(LISTENER_CONF_ELEMENT_NAME);
- if (children != null && children.getLength() > 0)
- configuration = children.item(0);
-
- try
- {
- listener = (TestUpdateListener)inClazz.newInstance();
- }
- catch (Exception ex)
- {
- throw new NestedXMLProcessingRuntimeException(ex);
- }
- if (configuration != null)
- listener.setConfiguration(configuration);
- }
-
- public TestUpdateListener getListener()
- {
- return listener;
- }
-
- public Node getConfiguration()
- {
- return configuration;
- }
-
- public String toString()
- {
- return name
- + " "
- + " "
- + listener.getClass()
- + " "
- + DomUtils.toString(configuration);
- }
- }
-}
+package org.apache.beehive.test.tools.tch.extension.update;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.PropertyNames;
+import org.apache.beehive.test.tools.tch.util.GeneralUtil;
+import org.apache.beehive.test.tools.tch.util.ValueHandler;
+import org.apache.beehive.test.tools.tch.util.xml.DomUtils;
+import org.apache.beehive.test.tools.tch.util.xml.DynamicPropNodeVisitor;
+import org.apache.beehive.test.tools.tch.util.xml.NestedXMLProcessingException;
+import org.apache.beehive.test.tools.tch.util.xml.NestedXMLProcessingRuntimeException;
+
+/**
+ * In memory representation of xml configuration file
+ *
+ */
+/* package */
+class UpdateConfiguration
+{
+ private static final String CONF_FILE =
+ AntProperties.getHomeDir() + "/" + "tch-update-conf.xml";
+
+ // some listener xml element names
+ public static final String LISTENER_ROOT_ELEMENT_NAME = "update-listener",
+ LISTENER_ELEMENT_NAME = "listener",
+ LISTENER_CONF_ELEMENT_NAME = "configuration",
+ LISTENER_NAME_ATTR = "name",
+ LISTENER_CLASS_ATTR = "classname",
+ LISTENER_EXEC_TASK_ATTR = "exectask";
+
+ // some updatable entity xml element names
+ public static final String UPDATABLE_ROOT_ELEMENT_NAME = "updatable-entity",
+ UPDATABLE_ENTITY_ELEMENT_NAME = "entity",
+ UPDATABLE_NAME_ATTR = "name",
+ UPDATABLE_PROP_ATTR = "property-name";
+
+ // default listener key
+ public static final String DEFAULT_LISTENER_KEY = "_default_listener";
+
+ // Maps exectask name (String) to ListenerEntry
+ // if no mapping for particular exectask, get default one using
+ // DEFAULT_LISTENER_KEY
+ private Map listenerMap = new HashMap();
+
+ // also store collection of all available listeners
+ // for easy access
+ // (intances of UpdateListener)
+ private Collection allListeners = new HashSet();
+
+ // Maps prop name (String) to UpdatableEntityEntry
+ private Map updatableEntityMap = new HashMap();
+
+ public void load()
+ {
+ Document root = loadRoot();
+ resolveTchHome(root);
+ populateUpdateListeners(root);
+ populateUpdateEntites(root);
+ }
+
+ public Map getUpdatableEntities()
+ {
+ return Collections.unmodifiableMap(updatableEntityMap);
+ }
+
+ public TestUpdateListener getListener(String execTaskName)
+ {
+ ListenerEntry entry = (ListenerEntry)listenerMap.get(execTaskName);
+ if (entry == null)
+ entry = (ListenerEntry)listenerMap.get(DEFAULT_LISTENER_KEY);
+ return entry.getListener();
+ }
+
+ public Collection getAllListeners()
+ {
+ return Collections.unmodifiableCollection(allListeners);
+ }
+
+ private void populateUpdateListeners(Document root)
+ {
+ Element listenerRoot =
+ (Element)root.getElementsByTagName(LISTENER_ROOT_ELEMENT_NAME).item(0);
+ NodeList listeners =
+ listenerRoot.getElementsByTagName(LISTENER_ELEMENT_NAME);
+ for (int i = 0; i < listeners.getLength(); i++)
+ {
+ Element listenerNode = (Element)listeners.item(i);
+ String name = listenerNode.getAttribute(LISTENER_NAME_ATTR);
+ // try to load listener class
+ Class clazz = null;
+ try
+ {
+ clazz = Class.forName(listenerNode.getAttribute(LISTENER_CLASS_ATTR));
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new NestedXMLProcessingRuntimeException(ex);
+ }
+ registerListener(
+ GeneralUtil.emptyStringOrNullToNull(
+ listenerNode.getAttribute(LISTENER_EXEC_TASK_ATTR)),
+ new ListenerEntry(name, clazz, listenerNode));
+ }
+ }
+
+ private void populateUpdateEntites(Document root)
+ {
+ Element updatableRoot =
+ (Element)root.getElementsByTagName(UPDATABLE_ROOT_ELEMENT_NAME).item(0);
+ NodeList updatableEntities =
+ updatableRoot.getElementsByTagName(UPDATABLE_ENTITY_ELEMENT_NAME);
+ for (int i = 0; i < updatableEntities.getLength(); i++)
+ {
+ Element entityNode = (Element)updatableEntities.item(i);
+ String name = entityNode.getAttribute(UPDATABLE_NAME_ATTR);
+ String propName =
+ AntProperties.appendTch(
+ entityNode.getAttribute(UPDATABLE_PROP_ATTR));
+ UpdatableEntityEntry entry = new UpdatableEntityEntry(name, propName);
+ registerUpdatableEntity(entry);
+ }
+ }
+
+ private Document loadRoot()
+ {
+ try
+ {
+ return DomUtils.instantiateDom(new File(CONF_FILE));
+ }
+ catch (NestedXMLProcessingException ex)
+ {
+ // parsing error
+ throw new NestedXMLProcessingRuntimeException(ex);
+ }
+ }
+
+ private void registerListener(String execTaskKey, ListenerEntry entry)
+ {
+ String key = DEFAULT_LISTENER_KEY;
+ if (execTaskKey != null)
+ key = execTaskKey;
+ listenerMap.put(key, entry);
+
+ // also store all listeners in a Collection
+ allListeners.add(entry.getListener());
+ }
+
+ private void registerUpdatableEntity(UpdatableEntityEntry entry)
+ {
+ updatableEntityMap.put(entry.getPropName(), entry);
+ }
+
+ // we try to resolve tch home in the conf file
+ // we don't support other props at this point
+ private void resolveTchHome(Document root)
+ {
+ Map props = new HashMap(1);
+ props.put(
+ PropertyNames.TCH_PREFIX + PropertyNames.TCH_HOME_PROPERTY,
+ AntProperties.getHomeDir());
+ // using '%' for consistency
+ DomUtils.visitDom(
+ root,
+ new DynamicPropNodeVisitor(new ValueHandler(props, '%')));
+ }
+
+ public String toString()
+ {
+ return "Listeners: "
+ + listenerMap.toString()
+ + " updatable entites: "
+ + updatableEntityMap.toString();
+ }
+
+ static class UpdatableEntityEntry
+ {
+ private String name = null;
+ private String propName = null;
+
+ UpdatableEntityEntry(String inName, String inPropName)
+ {
+ name = inName;
+ propName = inPropName;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getPropName()
+ {
+ return propName;
+ }
+
+ public String toString()
+ {
+ return name + " " + propName;
+ }
+ }
+
+ static class ListenerEntry
+ {
+ private String name = null;
+ private TestUpdateListener listener = null;
+
+ // an update listener may have additional configuration
+ private Node configuration = null;
+
+ ListenerEntry(String inName, Class inClazz, Element inListenerNode)
+ {
+ name = inName;
+
+ // extract optional nested configuration
+ NodeList children =
+ inListenerNode.getElementsByTagName(LISTENER_CONF_ELEMENT_NAME);
+ if (children != null && children.getLength() > 0)
+ configuration = children.item(0);
+
+ try
+ {
+ listener = (TestUpdateListener)inClazz.newInstance();
+ }
+ catch (Exception ex)
+ {
+ throw new NestedXMLProcessingRuntimeException(ex);
+ }
+ if (configuration != null)
+ listener.setConfiguration(configuration);
+ }
+
+ public TestUpdateListener getListener()
+ {
+ return listener;
+ }
+
+ public Node getConfiguration()
+ {
+ return configuration;
+ }
+
+ public String toString()
+ {
+ return name
+ + " "
+ + " "
+ + listener.getClass()
+ + " "
+ + DomUtils.toString(configuration);
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateManager.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateManager.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateManager.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateManager.java Fri Aug 12 08:12:28 2005
@@ -1,156 +1,156 @@
-package org.apache.beehive.test.tools.tch.extension.update;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.tools.ant.Task;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.ExecutionTask;
-import org.apache.beehive.test.tools.tch.core.LogicalTest;
-import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
-import org.apache.beehive.test.tools.tch.scm.SourceControlManagerFactory;
-import org.apache.beehive.test.tools.tch.util.AntUtils;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.OrderedSet;
-
-/**
- * Handles high level update functions.
- *
- * - Parse update config.
- * - Populates update description Object.
- * - Handles UpdateListener callbacks.
- *
- */
-public class UpdateManager extends Task
-{
- private UpdateConfiguration conf = null;
-
- public void execute()
- {
- if (!AntProperties.getUpdateProps().isEmpty())
- {
- AntProperties.setInitModeOnly(true);
- getProject().setProperty(
- "tch.internal.init-mode-only-enabled",
- "true");
- log("Running update");
- runInit();
- runUpdate();
- runUpdateComplete();
- }
- }
-
- private void runInit()
- {
- // parse our internal config file
- conf = new UpdateConfiguration();
- conf.load();
- //log(conf.toString());
-
- for (Iterator iter = conf.getAllListeners().iterator(); iter.hasNext();)
- {
- ((TestUpdateListener)iter.next()).init();
- }
- }
-
- private void runUpdateComplete()
- {
- for (Iterator iter = conf.getAllListeners().iterator(); iter.hasNext();)
- {
- ((TestUpdateListener)iter.next()).updateComplete(
- SourceControlManagerFactory.getSCM());
- }
- }
-
- private void runUpdate()
- {
- // get all logical tests configured to run
- // for each test, call the configured update listeners
- Collection tests =
- TestRegistry.getRegistry().getAllLogicalTestEntriesThatWillRun();
- for (Iterator iter = tests.iterator(); iter.hasNext();)
- {
- TestRegistry.Entry entry = (TestRegistry.Entry)iter.next();
- LogicalTest test = entry.getLogicalTest();
- Collection executionTasks = test.getExecutionTasks();
- // this needs to be fixed to work with test-blocks
- // maybe, instead of iterating over all contained execution tasks,
- // iterate over all contained tests
- // for now just take first execution task
- ExecutionTask execTask = (ExecutionTask)executionTasks.iterator().next();
- TestUpdateListener listener = conf.getListener(execTask.getTaskName());
- notifyListener(entry, conf.getUpdatableEntities(), listener, execTask);
- }
- }
-
- private void notifyListener(
- TestRegistry.Entry testEntry,
- Map updatableEntityEntries,
- TestUpdateListener listener,
- ExecutionTask execTask)
- {
- for (Iterator iter = AntProperties.getUpdateProps().entrySet().iterator();
- iter.hasNext();
- )
- {
- Map.Entry entry = (Map.Entry)iter.next();
- String propName = (String)entry.getKey();
- String value = (String)entry.getValue();
- UpdateConfiguration.UpdatableEntityEntry updateEntry =
- (UpdateConfiguration.UpdatableEntityEntry)updatableEntityEntries.get(
- propName);
-
- if (updateEntry == null)
- {
- throw new RuntimeException("Unknow update entity: " + propName);
- }
-
- TestUpdateDescriptor desc =
- getDescriptor(testEntry, updateEntry, execTask);
- listener.update(desc);
- }
- }
-
- private TestUpdateDescriptor getDescriptor(
- TestRegistry.Entry testEntry,
- UpdateConfiguration.UpdatableEntityEntry updateEntry,
- ExecutionTask execTask)
- {
- TestUpdateDescriptorImpl desc = new TestUpdateDescriptorImpl();
- desc.setExecutionTask(execTask);
- LogicalTest test = testEntry.getLogicalTest();
- desc.setTestName(test.getLocalName());
-
- // set new values
- String val =
- (String)AntProperties.getUpdateProps().get(updateEntry.getPropName());
-
- // here's the rule that determines if we update/add, or delete
- // (I wanted to avoid creating yet another property)
- // if the value is the empty string, we delete
- // else we update
- if (val.length() == 0)
- {
- desc.setDelete(true);
- }
- else
- {
- desc.setDelete(false);
- Collection c = new OrderedSet();
- TchUtils.parseStringToStrings(val, ",", c);
- desc.setNewValues(c);
- }
-
- desc.setSourceFile(new File(AntUtils.getBuildfileName(test.getLocation())));
- desc.setLineNumber(
- Integer.parseInt(AntUtils.getLineNumber(test.getLocation())));
- desc.setEntityName(updateEntry.getName());
-
- desc.setSourceControlManager(SourceControlManagerFactory.getSCM());
-
- return desc;
- }
-}
+package org.apache.beehive.test.tools.tch.extension.update;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tools.ant.Task;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.ExecutionTask;
+import org.apache.beehive.test.tools.tch.core.LogicalTest;
+import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
+import org.apache.beehive.test.tools.tch.scm.SourceControlManagerFactory;
+import org.apache.beehive.test.tools.tch.util.AntUtils;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.OrderedSet;
+
+/**
+ * Handles high level update functions.
+ *
+ * - Parse update config.
+ * - Populates update description Object.
+ * - Handles UpdateListener callbacks.
+ *
+ */
+public class UpdateManager extends Task
+{
+ private UpdateConfiguration conf = null;
+
+ public void execute()
+ {
+ if (!AntProperties.getUpdateProps().isEmpty())
+ {
+ AntProperties.setInitModeOnly(true);
+ getProject().setProperty(
+ "tch.internal.init-mode-only-enabled",
+ "true");
+ log("Running update");
+ runInit();
+ runUpdate();
+ runUpdateComplete();
+ }
+ }
+
+ private void runInit()
+ {
+ // parse our internal config file
+ conf = new UpdateConfiguration();
+ conf.load();
+ //log(conf.toString());
+
+ for (Iterator iter = conf.getAllListeners().iterator(); iter.hasNext();)
+ {
+ ((TestUpdateListener)iter.next()).init();
+ }
+ }
+
+ private void runUpdateComplete()
+ {
+ for (Iterator iter = conf.getAllListeners().iterator(); iter.hasNext();)
+ {
+ ((TestUpdateListener)iter.next()).updateComplete(
+ SourceControlManagerFactory.getSCM());
+ }
+ }
+
+ private void runUpdate()
+ {
+ // get all logical tests configured to run
+ // for each test, call the configured update listeners
+ Collection tests =
+ TestRegistry.getRegistry().getAllLogicalTestEntriesThatWillRun();
+ for (Iterator iter = tests.iterator(); iter.hasNext();)
+ {
+ TestRegistry.Entry entry = (TestRegistry.Entry)iter.next();
+ LogicalTest test = entry.getLogicalTest();
+ Collection executionTasks = test.getExecutionTasks();
+ // this needs to be fixed to work with test-blocks
+ // maybe, instead of iterating over all contained execution tasks,
+ // iterate over all contained tests
+ // for now just take first execution task
+ ExecutionTask execTask = (ExecutionTask)executionTasks.iterator().next();
+ TestUpdateListener listener = conf.getListener(execTask.getTaskName());
+ notifyListener(entry, conf.getUpdatableEntities(), listener, execTask);
+ }
+ }
+
+ private void notifyListener(
+ TestRegistry.Entry testEntry,
+ Map updatableEntityEntries,
+ TestUpdateListener listener,
+ ExecutionTask execTask)
+ {
+ for (Iterator iter = AntProperties.getUpdateProps().entrySet().iterator();
+ iter.hasNext();
+ )
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ String propName = (String)entry.getKey();
+ String value = (String)entry.getValue();
+ UpdateConfiguration.UpdatableEntityEntry updateEntry =
+ (UpdateConfiguration.UpdatableEntityEntry)updatableEntityEntries.get(
+ propName);
+
+ if (updateEntry == null)
+ {
+ throw new RuntimeException("Unknow update entity: " + propName);
+ }
+
+ TestUpdateDescriptor desc =
+ getDescriptor(testEntry, updateEntry, execTask);
+ listener.update(desc);
+ }
+ }
+
+ private TestUpdateDescriptor getDescriptor(
+ TestRegistry.Entry testEntry,
+ UpdateConfiguration.UpdatableEntityEntry updateEntry,
+ ExecutionTask execTask)
+ {
+ TestUpdateDescriptorImpl desc = new TestUpdateDescriptorImpl();
+ desc.setExecutionTask(execTask);
+ LogicalTest test = testEntry.getLogicalTest();
+ desc.setTestName(test.getLocalName());
+
+ // set new values
+ String val =
+ (String)AntProperties.getUpdateProps().get(updateEntry.getPropName());
+
+ // here's the rule that determines if we update/add, or delete
+ // (I wanted to avoid creating yet another property)
+ // if the value is the empty string, we delete
+ // else we update
+ if (val.length() == 0)
+ {
+ desc.setDelete(true);
+ }
+ else
+ {
+ desc.setDelete(false);
+ Collection c = new OrderedSet();
+ TchUtils.parseStringToStrings(val, ",", c);
+ desc.setNewValues(c);
+ }
+
+ desc.setSourceFile(new File(AntUtils.getBuildfileName(test.getLocation())));
+ desc.setLineNumber(
+ Integer.parseInt(AntUtils.getLineNumber(test.getLocation())));
+ desc.setEntityName(updateEntry.getName());
+
+ desc.setSourceControlManager(SourceControlManagerFactory.getSCM());
+
+ return desc;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/UpdateManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/XMLUpdateListener.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/XMLUpdateListener.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/XMLUpdateListener.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/XMLUpdateListener.java Fri Aug 12 08:12:28 2005
@@ -1,14 +1,14 @@
-package org.apache.beehive.test.tools.tch.extension.update;
-
-/**
- */
-public class XMLUpdateListener extends AbstractUpdateListener implements TestUpdateListener
-{
- public void update(TestUpdateDescriptor desc)
- {
- System.out.println("XML update called with desc ");
- System.out.println(desc.toString());
- System.out.println("====");
- }
-
-}
+package org.apache.beehive.test.tools.tch.extension.update;
+
+/**
+ */
+public class XMLUpdateListener extends AbstractUpdateListener implements TestUpdateListener
+{
+ public void update(TestUpdateDescriptor desc)
+ {
+ System.out.println("XML update called with desc ");
+ System.out.println(desc.toString());
+ System.out.println("====");
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/XMLUpdateListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/ClassParser.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/ClassParser.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/ClassParser.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/ClassParser.java Fri Aug 12 08:12:28 2005
@@ -1,226 +1,226 @@
-/*
- * Created on Feb 1, 2004
- */
-package org.apache.beehive.test.tools.tch.extension.update.clazz;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.StringUtils;
-
-/**
- */
-public class ClassParser
-{
- private static final String SEP = System.getProperty("line.separator");
-
- private File classFile = null;
- private List lines = new ArrayList();
-
- // String (name) -> JavadocComment
- private Map comments = new HashMap();
-
- private JavadocComment classLevelComment = null;
-
- public ClassParser(File f)
- {
- classFile = f;
- String s = open();
- parse(s);
- }
-
- public String getName()
- {
- return classFile.getName().substring(0, classFile.getName().indexOf("."));
- }
-
- public boolean hasBeenModified()
- {
- if (classLevelComment != null && classLevelComment.hasBeenModified())
- {
- return true;
- }
- else
- {
- for (Iterator iter = comments.values().iterator(); iter.hasNext();)
- {
- if (((JavadocComment)iter.next()).hasBeenModified())
- return true;
- }
- }
- return false;
- }
-
- private String open()
- {
- String content = TchUtils.getContentsAsString(classFile);
- if (content == null)
- {
- // FIXME
- throw new RuntimeException(
- "Could not read file " + classFile.getAbsolutePath());
- }
- return content;
- }
-
- private void parse(String content)
- {
- Collection allLines = StringUtils.splitByNewline(content, true);
- boolean inJavadocComment = false;
- Collection commentLines = null;
- for (Iterator iter = allLines.iterator(); iter.hasNext();)
- {
- String line = iter.next().toString();
- if (JavadocComment.isJavadocLine(line) && !inJavadocComment)
- {
- commentLines = new ArrayList();
- inJavadocComment = true;
- }
- if (inJavadocComment)
- {
- commentLines.add(line);
- if (line.trim().length() > 0 && !JavadocComment.isJavadocLine(line))
- {
- inJavadocComment = false;
- JavadocComment comment = JavadocComment.createComment(commentLines);
- if (comment.getType() == JavadocType.CLASS)
- classLevelComment = comment;
- else
- comments.put(comment.getOwnerName(), comment);
- lines.add(comment);
- lines.add(line);
- }
- }
- else
- {
- lines.add(line);
- }
- }
- }
-
- public JavadocComment getClassJavadoc()
- {
- if (classLevelComment == null)
- classLevelComment = createEmptyComment(getName());
- return classLevelComment;
- }
-
- public boolean hasJavadoc(String name)
- {
- return comments.containsKey(name);
- }
-
- public JavadocComment getJavadoc(String name)
- {
- // if method/class does not have javadoc, create new one
- if (hasJavadoc(name))
- return (JavadocComment)comments.get(name);
- else
- return createEmptyComment(name);
- }
-
- private JavadocComment createEmptyComment(String name)
- {
- int i = getMethodOrClassPos(name);
- if (i == -1)
- return null;
- else
- {
- JavadocComment emptyComment =
- JavadocComment.createEmptyComment(name, getLineIndent(i));
- lines.add(i, emptyComment);
- comments.put(name, emptyComment);
- return emptyComment;
- }
- }
-
- private String getLineIndent(int pos)
- {
- String line = (String)lines.get(pos);
- StringBuffer rtn = new StringBuffer();
- for (int i = 0; line.charAt(i) == ' '; i++)
- {
- rtn.append(' ');
- }
- return rtn.toString();
- }
-
- private int getMethodOrClassPos(String name)
- {
- for (int i = 0; i < lines.size(); i++)
- {
- String line = lines.get(i).toString();
- // FIXME use regexp
- if (line.indexOf(name + "(") > -1
- || line.indexOf(name + " (") > -1
- || line.indexOf(name + " (") > -1
- || line.indexOf("class " + name) > -1
- || line.indexOf("class " + name) > -1
- || line.indexOf("class " + name) > -1)
- {
- return i;
- }
- }
- return -1;
- }
-
- public void writeClass() throws IOException
- {
- writeClass(new PrintWriter(new FileWriter(classFile)));
- }
-
- public void writeClass(PrintWriter pw)
- {
- for (Iterator iter = lines.iterator(); iter.hasNext();)
- {
- pw.print(iter.next().toString());
- }
- pw.flush();
- }
-
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- sb.append(classFile.getName()).append("\n\nComments:\n\n");
- for (Iterator iter = comments.keySet().iterator(); iter.hasNext();)
- {
- String name = (String)iter.next();
- JavadocComment comment = (JavadocComment)comments.get(name);
- sb.append(comment.dump());
- sb.append("\n\n");
- }
- sb.append("Keys: ").append(comments.keySet()).append("\n");
- return sb.toString();
- }
-
- // testing
-
- public static void main(String args[]) throws IOException
- {
- File f = new File("TchVMTask.java");
- ClassParser parser = new ClassParser(f);
- System.out.println(parser.toString());
-
- JavadocComment classComment = parser.getClassJavadoc();
- classComment.setTagValue("freq", "daily");
- classComment.setTagValue("Moonna", "nya");
- classComment.setTagValue("Moonna2", "nya2");
-
- JavadocComment newComment = parser.getJavadoc("setDeployPath");
- newComment.setTagValue("test", "foo");
-
- System.out.println("Writing to file fx");
- parser.writeClass(new PrintWriter(new FileWriter(new File("fx"))));
- }
-
-}
+/*
+ * Created on Feb 1, 2004
+ */
+package org.apache.beehive.test.tools.tch.extension.update.clazz;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.StringUtils;
+
+/**
+ */
+public class ClassParser
+{
+ private static final String SEP = System.getProperty("line.separator");
+
+ private File classFile = null;
+ private List lines = new ArrayList();
+
+ // String (name) -> JavadocComment
+ private Map comments = new HashMap();
+
+ private JavadocComment classLevelComment = null;
+
+ public ClassParser(File f)
+ {
+ classFile = f;
+ String s = open();
+ parse(s);
+ }
+
+ public String getName()
+ {
+ return classFile.getName().substring(0, classFile.getName().indexOf("."));
+ }
+
+ public boolean hasBeenModified()
+ {
+ if (classLevelComment != null && classLevelComment.hasBeenModified())
+ {
+ return true;
+ }
+ else
+ {
+ for (Iterator iter = comments.values().iterator(); iter.hasNext();)
+ {
+ if (((JavadocComment)iter.next()).hasBeenModified())
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private String open()
+ {
+ String content = TchUtils.getContentsAsString(classFile);
+ if (content == null)
+ {
+ // FIXME
+ throw new RuntimeException(
+ "Could not read file " + classFile.getAbsolutePath());
+ }
+ return content;
+ }
+
+ private void parse(String content)
+ {
+ Collection allLines = StringUtils.splitByNewline(content, true);
+ boolean inJavadocComment = false;
+ Collection commentLines = null;
+ for (Iterator iter = allLines.iterator(); iter.hasNext();)
+ {
+ String line = iter.next().toString();
+ if (JavadocComment.isJavadocLine(line) && !inJavadocComment)
+ {
+ commentLines = new ArrayList();
+ inJavadocComment = true;
+ }
+ if (inJavadocComment)
+ {
+ commentLines.add(line);
+ if (line.trim().length() > 0 && !JavadocComment.isJavadocLine(line))
+ {
+ inJavadocComment = false;
+ JavadocComment comment = JavadocComment.createComment(commentLines);
+ if (comment.getType() == JavadocType.CLASS)
+ classLevelComment = comment;
+ else
+ comments.put(comment.getOwnerName(), comment);
+ lines.add(comment);
+ lines.add(line);
+ }
+ }
+ else
+ {
+ lines.add(line);
+ }
+ }
+ }
+
+ public JavadocComment getClassJavadoc()
+ {
+ if (classLevelComment == null)
+ classLevelComment = createEmptyComment(getName());
+ return classLevelComment;
+ }
+
+ public boolean hasJavadoc(String name)
+ {
+ return comments.containsKey(name);
+ }
+
+ public JavadocComment getJavadoc(String name)
+ {
+ // if method/class does not have javadoc, create new one
+ if (hasJavadoc(name))
+ return (JavadocComment)comments.get(name);
+ else
+ return createEmptyComment(name);
+ }
+
+ private JavadocComment createEmptyComment(String name)
+ {
+ int i = getMethodOrClassPos(name);
+ if (i == -1)
+ return null;
+ else
+ {
+ JavadocComment emptyComment =
+ JavadocComment.createEmptyComment(name, getLineIndent(i));
+ lines.add(i, emptyComment);
+ comments.put(name, emptyComment);
+ return emptyComment;
+ }
+ }
+
+ private String getLineIndent(int pos)
+ {
+ String line = (String)lines.get(pos);
+ StringBuffer rtn = new StringBuffer();
+ for (int i = 0; line.charAt(i) == ' '; i++)
+ {
+ rtn.append(' ');
+ }
+ return rtn.toString();
+ }
+
+ private int getMethodOrClassPos(String name)
+ {
+ for (int i = 0; i < lines.size(); i++)
+ {
+ String line = lines.get(i).toString();
+ // FIXME use regexp
+ if (line.indexOf(name + "(") > -1
+ || line.indexOf(name + " (") > -1
+ || line.indexOf(name + " (") > -1
+ || line.indexOf("class " + name) > -1
+ || line.indexOf("class " + name) > -1
+ || line.indexOf("class " + name) > -1)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public void writeClass() throws IOException
+ {
+ writeClass(new PrintWriter(new FileWriter(classFile)));
+ }
+
+ public void writeClass(PrintWriter pw)
+ {
+ for (Iterator iter = lines.iterator(); iter.hasNext();)
+ {
+ pw.print(iter.next().toString());
+ }
+ pw.flush();
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(classFile.getName()).append("\n\nComments:\n\n");
+ for (Iterator iter = comments.keySet().iterator(); iter.hasNext();)
+ {
+ String name = (String)iter.next();
+ JavadocComment comment = (JavadocComment)comments.get(name);
+ sb.append(comment.dump());
+ sb.append("\n\n");
+ }
+ sb.append("Keys: ").append(comments.keySet()).append("\n");
+ return sb.toString();
+ }
+
+ // testing
+
+ public static void main(String args[]) throws IOException
+ {
+ File f = new File("TchVMTask.java");
+ ClassParser parser = new ClassParser(f);
+ System.out.println(parser.toString());
+
+ JavadocComment classComment = parser.getClassJavadoc();
+ classComment.setTagValue("freq", "daily");
+ classComment.setTagValue("Moonna", "nya");
+ classComment.setTagValue("Moonna2", "nya2");
+
+ JavadocComment newComment = parser.getJavadoc("setDeployPath");
+ newComment.setTagValue("test", "foo");
+
+ System.out.println("Writing to file fx");
+ parser.writeClass(new PrintWriter(new FileWriter(new File("fx"))));
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/ClassParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocComment.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocComment.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocComment.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocComment.java Fri Aug 12 08:12:28 2005
@@ -1,317 +1,317 @@
-package org.apache.beehive.test.tools.tch.extension.update.clazz;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.apache.beehive.test.tools.tch.util.OrderedMap;
-
-public class JavadocComment
-{
- public final static String DEFAULT_INDENT = " ";
- public final static String DEFAULT_START_JAVADOC_INDENT = " ";
- public final static String DEFAULT_INNER_INDENT = " ";
-
- private final static String SEP = System.getProperty("line.separator");
- private final static JavadocLine NEWLINE_JAVADOC_LINE = new JavadocLine(SEP);
-
- // map tag name (String) -> JavadocLine
- private Map tagMapping = new OrderedMap();
-
- // JavadocLines
- private List javadocLines = new ArrayList();
-
- private String owner = null;
- private JavadocType type = null;
-
- // keeping track if a call to a set-value
- // method actually modified the content of this
- // javadoc comment
- private boolean modifiedComment = false;
-
- // keep track at which line num the first tag (@) starts
- // so that when adding new tags, we can have them live close
- // to existing tags
- private int tagInsertionPos = -1;
-
- private JavadocComment()
- {}
-
- public static JavadocComment createComment(Collection lines)
- {
- JavadocComment comment = new JavadocComment();
- comment.parse(lines);
- if (comment.hasComment())
- return comment;
- else
- return null;
-
- }
-
- /**
- * Factory method. Returns javadoc comment if it finds one, else null.
- * @param methodText
- * @return
- */
- public static JavadocComment createComment(String methodText)
- {
- Collection lines = new ArrayList();
- StringTokenizer st = new StringTokenizer(methodText, SEP);
- while (st.hasMoreTokens())
- lines.add(st.nextToken());
-
- return JavadocComment.createComment(lines);
- }
-
- /**
- * Factory method. Creates default javadoc comment.
- * @param methodText
- * @return
- */
- public static JavadocComment createEmptyComment(String ownerName)
- {
- return JavadocComment.createEmptyComment(ownerName, JavadocComment.DEFAULT_INDENT);
- }
-
- /**
- * Factory method. Creates default javadoc comment.
- * @param methodText
- * @return
- */
- public static JavadocComment createEmptyComment(
- String ownerName,
- String ownerIndent)
- {
- Collection lines = new ArrayList();
- lines.add(ownerIndent + "/**");
- lines.add(SEP);
- lines.add(ownerIndent + " *");
- lines.add(SEP);
- lines.add(ownerIndent + " */");
- lines.add(SEP);
- JavadocComment comment = createComment(lines);
- comment.setOwnerName(ownerName);
- comment.tagInsertionPos = 2;
- return comment;
- }
-
- private void setOwnerName(String name)
- {
- owner = name;
- }
-
- public String getOwnerName()
- {
- return owner;
- }
-
- public JavadocType getType()
- {
- return type;
- }
-
- private void addJavadocLine(String tagName, String tagValue)
- {
- // figure out consistent indentation
- JavadocLine c = (JavadocLine)javadocLines.get(tagInsertionPos);
- register(NEWLINE_JAVADOC_LINE, tagInsertionPos + 1);
- register(
- new JavadocLine(
- c.getIndentation(),
- c.getInnerIndentation(),
- tagName,
- tagValue),
- tagInsertionPos + 2);
- tagInsertionPos += 2;
- }
-
- private void parse(Collection lines)
- {
- for (Iterator iter = lines.iterator(); iter.hasNext();)
- {
- String token = (String)iter.next();
-
- // javadoc
- if (JavadocComment.isJavadocLine(token) || token.trim().length() == 0)
- {
- JavadocLine line = new JavadocLine(token);
- register(line);
-
- // update insertion position
- if (line.hasTag())
- {
- tagInsertionPos = javadocLines.size() - 1;
- }
-
- if (JavadocComment.isJavadocEnd(token) && tagInsertionPos == -1)
- {
- // did not find any tags, set insertion point to end of comment
- tagInsertionPos = javadocLines.size() - 3;
- }
- }
- else
- {
- populateNameAndType(token);
- return;
- }
- }
- }
-
- private void populateNameAndType(String line)
- {
- String s = line.trim();
- if (s.indexOf("(") > -1) // method level
- {
- // assuming this is a method declaration, but could be anything if
- // we found a javadoc style comment in the middle of the code
- s = s.substring(0, s.indexOf("("));
- int spaceIndex = s.lastIndexOf(" ");
- if (spaceIndex != -1)
- owner = s.substring(spaceIndex).trim();
- type = JavadocType.METHOD;
- }
- else if (s.indexOf("class") > -1) // class level
- {
- s = s.substring(s.indexOf("class") + "class".length() + 1).trim();
- int i = s.indexOf(" ");
- if (i == -1) // if no word after class name (no implements or extends)
- i = s.length();
- owner = s.substring(0, i);
- type = JavadocType.CLASS;
- }
-
- // broken, but ok since we only care about method level and class level
- if (owner == null || type == null)
- {
- owner = "#none";
- type = JavadocType.UNKNOWN;
- }
- }
-
- private void register(JavadocLine line)
- {
- register(line, javadocLines.size());
- }
-
- private void register(JavadocLine line, int index)
- {
- javadocLines.add(index, line);
- if (line.hasTag())
- {
- tagMapping.put(line.getTagName(), line);
- }
- }
-
- public boolean hasBeenModified()
- {
- return modifiedComment;
- }
-
- public void deleteTag(String tagName)
- {
- JavadocLine line = (JavadocLine)tagMapping.get(tagName);
- if (line == null)
- return;
- int i = javadocLines.indexOf(line);
- // remove the line, and the carriage return
- javadocLines.remove(i);
- javadocLines.remove(i);
- tagMapping.remove(tagName);
- modifiedComment = true;
- }
-
- public void setTagValue(String tagName, String tagValue)
- {
- if (!tagMapping.containsKey(tagName))
- {
- addJavadocLine(tagName, tagValue);
- modifiedComment = true;
- }
- else
- {
- JavadocLine line = (JavadocLine)tagMapping.get(tagName);
- if (!tagValue.equals(line.getTagValue()))
- {
- line.setTagValue(tagValue);
- modifiedComment = true;
- }
- }
- }
-
- public String getTagValue(String tagName)
- {
- if (tagMapping.containsKey(tagName))
- return ((JavadocLine)tagMapping.get(tagName)).getTagValue();
- else
- return null;
- }
-
- public String toString()
- {
- return getComment();
- }
-
- public String dump()
- {
- StringBuffer sb = new StringBuffer();
- sb.append("Owner " + getOwnerName()).append("\n");
- for (Iterator iter = javadocLines.iterator(); iter.hasNext();)
- {
- JavadocLine line = (JavadocLine)iter.next();
- sb.append(line.dump());
- }
- return sb.toString();
- }
-
- private String getComment()
- {
- StringBuffer rtn = new StringBuffer();
- for (Iterator iter = javadocLines.iterator(); iter.hasNext();)
- {
- rtn.append(iter.next().toString());
- }
- return rtn.toString();
- }
-
- private boolean hasComment()
- {
- return !javadocLines.isEmpty();
- }
-
- public static boolean isJavadocEnd(String line)
- {
- return line.trim().startsWith("*/");
- }
-
- public static boolean isJavadocLine(String line)
- {
- String trimmed = line.trim();
- return (
- trimmed.startsWith("/**")
- || trimmed.startsWith("/*")
- || trimmed.startsWith("*")
- || isJavadocEnd(line));
- }
-
- //testing
- public static void main(String args[])
- {
- String aMethod =
- " /**\n"
- + " * javadoc\n"
- + " * @freq bvt\n"
- + " * @owner stoens\n"
- + " */\n"
- + " public class fooclass\n"
- + " {\n"
- + " blah;\n"
- + " }\n";
-
- JavadocComment comment = createComment(aMethod);
- System.out.println(comment.toString());
- }
-}
+package org.apache.beehive.test.tools.tch.extension.update.clazz;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.beehive.test.tools.tch.util.OrderedMap;
+
+public class JavadocComment
+{
+ public final static String DEFAULT_INDENT = " ";
+ public final static String DEFAULT_START_JAVADOC_INDENT = " ";
+ public final static String DEFAULT_INNER_INDENT = " ";
+
+ private final static String SEP = System.getProperty("line.separator");
+ private final static JavadocLine NEWLINE_JAVADOC_LINE = new JavadocLine(SEP);
+
+ // map tag name (String) -> JavadocLine
+ private Map tagMapping = new OrderedMap();
+
+ // JavadocLines
+ private List javadocLines = new ArrayList();
+
+ private String owner = null;
+ private JavadocType type = null;
+
+ // keeping track if a call to a set-value
+ // method actually modified the content of this
+ // javadoc comment
+ private boolean modifiedComment = false;
+
+ // keep track at which line num the first tag (@) starts
+ // so that when adding new tags, we can have them live close
+ // to existing tags
+ private int tagInsertionPos = -1;
+
+ private JavadocComment()
+ {}
+
+ public static JavadocComment createComment(Collection lines)
+ {
+ JavadocComment comment = new JavadocComment();
+ comment.parse(lines);
+ if (comment.hasComment())
+ return comment;
+ else
+ return null;
+
+ }
+
+ /**
+ * Factory method. Returns javadoc comment if it finds one, else null.
+ * @param methodText
+ * @return
+ */
+ public static JavadocComment createComment(String methodText)
+ {
+ Collection lines = new ArrayList();
+ StringTokenizer st = new StringTokenizer(methodText, SEP);
+ while (st.hasMoreTokens())
+ lines.add(st.nextToken());
+
+ return JavadocComment.createComment(lines);
+ }
+
+ /**
+ * Factory method. Creates default javadoc comment.
+ * @param methodText
+ * @return
+ */
+ public static JavadocComment createEmptyComment(String ownerName)
+ {
+ return JavadocComment.createEmptyComment(ownerName, JavadocComment.DEFAULT_INDENT);
+ }
+
+ /**
+ * Factory method. Creates default javadoc comment.
+ * @param methodText
+ * @return
+ */
+ public static JavadocComment createEmptyComment(
+ String ownerName,
+ String ownerIndent)
+ {
+ Collection lines = new ArrayList();
+ lines.add(ownerIndent + "/**");
+ lines.add(SEP);
+ lines.add(ownerIndent + " *");
+ lines.add(SEP);
+ lines.add(ownerIndent + " */");
+ lines.add(SEP);
+ JavadocComment comment = createComment(lines);
+ comment.setOwnerName(ownerName);
+ comment.tagInsertionPos = 2;
+ return comment;
+ }
+
+ private void setOwnerName(String name)
+ {
+ owner = name;
+ }
+
+ public String getOwnerName()
+ {
+ return owner;
+ }
+
+ public JavadocType getType()
+ {
+ return type;
+ }
+
+ private void addJavadocLine(String tagName, String tagValue)
+ {
+ // figure out consistent indentation
+ JavadocLine c = (JavadocLine)javadocLines.get(tagInsertionPos);
+ register(NEWLINE_JAVADOC_LINE, tagInsertionPos + 1);
+ register(
+ new JavadocLine(
+ c.getIndentation(),
+ c.getInnerIndentation(),
+ tagName,
+ tagValue),
+ tagInsertionPos + 2);
+ tagInsertionPos += 2;
+ }
+
+ private void parse(Collection lines)
+ {
+ for (Iterator iter = lines.iterator(); iter.hasNext();)
+ {
+ String token = (String)iter.next();
+
+ // javadoc
+ if (JavadocComment.isJavadocLine(token) || token.trim().length() == 0)
+ {
+ JavadocLine line = new JavadocLine(token);
+ register(line);
+
+ // update insertion position
+ if (line.hasTag())
+ {
+ tagInsertionPos = javadocLines.size() - 1;
+ }
+
+ if (JavadocComment.isJavadocEnd(token) && tagInsertionPos == -1)
+ {
+ // did not find any tags, set insertion point to end of comment
+ tagInsertionPos = javadocLines.size() - 3;
+ }
+ }
+ else
+ {
+ populateNameAndType(token);
+ return;
+ }
+ }
+ }
+
+ private void populateNameAndType(String line)
+ {
+ String s = line.trim();
+ if (s.indexOf("(") > -1) // method level
+ {
+ // assuming this is a method declaration, but could be anything if
+ // we found a javadoc style comment in the middle of the code
+ s = s.substring(0, s.indexOf("("));
+ int spaceIndex = s.lastIndexOf(" ");
+ if (spaceIndex != -1)
+ owner = s.substring(spaceIndex).trim();
+ type = JavadocType.METHOD;
+ }
+ else if (s.indexOf("class") > -1) // class level
+ {
+ s = s.substring(s.indexOf("class") + "class".length() + 1).trim();
+ int i = s.indexOf(" ");
+ if (i == -1) // if no word after class name (no implements or extends)
+ i = s.length();
+ owner = s.substring(0, i);
+ type = JavadocType.CLASS;
+ }
+
+ // broken, but ok since we only care about method level and class level
+ if (owner == null || type == null)
+ {
+ owner = "#none";
+ type = JavadocType.UNKNOWN;
+ }
+ }
+
+ private void register(JavadocLine line)
+ {
+ register(line, javadocLines.size());
+ }
+
+ private void register(JavadocLine line, int index)
+ {
+ javadocLines.add(index, line);
+ if (line.hasTag())
+ {
+ tagMapping.put(line.getTagName(), line);
+ }
+ }
+
+ public boolean hasBeenModified()
+ {
+ return modifiedComment;
+ }
+
+ public void deleteTag(String tagName)
+ {
+ JavadocLine line = (JavadocLine)tagMapping.get(tagName);
+ if (line == null)
+ return;
+ int i = javadocLines.indexOf(line);
+ // remove the line, and the carriage return
+ javadocLines.remove(i);
+ javadocLines.remove(i);
+ tagMapping.remove(tagName);
+ modifiedComment = true;
+ }
+
+ public void setTagValue(String tagName, String tagValue)
+ {
+ if (!tagMapping.containsKey(tagName))
+ {
+ addJavadocLine(tagName, tagValue);
+ modifiedComment = true;
+ }
+ else
+ {
+ JavadocLine line = (JavadocLine)tagMapping.get(tagName);
+ if (!tagValue.equals(line.getTagValue()))
+ {
+ line.setTagValue(tagValue);
+ modifiedComment = true;
+ }
+ }
+ }
+
+ public String getTagValue(String tagName)
+ {
+ if (tagMapping.containsKey(tagName))
+ return ((JavadocLine)tagMapping.get(tagName)).getTagValue();
+ else
+ return null;
+ }
+
+ public String toString()
+ {
+ return getComment();
+ }
+
+ public String dump()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Owner " + getOwnerName()).append("\n");
+ for (Iterator iter = javadocLines.iterator(); iter.hasNext();)
+ {
+ JavadocLine line = (JavadocLine)iter.next();
+ sb.append(line.dump());
+ }
+ return sb.toString();
+ }
+
+ private String getComment()
+ {
+ StringBuffer rtn = new StringBuffer();
+ for (Iterator iter = javadocLines.iterator(); iter.hasNext();)
+ {
+ rtn.append(iter.next().toString());
+ }
+ return rtn.toString();
+ }
+
+ private boolean hasComment()
+ {
+ return !javadocLines.isEmpty();
+ }
+
+ public static boolean isJavadocEnd(String line)
+ {
+ return line.trim().startsWith("*/");
+ }
+
+ public static boolean isJavadocLine(String line)
+ {
+ String trimmed = line.trim();
+ return (
+ trimmed.startsWith("/**")
+ || trimmed.startsWith("/*")
+ || trimmed.startsWith("*")
+ || isJavadocEnd(line));
+ }
+
+ //testing
+ public static void main(String args[])
+ {
+ String aMethod =
+ " /**\n"
+ + " * javadoc\n"
+ + " * @freq bvt\n"
+ + " * @owner stoens\n"
+ + " */\n"
+ + " public class fooclass\n"
+ + " {\n"
+ + " blah;\n"
+ + " }\n";
+
+ JavadocComment comment = createComment(aMethod);
+ System.out.println(comment.toString());
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocComment.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocLine.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocLine.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocLine.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocLine.java Fri Aug 12 08:12:28 2005
@@ -1,173 +1,173 @@
-package org.apache.beehive.test.tools.tch.extension.update.clazz;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-
-public class JavadocLine
-{
- private Collection words = new ArrayList();
-
- // starts with '@'
- private StringBuffer tagName = null;
-
- private StringBuffer tagValue = null;
-
- public JavadocLine(String tagName, String tagValue)
- {
- this(" ", " ", tagName, tagValue);
- }
-
- JavadocLine(
- String indentation,
- String innerIndent,
- String tagName,
- String tagValue)
- {
- this(indentation + "*" + innerIndent + "@" + tagName + " " + tagValue);
- }
-
- public JavadocLine(String line)
- {
- boolean foundTagName = false;
- boolean foundFirstValueToken = false;
-
- StringTokenizer st = new StringTokenizer(line, " ", true);
- while (st.hasMoreTokens())
- {
- String token = st.nextToken();
- if (token.startsWith("@"))
- {
- // assumes a single tag per line
- tagName = new StringBuffer(token.trim());
- words.add(tagName);
- foundTagName = true;
- }
- else if (foundTagName && !foundFirstValueToken && token.trim().length() > 0)
- {
- tagValue = new StringBuffer(token);
- words.add(tagValue);
- foundFirstValueToken = true;
- }
- else if (foundFirstValueToken)
- {
- tagValue.append(token);
- }
- else
- {
- words.add(token);
- }
- }
-
- // if we got a tag, but did not find a value
- // then value is empty string
- if (foundTagName && !foundFirstValueToken)
- {
- words.add(" ");
- tagValue = new StringBuffer();
- words.add(tagValue);
- }
-
- }
-
- public boolean hasTag()
- {
- return getTagName() != null;
- }
-
- public String getTagName()
- {
- if (tagName == null)
- return null;
- else
- return tagName.toString().substring(1, tagName.length());
- }
-
- public String getTagValue()
- {
- return tagValue.toString();
- }
-
- public void setTagName(String in)
- {
- // keep '@'
- tagName.delete(1, tagName.length());
- tagName.append(in);
- }
-
- public void setTagValue(String in)
- {
- if (tagValue == null)
- tagValue = new StringBuffer();
- tagValue.delete(0, tagValue.length());
- tagValue.append(in);
- }
-
- public String getIndentation()
- {
- String line = toString();
- StringBuffer rtn = new StringBuffer();
- for (int i = 0; line.charAt(i) == ' '; i++)
- {
- rtn.append(' ');
- }
- return rtn.toString();
- }
-
- public String getInnerIndentation()
- {
- String line = toString();
- // there may not be an inner indentation
- // * blah --> inner indentation is 2
- // * --> nothing to compute inner indentation, return default
- if (line.substring(getIndentation().length() + 1).trim().length() == 0)
- return JavadocComment.DEFAULT_INNER_INDENT;
- else
- {
- StringBuffer rtn = new StringBuffer();
- for (int i = getIndentation().length() + 1; line.charAt(i) == ' '; i++)
- {
- rtn.append(' ');
- }
- return rtn.toString();
- }
- }
-
- public String dump()
- {
- StringBuffer rtn = new StringBuffer();
- for (Iterator iter = words.iterator(); iter.hasNext();)
- {
- rtn.append(iter.next());
- }
- if (hasTag())
- rtn.append(" (").append(getTagName()).append("=").append(
- getTagValue()).append(
- ")");
- return rtn.toString();
- }
-
- public String toString()
- {
- StringBuffer rtn = new StringBuffer();
- for (Iterator iter = words.iterator(); iter.hasNext();)
- {
- rtn.append(iter.next());
- }
- return rtn.toString();
- }
-
- // testing
- public static void main(String args[])
- {
- JavadocLine line = new JavadocLine(" * fooo @freq bvt foo");
- System.out.println("org line: " + line.toString());
- line.setTagName("new-name");
- line.setTagValue("new-val");
- System.out.println("mod line: " + line.toString());
- line = new JavadocLine("t1", "v1");
- System.out.println("created line " + line);
- }
-
-}
+package org.apache.beehive.test.tools.tch.extension.update.clazz;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+public class JavadocLine
+{
+ private Collection words = new ArrayList();
+
+ // starts with '@'
+ private StringBuffer tagName = null;
+
+ private StringBuffer tagValue = null;
+
+ public JavadocLine(String tagName, String tagValue)
+ {
+ this(" ", " ", tagName, tagValue);
+ }
+
+ JavadocLine(
+ String indentation,
+ String innerIndent,
+ String tagName,
+ String tagValue)
+ {
+ this(indentation + "*" + innerIndent + "@" + tagName + " " + tagValue);
+ }
+
+ public JavadocLine(String line)
+ {
+ boolean foundTagName = false;
+ boolean foundFirstValueToken = false;
+
+ StringTokenizer st = new StringTokenizer(line, " ", true);
+ while (st.hasMoreTokens())
+ {
+ String token = st.nextToken();
+ if (token.startsWith("@"))
+ {
+ // assumes a single tag per line
+ tagName = new StringBuffer(token.trim());
+ words.add(tagName);
+ foundTagName = true;
+ }
+ else if (foundTagName && !foundFirstValueToken && token.trim().length() > 0)
+ {
+ tagValue = new StringBuffer(token);
+ words.add(tagValue);
+ foundFirstValueToken = true;
+ }
+ else if (foundFirstValueToken)
+ {
+ tagValue.append(token);
+ }
+ else
+ {
+ words.add(token);
+ }
+ }
+
+ // if we got a tag, but did not find a value
+ // then value is empty string
+ if (foundTagName && !foundFirstValueToken)
+ {
+ words.add(" ");
+ tagValue = new StringBuffer();
+ words.add(tagValue);
+ }
+
+ }
+
+ public boolean hasTag()
+ {
+ return getTagName() != null;
+ }
+
+ public String getTagName()
+ {
+ if (tagName == null)
+ return null;
+ else
+ return tagName.toString().substring(1, tagName.length());
+ }
+
+ public String getTagValue()
+ {
+ return tagValue.toString();
+ }
+
+ public void setTagName(String in)
+ {
+ // keep '@'
+ tagName.delete(1, tagName.length());
+ tagName.append(in);
+ }
+
+ public void setTagValue(String in)
+ {
+ if (tagValue == null)
+ tagValue = new StringBuffer();
+ tagValue.delete(0, tagValue.length());
+ tagValue.append(in);
+ }
+
+ public String getIndentation()
+ {
+ String line = toString();
+ StringBuffer rtn = new StringBuffer();
+ for (int i = 0; line.charAt(i) == ' '; i++)
+ {
+ rtn.append(' ');
+ }
+ return rtn.toString();
+ }
+
+ public String getInnerIndentation()
+ {
+ String line = toString();
+ // there may not be an inner indentation
+ // * blah --> inner indentation is 2
+ // * --> nothing to compute inner indentation, return default
+ if (line.substring(getIndentation().length() + 1).trim().length() == 0)
+ return JavadocComment.DEFAULT_INNER_INDENT;
+ else
+ {
+ StringBuffer rtn = new StringBuffer();
+ for (int i = getIndentation().length() + 1; line.charAt(i) == ' '; i++)
+ {
+ rtn.append(' ');
+ }
+ return rtn.toString();
+ }
+ }
+
+ public String dump()
+ {
+ StringBuffer rtn = new StringBuffer();
+ for (Iterator iter = words.iterator(); iter.hasNext();)
+ {
+ rtn.append(iter.next());
+ }
+ if (hasTag())
+ rtn.append(" (").append(getTagName()).append("=").append(
+ getTagValue()).append(
+ ")");
+ return rtn.toString();
+ }
+
+ public String toString()
+ {
+ StringBuffer rtn = new StringBuffer();
+ for (Iterator iter = words.iterator(); iter.hasNext();)
+ {
+ rtn.append(iter.next());
+ }
+ return rtn.toString();
+ }
+
+ // testing
+ public static void main(String args[])
+ {
+ JavadocLine line = new JavadocLine(" * fooo @freq bvt foo");
+ System.out.println("org line: " + line.toString());
+ line.setTagName("new-name");
+ line.setTagValue("new-val");
+ System.out.println("mod line: " + line.toString());
+ line = new JavadocLine("t1", "v1");
+ System.out.println("created line " + line);
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocLine.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocType.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocType.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocType.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocType.java Fri Aug 12 08:12:28 2005
@@ -1,11 +1,11 @@
-package org.apache.beehive.test.tools.tch.extension.update.clazz;
-
-/**
- */
-public class JavadocType
-{
- public static final JavadocType CLASS = new JavadocType();
- public static final JavadocType METHOD = new JavadocType();
- public static final JavadocType UNKNOWN = new JavadocType();
- private JavadocType(){}
-}
+package org.apache.beehive.test.tools.tch.extension.update.clazz;
+
+/**
+ */
+public class JavadocType
+{
+ public static final JavadocType CLASS = new JavadocType();
+ public static final JavadocType METHOD = new JavadocType();
+ public static final JavadocType UNKNOWN = new JavadocType();
+ private JavadocType(){}
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/clazz/JavadocType.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/junit/JunitUpdateListener.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/junit/JunitUpdateListener.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/junit/JunitUpdateListener.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/junit/JunitUpdateListener.java Fri Aug 12 08:12:28 2005
@@ -1,219 +1,219 @@
-package org.apache.beehive.test.tools.tch.extension.update.junit;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.extension.exectask.junit.JunitExecTask;
-import org.apache.beehive.test.tools.tch.extension.update.AbstractUpdateListener;
-import org.apache.beehive.test.tools.tch.extension.update.TestUpdateDescriptor;
-import org.apache.beehive.test.tools.tch.extension.update.TestUpdateListener;
-import org.apache.beehive.test.tools.tch.extension.update.clazz.ClassParser;
-import org.apache.beehive.test.tools.tch.extension.update.clazz.JavadocComment;
-import org.apache.beehive.test.tools.tch.scm.SCMOperationException;
-import org.apache.beehive.test.tools.tch.scm.SourceControlManager;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.NestedRuntimeException;
-
-/**
- */
-public class JunitUpdateListener
- extends AbstractUpdateListener
- implements TestUpdateListener
-{
- private static final String MAPPING_ELEMENT_NAME = "metadata-mapping";
- private static final String TCH_VAL_ATTR = "tch-val";
- private static final String JUNIT_VAL_ATTR = "junit-val";
-
- // Map File to ClassParser
- private Map classParserMap = new HashMap();
-
- private Map propertyMapping = new HashMap();
-
- public void update(TestUpdateDescriptor desc)
- {
- JunitExecTask task = (JunitExecTask)desc.getExecutionTask();
-
- // if no method names attr. && all subtests == conf. subtests
- // do class level update
- // else update conf. subtests.
-
- if (task.getMethodNames() == null
- && task.getSubtestsConfiguredToRun().containsAll(task.getAllSubtestNames()))
- {
- classLevelUpdate(desc);
- }
- else
- {
- methodLevelUpdate(desc);
- }
- }
-
- public void setConfiguration(Node root)
- {
- NodeList nodes = root.getChildNodes();
- int length = nodes.getLength();
- for (int i = 0; i < length; i++)
- {
- Node n = nodes.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE
- && n.getNodeName().equals(MAPPING_ELEMENT_NAME))
- {
- Element e = (Element)n;
- propertyMapping.put(
- e.getAttribute(TCH_VAL_ATTR).trim(),
- e.getAttribute(JUNIT_VAL_ATTR).trim());
- }
- }
- }
-
- private String translateName(String s)
- {
- if (propertyMapping.containsKey(s))
- return (String)propertyMapping.get(s);
- else
- return s;
- }
-
- private void classLevelUpdate(TestUpdateDescriptor desc)
- {
- JunitExecTask execTask = (JunitExecTask)desc.getExecutionTask();
- ClassParser parser = getParser(getClassFile(execTask.getTestClassName()));
- //System.out.println("Class level update for " + execTask.getTestClassName());
- updateMetadata(desc, parser.getClassJavadoc());
- }
-
- private void updateMetadata(TestUpdateDescriptor desc, JavadocComment javadoc)
- {
- String tagName = translateName(desc.getEntityName());
- if (desc.isDelete())
- {
- javadoc.deleteTag(tagName);
- }
- else
- {
- String newTagValue = getNewValues(desc);
- javadoc.setTagValue(tagName, newTagValue);
- }
- }
-
- private String getNewValues(TestUpdateDescriptor desc)
- {
- return TchUtils.collectionToString(desc.getNewValues(), " ");
- }
-
- private void methodLevelUpdate(TestUpdateDescriptor desc)
- {
- JunitExecTask execTask = (JunitExecTask)desc.getExecutionTask();
- ClassParser parser = getParser(getClassFile(execTask.getTestClassName()));
- for (Iterator iter = execTask.getSubtestsConfiguredToRun().iterator();
- iter.hasNext();
- )
- {
- String method = (String)iter.next();
- //System.out.println(
- // "Method level update for "
- // + execTask.getTestClassName()
- // + ":"
- // + method);
- updateMetadata(desc, parser.getJavadoc(method));
- }
- }
-
- /**
- * Write all java source files to disk.
- * Also handle source control
- *
- * @see org.apache.beehive.test.tools.tch.extension.update.TestUpdateListener#updateComplete()
- */
- public void updateComplete(SourceControlManager scm)
- {
- // map File --> ClassParser
- Map modifiedFiles = new HashMap();
-
- // find all modified files so we can run a single scm checkout command
- for (Iterator iter = classParserMap.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iter.next();
- File f = (File)entry.getKey();
- ClassParser parser = (ClassParser)entry.getValue();
- if (parser.hasBeenModified())
- {
- //System.out.println("Registering mod for " + parser.getName());
- modifiedFiles.put(f, parser);
- }
- else
- {
- //System.out.println("No mods for " + parser.getName());
- }
- }
-
- // if we did not modify any files (for example if we try to delete
- // a tag, but the tag was not found), return right here
- if (modifiedFiles.isEmpty())
- return;
-
- // checkout (p4 edit)
- try
- {
- scm.checkout((File[])modifiedFiles.keySet().toArray(new File[] {
- }));
- }
- catch (SCMOperationException ex)
- {
- throw new NestedRuntimeException(ex);
- }
-
- // write to disk
- for (Iterator iter = modifiedFiles.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iter.next();
- File f = (File)entry.getKey();
- ClassParser parser = (ClassParser)entry.getValue();
- try
- {
- parser.writeClass();
- }
- catch (IOException ex)
- {
- throw new NestedRuntimeException(ex);
- }
- }
- }
-
- private File getClassFile(String classPackageName)
- {
- File f =
- new File(
- AntProperties.getUpdateJunitSource(),
- classPackageName.replace('.', '/') + ".java");
- if (!f.exists())
- {
- // FIXME better exception
- throw new RuntimeException(
- "Cannot find java src at " + f.getAbsolutePath());
- }
- return f;
- }
-
- private ClassParser getParser(File f)
- {
- ClassParser rtn = (ClassParser)classParserMap.get(f);
- if (rtn == null)
- {
- if (AntProperties.isVerboseOn())
- System.out.println("Parsing class file: " + f.getAbsolutePath());
-
- rtn = new ClassParser(f);
- classParserMap.put(f, rtn);
- }
- return rtn;
- }
-}
+package org.apache.beehive.test.tools.tch.extension.update.junit;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.extension.exectask.junit.JunitExecTask;
+import org.apache.beehive.test.tools.tch.extension.update.AbstractUpdateListener;
+import org.apache.beehive.test.tools.tch.extension.update.TestUpdateDescriptor;
+import org.apache.beehive.test.tools.tch.extension.update.TestUpdateListener;
+import org.apache.beehive.test.tools.tch.extension.update.clazz.ClassParser;
+import org.apache.beehive.test.tools.tch.extension.update.clazz.JavadocComment;
+import org.apache.beehive.test.tools.tch.scm.SCMOperationException;
+import org.apache.beehive.test.tools.tch.scm.SourceControlManager;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.NestedRuntimeException;
+
+/**
+ */
+public class JunitUpdateListener
+ extends AbstractUpdateListener
+ implements TestUpdateListener
+{
+ private static final String MAPPING_ELEMENT_NAME = "metadata-mapping";
+ private static final String TCH_VAL_ATTR = "tch-val";
+ private static final String JUNIT_VAL_ATTR = "junit-val";
+
+ // Map File to ClassParser
+ private Map classParserMap = new HashMap();
+
+ private Map propertyMapping = new HashMap();
+
+ public void update(TestUpdateDescriptor desc)
+ {
+ JunitExecTask task = (JunitExecTask)desc.getExecutionTask();
+
+ // if no method names attr. && all subtests == conf. subtests
+ // do class level update
+ // else update conf. subtests.
+
+ if (task.getMethodNames() == null
+ && task.getSubtestsConfiguredToRun().containsAll(task.getAllSubtestNames()))
+ {
+ classLevelUpdate(desc);
+ }
+ else
+ {
+ methodLevelUpdate(desc);
+ }
+ }
+
+ public void setConfiguration(Node root)
+ {
+ NodeList nodes = root.getChildNodes();
+ int length = nodes.getLength();
+ for (int i = 0; i < length; i++)
+ {
+ Node n = nodes.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE
+ && n.getNodeName().equals(MAPPING_ELEMENT_NAME))
+ {
+ Element e = (Element)n;
+ propertyMapping.put(
+ e.getAttribute(TCH_VAL_ATTR).trim(),
+ e.getAttribute(JUNIT_VAL_ATTR).trim());
+ }
+ }
+ }
+
+ private String translateName(String s)
+ {
+ if (propertyMapping.containsKey(s))
+ return (String)propertyMapping.get(s);
+ else
+ return s;
+ }
+
+ private void classLevelUpdate(TestUpdateDescriptor desc)
+ {
+ JunitExecTask execTask = (JunitExecTask)desc.getExecutionTask();
+ ClassParser parser = getParser(getClassFile(execTask.getTestClassName()));
+ //System.out.println("Class level update for " + execTask.getTestClassName());
+ updateMetadata(desc, parser.getClassJavadoc());
+ }
+
+ private void updateMetadata(TestUpdateDescriptor desc, JavadocComment javadoc)
+ {
+ String tagName = translateName(desc.getEntityName());
+ if (desc.isDelete())
+ {
+ javadoc.deleteTag(tagName);
+ }
+ else
+ {
+ String newTagValue = getNewValues(desc);
+ javadoc.setTagValue(tagName, newTagValue);
+ }
+ }
+
+ private String getNewValues(TestUpdateDescriptor desc)
+ {
+ return TchUtils.collectionToString(desc.getNewValues(), " ");
+ }
+
+ private void methodLevelUpdate(TestUpdateDescriptor desc)
+ {
+ JunitExecTask execTask = (JunitExecTask)desc.getExecutionTask();
+ ClassParser parser = getParser(getClassFile(execTask.getTestClassName()));
+ for (Iterator iter = execTask.getSubtestsConfiguredToRun().iterator();
+ iter.hasNext();
+ )
+ {
+ String method = (String)iter.next();
+ //System.out.println(
+ // "Method level update for "
+ // + execTask.getTestClassName()
+ // + ":"
+ // + method);
+ updateMetadata(desc, parser.getJavadoc(method));
+ }
+ }
+
+ /**
+ * Write all java source files to disk.
+ * Also handle source control
+ *
+ * @see org.apache.beehive.test.tools.tch.extension.update.TestUpdateListener#updateComplete()
+ */
+ public void updateComplete(SourceControlManager scm)
+ {
+ // map File --> ClassParser
+ Map modifiedFiles = new HashMap();
+
+ // find all modified files so we can run a single scm checkout command
+ for (Iterator iter = classParserMap.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ File f = (File)entry.getKey();
+ ClassParser parser = (ClassParser)entry.getValue();
+ if (parser.hasBeenModified())
+ {
+ //System.out.println("Registering mod for " + parser.getName());
+ modifiedFiles.put(f, parser);
+ }
+ else
+ {
+ //System.out.println("No mods for " + parser.getName());
+ }
+ }
+
+ // if we did not modify any files (for example if we try to delete
+ // a tag, but the tag was not found), return right here
+ if (modifiedFiles.isEmpty())
+ return;
+
+ // checkout (p4 edit)
+ try
+ {
+ scm.checkout((File[])modifiedFiles.keySet().toArray(new File[] {
+ }));
+ }
+ catch (SCMOperationException ex)
+ {
+ throw new NestedRuntimeException(ex);
+ }
+
+ // write to disk
+ for (Iterator iter = modifiedFiles.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ File f = (File)entry.getKey();
+ ClassParser parser = (ClassParser)entry.getValue();
+ try
+ {
+ parser.writeClass();
+ }
+ catch (IOException ex)
+ {
+ throw new NestedRuntimeException(ex);
+ }
+ }
+ }
+
+ private File getClassFile(String classPackageName)
+ {
+ File f =
+ new File(
+ AntProperties.getUpdateJunitSource(),
+ classPackageName.replace('.', '/') + ".java");
+ if (!f.exists())
+ {
+ // FIXME better exception
+ throw new RuntimeException(
+ "Cannot find java src at " + f.getAbsolutePath());
+ }
+ return f;
+ }
+
+ private ClassParser getParser(File f)
+ {
+ ClassParser rtn = (ClassParser)classParserMap.get(f);
+ if (rtn == null)
+ {
+ if (AntProperties.isVerboseOn())
+ System.out.println("Parsing class file: " + f.getAbsolutePath());
+
+ rtn = new ClassParser(f);
+ classParserMap.put(f, rtn);
+ }
+ return rtn;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/update/junit/JunitUpdateListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/internal/test/CheckAgentHealthTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/internal/test/CheckAgentHealthTest.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/internal/test/CheckAgentHealthTest.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/internal/test/CheckAgentHealthTest.java Fri Aug 12 08:12:28 2005
@@ -1,28 +1,28 @@
-package org.apache.beehive.test.tools.tch.internal.test;
-
-import org.apache.beehive.test.tools.tch.compose.AutoTest;
-import org.apache.beehive.test.tools.tch.compose.TestContext;
-import org.apache.beehive.test.tools.tch.extension.process.listener.RemoteListenerProcessHandler;
-
-public class CheckAgentHealthTest extends AutoTest
-{
- public CheckAgentHealthTest(TestContext inTc)
- {
- super(inTc);
- }
-
- public boolean testGetAgentJavatops()
- {
- RemoteListenerProcessHandler ph = (RemoteListenerProcessHandler)getTestContext().getProcessEngine().getProcessHandler();
- return success("Agent javaopts are: " + ph.getJavaopts());
- }
-
- public boolean testIsAlive()
- {
- RemoteListenerProcessHandler ph = (RemoteListenerProcessHandler)getTestContext().getProcessEngine().getProcessHandler();
- if (ph.isAlive())
- return success("Agent " + ph.getName() + " is alive");
- else
- return failure("Agent " + ph.getName() + " is not alive");
- }
-}
+package org.apache.beehive.test.tools.tch.internal.test;
+
+import org.apache.beehive.test.tools.tch.compose.AutoTest;
+import org.apache.beehive.test.tools.tch.compose.TestContext;
+import org.apache.beehive.test.tools.tch.extension.process.listener.RemoteListenerProcessHandler;
+
+public class CheckAgentHealthTest extends AutoTest
+{
+ public CheckAgentHealthTest(TestContext inTc)
+ {
+ super(inTc);
+ }
+
+ public boolean testGetAgentJavatops()
+ {
+ RemoteListenerProcessHandler ph = (RemoteListenerProcessHandler)getTestContext().getProcessEngine().getProcessHandler();
+ return success("Agent javaopts are: " + ph.getJavaopts());
+ }
+
+ public boolean testIsAlive()
+ {
+ RemoteListenerProcessHandler ph = (RemoteListenerProcessHandler)getTestContext().getProcessEngine().getProcessHandler();
+ if (ph.isAlive())
+ return success("Agent " + ph.getName() + " is alive");
+ else
+ return failure("Agent " + ph.getName() + " is not alive");
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/internal/test/CheckAgentHealthTest.java
------------------------------------------------------------------------------
svn:eol-style = native