aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-12 09:23:43 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-12 09:23:43 +0200
commit45d043ba336e1ebd0e9f7f48976bbb4ad2b34974 (patch)
tree08a130679bd56aebdd0fb0e0653d9e9e4d643c38
parentb0d71975c7f6840acfcfc64c83a2de59889170fc (diff)
downloadsonarqube-45d043ba336e1ebd0e9f7f48976bbb4ad2b34974.tar.gz
sonarqube-45d043ba336e1ebd0e9f7f48976bbb4ad2b34974.zip
Fix some quality flaws
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java22
3 files changed, 27 insertions, 23 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
index e8326e916b1..20a8d9ef8f2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
@@ -89,21 +89,25 @@ public class DryRunDatabase implements BatchComponent {
}
LOG.debug("Dry Run database size: {}", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toFile)));
} catch (SonarException e) {
- Throwable rootCause = Throwables.getRootCause(e);
- if (rootCause instanceof SocketTimeoutException) {
- // Pico will unwrap the first runtime exception
- throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
- + CoreProperties.DRY_RUN_READ_TIMEOUT,
- readTimeout), e));
- }
- if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
- // Pico will unwrap the first runtime exception
- throw new SonarException(new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e));
- }
+ handleException(readTimeout, projectKey, e);
throw e;
}
}
+ private void handleException(int readTimeout, String projectKey, SonarException e) {
+ Throwable rootCause = Throwables.getRootCause(e);
+ if (rootCause instanceof SocketTimeoutException) {
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
+ + CoreProperties.DRY_RUN_READ_TIMEOUT,
+ readTimeout), e));
+ }
+ if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e));
+ }
+ }
+
private void replaceSettings(String databasePath) {
settings
.removeProperty("sonar.jdbc.schema")
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
index 39edd95d0f1..a046369d920 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
@@ -82,7 +82,7 @@ public class ServerClient implements BatchComponent {
return request(pathStartingWithSlash, wrapHttpException, null);
}
- public String request(String pathStartingWithSlash, boolean wrapHttpException, Integer timeoutMillis) {
+ public String request(String pathStartingWithSlash, boolean wrapHttpException, @Nullable Integer timeoutMillis) {
InputSupplier<InputStream> inputSupplier = doRequest(pathStartingWithSlash, timeoutMillis);
try {
return IOUtils.toString(inputSupplier.getInput(), "UTF-8");
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java
index 4f4205d2bcf..2a18e96a475 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/CoberturaReportParserUtils.java
@@ -46,7 +46,7 @@ public class CoberturaReportParserUtils {
private CoberturaReportParserUtils() {
}
- public static interface FileResolver {
+ public interface FileResolver {
/**
* Return a SonarQube file resource from a filename present in Cobertura report
@@ -62,12 +62,8 @@ public class CoberturaReportParserUtils {
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
- try {
- rootCursor.advance();
- collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver);
- } catch (ParseException e) {
- throw new XMLStreamException(e);
- }
+ rootCursor.advance();
+ collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver);
}
});
parser.parse(xmlFile);
@@ -76,7 +72,7 @@ public class CoberturaReportParserUtils {
}
}
- private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws ParseException, XMLStreamException {
+ private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws XMLStreamException {
while (pack.getNext() != null) {
Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap();
collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename);
@@ -96,7 +92,7 @@ public class CoberturaReportParserUtils {
return context.getResource(file) != null;
}
- private static void collectFileMeasures(SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename) throws ParseException, XMLStreamException {
+ private static void collectFileMeasures(SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename) throws XMLStreamException {
while (clazz.getNext() != null) {
String fileName = clazz.getAttrValue("filename");
CoverageMeasuresBuilder builder = builderByFilename.get(fileName);
@@ -108,11 +104,15 @@ public class CoberturaReportParserUtils {
}
}
- private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws ParseException, XMLStreamException {
+ private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws XMLStreamException {
SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
while (line.getNext() != null) {
int lineId = Integer.parseInt(line.getAttrValue("number"));
- builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
+ try {
+ builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
+ } catch (ParseException e) {
+ throw new XmlParserException(e);
+ }
String isBranch = line.getAttrValue("branch");
String text = line.getAttrValue("condition-coverage");