[jscover] 55/69: Tidying
Sylvestre Ledru
sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
sylvestre pushed a commit to branch master
in repository jscover.
commit 13b30942394e0dbf58c7be1e2b288f728594419c
Author: tntim96 <tntim96 at gmail.com>
Date: Sun Jul 27 20:53:13 2014 +1000
Tidying
---
.../jscover/report/ConfigurationForReport.java | 99 +++++++++++++---------
src/main/java/jscover/server/ProxyService.java | 6 +-
src/main/java/jscover/util/LogFormatter.java | 4 +-
src/main/java/jscover/util/LoggerUtils.java | 30 ++++---
4 files changed, 81 insertions(+), 58 deletions(-)
diff --git a/src/main/java/jscover/report/ConfigurationForReport.java b/src/main/java/jscover/report/ConfigurationForReport.java
index 241c700..3175a0b 100644
--- a/src/main/java/jscover/report/ConfigurationForReport.java
+++ b/src/main/java/jscover/report/ConfigurationForReport.java
@@ -423,22 +423,7 @@ public class ConfigurationForReport extends Configuration {
}
public ConfigurationForReport parse(String[] args) {
- for (int i = 0; i < args.length; i++) {
- String arg = args[i];
- if (arg.equals(HELP_PREFIX1) || arg.equals(HELP_PREFIX2)) {
- showHelp = true;
- return this;
- } else if (arg.startsWith(FORMAT_PREFIX)) {
- format = true;
- reportFormat = ReportFormat.valueOf(arg.substring(FORMAT_PREFIX.length()));
- } else if (arg.startsWith(MERGE_PREFIX)) {
- merge = true;
- } else {
- if (merge) {
- mergeDirs.add(new File(arg));
- }
- }
- }
+ if (parseArgs(args)) return this;
if (format && merge || (!format && !merge)) {
invalid = true;
@@ -446,40 +431,70 @@ public class ConfigurationForReport extends Configuration {
return this;
}
if (merge) {
- if (mergeDirs.size() < 3) {
- System.err.println("Must specify more than one directory to merge");
+ if (parseForMerge()) return this;
+ } else {//Must be format
+ if (parseForFormat(args)) return this;
+ }
+ return this;
+ }
+
+ private boolean parseForFormat(String[] args) {
+ if (reportFormat == LCOV || reportFormat == COBERTURAXML) {
+ if (args.length != 3) {
invalid = true;
showHelp = true;
- return this;
+ return true;
}
- mergeDestDir = mergeDirs.get(mergeDirs.size()-1);
- mergeDirs.remove(mergeDestDir);
- for (File mergeDir : mergeDirs) {
- if (!isValidReportDirectory(mergeDir)) {
- invalid = true;
- showHelp = true;
- return this;
- }
+ jsonDirectory = getDirectory(args[args.length - 2]);
+ sourceDirectory = getDirectory(args[args.length - 1]);
+ } else {
+ if (args.length != 2) {
+ invalid = true;
+ showHelp = true;
+ return true;
}
- } else {//Must be format
- if (reportFormat == LCOV || reportFormat == COBERTURAXML) {
- if (args.length != 3) {
- invalid = true;
- showHelp = true;
- return this;
- }
- jsonDirectory = getDirectory(args[args.length - 2]);
- sourceDirectory = getDirectory(args[args.length - 1]);
+ jsonDirectory = getDirectory(args[args.length - 1]);
+ }
+ return false;
+ }
+
+ private boolean parseForMerge() {
+ if (mergeDirs.size() < 3) {
+ System.err.println("Must specify more than one directory to merge");
+ invalid = true;
+ showHelp = true;
+ return true;
+ }
+ mergeDestDir = mergeDirs.get(mergeDirs.size()-1);
+ mergeDirs.remove(mergeDestDir);
+ for (File mergeDir : mergeDirs) {
+ if (!isValidReportDirectory(mergeDir)) {
+ invalid = true;
+ showHelp = true;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean parseArgs(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i];
+ if (arg.equals(HELP_PREFIX1) || arg.equals(HELP_PREFIX2)) {
+ showHelp = true;
+ return true;
+ } else if (arg.startsWith(FORMAT_PREFIX)) {
+ format = true;
+ reportFormat = ReportFormat.valueOf(arg.substring(FORMAT_PREFIX.length()));
+ } else if (arg.startsWith(MERGE_PREFIX)) {
+ merge = true;
} else {
- if (args.length != 2) {
- invalid = true;
- showHelp = true;
- return this;
+ if (merge) {
+ mergeDirs.add(new File(arg));
}
- jsonDirectory = getDirectory(args[args.length - 1]);
}
}
- return this;
+ return false;
}
boolean isValidReportDirectory(File dir) {
diff --git a/src/main/java/jscover/server/ProxyService.java b/src/main/java/jscover/server/ProxyService.java
index c325f86..fffa0ea 100644
--- a/src/main/java/jscover/server/ProxyService.java
+++ b/src/main/java/jscover/server/ProxyService.java
@@ -369,7 +369,7 @@ public class ProxyService {
protected void handleProxyRequest(HttpRequest request, OutputStream os, String method) {
logger.log(FINE, "handleProxyRequest for {0}", request.getUrl());
URL url = request.getUrl();
- Socket socket;
+ Socket socket = null;
InputStream remoteInputStream = null;
OutputStream remoteOutputStream = null;
try {
@@ -388,12 +388,13 @@ public class ProxyService {
} finally {
ioUtils.closeQuietly(remoteOutputStream);
ioUtils.closeQuietly(remoteInputStream);
+ ioUtils.closeQuietly(socket);
}
}
protected void handleProxyPostOrPut(HttpRequest request) {
URL url = request.getUrl();
- Socket socket;
+ Socket socket = null;
InputStream remoteInputStream = null;
OutputStream remoteOutputStream = null;
try {
@@ -408,6 +409,7 @@ public class ProxyService {
} finally {
ioUtils.closeQuietly(remoteOutputStream);
ioUtils.closeQuietly(remoteInputStream);
+ ioUtils.closeQuietly(socket);
}
}
diff --git a/src/main/java/jscover/util/LogFormatter.java b/src/main/java/jscover/util/LogFormatter.java
index 5c1d688..b9361c2 100644
--- a/src/main/java/jscover/util/LogFormatter.java
+++ b/src/main/java/jscover/util/LogFormatter.java
@@ -362,12 +362,14 @@ public class LogFormatter extends Formatter {
pw.close();
throwable = sw.toString();
}
-
String message = record.getMessage();
if (record.getParameters() != null && record.getParameters().length > 0) {
message = MessageFormat.format(record.getMessage(), record.getParameters());
}
+ return getFormat(record, throwable, message);
+ }
+ private String getFormat(LogRecord record, String throwable, String message) {
return String.format("%1$tY%1$tm%1$td %1$tk:%1$tM:%1$tS.%1$tL,%2$d,%3$s,\"%4$s\",%5$s,%6$s%n"
, new Date(record.getMillis())
, record.getThreadID()
diff --git a/src/main/java/jscover/util/LoggerUtils.java b/src/main/java/jscover/util/LoggerUtils.java
index bb53b52..d4be0f3 100644
--- a/src/main/java/jscover/util/LoggerUtils.java
+++ b/src/main/java/jscover/util/LoggerUtils.java
@@ -374,24 +374,28 @@ public class LoggerUtils {
File file = new File(dir, "jscover.log");
if (file.exists())
file.delete();
- FileHandler fileTxt = new FileHandler(file.getAbsolutePath(), true);
- Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
- while (names.hasMoreElements()) {
- String loggerName = names.nextElement();
- Logger logger = LogManager.getLogManager().getLogger(loggerName);
- logger.setLevel(level);
- logger.addHandler(fileTxt);
- Handler[] handlers = logger.getHandlers();
- for (int index = 0; index < handlers.length; index++) {
- handlers[index].setLevel(level);
- handlers[index].setFormatter(logFormatter);
- }
- }
+ alterLoggers(level, file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
+ private void alterLoggers(Level level, File file) throws IOException {
+ FileHandler fileTxt = new FileHandler(file.getAbsolutePath(), true);
+ Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
+ while (names.hasMoreElements()) {
+ String loggerName = names.nextElement();
+ Logger logger = LogManager.getLogManager().getLogger(loggerName);
+ logger.setLevel(level);
+ logger.addHandler(fileTxt);
+ Handler[] handlers = logger.getHandlers();
+ for (int index = 0; index < handlers.length; index++) {
+ handlers[index].setLevel(level);
+ handlers[index].setFormatter(logFormatter);
+ }
+ }
+ }
+
private void addExceptionRecorder() {
Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
while (names.hasMoreElements()) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git
More information about the pkg-java-commits
mailing list