Count using xslt when looking at sub-strings - templates

I would like to count the number of items that match the following conditions:
/results/errors/error/[#severity='warning']
and
test="not(string-length(substring-before(/results/errors/error/location/#file,'cow'))=0)"
So, while my first condition can easily be counted by using the built in count function
count(//results/errors/error[#severity='warning'])
I do not know how to use the count function for the second condition, as it is not in Xpath format.
Any help you can provide to me would be greatly appreciated. (My XML is below)
The desired answer would be: 2
Thank you,
Belinda
My xml looks like this:
<results version="2">
<errors>
<error id="redundantAssignment" severity="performance" msg="blah, blah.">
<location file="/farm/user/cow/src/IO/file1.cpp"/>
<location file="/farm/user/horse//src/IO/file5.cpp"/>
</error>
<error id="redundantAssignment" severity="warning" msg="blah, blah.">
<location file="/farm/user/sheep/src/IO/file1.cpp"/>
<location file="/farm/user/cow/src/IO/file2.cpp"/>
</error>
<error id="redundantAssignment" severity="error" msg="blah, blah.">
<location file="/farm/user/horse/src/IO/file1.cpp"/>
<location file="/farm/user/cow//src/IO/file3.cpp"/>
</error>
<error id="redundantAssignment" severity="warning" msg="blah, blah.">
<location file="/farm/user/sheep/src/IO/file1.cpp"/>
<location file="/farm/user/cow/src/IO/file3.cpp"/>
</error>
<error id="redundantAssignment" severity="warning" msg="blah, blah.">
<location file="/farm/user/sheep/src/IO/file1.cpp"/>
<location file="/farm/user/horse/src/IO/file3.cpp"/>
</error>
<error id="redundantAssignment" severity="style" msg="blah, blah.">
<location file="/farm/user/sheep/src/IO/file1.cpp"/>
<location file="/farm/user/horse/src/IO/file4.cpp"/>
</error>
<error id="redundantAssignment" severity="style" msg="blah, blah.">
<location file="/farm/user/sheep/src/IO/file1.cpp"/>
<location file="/farm/user/horse/src/IO/file2.cpp"/>
</error>
</errors>
</results>

You should be able to combine both into a single count() by adding the second test to the first predicate:
count(/results/errors/error[#severity='warning' and location[not(string-length(substring-before(#file,'cow'))=0)]])
Using your sample XML input, this produces 2.
Simplification using contains() suggested by Tim C...
count(/results/errors/error[#severity='warning' and location[contains(#file,'cow')]])

Related

cppcheck generates wrong xml structure

I am trying to parse the XML data from the output of cppcheck. But the XML structure seems wrong.
cppcheck src --enable=warning,style,unusedFunction --xml --inconclusive --std=posix --std=c++11 2> error_s.xml
cppcheck XML output:
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.82"/>
<errors>
<error id="funcArgNamesDifferent" severity="style" msg="Blah Blah bLah." verbose="Blah Blah Verbose" cwe="628" inconclusive="true">
<location file="src/DataLayer/ABC.cpp" line="329"/>
<location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
<location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
<location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
</error>
</errors>
</results>
Shouldn't the location node be inside an array like locations?
<locations>
<location file="src/DataLayer/ABC.cpp" line="329"/>
<location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
</locations>
unfortunately it cannot be accessed with out writting too many if-statements ..
if(isset($location)){
}
Conversation with CppChecker Developer.. Hopefully it would get fixed when they release v3
for now, the only way to access is using too many if-Statements.
if not, there is also library htmlreport which will generate html pages..

Stackdriver Logging | Missing TraceId and SpanId

I am trying to integrate SpringBootApplication(microservice) with StackdriverLogging by using spring-cloud-gcp-starter-logging. I am able to see the logs in GCP but in the logs traceId and SpanId is missing.For this I tried to use Spring-cloud-sleuth also, but as I am using apache kafka in my microservice sleuth is not working properly.
Can anyone help me how Can I add traceId and SpanId information in logs??
POM.xml Configuration :
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>
logback.xml :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/cloud/gcp/autoconfigure/logging/logback-json-appender.xml" />
<appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.springframework.cloud.gcp.logging.StackdriverJsonLayout">
<includeTraceId>true</includeTraceId>
<includeSpanId>true</includeSpanId>
<includeThreadName>false</includeThreadName>
</layout>
</encoder>
</appender>
<logger name="org.apache.kafka" level="warn">
<appender-ref ref="CONSOLE_JSON" />
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE_JSON" />
</root>
</configuration>
By default, Sleuth doesn’t send the trace data for every single request. You probably don’t want to trace every single request either. The trace sampling rate can be adjusted by configuring the spring.sleuth.sampler.percentage property. For more details please refer to "Spring Boot and Spring Cloud Sleuth" in this link and have a look to this video.

WiX Heat.exe generates different output after VS2008 -> VS2015 upgrade

We execute the following command line with heat (3.0.5210.0):
heat.exe -srd -suid file OurLib.dll -out bin_OurLib.tmp
OurLib.dll is a VC++ 2008 dll file, it's a COM component.
Output (bin_OurLib.tmp)
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="OurLib.dll" Guid="PUT-GUID-HERE">
<File Id="OurLib.dll" KeyPath="yes" Source="SourceDir\OurLib.dll">
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}" Context="InprocServer32" Description="OurProduct.OurLib">
<ProgId Id="OurProduct.OurLib" Description="OurProduct.OurLib" />
</Class>
</File>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
This works fine.
Now we updated the VS to 2015, and compiled OurLib with it.
Running the same heat command now results in different output:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="OurLib.dll" Guid="PUT-GUID-HERE">
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}" Context="InprocServer32" Description="OurProduct.OurLib">
<ProgId Id="OurProduct.OurLib" Description="OurProduct.OurLib" />
</Class>
<File Id="OurLib.dll" KeyPath="yes" Source="SourceDir\OurLib.dll" />
<RegistryValue Root="HKCR" Key="CLSID\{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}\InProcServer32" Value=""[#OurLib.dll]"" Type="string" Action="write" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
And when wix is linking, it gives error:
error LGHT0130 : The primary key 'reg51A1FC16367511AF81E9B18CA009A1C6' is duplicated in table 'Registry'. Please remove one of the entries or rename a part of the primary key to avoid the collision.
Checking the wixobj file, reg51A1FC16367511AF81E9B18CA009A1C6 is related to line
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}...." and <RegistryValue Root="HKCR" Key="CLSID\{B1AB.... - obviously.
Anwyay, this is obviously due to the generated wix output files are different.
Why is that if compiling a dll with a newer C++ compiler will cause WIX HEAT to generate different output, while running the same options, etc.
And how can I have back the same "old" output, which we need.
Tried with -scom and -sreg, none of them gave back the "old" output.
Well primary key duplicated means you've got that same RegistryValue in two different places in your wix source code somehow.
Or maybe the newer DLL is self-registering differently? It's putting the InProcServer32 value in quotes. I don't think that's normal.
Or have you checked that your 2008 and 2015 DLL source and project files are identical? The VS project upgrade process changes things...

PHPUnit doesn't load some of the tests

I have a tests folder in one of my modules, with 3 subfolders:
Model
Helper
Integration
running
phpunit --group My_Module
executes only the tests in Model and Helper directories, with the Integration folder left untouched. Test files reside directly in the folder in all of the cases, so I'm not sure what's causing the problem.
Here's my phpunit.xml:
<?xml version="1.0"?>
<!-- initial phpunit configuration file, that you can modify for your project needs -->
<phpunit cacheTokens="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false"
bootstrap="app/code/community/EcomDev/PHPUnit/bootstrap.php">
<listeners>
<listener file="app/code/community/EcomDev/PHPUnit/Test/Listener.php" class="EcomDev_PHPUnit_Test_Listener" />
</listeners>
<testsuites>
<testsuite name="MyApp">
<directory suffix=".php">app/code/local/*/*/Test/*/</directory>
</testsuite>
<testsuite name="Magento Test Suite">
<file>app/code/community/EcomDev/PHPUnit/Test/Suite.php</file>
</testsuite>
</testsuites>
<filter>
<blacklist>
<!-- Exclude Magento Core files from code coverage -->
<directory suffix=".php">app/code/core</directory>
<!-- Exclude EcomDev_PHPUnit classes from code coverage -->
<directory suffix=".php">app/code/community/EcomDev/PHPUnit</directory>
<directory suffix=".php">lib/EcomDev/Utils</directory>
<directory suffix=".php">lib/EcomDev/PHPUnit</directory>
<directory suffix=".php">lib/Spyc</directory>
<directory suffix=".php">lib/vfsStream</directory>
<!-- Exclude Mage.php file from code coverage -->
<file>app/Mage.php</file>
<!-- Exclude template files -->
<directory suffix=".phtml">app/design</directory>
<!-- Exclude Varien & Zend libraries -->
<directory suffix=".php">lib/Varien</directory>
<directory suffix=".php">lib/Zend</directory>
</blacklist>
</filter>
<logging>
<!-- Uncomment this line if you want to have coverage report generated every test run
<log type="coverage-html" target="var/phpunit/coverage" charset="UTF-8"
yui="true" highlight="false"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="var/phpunit/coverage.xml"/>
-->
<log type="junit" target="../build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
The version of PHPunit I'm running on ubuntu VM is 3.7.28. How can I get all of the tests to run? Help would be much appreciated.
Try to call
phpunit --list-groups
This show you list of available test groups. Do you see My_Module in list?
1) Yes - issue in tests folders/structure.
2) No - issue in xml configuration.

Configuring context path for jetty with static resources

I have a maven application configured to start Jetty and also load statics from ../client . Configuration is below:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.4.v20120524</version>
<configuration>
<scanIntervalSeconds>25</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>9095</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppSourceDirectory>../client/</webAppSourceDirectory>
<webAppConfig>
<resourceBases>
<resourceBase>src/main/webapp</resourceBase>
<resourceBase>../client/</resourceBase>
</resourceBases>
</webAppConfig>
</configuration>
</plugin>
What I am trying to do is to move only webapp under /API resource base. To be more explicit I want to have the mappings:
src/main/webapp ---> /API
../client/ ---> /
Finally found the right config:
<webAppConfig>
<contextPath>/API</contextPath>
</webAppConfig>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<contextPath>/</contextPath>
<resourceBase>../client/</resourceBase>
</contextHandler>
</contextHandlers>