Skip to content

Commit

Permalink
fix sslr-toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
guwirth committed Feb 13, 2020
1 parent d784fad commit 6c40872
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
18 changes: 8 additions & 10 deletions cxx-squid/src/main/java/org/sonar/cxx/CxxConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CxxConfiguration extends SquidConfiguration {
private final Map<String, Set<String>> uniqueDefines = new HashMap<>();
private List<String> forceIncludeFiles = new ArrayList<>();
private List<String> headerFileSuffixes = new ArrayList<>();
private String baseDir;
private String baseDir = "";
private boolean errorRecoveryEnabled = true;
private List<String> cFilesPatterns = new ArrayList<>();
private String jsonCompilationDatabaseFile;
Expand Down Expand Up @@ -95,12 +95,10 @@ public void setCollectMissingIncludes(boolean collectMissingIncludes) {
}

public void setDefines(@Nullable String[] defines) {
if (defines == null) {
return;
if (defines != null && defines.length > 0) {
Set<String> overallDefs = uniqueDefines.get(OVERALLDEFINEKEY);
overallDefs.addAll(Arrays.asList(defines));
}

Set<String> overallDefs = uniqueDefines.get(OVERALLDEFINEKEY);
overallDefs.addAll(Arrays.asList(defines));
}

public void addOverallDefine(String define) {
Expand Down Expand Up @@ -135,7 +133,7 @@ public void addOverallIncludeDirectory(String includeDirectory) {
}

public void setIncludeDirectories(@Nullable String[] includeDirectories) {
if (includeDirectories != null) {
if (includeDirectories != null && includeDirectories.length > 0) {
setIncludeDirectories(Arrays.asList(includeDirectories));
}
}
Expand All @@ -155,7 +153,7 @@ public void setForceIncludeFiles(List<String> forceIncludeFiles) {
}

public void setForceIncludeFiles(@Nullable String[] forceIncludeFiles) {
if (forceIncludeFiles != null) {
if (forceIncludeFiles != null && forceIncludeFiles.length > 0) {
setForceIncludeFiles(Arrays.asList(forceIncludeFiles));
}
}
Expand Down Expand Up @@ -185,7 +183,7 @@ public List<String> getCFilesPatterns() {
}

public void setCFilesPatterns(@Nullable String[] cFilesPatterns) {
if (cFilesPatterns != null) {
if (cFilesPatterns != null && cFilesPatterns.length > 0) {
this.cFilesPatterns = Arrays.asList(cFilesPatterns);
}
}
Expand All @@ -195,7 +193,7 @@ public void setHeaderFileSuffixes(List<String> headerFileSuffixes) {
}

public void setHeaderFileSuffixes(@Nullable String[] headerFileSuffixes) {
if (headerFileSuffixes != null) {
if (headerFileSuffixes != null && headerFileSuffixes.length > 0) {
setHeaderFileSuffixes(Arrays.asList(headerFileSuffixes));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
Expand All @@ -43,22 +44,21 @@ public class SourceCodeProvider {

public void setIncludeRoots(List<Path> includeRoots, String baseDir) {
for (Path includeRoot : includeRoots) {

if (!includeRoot.isAbsolute()) {
includeRoot = Paths.get(baseDir).resolve(includeRoot);
}

try {
if (!includeRoot.isAbsolute()) {
includeRoot = Paths.get(baseDir).resolve(includeRoot);
}
includeRoot = includeRoot.toRealPath();
} catch (java.io.IOException io) {
LOG.error("cannot get canonical form of: '{}'", includeRoot.toString(), io);
}

if (Files.isDirectory(includeRoot)) {
LOG.debug("storing include root: '{}'", includeRoot.toString());
this.includeRoots.add(includeRoot);
} else {
LOG.warn("the include root '{}' doesn't exist", includeRoot.toAbsolutePath().toString());
if (Files.isDirectory(includeRoot)) {
LOG.debug("storing include root: '{}'", includeRoot.toString());
this.includeRoots.add(includeRoot);
} else {
LOG.warn("include root '{}' is not a directory", includeRoot.toString());
}

} catch (IOException | InvalidPathException ex) {
LOG.error("cannot get absolute path of include root '{}'", includeRoot.toString());
}
}
}
Expand Down

0 comments on commit 6c40872

Please sign in to comment.