import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.web.Footer;
-import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.Page;
import org.sonar.api.web.RubyRailsWebservice;
import org.sonar.api.web.Widget;
*/
package org.sonar.application;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.sonar.process.ConfigurationUtils;
import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.net.URISyntaxException;
import java.util.Properties;
Properties p = new Properties();
File propsFile = new File(homeDir, "conf/sonar.properties");
if (propsFile.exists()) {
- FileReader reader = new FileReader(propsFile);
- try {
+ try (Reader reader = new InputStreamReader(new FileInputStream(propsFile), Charsets.UTF_8)) {
p.load(reader);
- } finally {
- IOUtils.closeQuietly(reader);
}
}
return p;
*/
package org.sonar.batch.mediumtest;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.Charsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.SonarPlugin;
import org.sonar.core.source.SnapshotDataTypes;
import javax.annotation.CheckForNull;
-
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public TaskBuilder newScanTask(File sonarProps) {
Properties prop = new Properties();
- FileReader reader = null;
- try {
- reader = new FileReader(sonarProps);
+ try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), Charsets.UTF_8)) {
prop.load(reader);
} catch (Exception e) {
throw new IllegalStateException("Unable to read configuration file", e);
- } finally {
- if (reader != null) {
- IOUtils.closeQuietly(reader);
- }
}
TaskBuilder builder = new TaskBuilder(this);
builder.property("sonar.task", "scan");
}
public static class TaskBuilder {
- private final Map<String, String> taskProperties = new HashMap<String, String>();
+ private final Map<String, String> taskProperties = new HashMap<>();
private BatchMediumTester tester;
public TaskBuilder(BatchMediumTester tester) {
*/
package org.sonar.batch.scan.maven;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.Charsets;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.resources.Project;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
public class MavenPluginsConfigurator implements BatchComponent {
MavenProject pom = project.getPom();
if (pom != null) {
File targetPom = new File(project.getFileSystem().getSonarWorkingDirectory(), "sonar-pom.xml");
- FileWriter fileWriter = null;
- try {
- fileWriter = new FileWriter(targetPom, false);
+ try (Writer fileWriter = new OutputStreamWriter(new FileOutputStream(targetPom, false), Charsets.UTF_8)) {
pom.writeModel(fileWriter);
} catch (IOException e) {
throw new IllegalStateException("Can not save pom to " + targetPom, e);
- } finally {
- IOUtils.closeQuietly(fileWriter);
}
}
}
*/
package org.sonar.batch.scan2;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.utils.text.JsonWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.util.Properties;
public final class AnalysisPublisher {
private void exportIssues(File exportDir) {
File issuesFile = new File(exportDir, "issues.json");
- FileWriter issueWriter = null;
- try {
- issueWriter = new FileWriter(issuesFile);
+ try (Writer issueWriter = new OutputStreamWriter(new FileOutputStream(issuesFile), Charsets.UTF_8)) {
JsonWriter jsonWriter = JsonWriter.of(issueWriter);
jsonWriter
.beginObject().name("issues")
.close();
} catch (IOException e) {
throw unableToExport(e);
- } finally {
- IOUtils.closeQuietly(issueWriter);
}
}
private void exportMeasures(File exportDir) {
File measuresFile = new File(exportDir, "measures.json");
- FileWriter measureWriter = null;
- try {
- measureWriter = new FileWriter(measuresFile);
+ try (Writer measureWriter = new OutputStreamWriter(new FileOutputStream(measuresFile), Charsets.UTF_8)) {
JsonWriter jsonWriter = JsonWriter.of(measureWriter);
jsonWriter
.beginObject().name("measures")
.close();
} catch (IOException e) {
throw unableToExport(e);
- } finally {
- IOUtils.closeQuietly(measureWriter);
}
}
File propsFile = new File(exportDir, "analysis.properties");
Properties props = new Properties();
props.putAll(settings.getProperties());
- FileWriter writer = null;
- try {
- writer = new FileWriter(propsFile);
+ try (Writer writer = new OutputStreamWriter(new FileOutputStream(propsFile), Charsets.UTF_8)) {
props.store(writer, "SonarQube batch");
} catch (IOException e) {
throw unableToExport(e);
- } finally {
- IOUtils.closeQuietly(writer);
}
}
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
*/
package org.sonar.api.utils.command;
+import com.google.common.base.Charsets;
import com.google.common.io.Closeables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nullable;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
return execute(command, new DefaultConsumer(), new DefaultConsumer(), timeoutMilliseconds);
}
- private void closeStreams(Process process) {
+ private void closeStreams(@Nullable Process process) {
if (process != null) {
Closeables.closeQuietly(process.getInputStream());
Closeables.closeQuietly(process.getInputStream());
}
}
- private void waitUntilFinish(StreamGobbler thread) {
+ private void waitUntilFinish(@Nullable StreamGobbler thread) {
if (thread != null) {
try {
thread.join();
@Override
public void run() {
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- try {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
consumeLine(line);
}
} catch (IOException ioe) {
exception = ioe;
-
- } finally {
- Closeables.closeQuietly(br);
- Closeables.closeQuietly(isr);
}
}
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
// And fail only if there are missing keys
return missingKeys.isEmpty();
} catch (IOException e) {
- fail("An error occured while reading the bundles: " + e.getMessage());
+ fail("An error occurred while reading the bundles: " + e.getMessage());
return false;
} finally {
IOUtils.closeQuietly(bundleInputStream);
dumpFile.delete();
}
dumpFile.getParentFile().mkdirs();
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(new FileOutputStream(dumpFile), Charsets.UTF_8);
+ try (Writer writer = new OutputStreamWriter(new FileOutputStream(dumpFile), Charsets.UTF_8)) {
writer.write(details);
} catch (IOException e) {
throw new IllegalStateException("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'", e);
- } finally {
- IOUtils.closeQuietly(writer);
}
}
protected static SortedMap<String, String> retrieveMissingTranslations(InputStream bundle, InputStream referenceBundle) throws IOException {
- SortedMap<String, String> missingKeys = new TreeMap();
+ SortedMap<String, String> missingKeys = new TreeMap<>();
Properties bundleProps = loadProperties(bundle);
Properties referenceProperties = loadProperties(referenceBundle);