Skip to content

Commit c24b8e0

Browse files
author
Gilles Grousset
committed
Code reformatting
1 parent 065604d commit c24b8e0

File tree

77 files changed

+4145
-4213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4145
-4213
lines changed

commons/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
2020
-->
21-
<project xmlns="http://maven.apache.org/POM/4.0.0"
22-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xmlns="http://maven.apache.org/POM/4.0.0"
2323
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2424
<parent>
2525
<artifactId>backelite-swift</artifactId>

commons/src/main/java/com/backelite/sonarqube/commons/surefire/BaseSurefireParser.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ protected BaseSurefireParser(FileSystem fileSystem, ResourcePerspectives perspec
5353
this.context = context;
5454
}
5555

56+
private static void parseFiles(File[] reports, UnitTestIndex index) {
57+
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
58+
StaxParser parser = new StaxParser(staxParser, false);
59+
for (File report : reports) {
60+
try {
61+
parser.parse(report);
62+
} catch (XMLStreamException e) {
63+
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
64+
}
65+
}
66+
}
67+
5668
public void collect(File reportsDir) {
5769

5870

@@ -89,18 +101,6 @@ private void parseFiles(File[] reports) {
89101
save(index);
90102
}
91103

92-
private static void parseFiles(File[] reports, UnitTestIndex index) {
93-
SurefireStaxHandler staxParser = new SurefireStaxHandler(index);
94-
StaxParser parser = new StaxParser(staxParser, false);
95-
for (File report : reports) {
96-
try {
97-
parser.parse(report);
98-
} catch (XMLStreamException e) {
99-
throw new IllegalStateException("Fail to parse the Surefire report: " + report, e);
100-
}
101-
}
102-
}
103-
104104
private void save(UnitTestIndex index) {
105105
long negativeTimeTestNumber = 0;
106106

commons/src/main/java/com/backelite/sonarqube/commons/surefire/BaseSurefireSensor.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.backelite.sonarqube.commons.surefire;
1919

2020
import com.backelite.sonarqube.commons.Constants;
21-
import org.apache.commons.lang.StringUtils;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
2423
import org.sonar.api.batch.Sensor;
@@ -36,12 +35,9 @@
3635
*/
3736
public abstract class BaseSurefireSensor implements Sensor {
3837

39-
protected static final Logger LOGGER = LoggerFactory.getLogger(BaseSurefireSensor.class);
40-
4138
public static final String REPORTS_PATH_KEY = Constants.PROPERTY_PREFIX + ".surefire.junit.reportsPath";
4239
public static final String DEFAULT_REPORTS_PATH = "sonar-reports/";
43-
44-
40+
protected static final Logger LOGGER = LoggerFactory.getLogger(BaseSurefireSensor.class);
4541
protected final FileSystem fileSystem;
4642
protected final PathResolver pathResolver;
4743
protected final ResourcePerspectives resourcePerspectives;

commons/src/main/java/com/backelite/sonarqube/commons/surefire/SurefireStaxHandler.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,6 @@ public SurefireStaxHandler(UnitTestIndex index) {
3737
this.index = index;
3838
}
3939

40-
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
41-
SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite"));
42-
SMEvent testSuiteEvent;
43-
for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) {
44-
if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) {
45-
String testSuiteClassName = testSuite.getAttrValue("name");
46-
if (StringUtils.contains(testSuiteClassName, "$")) {
47-
// test suites for inner classes are ignored
48-
return;
49-
}
50-
SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase"));
51-
SMEvent event;
52-
for (event = testCase.getNext(); event != null; event = testCase.getNext()) {
53-
if (event.compareTo(SMEvent.START_ELEMENT) == 0) {
54-
String testClassName = getClassname(testCase, testSuiteClassName);
55-
UnitTestClassReport classReport = index.index(testClassName);
56-
parseTestCase(testCase, classReport);
57-
}
58-
}
59-
}
60-
}
61-
}
62-
6340
private static String getClassname(SMInputCursor testCaseCursor,
6441
String defaultClassname) throws XMLStreamException {
6542
String testClassName = testCaseCursor.getAttrValue("classname");
@@ -136,4 +113,27 @@ private static String getTestCaseName(SMInputCursor testCaseCursor) throws XMLSt
136113
}
137114
return name;
138115
}
116+
117+
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
118+
SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite"));
119+
SMEvent testSuiteEvent;
120+
for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) {
121+
if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) {
122+
String testSuiteClassName = testSuite.getAttrValue("name");
123+
if (StringUtils.contains(testSuiteClassName, "$")) {
124+
// test suites for inner classes are ignored
125+
return;
126+
}
127+
SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase"));
128+
SMEvent event;
129+
for (event = testCase.getNext(); event != null; event = testCase.getNext()) {
130+
if (event.compareTo(SMEvent.START_ELEMENT) == 0) {
131+
String testClassName = getClassname(testCase, testSuiteClassName);
132+
UnitTestClassReport classReport = index.index(testClassName);
133+
parseTestCase(testCase, classReport);
134+
}
135+
}
136+
}
137+
}
138+
}
139139
}

commons/src/main/java/com/backelite/sonarqube/commons/surefire/UnitTestIndex.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public int size() {
6161

6262
public UnitTestClassReport merge(String classname, String intoClassname) {
6363
UnitTestClassReport from = indexByClassname.get(classname);
64-
if (from!=null) {
64+
if (from != null) {
6565
UnitTestClassReport to = index(intoClassname);
6666
to.add(from);
6767
indexByClassname.remove(classname);

objclang/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
2020
-->
21-
<project xmlns="http://maven.apache.org/POM/4.0.0"
22-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xmlns="http://maven.apache.org/POM/4.0.0"
2323
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2424
<parent>
2525
<artifactId>backelite-swift</artifactId>

objclang/src/main/java/com/backelite/sonarqube/objectivec/ObjectiveCSquidSensor.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec;
1919

20+
import com.backelite.sonarqube.objectivec.lang.ObjectiveCAstScanner;
21+
import com.backelite.sonarqube.objectivec.lang.ObjectiveCConfiguration;
22+
import com.backelite.sonarqube.objectivec.lang.api.ObjectiveCGrammar;
23+
import com.backelite.sonarqube.objectivec.lang.api.ObjectiveCMetric;
24+
import com.backelite.sonarqube.objectivec.lang.checks.CheckList;
2025
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
2126
import com.google.common.collect.ImmutableList;
2227
import com.google.common.collect.Lists;
@@ -35,11 +40,6 @@
3540
import org.sonar.api.resources.Resource;
3641
import org.sonar.api.rule.RuleKey;
3742
import org.sonar.api.scan.filesystem.PathResolver;
38-
import com.backelite.sonarqube.objectivec.lang.ObjectiveCAstScanner;
39-
import com.backelite.sonarqube.objectivec.lang.ObjectiveCConfiguration;
40-
import com.backelite.sonarqube.objectivec.lang.api.ObjectiveCGrammar;
41-
import com.backelite.sonarqube.objectivec.lang.api.ObjectiveCMetric;
42-
import com.backelite.sonarqube.objectivec.lang.checks.CheckList;
4343
import org.sonar.squidbridge.AstScanner;
4444
import org.sonar.squidbridge.SquidAstVisitor;
4545
import org.sonar.squidbridge.api.CheckMessage;

objclang/src/main/java/com/backelite/sonarqube/objectivec/cpd/ObjectiveCCpdMapping.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec.cpd;
1919

20-
import java.nio.charset.Charset;
21-
2220
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
2321
import net.sourceforge.pmd.cpd.Tokenizer;
24-
2522
import org.sonar.api.batch.AbstractCpdMapping;
2623
import org.sonar.api.batch.fs.FileSystem;
2724
import org.sonar.api.resources.Language;
2825

26+
import java.nio.charset.Charset;
27+
2928
public class ObjectiveCCpdMapping extends AbstractCpdMapping {
3029

3130
private final ObjectiveC language;

objclang/src/main/java/com/backelite/sonarqube/objectivec/cpd/ObjectiveCTokenizer.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec.cpd;
1919

20-
import java.io.File;
21-
import java.io.IOException;
22-
import java.nio.charset.Charset;
23-
import java.util.List;
24-
20+
import com.backelite.sonarqube.objectivec.lang.ObjectiveCConfiguration;
21+
import com.backelite.sonarqube.objectivec.lang.lexer.ObjectiveCLexer;
22+
import com.sonar.sslr.api.Token;
23+
import com.sonar.sslr.impl.Lexer;
2524
import net.sourceforge.pmd.cpd.SourceCode;
2625
import net.sourceforge.pmd.cpd.TokenEntry;
2726
import net.sourceforge.pmd.cpd.Tokenizer;
2827
import net.sourceforge.pmd.cpd.Tokens;
2928

30-
import com.backelite.sonarqube.objectivec.lang.ObjectiveCConfiguration;
31-
import com.backelite.sonarqube.objectivec.lang.lexer.ObjectiveCLexer;
32-
33-
import com.sonar.sslr.api.Token;
34-
import com.sonar.sslr.impl.Lexer;
29+
import java.io.File;
30+
import java.io.IOException;
31+
import java.nio.charset.Charset;
32+
import java.util.List;
3533

3634
public class ObjectiveCTokenizer implements Tokenizer {
3735

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/ObjectiveCProfile.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec.issues;
1919

20-
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
2120
import com.backelite.sonarqube.objectivec.issues.fauxpas.FauxPasProfile;
2221
import com.backelite.sonarqube.objectivec.issues.fauxpas.FauxPasProfileImporter;
2322
import com.backelite.sonarqube.objectivec.issues.oclint.OCLintProfile;
23+
import com.backelite.sonarqube.objectivec.issues.oclint.OCLintProfileImporter;
24+
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
2425
import com.google.common.io.Closeables;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728
import org.sonar.api.profiles.ProfileDefinition;
2829
import org.sonar.api.profiles.RulesProfile;
2930
import org.sonar.api.rules.ActiveRule;
3031
import org.sonar.api.utils.ValidationMessages;
31-
import com.backelite.sonarqube.objectivec.issues.oclint.OCLintProfileImporter;
3232

3333
import java.io.InputStreamReader;
3434
import java.io.Reader;

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/fauxpas/FauxPasReportParser.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838

3939
public class FauxPasReportParser {
4040

41+
private static final Logger LOGGER = LoggerFactory.getLogger(FauxPasReportParser.class);
4142
private final Project project;
4243
private final SensorContext context;
4344
private final ResourcePerspectives resourcePerspectives;
4445
private final FileSystem fileSystem;
4546

46-
private static final Logger LOGGER = LoggerFactory.getLogger(FauxPasReportParser.class);
47-
4847
public FauxPasReportParser(final Project p, final SensorContext c, final ResourcePerspectives resourcePerspectives, final FileSystem fileSystem) {
4948
project = p;
5049
context = c;
@@ -63,8 +62,8 @@ public void parseReport(File reportFile) {
6362
// Record issues
6463
if (reportObj != null) {
6564

66-
JSONObject reportJson = (JSONObject)reportObj;
67-
JSONArray diagnosticsJson = (JSONArray)reportJson.get("diagnostics");
65+
JSONObject reportJson = (JSONObject) reportObj;
66+
JSONArray diagnosticsJson = (JSONArray) reportJson.get("diagnostics");
6867

6968
for (Object obj : diagnosticsJson) {
7069
recordIssue((JSONObject) obj);
@@ -79,7 +78,7 @@ public void parseReport(File reportFile) {
7978

8079
private void recordIssue(final JSONObject diagnosticJson) {
8180

82-
String filePath = (String)diagnosticJson.get("file");
81+
String filePath = (String) diagnosticJson.get("file");
8382

8483
if (filePath != null) {
8584

@@ -89,12 +88,12 @@ private void recordIssue(final JSONObject diagnosticJson) {
8988

9089
if (issuable != null && inputFile != null) {
9190

92-
JSONObject extent = (JSONObject)diagnosticJson.get("extent");
93-
JSONObject start = (JSONObject)extent.get("start");
91+
JSONObject extent = (JSONObject) diagnosticJson.get("extent");
92+
JSONObject start = (JSONObject) extent.get("start");
9493

95-
String info = (String)diagnosticJson.get("info");
94+
String info = (String) diagnosticJson.get("info");
9695
if (info == null) {
97-
info = (String)diagnosticJson.get("ruleName");
96+
info = (String) diagnosticJson.get("ruleName");
9897
}
9998

10099
// Prevent line num 0 case

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/fauxpas/FauxPasRulesDefinition.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@
3838
*/
3939
public class FauxPasRulesDefinition implements RulesDefinition {
4040

41-
private static final Logger LOGGER = LoggerFactory.getLogger(FauxPasRulesDefinition.class);
42-
4341
public static final String REPOSITORY_KEY = "FauxPas";
4442
public static final String REPOSITORY_NAME = REPOSITORY_KEY;
45-
43+
private static final Logger LOGGER = LoggerFactory.getLogger(FauxPasRulesDefinition.class);
4644
private static final String RULES_FILE = "/org/sonar/plugins/fauxpas/rules.json";
4745

4846
@Override
@@ -74,13 +72,13 @@ private void loadRules(NewRepository repository) throws IOException {
7472
Object rulesObj = JSONValue.parse(jsonString);
7573

7674
if (rulesObj != null) {
77-
JSONArray slRules = (JSONArray)rulesObj;
75+
JSONArray slRules = (JSONArray) rulesObj;
7876
for (Object obj : slRules) {
79-
JSONObject fpRule = (JSONObject)obj;
77+
JSONObject fpRule = (JSONObject) obj;
8078

81-
RulesDefinition.NewRule rule = repository.createRule((String)fpRule.get("key"));
79+
RulesDefinition.NewRule rule = repository.createRule((String) fpRule.get("key"));
8280
rule.setName((String) fpRule.get("name"));
83-
rule.setSeverity((String)fpRule.get("severity"));
81+
rule.setSeverity((String) fpRule.get("severity"));
8482
rule.setHtmlDescription((String) fpRule.get("description"));
8583

8684
}

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/fauxpas/FauxPasSensor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.sonar.api.component.ResourcePerspectives;
2929
import org.sonar.api.config.Settings;
3030
import org.sonar.api.resources.Project;
31-
import com.backelite.sonarqube.objectivec.ObjectiveCConstants;
3231

3332
import java.io.File;
3433

@@ -55,6 +54,7 @@ public boolean shouldExecuteOnProject(final Project project) {
5554

5655
return project.isRoot() && fileSystem.languages().contains(ObjectiveC.KEY);
5756
}
57+
5858
@Override
5959
public void analyse(Project module, SensorContext context) {
6060

@@ -74,7 +74,7 @@ private void parseReportIn(final String baseDir, final FauxPasReportParser parse
7474
scanner.scan();
7575
String[] files = scanner.getIncludedFiles();
7676

77-
for(String filename : files) {
77+
for (String filename : files) {
7878
LOGGER.info("Processing FauxPas report {}", filename);
7979
parser.parseReport(new File(filename));
8080
}

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/oclint/OCLintParser.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec.issues.oclint;
1919

20-
import java.io.File;
21-
import java.io.FileInputStream;
22-
import java.io.IOException;
23-
import java.io.InputStream;
24-
25-
import javax.xml.stream.XMLStreamException;
26-
2720
import org.slf4j.LoggerFactory;
2821
import org.sonar.api.batch.SensorContext;
2922
import org.sonar.api.batch.fs.FileSystem;
3023
import org.sonar.api.component.ResourcePerspectives;
3124
import org.sonar.api.resources.Project;
3225
import org.sonar.api.utils.StaxParser;
3326

27+
import javax.xml.stream.XMLStreamException;
28+
import java.io.File;
29+
import java.io.FileInputStream;
30+
import java.io.IOException;
31+
import java.io.InputStream;
32+
3433
final class OCLintParser {
3534

3635
private final Project project;

objclang/src/main/java/com/backelite/sonarqube/objectivec/issues/oclint/OCLintProfile.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
*/
1818
package com.backelite.sonarqube.objectivec.issues.oclint;
1919

20-
import java.io.InputStreamReader;
21-
import java.io.Reader;
22-
20+
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
21+
import com.google.common.io.Closeables;
2322
import org.slf4j.Logger;
2423
import org.slf4j.LoggerFactory;
2524
import org.sonar.api.profiles.ProfileDefinition;
2625
import org.sonar.api.profiles.RulesProfile;
2726
import org.sonar.api.utils.ValidationMessages;
28-
import com.backelite.sonarqube.objectivec.lang.core.ObjectiveC;
2927

30-
import com.google.common.io.Closeables;
28+
import java.io.InputStreamReader;
29+
import java.io.Reader;
3130

3231
public final class OCLintProfile extends ProfileDefinition {
3332

0 commit comments

Comments
 (0)