-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1096 from stefanweiser/master
Add an XSLT pre-analyse step
- Loading branch information
Showing
7 changed files
with
233 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
cxx-sensors/src/test/java/org/sonar/cxx/sensors/other/CxxOtherXsltTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Sonar C++ Plugin (Community) | ||
* Copyright (C) 2010-2017 SonarOpenCommunity | ||
* http://github.com/SonarOpenCommunity/sonar-cxx | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.cxx.sensors.other; | ||
|
||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.File; | ||
import static org.fest.assertions.Assertions.assertThat; | ||
import org.junit.Assert; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.apache.commons.io.FileUtils; | ||
import org.sonar.api.batch.fs.FileSystem; | ||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | ||
import org.sonar.cxx.CxxLanguage; | ||
import org.sonar.api.config.Settings; | ||
import org.sonar.api.measures.CoreMetrics; | ||
import org.sonar.cxx.sensors.utils.TestUtils; | ||
|
||
public class CxxOtherXsltTest { | ||
|
||
private FileSystem fs; | ||
|
||
@Before | ||
public void setUp() { | ||
fs = TestUtils.mockFileSystem(); | ||
} | ||
|
||
@Test | ||
public void shouldReportNothingWhenNoReportFound() { | ||
SensorContextTester context = SensorContextTester.create(fs.baseDir()); | ||
CxxLanguage language = TestUtils.mockCxxLanguage(); | ||
when(language.getStringOption(CxxOtherSensor.REPORT_PATH_KEY)).thenReturn("notexistingpath"); | ||
when(language.getStringOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.STYLESHEET_KEY)).thenReturn("notexistingpath"); | ||
when(language.getStringArrayOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.INPUT_KEY)).thenReturn(new String[] {"notexistingpath"}); | ||
when(language.getStringArrayOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.OUTPUT_KEY)).thenReturn(new String[] {"notexistingpath"}); | ||
CxxOtherSensor sensor = new CxxOtherSensor(language); | ||
|
||
sensor.execute(context); | ||
|
||
File reportAfter = new File("notexistingpath"); | ||
Assert.assertFalse("The output file does exist!", reportAfter.exists() && reportAfter.isFile()); | ||
} | ||
|
||
@Test | ||
public void transformReport_shouldTransformReport() | ||
throws java.io.IOException, javax.xml.transform.TransformerException { | ||
System.out.print("Starting transformReport_shouldTransformReport"); | ||
String stylesheetFile = "externalrules-reports" + File.separator + "externalrules-xslt-stylesheet.xslt"; | ||
String inputFile = "externalrules-reports" + File.separator + "externalrules-xslt-input.xml"; | ||
String outputFile = "externalrules-reports" + File.separator + "externalrules-xslt-output.xml"; | ||
|
||
CxxLanguage language = TestUtils.mockCxxLanguage(); | ||
when(language.getStringOption(CxxOtherSensor.REPORT_PATH_KEY)).thenReturn("externalrules-xslt-output.xml"); | ||
when(language.getStringOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.STYLESHEET_KEY)).thenReturn(stylesheetFile); | ||
when(language.getStringArrayOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.INPUT_KEY)).thenReturn(new String[] {inputFile}); | ||
when(language.getStringArrayOption(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.OUTPUT_KEY)).thenReturn(new String[] {outputFile}); | ||
CxxOtherSensor sensor = new CxxOtherSensor(language); | ||
|
||
sensor.transformFiles(fs.baseDir()); | ||
|
||
File reportBefore = new File(fs.baseDir() + "/" + inputFile); | ||
File reportAfter = new File(fs.baseDir() + "/" + outputFile); | ||
Assert.assertTrue("The output file does not exist!", reportAfter.exists() && reportAfter.isFile()); | ||
Assert.assertTrue("The input and output file is equal!", !FileUtils.contentEquals(reportBefore, reportAfter)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../org/sonar/cxx/sensors/reports-project/externalrules-reports/externalrules-xslt-input.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<results> | ||
<warning filename="sources/utils/code_chunks.cpp" line="1" identifier="cxxexternal-unusedFunction" message="The function 'foo' is never used"/> | ||
<warning filename="sources/utils/utils.cpp" line="1" identifier="cxxexternal-unusedFunction" message="The function 'utils' is never used"/> | ||
</results> |
12 changes: 12 additions & 0 deletions
12
...onar/cxx/sensors/reports-project/externalrules-reports/externalrules-xslt-stylesheet.xslt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
<xsl:output method="xml" version="1.0" encoding="UTF-8"/> | ||
<xsl:template match="results"> | ||
<results> | ||
<xsl:apply-templates/> | ||
</results> | ||
</xsl:template> | ||
<xsl:template match="warning"> | ||
<error id="{@identifier}" msg="{@message}" file="{@filename}" line="{@line}" /> | ||
</xsl:template> | ||
</xsl:stylesheet> |