Skip to content

Instantly share code, notes, and snippets.

@LeeCampbell
Last active November 11, 2016 01:15
Show Gist options
  • Save LeeCampbell/9121b7f1b5e2dfeb94aa0ea72e4454ec to your computer and use it in GitHub Desktop.
Save LeeCampbell/9121b7f1b5e2dfeb94aa0ea72e4454ec to your computer and use it in GitHub Desktop.
Code Duplication command line reporter. Uses Jetbrains cmdline tools.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<html>
<body>
<h1>Statistics</h1>
<p>Total codebase size: <xsl:value-of select="//CodebaseCost"/></p>
<p>Code to analyze: <xsl:value-of select="//TotalDuplicatesCost"/></p>
<p>Total size of duplicated fragments: <xsl:value-of select="//CodebaseCost" /></p>
<h1>Detected Duplicates</h1>
<xsl:for-each select="//Duplicates/Duplicate">
<h2>Duplicated Code. Size: <xsl:value-of select="@Cost"/></h2>
<h3>Duplicated Fragments:</h3>
<xsl:for-each select="Fragment">
<xsl:variable name="i" select="position()"/>
<p>Fragment <xsl:value-of select="$i"/> in file <xsl:value-of select="FileName"/></p>
<pre><xsl:value-of select="Text"/></pre>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
#From https://download.jetbrains.com/resharper/JetBrains.ReSharper.CommandLineTools.2016.2.20160913.100041.zip
$codeDupFolder = 'C:\Users\lee.campbell\Downloads\JetBrains.ReSharper.CommandLineTools.2016.2.20160913.100041\'
$codeDuplicateExe = $codeDupFolder + '\dupfinder.exe'
$codeDuplicateXsl = $codeDupFolder + '\dupFinder.xsl'
$xmlOutput = 'C:\Users\lee.campbell\Desktop\LoanServiceSlnDupes.xml'
$htmlOutput = 'C:\Users\lee.campbell\Desktop\LoanServiceSlnDupes.html'
.$codeDuplicateExe --show-text --output="$xmlOutput" -e="**/*.Designer.cs" -e="**/*.generated.cs" -e="**/*Test*/**/*.cs" -e="**/*Event.cs" 'C:\Source\GitHub\Mercury\src\Mercury.LoanService.sln'
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load($codeDuplicateXsl);
$xslt.Transform($xmlOutput, $htmlOutput);
start $htmlOutput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment