Skip to content

Commit

Permalink
Merge pull request #95 from cnescatlab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
diegorodriguez31 authored Aug 2, 2023
2 parents 65b6df6 + a28d74b commit 2801bbf
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 461 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at L-lequal@cnes.fr. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The following is a set of guidelines for contributing to i-Code CNES plugin for
* [Git Commit Messages](#git-commit-messages)

## Code of Conduct
This project and everyone participating in it is governed by the [Lequal Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [L-lequal@cnes.fr](mailto:L-lequal@cnes.fr).
This project and everyone participating in it is governed by the [Lequal Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.

## How Can I Contribute?

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Here is the compatibility matrix of the plugin:
| 2.0.3 | 4.1.2 | 7.9 -> 8.2 | Fortran / Shell |
| 3.0.0 | 4.1.0 | 7.9 -> 8.2 | Fortran |
| 3.0.1 | 4.1.2 | 7.9 -> 8.2 | Fortran |
| 3.1.0 | 4.1.2 | 7.9 -> 9.9 | Fortran |

#### Run i-Code manually
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).
Expand Down Expand Up @@ -82,8 +83,6 @@ If you want to do a PR, please put inside of it the reason of this pull request.
All details are available in [CONTRIBUTING](https://github.com/cnescatlab/sonar-icode-cnes-plugin/blob/master/CONTRIBUTING.md).

### Feedback and Support
Contact : L-lequal@cnes.fr

Bugs and Feature requests: https://github.com/cnescatlab/sonar-icode-cnes-plugin/issues

### License
Expand Down
40 changes: 27 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>fr.cnes.sonar.plugins</groupId>
<artifactId>sonar-icode-cnes-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>3.0.1</version>
<version>3.1.0</version>

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

Expand Down Expand Up @@ -46,6 +46,12 @@
<url>https://github.com/WaldoFR</url>
<id>WaldoFR</id>
</developer>
<developer>
<name>Diego Rodriguez</name>
<organization>CNES</organization>
<url>https://github.com/diegorodriguez31</url>
<id>diegorodriguez31</id>
</developer>
</developers>

<properties>
Expand All @@ -55,14 +61,16 @@
<jdk.max.version>11</jdk.max.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.apiVersion>6.7.7</sonar.apiVersion>
<sonar.apiVersion>9.8.0.203</sonar.apiVersion>
<sonar.testingHarnessVersion>9.5.0.56709</sonar.testingHarnessVersion>
<sonar.apiImplVersion>9.9.1.69595</sonar.apiImplVersion>
<sonar.sslr-squid-bridge.version>2.6.1</sonar.sslr-squid-bridge.version>
<sonar-packaging-maven-plugin.version>1.17</sonar-packaging-maven-plugin.version>
<sonar-packaging-maven-plugin.version>1.21.0.505</sonar-packaging-maven-plugin.version>
<commons-lang.version>3.7</commons-lang.version>
<gson.version>2.8.2</gson.version>
<slf4j.version>1.7.25</slf4j.version>
<junit.version>4.13.2</junit.version>
<jacoco.version>0.8.4</jacoco.version>
<jacoco.version>0.8.10</jacoco.version>
<sonar.pluginKey>icode</sonar.pluginKey>
<sonar.pluginClass>fr.cnes.sonar.plugins.icode.ICodePlugin</sonar.pluginClass>
<sonar.pluginUrl>https://github.com/cnescatlab/sonar-icode-cnes-plugin</sonar.pluginUrl>
Expand All @@ -81,7 +89,7 @@

<dependencies>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.apiVersion}</version>
<scope>provided</scope>
Expand All @@ -100,12 +108,18 @@
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.apiVersion}</version>
<version>${sonar.testingHarnessVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>${sonar.apiImplVersion}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -134,7 +148,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.10.1</version>
<configuration>
<source>${jdk.min.version}</source>
<target>${jdk.min.version}</target>
Expand All @@ -145,13 +159,13 @@
<!-- UTF-8 bundles are not supported by Java, so they must be converted during build -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<version>2.0.1</version>
<executions>
<execution>
<goals>
<goal>native2ascii</goal>
</goals>
</execution>
<execution>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected Map<String, InputFile> getScannedFiles(final FileSystem fileSystem, fi
for(final AnalysisFile file : files) {
// Checks if the file system contains a file with corresponding path (relative or absolute).
final String fileToFind = new File(fileSystem.baseDir(), file.getFileName()).getPath();
final FilePredicate predicate = fileSystem.predicates().hasRelativePath(fileToFind);
final FilePredicate predicate = fileSystem.predicates().hasPath(fileToFind);
final InputFile inputFile = fileSystem.inputFile(predicate);
if(inputFile!=null) {
result.put(file.getFileName(), inputFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
*/
package fr.cnes.sonar.plugins.icode.languages;

import fr.cnes.sonar.plugins.icode.model.Rule;
import fr.cnes.sonar.plugins.icode.model.RulesDefinition;
import fr.cnes.sonar.plugins.icode.model.XmlHandler;
import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition;
import fr.cnes.sonar.plugins.icode.rules.RulesRepository;

import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.server.rule.RulesDefinition.NewRule;

import java.io.InputStream;
import java.util.List;

/**
* Built-in quality profile format since SonarQube 6.6.
* Built-in quality profile format since SonarQube 9.9
*/
public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinition {

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

private List<NewRule> f77Rules = RulesRepository.getInstance().getF77Rules();
private List<NewRule> f90Rules = RulesRepository.getInstance().getF90Rules();

/**
* Allow to create a plugin.
*
* @param context Context of the plugin.
*/
@Override
public void define(final Context context) {
createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML);
createBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML);
createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN77_REPOSITORY, Fortran77Language.KEY, f77Rules);
createBuiltInProfile(context, ICodeRulesDefinition.FORTRAN90_REPOSITORY, Fortran90Language.KEY, f90Rules);
}

/**
* Create a built in quality profile for a specific language.
*
* @param context SonarQube context in which create the profile.
* @param repository Rules' repository.
* @param language Language key of the associated profile.
* @param path Path to the xml definition of all rules.
* @param rules Rules to activate.
*/
private void createBuiltInProfile(final Context context, final String language, final String path) {
private void createBuiltInProfile(final Context context, final String repository, final String languageKey, final List<NewRule> rules) {
// Create a builder for the rules' repository.
final NewBuiltInQualityProfile defaultProfile =
context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, language);

// Retrieve all defined rules.
final InputStream stream = getClass().getResourceAsStream(path);
final RulesDefinition rules = (RulesDefinition) XmlHandler.unmarshal(stream, RulesDefinition.class);
final String repositoryKey = ICodeRulesDefinition.getRepositoryKeyForLanguage(language);
NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(I_CODE_RULES_PROFILE_NAME, languageKey);

// Activate all i-Code CNES rules.
for(final Rule rule : rules.getRules()) {
defaultProfile.activateRule(repositoryKey, rule.getKey());
LOGGER.debug(String.format("Rule %s added to repository %s.", rule.getKey(), repositoryKey));
for (NewRule rule : rules) {
profile.activateRule(repository, rule.key());
LOGGER.info(String.format("Rule %s added to repository %s.", rule.key(), repository));
}
LOGGER.debug(String.format("%s rules are activated.", defaultProfile.activeRules().size()));

// Save the default profile.
defaultProfile.setDefault(true);
defaultProfile.done();
profile.setDefault(true);
profile.done();
LOGGER.info(String.format("%s rules are activated for the repository %s.", profile.activeRules().size(), repository));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ public static void saveMeasure(final SensorContext context, final Map<String, In
if(metricScope.equals(CLASS)) {
// Get i-Code rule id to test if issue must be saved here.
final String metricKey = icodeMeasure.getAnalysisRuleId();
// Take F77 / F90 ncloc into account
if (metricKey.contains("MET.LineOfCode")) {
// Take F77 / F90 ncloc and number of comment lines into account
if (metricKey.contains("MET.Line")) {
saveSonarQubeNewMeasure(context, files, CoreMetrics.NCLOC, icodeMeasure);
}
// Take F77 / F90 number of comment lines into account
else if (metricKey.contains("MET.LineOfComment")) {
saveSonarQubeNewMeasure(context, files, CoreMetrics.COMMENT_LINES, icodeMeasure);
}
}
Expand Down Expand Up @@ -206,7 +203,7 @@ private static void computeFunctions(final SensorContext context, final Map<Stri

// Collect all ncloc measures in one list.
measures.forEach((x,y) -> {
if(x.contains(".MET.LineOfCode")) {
if(x.contains(".MET.Line")) {
rawMeasures.addAll(y);
}
});
Expand Down
Loading

0 comments on commit 2801bbf

Please sign in to comment.