How to generate an HTML report from PartCover results .xml - code-coverage

How to generate an HTML report from PartCover results .xml

There is a tool you can use to generate a HTML report:
https://github.com/danielpalme/ReportGenerator
Here you can find an article how to integrate the tool into MSBuild:
http://www.palmmedia.de/Blog/2009/10/30/msbuild-code-coverage-analysis-with-partcover-and-reportgenerator

To my knowledge, there is no convenient tool like NCoverExplorer that can transform a PartCover results .xml file into a .html report, but there are some .xsl files that can be used to transform PartCover's results to .html in CruiseControl.NET: Using CruiseControl.NET with PartCover.
You could take those .xsl files from CruiseControl.NET and convert your PartCover results.xml using something like Sandcastle's XslTransform.exe.
By the way, if this happens to be related to TeamCity, the upcoming 5.0 release will include support for .NET coverage using PartCover or NCover. See the documentation for more informations. Otherwise ignore this paragraph ;-)

Easiest solution is probably to use msxsl, a simple command line transformer. I use it for exactly this purpose, and it's easy to integrate into your build system.
http://www.microsoft.com/downloads/details.aspx?FamilyID=2FB55371-C94E-4373-B0E9-DB4816552E41&displaylang=en

Maybe a complicated way of doing it, but I did this with the Simian xml report. Created an XSL file for the formatting, then wrote a dumb little console application;
private const string MissingExtension = "Please enter a valid {0} file, this is missing the extension.";
private const string InvalidExtension = "Please enter a valid {0} file, the file provided has an invalid extension.";
public static void Main(string[] args)
{
if (args.Length < 2)
{
System.Console.WriteLine("Please enter a xsl file and xml file full path.");
return;
}
var xslFile = args[0];
var xmlFile = args[1];
if (!CheckFileNameFormat(xslFile, false))
return;
if (!CheckFileNameFormat(xmlFile, true))
return;
var transform = new XslCompiledTransform();
// Load the XSL stylesheet.
transform.Load(xslFile);
// Transform xml file into an html using the xsl file provided.
transform.Transform(xmlFile, xmlFile.Replace("xml", "html"));
}
private static bool CheckFileNameFormat(string fileName, bool isXmlFile)
{
var extension = isXmlFile ? "xml" : "xsl";
// valida that the argument has a period
if (fileName.IndexOf(".") < 1)
{
System.Console.WriteLine(string.Format(MissingExtension, extension));
return false;
}
var filePieces = fileName.Split('.');
// split on the period and make sure the extension is valid
if (filePieces[filePieces.GetUpperBound(0)] != extension)
{
System.Console.WriteLine(string.Format(InvalidExtension, extension));
return false;
}
return true;
}
Then I can call it from a MSBuild file like so;
<Target Name="RunSimian" DependsOnTargets="RebuildSolution">
<Exec IgnoreExitCode="true" Command=""$(MSBuildProjectDirectory)\..\Build\Packages\Simian\simian-2.2.24.exe" -formatter=xml:$(MSBuildProjectDirectory)\..\Build\Artifacts\simian.xml -language=cs -excludes=$(MSBuildProjectDirectory)\..\Product\Production\**\*.Designer.cs $(MSBuildProjectDirectory)\Production\**\*.cs" >
</Exec>
<Exec IgnoreExitCode="true" Command=""$(MSBuildProjectDirectory)\..\Build\Packages\XmlToHtmlConverter.exe" $(MSBuildProjectDirectory)\..\Build\Packages\Simian\simian.xsl $(MSBuildProjectDirectory)\..\Build\Artifacts\simian.xml">
</Exec>

Related

How to guess Checksum Algorithm Type?

I am trying to figure out if what I have so far is correct. Just feeling that I am chasing my own tail here, but I do feel that maybe I understand it correctly.
I have this file, where it includes a checksum that is oddly short. This is a set of two files, this one and the one I copied at pastbin under. I noticed that the first file includes the checksum, however it seems that if I change any parameter or the serial number the file will than fail to load.
I am correct to assume that the software looks for some of the xml values add in a string and create the checksum, and than compares it to the checksum in the file? I am not sure how they would have been able to add the checksum in the file itself otherwise, so I guess maybe it just takes some of the values.
Second, am I correct to assume that they just truncated the checksum? I never seen one that small.
In the end I am trying to figure out how to create my own checksum calibration but at the moment I am trying to at minimum understand how it works. Far from braking it :)
<?xml version="1.0" encoding="utf-8"?>
<InstrumentData xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/AcquisitionEngine.Types">
<CalibrationMode>parabolic</CalibrationMode>
<CalibrationTemperatures
xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:double>28</d2p1:double>
<d2p1:double>52</d2p1:double>
<d2p1:double>76</d2p1:double>
<d2p1:double>90</d2p1:double>
</CalibrationTemperatures>
<Checksum>6E23D45E</Checksum>
<ClusterSize>1</ClusterSize>
<HardwareVariant>Hardware_Legacy</HardwareVariant>
<InstrumentID>undefined</InstrumentID>
<LineFrequency>LineFrequency_50Hz</LineFrequency>
<MaxCalibrationDeviation>0.152</MaxCalibrationDeviation>
<SerialNo>6328ZG200015</SerialNo>
<Version>3.2</Version>
</InstrumentData>
The second file is included here https://pastebin.com/YQ1qKZ2v
Update: I have been able to find the code that generates this but I am still not getting the same hash.
private string GenerateChecksum(string serialno)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(this.HardwareVariant);
stringBuilder.Append(serialno);
return HashGenerator.GetHash32AsHex(stringBuilder.ToString());
}
From this line it seems to take the HadwareVariant and the serial number.
Than it seems to take this and generate a hash32 and than add an X2 at the end of it? My background is php, but am I understand this correct?
internal static class HashGenerator
{
private static HashAlgorithm CryptographicHasher;
static HashGenerator()
{
HashGenerator.CryptographicHasher = MD5.Create();
}
public static int GetHash32(string value)
{
byte[] bytes = Encoding.UTF8.GetBytes(value);
return
BitConverter.ToInt32(HashGenerator.CryptographicHasher.ComputeHash(bytes), 0);
}
public static string GetHash32AsHex(string value)
{
return HashGenerator.GetHash32(value).ToString("X2");
}
}

Absolute path on Xtext project

I wanted to know how I can get the absolute path of a file which is inside my project not in the application running.
For example this one:
C:\Users\Mr\Documents\Example\org.xtext.example.mydsl\src\example.txt
I have tried with paths like:
val file = new File("relative path");
val absolutePathString = file.getAbsolutePath();
or
System.getProperty("user.dir");
But all of them retrieves me Eclipse's path and not my project's path.
Thanks for the help!
There does not need to be a file. Assuming you have a default eclipse with default filesystem and talk about a file in a project you may have a look a at these
public void doit(Resource r) {
URI uri = r.getURI();
if (uri.isPlatformResource()) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
file.getLocation();
file.getLocationURI();
file.getRawLocation();
file.getRawLocationURI();
}
}

How does redirection in javac work?

I am currently new with javaC. I have installed JDK and set the path to make it work. I have already done several test programs and they worked.
Let's say I have a java file called Read.java and a text file called Numbers.txt
I have already set my directory to where the files are and I enter to command
javac Read.java
then
java Read < input.txt
Problem is how I can set Read.java program to receive the input.txt file?
I know you can read the file from the program itself without redirection. But I want to learn how you can read a file using redirection.
Java's main method looks something like:
public static void main(String[] args)
{
// method body
}
args is an array of parameters that the user can pass to the program - the first parameter would be args[0], the second args[1] and so on.
To receive the input text file, you can have the user type java Read input.txt. input.txt will be the first parameter, and so you can access it by using args[0] in your main method.
A simple example of command line arguments:
public static void main(String[] args)
{
String input = args[0];
System.out.println("You entered: " + input);
}
You can run this by typing java ProgramName hello, and the output will be You entered hello.
You need to read from standard input:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class IORedirection {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line;
while((line = in.readLine()) != null){
System.out.println(line);
}
}
}
> echo "hello stdin" | java IORedirection
> hello stdin
how I can set Read.java program to receive the input.txt file? I know you can read the file from the program itself without redirection. But I want to learn how you can read a file using redirection.
There are several ways to get input to your program.
This isn't about "Java", but rather what are the ways for the caller to write data to "standard input" (or "stdin"). Within any Java program, you can read stdin with System.in.
So, use System.in within your program, and then use a pipe (|) or a redirect (<). Below are two working examples from an answer I posted on a related question:
% cat input.txt | java SystemInExample.java
% java SystemInExample.java < input.txt

How to read file from an imported library

I have two packages: webserver and utils which provides assets to webserver.
The webserver needs access to static files inside utils. So I have this setup:
utils/
lib/
static.html
How can I access the static.html file in one of my dart scripts in webserver?
EDIT: What I tried so far, is to use mirrors to get the path of the library, and read it from there. The problem with that approach is, that if utils is included with package:, the url returned by currentMirrorSystem().findLibrary(#utils).uri is a package uri, that can't be transformed to an actual file entity.
Use the Resource class, a new class in Dart SDK 1.12.
Usage example:
var resource = new Resource('package:myapp/myfile.txt');
var contents = await resource.loadAsString();
print(contents);
This works on the VM, as of 1.12.
However, this doesn't directly address your need to get to the actual File entity, from a package: URI. Given the Resource class today, you'd have to route the bytes from loadAsString() into the HTTP server's Response object.
I tend to use Platform.script or mirrors to find the main package top folder (i.e. where pubspec.yaml is present) and find imported packages exported assets. I agree this is not a perfect solution but it works
import 'dart:io';
import 'package:path/path.dart';
String getProjectTopPath(String resolverPath) {
String dirPath = normalize(absolute(resolverPath));
while (true) {
// Find the project root path
if (new File(join(dirPath, "pubspec.yaml")).existsSync()) {
return dirPath;
}
String newDirPath = dirname(dirPath);
if (newDirPath == dirPath) {
throw new Exception("No project found for path '$resolverPath");
}
dirPath = newDirPath;
}
}
String getPackagesPath(String resolverPath) {
return join(getProjectTopPath(resolverPath), 'packages');
}
class _TestUtils {}
main(List<String> arguments) {
// User Platform.script - does not work in unit test
String currentScriptPath = Platform.script.toFilePath();
String packagesPath = getPackagesPath(currentScriptPath);
// Get your file using the package name and its relative path from the lib folder
String filePath = join(packagesPath, "utils", "static.html");
print(filePath);
// use mirror to find this file path
String thisFilePath = (reflectClass(_TestUtils).owner as LibraryMirror).uri.toString();
packagesPath = getPackagesPath(thisFilePath);
filePath = join(packagesPath, "utils", "static.html");
print(filePath);
}
To note that since recently Platform.script is not reliable in unit test when using the new test package so you might use the mirror tricks that I propose above and explained here: https://github.com/dart-lang/test/issues/110

TypeScript localization issues

If I use typescript and declare a string there, and set that string to some Russian text.
Then typescript compiler compiles to JavaScript with no regard to encoding I use in solution.
So I get that "questions in rombic symbols" instead of normal letters.
So, do you know how to fix it?
TypeScript as default creates an ANSI encoded file when added using visual studio. (or visual studio creates ansi files as standard)
To fix open the file in notepad and use "save as" and change the encoding to UTF8 or UNICODE.
You need to change your file encoding to UNICODE.
Compiling:
var x = "привет мир";
class foo {
public done() {
return "привет мир";
}
}
Gave the following JS for me:
var x = "привет мир";
var foo = (function () {
function foo() { }
foo.prototype.done = function () {
return "привет мир";
};
return foo;
})();
I have the same issue when I use cscript to run tsc.js compiler.
I've found that the input file for tsc should be in utf-8 with signature (BOM) or unicode-16 encoding.
If I use nodejs to run tsc.js the input file could be in utf-8 even without signature and everything is ok.

Resources