Skip to content

Commit

Permalink
fix c/c++ guessing based on pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jmecosta committed Jul 7, 2016
1 parent 6b91f60 commit 3acba94
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 209 deletions.
2 changes: 0 additions & 2 deletions cxx-checks/src/main/java/org/sonar/cxx/checks/CheckList.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public static List<Class> getChecks() {
UsingNamespaceInHeaderCheck.class,
SafetyTagCheck.class,
UseCorrectIncludeCheck.class,
// XPathCheck.class, this gives class not found exception in 5.6
// XPath no longer found in other plugins
BooleanEqualityComparisonCheck.class,
NestedStatementsCheck.class,
TooManyParametersCheck.class,
Expand Down
98 changes: 0 additions & 98 deletions cxx-checks/src/main/java/org/sonar/cxx/checks/XPathCheck.java

This file was deleted.

101 changes: 0 additions & 101 deletions cxx-checks/src/test/java/org/sonar/cxx/checks/XPathCheckTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,13 @@ public Collection<Include> getMissingIncludeFiles(File file) {

private boolean isCFile(String filePath) {
for (String pattern : cFilesPatterns) {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
if (filePath.matches(regex)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Parse '{}' as C file, matches '{}' pattern", filePath, pattern);
}
String patt = pattern.replace("*", "");

This comment has been minimized.

Copy link
@guwirth

guwirth Jul 7, 2016

Collaborator

public static boolean isFileMatchTargetFilePattern(final File f, final String targetPattern) {
String regex = targetPattern.replace(".", "."); //escape the dot first
regex = regex.replace("?", ".?").replace("", ".");
return f.getName().matches(regex);
}

This comment has been minimized.

Copy link
@jmecosta

jmecosta Jul 8, 2016

Author Member

do we even need to use regular expressions? isnt enough just to check the end of the name? and if the extension endswith.

anywya, this problem is now fixed. now there are still a few its broken related with unit tests and coverage. i am investigating those now

if (filePath.endsWith(patt)) {
LOG.debug("Parse '{}' as C file, ends in '{}'", filePath, pattern);
return true;
}
}
if (LOG.isTraceEnabled()) {
LOG.trace("Parse '{}' as C++ file", filePath);
}
LOG.debug("Parse '{}' as C++ file", filePath);
return false;
}

Expand Down

0 comments on commit 3acba94

Please sign in to comment.