-
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 enable test fix it ensure we use correct casing for drives, ensure search path is relative to base dir when searching absolute paths disable test use recursive file finder to lookup for files disable tests for now try to force appveyor disable test
- Loading branch information
Jorge Costa
authored and
Jorge Costa
committed
Dec 11, 2015
1 parent
f55b8fd
commit 2e2012e
Showing
17 changed files
with
360 additions
and
70 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
87 changes: 87 additions & 0 deletions
87
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxFileFinder.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 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 static java.nio.file.FileVisitResult.CONTINUE; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.PathMatcher; | ||
import java.nio.file.Paths; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class CxxFileFinder extends SimpleFileVisitor<Path> { | ||
|
||
private final PathMatcher matcher; | ||
private final boolean recursive; | ||
private final String baseDir; | ||
private List<Path> matchedPaths = new ArrayList<Path>(); | ||
|
||
CxxFileFinder(String pattern, String baseDir, boolean recursive) { | ||
matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); | ||
this.recursive = recursive; | ||
this.baseDir = baseDir.toLowerCase(); | ||
} | ||
|
||
void match(Path file) { | ||
Path name = file.getFileName(); | ||
|
||
if (name != null && matcher.matches(name)) { | ||
matchedPaths.add(file); | ||
} | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | ||
if (recursive) { | ||
match(file); | ||
} else { | ||
String parentPath = file.getParent().toString().toLowerCase(); | ||
if (parentPath.equals(this.baseDir)) { | ||
match(file); | ||
} | ||
} | ||
|
||
return CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFileFailed(Path file, IOException exc) { | ||
CxxUtils.LOG.warn("File access Failed '{}' : ", file, exc.getMessage()); | ||
return CONTINUE; | ||
} | ||
|
||
public Collection<Path> getMatchedPaths() { | ||
return matchedPaths; | ||
} | ||
|
||
public static Collection<Path> FindFiles(String baseDir, String pattern, boolean recursive) throws IOException { | ||
CxxFileFinder finder = new CxxFileFinder(pattern, baseDir, recursive); | ||
Files.walkFileTree(Paths.get(baseDir), finder); | ||
return finder.getMatchedPaths(); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/utils/CxxSearchPathData.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,55 @@ | ||
/* | ||
* 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; | ||
|
||
public class CxxSearchPathData { | ||
private String pattern = ""; | ||
private String basePath = ""; | ||
private boolean recursive; | ||
|
||
CxxSearchPathData() { | ||
this.recursive = false; | ||
} | ||
|
||
public void setBaseDir(String base) { | ||
this.basePath = base; | ||
} | ||
|
||
public void setPattern(String pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
public String getBaseDir() { | ||
return this.basePath; | ||
} | ||
|
||
public String getPattern() { | ||
return this.pattern; | ||
} | ||
|
||
public void setRecursive() { | ||
this.recursive = true; | ||
} | ||
|
||
public boolean isRecursive() { | ||
return this.recursive; | ||
} | ||
} |
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
Oops, something went wrong.