Skip to content

Commit

Permalink
Support TFS team builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk committed Aug 23, 2015
1 parent d83b079 commit df04208
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.MatchResult;

import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;

import org.sonar.plugins.cxx.utils.CxxUtils;

/**
Expand All @@ -39,7 +39,7 @@ public class CxxCompilerVcParser implements CompilerParser {
// ToDo: as long as java 7 API is not used the support of named groups for regular expression is not possible
// sample regex for VS2012/2013: "^.*>(?<filename>.*)\\((?<line>\\d+)\\):\\x20warning\\x20(?<id>C\\d+):(?<message>.*)$";
// get value with e.g. scanner.match().group("filename");
public static final String DEFAULT_CHARSET_DEF = "UTF-8"; // use "UTF-16" for VS2010 build log
public static final String DEFAULT_CHARSET_DEF = "UTF-8"; // use "UTF-16" for VS2010 build log or TFS Team build log file

/**
* {@inheritDoc}
Expand Down Expand Up @@ -74,10 +74,10 @@ public String defaultCharset() {
*/
public void processReport(final Project project, final SensorContext context, File report, String charset, String reportRegEx, List<Warning> warnings) throws java.io.FileNotFoundException
{
CxxUtils.LOG.info("Parsing 'Visual C++' format");
CxxUtils.LOG.info("Parsing 'Visual C++' format ({})",charset);
Scanner scanner = new Scanner(report, charset);
Pattern p = Pattern.compile(reportRegEx, Pattern.MULTILINE);
CxxUtils.LOG.debug("Using pattern : '" + p.toString() + "'");
CxxUtils.LOG.info("Using pattern : '" + p.toString() + "'");
MatchResult matchres = null;
while (scanner.findWithinHorizon(p, 0) != null) {
matchres = scanner.match();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import java.util.ArrayList;
import java.util.Set;

import org.apache.tools.ant.DirectoryScanner;
import org.apache.commons.io.FilenameUtils;
import org.sonar.api.batch.Sensor;
Expand Down Expand Up @@ -157,53 +156,59 @@ public static List<File> getReports(Settings conf,
String reportPath = conf.getString(reportPathPropertyKey);
List<File> reports = new ArrayList<File>();
if (reportPath != null && !reportPath.isEmpty()) {
// ToDo: Remove the dependency to org.apache.commons.io and use java.nio.file.Paths instead (Java 1.7)
reportPath = FilenameUtils.normalize(reportPath);
CxxUtils.LOG.debug("Using pattern '{}' to find reports", reportPath);

DirectoryScanner scanner = new DirectoryScanner();
String[] includes = new String[1];
includes[0] = reportPath;
scanner.setIncludes(includes);
String baseDirPath = baseDirPath1;
scanner.setBasedir(new File(baseDirPath));
String[] relPaths = new String[0];
try {
scanner.scan();
relPaths = scanner.getIncludedFiles();
} catch (IllegalStateException e) {
CxxUtils.LOG.error("Invalid report baseDir '{}'", baseDirPath);
}
if (relPaths.length < 1 && !baseDirPath2.isEmpty()) {
baseDirPath = baseDirPath2;
File singleFile = new File(reportPath);
if (singleFile.exists()) {
reports.add(singleFile);
} else {
CxxUtils.LOG.debug("Using pattern '{}' to find reports", reportPath);
// ToDo: Does the ant pattern search makes any sense for tool reports???
// Why shouldn't we use a list of report files ...
DirectoryScanner scanner = new DirectoryScanner();
String[] includes = new String[1];
includes[0] = reportPath;
scanner.setIncludes(includes);
String baseDirPath = baseDirPath1;
scanner.setBasedir(new File(baseDirPath));
String[] relPaths = new String[0];
try {
scanner.scan();
relPaths = scanner.getIncludedFiles();
} catch (IllegalStateException e) {
CxxUtils.LOG.error("Invalid report baseDir '{}'", baseDirPath);
}
}

for (String relPath : relPaths) {
String path = CxxUtils.normalizePath(new File(baseDirPath, relPath).getAbsolutePath());
try {
File reportFile = new File(path);
if (reportFile.exists()) {
reports.add(reportFile);
} else {
CxxUtils.LOG.error("Can't read report '{}'", path);
if (relPaths.length < 1 && !baseDirPath2.isEmpty()) {
baseDirPath = baseDirPath2;
scanner.setBasedir(new File(baseDirPath));
try {
scanner.scan();
relPaths = scanner.getIncludedFiles();
} catch (IllegalStateException e) {
CxxUtils.LOG.error("Invalid report baseDir '{}'", baseDirPath);
}
} catch (SecurityException e) {
CxxUtils.LOG.error("Read access to report '{}' denied", path);
}
}
if (reports.isEmpty()) {
CxxUtils.LOG.warn("Cannot find a report for '{}={}'", reportPathPropertyKey, reportPath);

for (String relPath : relPaths) {
String path = CxxUtils.normalizePath(new File(baseDirPath, relPath).getAbsolutePath());
try {
File reportFile = new File(path);
if (reportFile.exists()) {
reports.add(reportFile);
} else {
CxxUtils.LOG.error("Can't read report '{}'", path);
}
} catch (SecurityException e) {
CxxUtils.LOG.error("Read access to report '{}' denied", path);
}
}
if (reports.isEmpty()) {
CxxUtils.LOG.warn("Cannot find a report for '{}={}'", reportPathPropertyKey, reportPath);
}
}
} else {
CxxUtils.LOG.error("Undefined report path value for key '{}'", reportPathPropertyKey);
}

return reports;
}

Expand Down

0 comments on commit df04208

Please sign in to comment.