Skip to content

Commit 0d7ed80

Browse files
author
Gilles Grousset
committed
Implemented SwiftFileSystem to prepare new API refacto
1 parent 19d5e67 commit 0d7ed80

File tree

12 files changed

+105
-36
lines changed

12 files changed

+105
-36
lines changed

build-and-deploy.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ if [ "$?" != 0 ]; then
2626
exit $?
2727
fi
2828

29-
# Run shell tests
29+
# Run shell surefire
3030
#shelltest src/test/shell --execdir --diff
3131
#if [ "$?" != 0 ]; then
32-
# echo "ERROR - Shell tests failed!" 1>&2
32+
# echo "ERROR - Shell surefire failed!" 1>&2
3333
# exit $?
3434
#fi
3535

sonar-project.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sonar.sources=SourceDir
3636
# Path to test directories (comment if no test)
3737
sonar.tests=TestDir
3838

39-
# Destination Simulator to run tests
39+
# Destination Simulator to run surefire
4040
# As string expected in destination argument of xcodebuild command
4141
# Example = sonar.swift.simulator=platform=iOS Simulator,name=iPhone 6,OS=9.2
4242
sonar.swift.simulator=platform=iOS Simulator,name=iPhone 6,OS=9.2
@@ -91,7 +91,7 @@ sonar.sourceEncoding=UTF-8
9191
# Change it only if you generate the file on your own
9292
# sonar.swift.tailor.report=sonar-reports/*tailor.txt
9393

94-
# Paths to exclude from coverage report (tests, 3rd party libraries etc.)
94+
# Paths to exclude from coverage report (surefire, 3rd party libraries etc.)
9595
# sonar.swift.excludedPathsFromCoverage=pattern1,pattern2
9696
sonar.swift.excludedPathsFromCoverage=.*Tests.*
9797

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/SwiftPlugin.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.sonar.api.Properties;
2323
import org.sonar.api.Property;
2424
import org.sonar.api.SonarPlugin;
25-
import org.sonar.plugins.swift.colorizer.SwiftCodeColorizerFormat;
2625
import org.sonar.plugins.swift.complexity.LizardSensor;
2726
import org.sonar.plugins.swift.coverage.SwiftCoberturaSensor;
2827
import org.sonar.plugins.swift.cpd.SwiftCpdMapping;
@@ -36,7 +35,7 @@
3635
import org.sonar.plugins.swift.issues.tailor.TailorRulesDefinition;
3736
import org.sonar.plugins.swift.issues.tailor.TailorSensor;
3837
import org.sonar.plugins.swift.lang.core.Swift;
39-
import org.sonar.plugins.swift.tests.SwiftSurefireSensor;
38+
import org.sonar.plugins.swift.surefire.SwiftSurefireSensor;
4039

4140
import com.google.common.collect.ImmutableList;
4241

@@ -112,7 +111,7 @@ public List getExtensions() {
112111
// code
113112
SwiftSquidSensor.class,
114113

115-
// tests
114+
// surefire
116115
SwiftSurefireSensor.class,
117116
SwiftCoberturaSensor.class,
118117

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* backelite-sonar-swift-plugin - Enables analysis of Swift projects into SonarQube.
3+
* Copyright © 2015 Backelite (${email})
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package org.sonar.plugins.swift.lang;
19+
20+
import org.sonar.api.batch.BatchSide;
21+
import org.sonar.api.batch.fs.FilePredicate;
22+
import org.sonar.api.batch.fs.FilePredicates;
23+
import org.sonar.api.batch.fs.FileSystem;
24+
import org.sonar.api.batch.fs.InputFile;
25+
import org.sonar.plugins.swift.lang.core.Swift;
26+
27+
import javax.annotation.CheckForNull;
28+
import java.io.File;
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
33+
@BatchSide
34+
public class SwiftFileSystem {
35+
36+
private final FileSystem fileSystem;
37+
private final FilePredicates predicates;
38+
private final FilePredicate isSwiftLanguage;
39+
private final FilePredicate isMainTypeFile;
40+
41+
public SwiftFileSystem(FileSystem fileSystem) {
42+
this.fileSystem = fileSystem;
43+
this.predicates = fileSystem.predicates();
44+
this.isSwiftLanguage = predicates.hasLanguage(Swift.KEY);
45+
this.isMainTypeFile = predicates.hasType(InputFile.Type.MAIN);
46+
}
47+
48+
public boolean hasSwiftFiles() {
49+
return fileSystem.hasFiles(isSwiftLanguage);
50+
}
51+
52+
public List<File> sourceFiles() {
53+
Iterable<File> files = fileSystem.files(predicates.and(isSwiftLanguage, isMainTypeFile));
54+
List<File> list = new ArrayList<>();
55+
files.iterator().forEachRemaining(list::add);
56+
return list;
57+
}
58+
59+
public List<InputFile> swiftInputFiles() {
60+
Iterable<InputFile> inputFiles = fileSystem.inputFiles(isSwiftLanguage);
61+
List<InputFile> list = new ArrayList<>();
62+
inputFiles.iterator().forEachRemaining(list::add);
63+
return list;
64+
}
65+
66+
public List<InputFile> sourceInputFiles() {
67+
Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(isSwiftLanguage, isMainTypeFile));
68+
List<InputFile> list = new ArrayList<>();
69+
inputFiles.iterator().forEachRemaining(list::add);
70+
return list;
71+
}
72+
73+
@CheckForNull
74+
public InputFile sourceInputFileFromRelativePath(String relativePath) {
75+
return fileSystem.inputFile(predicates.and(predicates.matchesPathPattern("**/" + relativePath), isSwiftLanguage, isMainTypeFile));
76+
}
77+
78+
public File baseDir() {
79+
return fileSystem.baseDir();
80+
}
81+
}

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/SwiftSurefireParser.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/SwiftSurefireParser.java

+7-15
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests;
18+
package org.sonar.plugins.swift.surefire;
1919

2020
import com.google.common.collect.ImmutableList;
21-
import org.apache.commons.lang.StringEscapeUtils;
2221
import org.apache.commons.lang.StringUtils;
2322
import org.slf4j.Logger;
2423
import org.slf4j.LoggerFactory;
@@ -27,25 +26,18 @@
2726
import org.sonar.api.batch.fs.InputFile;
2827
import org.sonar.api.component.ResourcePerspectives;
2928
import org.sonar.api.measures.CoreMetrics;
30-
import org.sonar.api.measures.Measure;
3129
import org.sonar.api.measures.Metric;
32-
import org.sonar.api.resources.Project;
33-
import org.sonar.api.resources.Qualifiers;
3430
import org.sonar.api.resources.Resource;
3531
import org.sonar.api.test.MutableTestPlan;
3632
import org.sonar.api.test.TestCase;
3733
import org.sonar.api.utils.ParsingUtils;
3834
import org.sonar.api.utils.StaxParser;
39-
import org.sonar.api.utils.XmlParserException;
40-
import org.sonar.plugins.swift.tests.surefire.SurefireStaxHandler;
41-
import org.sonar.plugins.swift.tests.surefire.UnitTestClassReport;
42-
import org.sonar.plugins.swift.tests.surefire.UnitTestIndex;
43-
import org.sonar.plugins.swift.tests.surefire.UnitTestResult;
44-
45-
import javax.annotation.Nonnull;
46-
import javax.annotation.Nullable;
35+
import org.sonar.plugins.swift.surefire.data.SurefireStaxHandler;
36+
import org.sonar.plugins.swift.surefire.data.UnitTestClassReport;
37+
import org.sonar.plugins.swift.surefire.data.UnitTestIndex;
38+
import org.sonar.plugins.swift.surefire.data.UnitTestResult;
39+
4740
import javax.xml.stream.XMLStreamException;
48-
import javax.xml.transform.TransformerException;
4941
import java.io.File;
5042
import java.io.FilenameFilter;
5143
import java.util.List;
@@ -138,7 +130,7 @@ private void save(UnitTestIndex index) {
138130
}
139131
}
140132
if (negativeTimeTestNumber > 0) {
141-
LOGGER.warn("There is {} test(s) reported with negative time by surefire, total duration may not be accurate.", negativeTimeTestNumber);
133+
LOGGER.warn("There is {} test(s) reported with negative time by data, total duration may not be accurate.", negativeTimeTestNumber);
142134
}
143135
}
144136

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/SwiftSurefireSensor.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/SwiftSurefireSensor.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests;
18+
package org.sonar.plugins.swift.surefire;
1919

2020
import org.apache.commons.lang.StringUtils;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
23-
import org.sonar.api.batch.CoverageExtension;
24-
import org.sonar.api.batch.DependsUpon;
2523
import org.sonar.api.batch.Sensor;
2624
import org.sonar.api.batch.SensorContext;
2725
import org.sonar.api.batch.fs.FileSystem;
2826
import org.sonar.api.component.ResourcePerspectives;
2927
import org.sonar.api.config.Settings;
3028
import org.sonar.api.resources.Project;
3129
import org.sonar.api.scan.filesystem.PathResolver;
32-
import org.sonar.plugins.swift.lang.core.Swift;
3330

3431
import java.io.File;
3532

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/surefire/SurefireStaxHandler.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/data/SurefireStaxHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests.surefire;
18+
package org.sonar.plugins.swift.surefire.data;
1919

2020
import org.apache.commons.lang.StringUtils;
2121
import org.codehaus.staxmate.in.ElementFilter;
@@ -96,7 +96,7 @@ private static UnitTestResult parseTestResult(SMInputCursor testCaseCursor) thro
9696
String elementName = childNode.getLocalName();
9797
if ("skipped".equals(elementName)) {
9898
status = UnitTestResult.STATUS_SKIPPED;
99-
// bug with surefire reporting wrong time for skipped tests
99+
// bug with data reporting wrong time for skipped surefire
100100
duration = 0L;
101101

102102
} else if ("failure".equals(elementName)) {

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/surefire/UnitTestClassReport.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/data/UnitTestClassReport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests.surefire;
18+
package org.sonar.plugins.swift.surefire.data;
1919

2020
import com.google.common.collect.Lists;
2121

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/surefire/UnitTestIndex.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/data/UnitTestIndex.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests.surefire;
18+
package org.sonar.plugins.swift.surefire.data;
1919

2020
import com.google.common.collect.Maps;
2121
import com.google.common.collect.Sets;

sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/tests/surefire/UnitTestResult.java renamed to sonar-swift-plugin/src/main/java/org/sonar/plugins/swift/surefire/data/UnitTestResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
package org.sonar.plugins.swift.tests.surefire;
18+
package org.sonar.plugins.swift.surefire.data;
1919

2020
public final class UnitTestResult {
2121
public static final String STATUS_OK = "ok";

sonar-swift-plugin/src/main/shell/run-sonar-swift.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ if [ "$vflag" = "on" ]; then
254254
echo "Destination simulator is: $destinationSimulator"
255255
echo "Excluded paths from coverage are: $excludedPathsFromCoverage"
256256
else
257-
echo "Unit tests are disabled"
257+
echo "Unit surefire are disabled"
258258
fi
259259
fi
260260

@@ -275,13 +275,13 @@ rm -rf sonar-reports
275275
mkdir sonar-reports
276276

277277
if [ "$unittests" = "on" ]; then
278-
# Unit tests and coverage
278+
# Unit surefire and coverage
279279

280-
# Put default xml files with no tests and no coverage...
280+
# Put default xml files with no surefire and no coverage...
281281
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
282282
echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage-swift.xml
283283

284-
echo -n 'Running tests'
284+
echo -n 'Running surefire'
285285
buildCmd=(xcodebuild clean build test)
286286
if [[ ! -z "$workspaceFile" ]]; then
287287
buildCmd+=(-workspace "$workspaceFile")

sonar-swift-plugin/src/test/java/org/sonar/plugins/swift/complexity/LizardSensorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void setUp() {
4343
}
4444

4545
/**
46-
* this method tests that the sensor should be executed when a project is a root project and uses objective c
46+
* this method surefire that the sensor should be executed when a project is a root project and uses objective c
4747
*/
4848
@Test
4949
public void shouldExecuteOnProjectShouldBeTrueWhenProjectIsObjc() {

0 commit comments

Comments
 (0)