Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quality gate isssues #1677

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public class ReservedNamesCheck extends SquidCheck<Grammar> implements CxxCharse
@Override
public void visitFile(AstNode astNode) {

try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
String line;
int nr = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public class UseCorrectIncludeCheck extends SquidCheck<Grammar> implements CxxCh

@Override
public void visitFile(AstNode astNode) {
try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));

// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
String line;
int nr = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public void setCharset(Charset charset) {

@Override
public void visitFile(AstNode astNode) {
try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));

// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
String line;
int nr = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public void setCharset(Charset charset) {

@Override
public void visitFile(AstNode astNode) {
try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));

// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
String line;
int nr = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ public void init() {

@Override
public void visitFile(AstNode astNode) {
try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));

// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {

if (isRegularExpression) {
String fileContent = br.lines().collect(Collectors.joining(System.lineSeparator()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ public void setCharset(Charset charset) {

@Override
public void visitFile(AstNode fileNode) {
try {
if (!compare(invertFilePattern, matchFile())) {
return;
}
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
if (!compare(invertFilePattern, matchFile())) {
return;
}
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
final String fileContent = br.lines().collect(Collectors.joining(System.lineSeparator()));
Matcher matcher = pattern.matcher(fileContent);
if (compare(invertRegularExpression, matcher.find())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public void setCharset(Charset charset) {
@Override
public void visitFile(AstNode fileNode) {
if (compare(invertFilePattern, matchFile())) {
try {
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
String line;
int nr = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public static List<DrMemoryError> parse(File file, String charset) {
public static List<String> getElements(File file, String charset) {

List<String> list = new ArrayList<>();
try (InputStream input = java.nio.file.Files.newInputStream(file.toPath())) {
BufferedReader br = new BufferedReader(new InputStreamReader(input, charset));
try (BufferedReader br = new BufferedReader(
new InputStreamReader(java.nio.file.Files.newInputStream(file.toPath()), charset))) {
StringBuilder sb = new StringBuilder(4096);
String line;
int cnt = 0;
Expand All @@ -109,14 +109,12 @@ public static List<String> getElements(File file, String charset) {
sb.append('\n');
}
}
cnt++;
++cnt;
}

if (sb.length() > 0) {
list.add(sb.toString());
}

br.close();
} catch (IOException e) {
String msg = new StringBuilder(512).append("Cannot feed the data into sonar, details: '")
.append(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public void parseVCppLine(String line, String projectPath, String compilationFil
*/
public void parseVCppLog(File buildLog, String baseDir, String charsetName) {
boolean detectedPlatform = false;
try (InputStream input = java.nio.file.Files.newInputStream(buildLog.toPath())) {
BufferedReader br = new BufferedReader(new InputStreamReader(input, charsetName));
try (BufferedReader br = new BufferedReader(
new InputStreamReader(java.nio.file.Files.newInputStream(buildLog.toPath()), charsetName))) {
String line;
if (LOG.isDebugEnabled()) {
LOG.debug("build log parser baseDir='{}'", baseDir);
Expand Down Expand Up @@ -179,7 +179,6 @@ public void parseVCppLog(File buildLog, String baseDir, String charsetName) {
}
}
}
br.close();
} catch (IOException ex) {
LOG.error("Cannot parse build log", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ public class CxxConfigurationModel extends AbstractConfigurationModel {

private final MapSettings settings = new MapSettings();

ConfigurationProperty charsetProperty = new ConfigurationProperty("Charset", CHARSET_PROPERTY_KEY,
private final ConfigurationProperty charsetProperty = new ConfigurationProperty("Charset", CHARSET_PROPERTY_KEY,
getPropertyOrDefaultValue(CHARSET_PROPERTY_KEY, "UTF-8"),
Validators.charsetValidator());

ConfigurationProperty errorRecoveryEnabled = new ConfigurationProperty("Error Recovery", ERROR_RECOVERY_PROPERTY_KEY,
private final ConfigurationProperty errorRecoveryEnabled = new ConfigurationProperty("Error Recovery", ERROR_RECOVERY_PROPERTY_KEY,
getPropertyOrDefaultValue(ERROR_RECOVERY_PROPERTY_KEY, "false"),
Validators.booleanValidator());

ConfigurationProperty defines = new ConfigurationProperty("Defines", DEFINES_PROPERTY_KEY
private final ConfigurationProperty defines = new ConfigurationProperty("Defines", DEFINES_PROPERTY_KEY
+ " (use \\n\\ as separator)",
getPropertyOrDefaultValue(DEFINES_PROPERTY_KEY, ""));

ConfigurationProperty includeDirectories = new ConfigurationProperty("Include Directories",
private final ConfigurationProperty includeDirectories = new ConfigurationProperty("Include Directories",
INCLUDE_DIRECTORIES_PROPERTY_KEY + " (use , as separator)",
getPropertyOrDefaultValue(INCLUDE_DIRECTORIES_PROPERTY_KEY, ""));

ConfigurationProperty forceIncludes = new ConfigurationProperty("Force Includes", FORCE_INCLUDES_PROPERTY_KEY
private final ConfigurationProperty forceIncludes = new ConfigurationProperty("Force Includes", FORCE_INCLUDES_PROPERTY_KEY
+ " (use , as separator)",
getPropertyOrDefaultValue(FORCE_INCLUDES_PROPERTY_KEY, ""));

Expand Down