Skip to content

Commit 4b370e5

Browse files
Merge pull request #94 from cnescatlab/feature-update-for-SQ9
Feature update for sq9
2 parents 826da0b + 42bbb08 commit 4b370e5

File tree

14 files changed

+271
-457
lines changed

14 files changed

+271
-457
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Here is the compatibility matrix of the plugin:
3434
| 2.0.3 | 4.1.2 | 7.9 -> 8.2 | Fortran / Shell |
3535
| 3.0.0 | 4.1.0 | 7.9 -> 8.2 | Fortran |
3636
| 3.0.1 | 4.1.2 | 7.9 -> 8.2 | Fortran |
37+
| 3.1.0 | 4.1.2 | 7.9 -> 9.9 | Fortran |
3738

3839
#### Run i-Code manually
3940
If you need help to run i-Code please refer to the [official user manual](https://github.com/cnescatlab/i-CodeCNES/wiki/User-Manual) or [i-Code issue tracker](https://github.com/cnescatlab/i-CodeCNES/issues).

pom.xml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>fr.cnes.sonar.plugins</groupId>
77
<artifactId>sonar-icode-cnes-plugin</artifactId>
88
<packaging>sonar-plugin</packaging>
9-
<version>3.0.1</version>
9+
<version>3.1.0</version>
1010

1111
<name>Sonar i-Code CNES plugin</name>
1212

@@ -46,6 +46,12 @@
4646
<url>https://github.com/WaldoFR</url>
4747
<id>WaldoFR</id>
4848
</developer>
49+
<developer>
50+
<name>Diego Rodriguez</name>
51+
<organization>CNES</organization>
52+
<url>https://github.com/WaldoFR</url>
53+
<id>WaldoFR</id>
54+
</developer>
4955
</developers>
5056

5157
<properties>
@@ -55,14 +61,16 @@
5561
<jdk.max.version>11</jdk.max.version>
5662
<maven.compiler.source>1.8</maven.compiler.source>
5763
<maven.compiler.target>1.8</maven.compiler.target>
58-
<sonar.apiVersion>6.7.7</sonar.apiVersion>
64+
<sonar.apiVersion>9.8.0.203</sonar.apiVersion>
65+
<sonar.testingHarnessVersion>9.5.0.56709</sonar.testingHarnessVersion>
66+
<sonar.apiImplVersion>9.9.1.69595</sonar.apiImplVersion>
5967
<sonar.sslr-squid-bridge.version>2.6.1</sonar.sslr-squid-bridge.version>
60-
<sonar-packaging-maven-plugin.version>1.17</sonar-packaging-maven-plugin.version>
68+
<sonar-packaging-maven-plugin.version>1.21.0.505</sonar-packaging-maven-plugin.version>
6169
<commons-lang.version>3.7</commons-lang.version>
6270
<gson.version>2.8.2</gson.version>
6371
<slf4j.version>1.7.25</slf4j.version>
6472
<junit.version>4.13.2</junit.version>
65-
<jacoco.version>0.8.4</jacoco.version>
73+
<jacoco.version>0.8.10</jacoco.version>
6674
<sonar.pluginKey>icode</sonar.pluginKey>
6775
<sonar.pluginClass>fr.cnes.sonar.plugins.icode.ICodePlugin</sonar.pluginClass>
6876
<sonar.pluginUrl>https://github.com/cnescatlab/sonar-icode-cnes-plugin</sonar.pluginUrl>
@@ -81,7 +89,7 @@
8189

8290
<dependencies>
8391
<dependency>
84-
<groupId>org.sonarsource.sonarqube</groupId>
92+
<groupId>org.sonarsource.api.plugin</groupId>
8593
<artifactId>sonar-plugin-api</artifactId>
8694
<version>${sonar.apiVersion}</version>
8795
<scope>provided</scope>
@@ -100,12 +108,18 @@
100108
<dependency>
101109
<groupId>org.sonarsource.sonarqube</groupId>
102110
<artifactId>sonar-testing-harness</artifactId>
103-
<version>${sonar.apiVersion}</version>
111+
<version>${sonar.testingHarnessVersion}</version>
104112
<scope>test</scope>
105113
</dependency>
114+
<dependency>
115+
<groupId>org.sonarsource.sonarqube</groupId>
116+
<artifactId>sonar-plugin-api-impl</artifactId>
117+
<version>${sonar.apiImplVersion}</version>
118+
</dependency>
106119
<dependency>
107120
<groupId>junit</groupId>
108121
<artifactId>junit</artifactId>
122+
<version>4.11</version>
109123
<scope>test</scope>
110124
</dependency>
111125
<dependency>
@@ -134,7 +148,7 @@
134148
<plugin>
135149
<groupId>org.apache.maven.plugins</groupId>
136150
<artifactId>maven-compiler-plugin</artifactId>
137-
<version>3.5.1</version>
151+
<version>3.10.1</version>
138152
<configuration>
139153
<source>${jdk.min.version}</source>
140154
<target>${jdk.min.version}</target>
@@ -145,13 +159,13 @@
145159
<!-- UTF-8 bundles are not supported by Java, so they must be converted during build -->
146160
<groupId>org.codehaus.mojo</groupId>
147161
<artifactId>native2ascii-maven-plugin</artifactId>
148-
<version>1.0-beta-1</version>
162+
<version>2.0.1</version>
149163
<executions>
150-
<execution>
151-
<goals>
152-
<goal>native2ascii</goal>
153-
</goals>
154-
</execution>
164+
<execution>
165+
<goals>
166+
<goal>resources</goal>
167+
</goals>
168+
</execution>
155169
</executions>
156170
</plugin>
157171

src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ protected Map<String, InputFile> getScannedFiles(final FileSystem fileSystem, fi
338338
for(final AnalysisFile file : files) {
339339
// Checks if the file system contains a file with corresponding path (relative or absolute).
340340
final String fileToFind = new File(fileSystem.baseDir(), file.getFileName()).getPath();
341-
final FilePredicate predicate = fileSystem.predicates().hasRelativePath(fileToFind);
341+
final FilePredicate predicate = fileSystem.predicates().hasPath(fileToFind);
342342
final InputFile inputFile = fileSystem.inputFile(predicate);
343343
if(inputFile!=null) {
344344
result.put(file.getFileName(), inputFile);

src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
*/
1717
package fr.cnes.sonar.plugins.icode.languages;
1818

19-
import fr.cnes.sonar.plugins.icode.model.Rule;
20-
import fr.cnes.sonar.plugins.icode.model.RulesDefinition;
21-
import fr.cnes.sonar.plugins.icode.model.XmlHandler;
2219
import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition;
20+
import fr.cnes.sonar.plugins.icode.rules.RulesRepository;
21+
2322
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
2423
import org.sonar.api.utils.log.Logger;
2524
import org.sonar.api.utils.log.Loggers;
25+
import org.sonar.api.server.rule.RulesDefinition.NewRule;
2626

27-
import java.io.InputStream;
27+
import java.util.List;
2828

2929
/**
30-
* Built-in quality profile format since SonarQube 6.6.
30+
* Built-in quality profile format since SonarQube 9.9
3131
*/
3232
public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinition {
3333

@@ -37,43 +37,39 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit
3737
/** Display name for the built-in quality profile. **/
3838
private static final String I_CODE_RULES_PROFILE_NAME = "Sonar way";
3939

40+
private List<NewRule> f77Rules = RulesRepository.getInstance().getF77Rules();
41+
private List<NewRule> f90Rules = RulesRepository.getInstance().getF90Rules();
42+
4043
/**
4144
* Allow to create a plugin.
4245
*
4346
* @param context Context of the plugin.
4447
*/
4548
@Override
4649
public void define(final Context context) {
47-
createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML);
48-
createBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML);
50+
createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, f77Rules);
51+
createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, f90Rules);
4952
}
5053

5154
/**
5255
* Create a built in quality profile for a specific language.
5356
*
5457
* @param context SonarQube context in which create the profile.
58+
* @param repository Rules' repository.
5559
* @param language Language key of the associated profile.
56-
* @param path Path to the xml definition of all rules.
60+
* @param rules Rules to activate.
5761
*/
58-
private void createBuiltInProfile(final Context context, final String language, final String path) {
62+
private void createBuiltInProfile(final Context context, final String repository, final String languageKey, final List<NewRule> rules) {
5963
// Create a builder for the rules' repository.
60-
final NewBuiltInQualityProfile defaultProfile =
61-
context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, language);
62-
63-
// Retrieve all defined rules.
64-
final InputStream stream = getClass().getResourceAsStream(path);
65-
final RulesDefinition rules = (RulesDefinition) XmlHandler.unmarshal(stream, RulesDefinition.class);
66-
final String repositoryKey = ICodeRulesDefinition.getRepositoryKeyForLanguage(language);
64+
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, languageKey);
6765

6866
// Activate all i-Code CNES rules.
69-
for(final Rule rule : rules.getRules()) {
70-
defaultProfile.activateRule(repositoryKey, rule.getKey());
71-
LOGGER.debug(String.format("Rule %s added to repository %s.", rule.getKey(), repositoryKey));
67+
for (NewRule rule : rules) {
68+
profile.activateRule(repository, rule.key());
69+
LOGGER.info(String.format("Rule %s added to repository %s.", rule.key(), repository));
7270
}
73-
LOGGER.debug(String.format("%s rules are activated.", defaultProfile.activeRules().size()));
74-
75-
// Save the default profile.
76-
defaultProfile.setDefault(true);
77-
defaultProfile.done();
71+
profile.setDefault(true);
72+
profile.done();
73+
LOGGER.info(String.format("%s rules are activated for the repository %s.", profile.activeRules().size(), repository));
7874
}
7975
}

src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ public static void saveMeasure(final SensorContext context, final Map<String, In
7878
if(metricScope.equals(CLASS)) {
7979
// Get i-Code rule id to test if issue must be saved here.
8080
final String metricKey = icodeMeasure.getAnalysisRuleId();
81-
// Take F77 / F90 ncloc into account
82-
if (metricKey.contains("MET.LineOfCode")) {
81+
// Take F77 / F90 ncloc and number of comment lines into account
82+
if (metricKey.contains("MET.Line")) {
8383
saveSonarQubeNewMeasure(context, files, CoreMetrics.NCLOC, icodeMeasure);
84-
}
85-
// Take F77 / F90 number of comment lines into account
86-
else if (metricKey.contains("MET.LineOfComment")) {
8784
saveSonarQubeNewMeasure(context, files, CoreMetrics.COMMENT_LINES, icodeMeasure);
8885
}
8986
}
@@ -206,7 +203,7 @@ private static void computeFunctions(final SensorContext context, final Map<Stri
206203

207204
// Collect all ncloc measures in one list.
208205
measures.forEach((x,y) -> {
209-
if(x.contains(".MET.LineOfCode")) {
206+
if(x.contains(".MET.Line")) {
210207
rawMeasures.addAll(y);
211208
}
212209
});

0 commit comments

Comments
 (0)