-
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.
allow to specify absolute paths for reports. to support msbuild runner
handle paths that are outside project source dir add unit tests support absolute paths
- Loading branch information
Jorge Costa
authored and
Jorge Costa
committed
Nov 29, 2015
1 parent
79b472f
commit 6b2fd4c
Showing
5 changed files
with
222 additions
and
30 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
48 changes: 48 additions & 0 deletions
48
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/DirectoryScannerData.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,48 @@ | ||
/* | ||
* Sonar C++ Plugin (Community) | ||
* Copyright (C) 2010 Neticoa SAS France | ||
* [email protected] | ||
* | ||
* 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 02 | ||
*/ | ||
|
||
package org.sonar.plugins.cxx.utils; | ||
|
||
import java.io.File; | ||
import org.apache.tools.ant.DirectoryScanner; | ||
|
||
public class DirectoryScannerData extends DirectoryScanner { | ||
|
||
DirectoryScannerData() { | ||
} | ||
|
||
public void setBaseDir(String base) { | ||
this.setBasedir(new File(base)); | ||
} | ||
|
||
public void setInclude(String include) { | ||
String[] incls = new String[1]; | ||
incls[0] = include; | ||
this.setIncludes(incls); | ||
} | ||
|
||
public File getBaseDir() { | ||
return this.basedir; | ||
} | ||
|
||
public String [] getIncludes() { | ||
return this.includes; | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/utils/CxxUtilsTest.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,93 @@ | ||
/* | ||
* Sonar C++ Plugin (Community) | ||
* Copyright (C) 2010 Neticoa SAS France | ||
* [email protected] | ||
* | ||
* 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 02 | ||
*/ | ||
package org.sonar.plugins.cxx.utils; | ||
|
||
import org.apache.tools.ant.DirectoryScanner; | ||
import static org.fest.assertions.Assertions.assertThat; | ||
import org.junit.Test; | ||
import org.sonar.plugins.cxx.TestUtils; | ||
|
||
public class CxxUtilsTest { | ||
|
||
@Test | ||
public void whenPathIsAbsoluteAndOutsideBaseDirShouldUseDriveLetterWindows() { | ||
if (TestUtils.isWindows()) { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("m:\\abc\\abs\\", "x:\\src\\abs\\abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("x:"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("x:\\src\\abs\\abc.xml"); | ||
} else { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("/abc/abs", "/src/abs/abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("/"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("/src/abs/abc.xml"); | ||
} | ||
} | ||
|
||
@Test | ||
public void whenPathIsAbsoluteAndIsInBaseDirShouldShouldUseBaseDir() { | ||
if (TestUtils.isWindows()) { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("x:\\src\\abs\\", "x:\\src\\abs\\abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("x:\\src\\abs"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} else { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("/src/abs", "/src/abs/abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("/src/abs"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} | ||
} | ||
|
||
@Test | ||
public void whenPathIsAbsoluteAndIsOutsideProjectShouldShouldUseRootOrDrive() { | ||
if (TestUtils.isWindows()) { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("x:\\mmm\\mmmm\\", "x:\\src\\abs\\abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("x:"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("x:\\src\\abs\\abc.xml"); | ||
} else { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("/bbb/dddd", "/src/abs/abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("/"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("/src/abs/abc.xml"); | ||
} | ||
} | ||
|
||
@Test | ||
public void whenPathIsRelativeAndIsInsideProjectShouldUseProjectDir() { | ||
if (TestUtils.isWindows()) { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("x:\\src\\abs\\", "abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("x:\\src\\abs"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} else { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("/src/abs", "abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("/src/abs"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} | ||
} | ||
|
||
@Test | ||
public void whenPathIsRelativeAndIsOutsideProjectShouldUseFileBaseDir() { | ||
if (TestUtils.isWindows()) { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("x:\\src\\abs\\", "../../abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("x:\\"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} else { | ||
DirectoryScannerData scanner = CxxUtils.GetDirectoryScannerForReport("/src/abs", "../../abc.xml"); | ||
assertThat(scanner.getBasedir().getPath()).isEqualTo("/"); | ||
assertThat(scanner.getIncludes()[0]).isEqualTo("abc.xml"); | ||
} | ||
} | ||
} |