Skip to content

Commit

Permalink
Merge branch 'release/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Grousset committed Apr 26, 2021
2 parents 7be990e + b45b804 commit 6119eeb
Show file tree
Hide file tree
Showing 16 changed files with 803 additions and 238 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# SonarQube Plugin for Flutter / Dart

## 0.3.2

#### Breaking

- None.

#### Experimental

- None.

#### Enhancements

- Allow re-using an existing dartanalyzer report with `sonar.dart.analysis.reportPath` (thanks to [Peter Leibiger](https://github.com/kuhnroyal))
- Add missing dart keywords `extension`, `on`, `mixin` (thanks to [Peter Leibiger](https://github.com/kuhnroyal))
- Add pedantic 1.9.0 profile (thanks to [Daniel Morawetz](https://github.com/dmorawetz))
- Faster analysis with 'flutter analyze' and support for different analysis modes with `sonar.flutter.analyzer.mode` (thanks to [Marc Reichelt](https://github.com/mreichelt))

#### Bug Fixes

- Ensure analyzer encoding is UTF-8 (thanks to [Daniel Morawetz](https://github.com/dmorawetz))


## 0.3.1

#### Breaking
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ sonar.projectVersion=1.0
# Use commas to specify more than one folder.
sonar.sources=lib
sonar.tests=test

# Encoding of the source code. Default is default system encoding.
sonar.sourceEncoding=UTF-8

# Allows reuse of an existing analyzer report
# sonar.dart.analysis.reportPath=

# Analyzer mode
# Can be:
# - flutter (flutter analyze) - default
# - dart (dart analyze)
# - legacy (dartanalyzer)
# sonar.flutter.analyzer.mode=
```

*For a complete list of available options, please refer to the [SonarQube documentation](https://docs.sonarqube.org/latest/analysis/analysis-parameters/).*
Expand All @@ -84,10 +94,11 @@ Use the following commands from the root folder to start an analysis:
```console
# Download dependencies
flutter pub get
# Run tests
flutter test --machine > tests.output
# Compute coverage (--machine and --coverage cannot be run at once...)
flutter test --coverage
# Run tests with User feedback (in case some test are failing)
flutter test
# Run tests without user feedback regeneration tests.output and coverage/lcov.info
flutter test --machine --coverage > tests.output

# Run the analysis and publish to the SonarQube server
sonar-scanner
```
Expand Down
2 changes: 1 addition & 1 deletion dart-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sonar-flutter</artifactId>
<groupId>fr.insideapp.sonarqube</groupId>
<version>0.3.1</version>
<version>0.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DartSensor implements Sensor {
private static final Logger LOGGER = LoggerFactory.getLogger(DartSensor.class);
private static final int EXECUTOR_TIMEOUT = 10000;
public static final String DART_ANALYSIS_USE_EXISTING_OPTIONS_KEY = "sonar.dart.analysis.useExistingOptions";
public static final String DART_ANALYSIS_USE_EXISTING_REPORT_PATH_KEY = "sonar.dart.analysis.reportPath";

@Override
public void describe(SensorDescriptor sensorDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SourceLine[] getLines(final InputStream inputStream, final Charset charse
}
sourceLines.add(new SourceLine(totalLines, count, global - count, global));
} catch (final Throwable e) {
LOGGER.warn("Error occured reading file", e);
LOGGER.warn("Error occurred reading file", e);
}

return sourceLines.toArray(new SourceLine[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SonarQube Flutter Plugin
* Copyright (C) 2020 inside|app
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.insideapp.sonarqube.dart.lang.issues;

import fr.insideapp.sonarqube.dart.lang.Dart;
import fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerRulesDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;

public class DartProfilePedantic190 implements BuiltInQualityProfilesDefinition {

private static final Logger LOGGER = LoggerFactory.getLogger(DartProfile.class);
public static final String DARTANALYZER_PROFILE_PATH = "fr/insideapp/sonarqube/dart/dartanalyzer/profile-pedantic.1.9.0.xml";

@Override
public void define(BuiltInQualityProfilesDefinition.Context context) {

// dartanalyzer profile
LOGGER.info("Creating dartanalyzer pedantic 1.9.0 Profile");
NewBuiltInQualityProfile nbiqp = context.createBuiltInQualityProfile("dartanalyzer pedantic 1.9.0", Dart.KEY);
XmlProfileParser.parse(DARTANALYZER_PROFILE_PATH, nbiqp);
nbiqp.done();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public static void parse(String path, NewBuiltInQualityProfile profile) {
String repositoryKey = getChildContent(ruleElement, "repositoryKey");
String key = getChildContent(ruleElement, "key");

NewBuiltInActiveRule newActiveRule = profile.activateRule(repositoryKey, key);
try {
NewBuiltInActiveRule newActiveRule = profile.activateRule(repositoryKey, key);

NodeList parameterNodeList = ruleElement.getElementsByTagName("parameter");
XmlFile.asList(parameterNodeList).forEach(parameter -> {
Element parameterElement = (Element) parameter;
String paramKey = getChildContent(parameterElement, "key");
String paramValue = getChildContent(parameterElement, "value");
newActiveRule.overrideParam(paramKey, paramValue);
});
NodeList parameterNodeList = ruleElement.getElementsByTagName("parameter");
XmlFile.asList(parameterNodeList).forEach(parameter -> {
Element parameterElement = (Element) parameter;
String paramKey = getChildContent(parameterElement, "key");
String paramValue = getChildContent(parameterElement, "value");
newActiveRule.overrideParam(paramKey, paramValue);
});

Optional<String> priority = getOptionalChildContent(ruleElement, "priority");
priority.ifPresent(newActiveRule::overrideSeverity);
Optional<String> priority = getOptionalChildContent(ruleElement, "priority");
priority.ifPresent(newActiveRule::overrideSeverity);
} catch (IllegalArgumentException e) {
// ignore, if rule was already registered in another profile
}

});

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SonarQube Flutter Plugin
* Copyright (C) 2020 inside|app
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer;

public enum AnalyzerMode {
flutter,
dart,
legacy;

public static final AnalyzerMode defaultMode = flutter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<DartAnalyzerReportIssue> parse(String input) {
List<DartAnalyzerReportIssue> issues = new ArrayList<>();

String[] lines = input.split(System.getProperty("line.separator"));
Pattern pattern = Pattern.compile("(error|hint|lint)(.*)(-|•)(.*)(-|•)(.*):(.*):(.*)(-|•)(.*)");
Pattern pattern = Pattern.compile("(hint|lint|info|warning|error)(.*)(-|•)(.*)(-|•)(.*):(.*):(.*)(-|•)(.*)");
for (int i = 0; i < lines.length; i++) {
Matcher matcher = pattern.matcher(lines[i]);
while (matcher.find()) {
Expand Down
Loading

0 comments on commit 6119eeb

Please sign in to comment.