Sending Cppcheck result/report on email from Jenkins using email-ext plugin - groovy

I'm trying to send cppcheck report on an email using email-ext plugin from a Jenkins build. So far, only way seems to be by creating a custom template -- jelly or groovy. From this post -- "Can I configure jenkins to send an email with a static analysis report summary?" -- it looks like I should be able to instantiate CppcheckBuildAction and use its methods but for some reason, it doesn't seem to instantiate (ie. the object is null). Here's the code I've put in the jelly template to check this:
<j:set var="cppcBuildAction" value="${it.getAction('com.thalesgroup.hudson.plugins.cppcheck.CppcheckBuildAction')}"/>
<j:if test="${cppcBuildAction==null}">
<p><i>cppcBuildAction is null!</i></p>
</j:if>
(I also tried hudson.plugins.cppcheck.CppcheckBuildAction)
And, sure enough, I get cpppcBuildAction is null! in the build result email. (I had to put in "if" clause to test this on jelly because it doesn't throw out any error, otherwise. In groovy template, I actually get the error message like "Exception: javax.script.ScriptException: java.lang.NullPointerException: Cannot get property 'getResult' on null object" if I try to call getResult method on the object).
Has anybody tried sending Cppcheck result/report over email using this email-ext plugin or otherwise?
BTW, there is another post where someone else is trying to do what I'm trying to do but the thread doesn't seem to be active or there's no real interaction going on there -- "What's wrong with following jelly script template for cppcheck in email-ext plugin of hudson"

You just use wrong namespace, right one is: org.jenkinsci.plugins.cppcheck.CppcheckBuildAction.
For debugging you could use the following code:
<j:forEach var="a" items="${build.getActions()}">
action: ${a.getClass().getName()}
<BR/>
</j:forEach>
And finally the following code works for me:
<!-- CppCheck TEMPLATE -->
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>CPPCHECK RESULT</B></TD></TR>
<TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li>Found: ${cppcheckResult.report.getNumberTotal()}</li></B></TD></TR>
</TABLE>
<BR/>
</j:if>
</j:if>
Enjoy!

I found myself wanting to do the same thing: Send a email-ext email with the results of the cppcheck analysis.
This jelly script works with what Sergey provided above and makes a table similar to the one found in the results page.
Hopefully this will save someone an hour somewhere.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<html>
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<h2>Summary</h2>
<style type="text/css">
#cppcheckStatistics { width: auto; }
#cppcheckStatistics .number { text-align: right; }
</style>
<table class="pane sortable" id="cppcheckStatistics">
<thead>
<tr>
<td class="pane-header">Severity</td>
<td class="pane-header">Count</td>
<td class="pane-header">Delta</td>
</tr>
</thead>
<tbody>
<tr>
<td class="pane">Error</td>
<td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
</tr>
<tr>
<td class="pane">Warning</td>
<td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
</tr>
<tr>
<td class="pane">Style</td>
<td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
</tr>
<tr>
<td class="pane">Performance</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
</tr>
<tr>
<td class="pane">Portability</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
</tr>
<tr>
<td class="pane">Information</td>
<td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
</tr>
<tr>
<td class="pane">No category</td>
<td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
</tr>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">Total</td>
<td class="pane-header number"><B>${cppcheckResult.report.getNumberTotal()}</B></td>
<td class="pane-header number"><B>${cppcheckResult.getDiff().getNumberTotal()}</B></td>
</tr>
</tfoot>
</table>
</j:if>
</j:if>
</html>
</j:jelly>

Related

Use HTML Table without headers

I've a table, where the normal guidance for HTML tables arn't followed.
My best move will be, to just create a proper JSON-object, and using that.
But i'll like to ask, if there is any options for parsing an HTML table, "without headers", and define them in Tabulator, instead.
I know the case id odd, but i'll just like to hear :-)
Example where no thead and th is in the HTML-source:
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr height="16">
<td colspan="16">
Something
</td>
<td colspan="16">
14
</td>
<td colspan="16">
2020-01-28
</td>
</tr>
</tbody>
</table>
Im afraid not.
When Tabulator is built on a table element, it parses the HTML to create a JavaScript object for each row of the table, using the column headers as property names.
Without headers it would have no reasonable way to map the column values onto an object.
I solve problem like this
<table border="0" cellpadding="0" cellspacing="0">
<tr height="16" hidden>
<td colspan="16">
</td>
<td colspan="16">
</td>
<td colspan="16">
</td>
</tr>
<tr height="16">
<td colspan="16">
Something
</td>
<td colspan="16">
14
</td>
<td colspan="16">
2020-01-28
</td>
</tr>
</table>

how to find parent element that has specific child using By.xpath()?

Recently i've been scrapping by using selenium-webdriver in nodejs for a few days.
so i have to find element has specific child element but i don't know how find it.
i have used following operator but it doesn't work
By.xPath("tr[contains(#class, 'datetime2')]")
following html
<table>
<tbody>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
20:00
</td>
<tr>
<tr></tr>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
21:00
</td>
<tr>
<tr style="bacrgound-color:#eee">
<td class="datetime2">
22:00
</td>
<tr>
<tr></tr>
</tbody>
</table>
i need to find only 'tr' that include element <td class="datetime2">. not <tr></tr>
how find this element By using By.xpath()?? please help me
please try with following x-path.
//tr[td[#class='datetime2']]

Highlighting Kit/Package components on a picking ticket

I have a customer wanting kit components to be highlighted or specially formatted on a Picking Ticket with an advanced PDF.
I can format the parent with no problem, but the customer wants the components to display in a different background colour. (custom column field indicating a Kit item, then using <#if> on the form to change to Bold...
But i can't find a field or criteria to tell the template if the item in question is a KIT COMPONENT??
Anyone know how I can achieve this?
Cheers
Steve
Just for those who may be interested, I found a way to differentiate between kit parent and kit component on a Picking Ticket Advanced PDF Template.
Firstly, create a transaction column field. Check Box; Stored Value; Sale Item/IF;HIDDEN;Default is CHECKED.
During sales order entry, this field will be "checked" by default. However, as the kit components do not appear on the sales order entry, they will not inherit the default value and thus will remain NULL.
In the advanced PDF template, I did the following:
<#assign committed="${item.quantitycommitted}"/><#if committed="0"><#assign committed=''/></#if>
<#if item.custcol_notcomponent='T'>
<#if item.custcolitemtype="Kit/Package"><tr style="font-weight:bold">
<#else><tr style="font-weight:normal"></#if>
<td width="15%" class="item" font-size="7pt">${item.item}</td>
<td width="20%" class="item" align="center">${item.binnumber}</td>
<td width="40%" class="item">${item.description}</td>
<td width="8%" class="item" align="center">${item.quantity}</td>
<td width="8%" class="item" align="center">${committed}</td>
<td width="8%" class="item"> </td>
<td width="9%" class="item"> </td>
</tr>
<#else>
<tr>
<td width="15%" class="kititem" font-size="7pt"> ${item.item}</td>
<td width="20%" class="kititem" align="center">${item.binnumber}</td>
<td width="40%" class="kititem">${item.description}</td>
<td width="8%" class="kititem" align="center">${item.quantity}</td>
<td width="8%" class="kititem" align="center">${committed}</td>
<td width="8%" class="kititem"> </td>
<td width="9%" class="kititem"> </td>
</tr>
</#if>
The result, is a picking ticket with BOLD kit parents, greyed and indented kit components, and just regular black text for standard inventory items.
Something like this for the transaction lines:
Hope this helps someone out sometime :)
I tried your solution but it won't indent. Looks like it doesn't go to the <#else> part.
<#if item.custcol_f5_not_component = 'T'>
<#if item.custcol_item_type="Kit/Package"><tr style="font-weight:bold"><#else><tr style="font-weight:normal"></#if>
<td colspan="5">${item.custcol_f5_item}</td>
<td colspan="7">${item.description}</td>
<td colspan="2">${item.custcol_skl_bin_location}</td>
<td align="center" colspan="3">${item.quantity}</td>
<td align="center" colspan="2">${item.units}</td>
<td align="center" colspan="3"><b>${item.quantitycommitted}</b></td>
<td align="center" colspan="3">${item.quantitybackordered}</td>
</tr>
<#else>
<tr>
<td colspan="5" style="padding-left:10px;">${item.custcol_f5_item}</td>
<td colspan="7">${item.description}</td>
<td colspan="2">${item.custcol_skl_bin_location}</td>
<td align="center" colspan="3">${item.quantity}</td>
<td align="center" colspan="2">${item.units}</td>
<td align="center" colspan="3"><b>${item.quantitycommitted}</b></td>
<td align="center" colspan="3">${item.quantitybackordered}</td>
</tr>
</#if>

How to pass product TVs to SimpleCart's scGetCart snippet?

I need some TVs (weight, dimensions, etc) I've associated with my products to appear in the Cart page of my SimpleCart site.
Problem is I have no idea how to do this. I don't understand how the SimpleCart cart is built and there isn't documentation for this.
Would anyone know how I can show TVs associated with each product in the cart output chunk?
The cart snippet has the following code which gets data from the cart and puts it into Chunks:
$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return '';
 
$controller = $sc->loadController('Cart');
$output = $controller->run($scriptProperties);
The output Chunk looks like:
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<table>
<tr>
<th class="desc">[[%simplecart.cart.description]]</th>
<th class="price">[[%simplecart.cart.price]]</th>
<th class="quantity">[[%simplecart.cart.quantity]]</th>
[[+cart.total.vat_total:notempty=`<th class="quantity">[[%simplecart.cart.vat]]</th>`:isempty=``]]
<th class="subtotal">[[%simplecart.cart.subtotal]]</th>
<th> </th>
</tr>
[[+cart.wrapper]]
[[+cart.total.discount:notempty=`<tr class="total first discount">
<td colspan="[[+cart.total.vat_total:notempty=`3`:isempty=`2`]]"> </td>
<td class="label">[[%simplecart.cart.discount]]</td>
<td class="value">- [[+cart.total.discount_formatted]]</td>
<td class="extra">[[+cart.total.discount_percent:notempty=`([[+cart.total.discount_percent]]%)`:isempty=` `]]</td>
</tr>`:isempty=``]]
[[+cart.total.vat_total:notempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_ex_vat]]</td>
<td class="value">[[+cart.total.price_ex_vat_formatted]]</td>
<td class="extra"> </td>
</tr>
[[+cart.vat_rates]]
<tr class="total [[+cart.total.discount:notempty=`third`:isempty=`second`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_vat]]</td>
<td class="value">[[+cart.total.vat_total_formatted]]</td>
<td class="extra"> </td>
</tr>
<tr class="total [[+cart.total.discount:notempty=`fourth`:isempty=`third`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_in_vat]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`:isempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="2"> </td>
<td class="label">[[%simplecart.cart.total]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`]]
</table>
<div class="submit">
<input type="submit" value="[[%simplecart.cart.update]]" />
</div>
</form>
This does appear to be documented:
Product Options (TVs)
and to output them:
Modifying the Product Template
It appears that you would just output them normally [[*myProductOptions]]
Though, it appears that your template is using a placeholder, I would try
[[+cart.myProductOptions] as well. If all else fails you might try debugging the simplecart class and dump the array of product data before it populates the chunk, there might be a clue in there.
Found (through trial and error) you must use:
[[+product.tv.name_of_tv]]

Getting data from Website back to excel

I'm trying to automate a page scrape program in Excel using VBA but having difficulty getting the results from the webpage as the fields I want do not have id's, I have copied the source code below I think its contained within a table? how do you get the data using td Class and class?
<table>
<tbody>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of Liability</span></td>
<td class="vehicledetailstableright"><span class="bodytext">01 07 2014</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of First Registration</span></td>
<td class="vehicledetailstableright"><span class="bodytext">02 07 2013</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Year of Manufacture</span></td>
<td class="vehicledetailstableright"><span class="bodytext">2013</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Cylinder Capacity (cc)</span></td>
<td class="vehicledetailstableright"><span class="bodytext">2993cc</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">CO₂ Emissions</span></td>
<td class="vehicledetailstableright"><span class="bodytext">129 g/km</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Fuel Type</span></td>
<td class="vehicledetailstableright"><span id="fueltype" class="bodytext">HEAVY OIL</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Export Marker</span></td>
<td class="vehicledetailstableright"><span id="exportmarker" class="bodytext">N</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Status</span></td>
<td class="vehicledetailstableright"><span id="vehiclelicencestatus" class="bodytext">Licence Not Due</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Colour</span></td>
<td class="vehicledetailstableright"><span id="colour" class="bodytext">BLUE</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Type Approval</span></td>
<td class="vehicledetailstableright"><span class="bodytext">M1</span></td>
</tr>
<tr>
<td class="vehicledetailstableleft"><span class="bodytextbold">Date of Last V5C Issued</span>
</td>
<td class="vehicledetailstableright"><span class="bodytext">No Result Found</span>
</td>
</tr>
Tim is suggesting a code heavy way to do it, and it is technically correct. I suggest the same thing repeatedly here:
VBA spliting results from html imported table into excel
Basically, use the macro recorder, and then create a HTML query for data.
see my blog post on this as well.
http://automatic-office.com/?p=344
Many ways to skin the cat, but this is the easy way.

Resources