--On Wednesday, January 25, 2006 11:58 PM -1000 Aaron Kagawa <[EMAIL
PROTECTED]> wrote:
Thanks. I actually looked through that and it helped a little. This doc seems
to
explain eSDTs more that it does pMap. I finally found the portion of the doc
that
showed the use of SensorDataPropertyMap construct a pMap was hidden all the way
down in
section 3.1.4 (in the TestEvolSdt.java example). After reading this doc, I'm
still a
little confused on why the pMap has to be encoded and decode. My guess is that
we
couldn't come up with a good delimiter for the key-value pairs. I was hoping
for a HTML
doc about writing a sensor that uses pMap. I'm sure that it will be coming in
the
Developer docbook chapters.
I found myself studying that document intensely for the past few days, and I was the one
that wrote it! Yes, you're absolutely right, there needs to be Developer docbook
chapters to go through all of this stuff. The eSDT documention is just a temporary
pointer until I get to HACK-496.
I've just happened to be updating sensors today to use the new FileMetric SDT, which
provides some example code to help illustrate how to use pMaps in sensors.
Here's a method from the CCCC sensor that takes a list of objects called "ccccMetricMap",
each of which represents FileMetric data on a single C/C++ file. I'll annotate the code
so you can see how things work. Note that the FileMetric SDT has three required fields:
fileName, fileType, and totalLines. Everything else goes on the pMap.
public void createFileMetricEntries(List ccccFileMetricList) {
// First, create a "runtime" string to go on the pMap for all FileMetric entries in
this run.
String runtime = new Long((new Date()).getTime()).toString();
// Now we go through each of the ccccMetricMap objects and create a FileMetric entry
for each.
for (Iterator i = ccccFileMetricList.iterator(); i.hasNext();) {
Map ccccMetricMap = (Map) i.next();
// Get the fileName required field for FileMetric.
String fileName = (String) ccccMetricMap.get("sourceFileName");
// Get the fileType required field for FileMetric. Default to "cc" if ext
is weird.
String fileType = "cc";
int extIndex = fileName.lastIndexOf(".");
if (extIndex > 0) {
fileType = fileName.substring(extIndex + 1);
}
// Get the totalLines required field for FileMetric.
String sloc = (String)ccccMetricMap.get("sloc");
String cloc = (String)ccccMetricMap.get("cloc");
int totalLoc = Integer.parseInt(sloc) + Integer.parseInt(cloc);
String totalLines = new Integer(totalLoc).toString();
// Now make the pMap.
// We need to observe the FileMetric conventions for "optional" property
names.
// In this case, the ones we observe are: runtime, sourceLines,
commentLines
// We'll add all other entries from the ccccMetricMap to the pMap
unchanged.
SensorDataPropertyMap pMap = new SensorDataPropertyMap();
pMap.put("runtime", runtime);
Set keySet = ccccMetricMap.keySet();
for (Iterator j = keySet.iterator(); j.hasNext(); ) {
String metricName = (String)j.next();
String metricValue = (String)ccccMetricMap.get(metricName);
if ("sloc".equals(metricName)) {
pMap.put("sourceLines", metricValue);
} else if ("cloc".equals(metricName)) {
pMap.put("commentLines", metricValue);
} else {
pMap.put(metricName, metricValue);
}
}
// We've got all required fields and the pMap.
// Now create a FileMetric "add" command from them.
String [] addArgs = {
"add",
"tool=CCCC",
"fileName=" + fileName,
"fileType=" + fileType,
"totalLines=" + totalLines,
"pMap=" + pMap.encode()
};
// Give the add command to the sensorshell for later sending to Hackystat.
this.shell.doCommand(new Date(), "FileMetric", Arrays.asList(addArgs));
}
}
Cheers,
Philip