Skip to content

Commit

Permalink
Merge pull request #82 from cnescatlab/feature/shell-separation
Browse files Browse the repository at this point in the history
Remove shell from Icode plugin
  • Loading branch information
louisjdmartin authored Mar 30, 2022
2 parents c43db80 + d77742d commit 4c5aa48
Show file tree
Hide file tree
Showing 27 changed files with 425 additions and 1,510 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ buildNumber.properties

# Ignore IntelliJ files
.idea
*.iml
*.iml
.vscode
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

SonarQube plugin for the code analysis tool: i-Code CNES.

SonarQube is an open platform to manage code quality. This plugin adds the ability to check Fortran (77 & 90) & Shell with i-Code or import pre-existing results of i-Code.
SonarQube is an open platform to manage code quality. This plugin adds the ability to check Fortran (77 & 90) with i-Code or import pre-existing results of i-Code.

This plugin is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

You can get i-Code CNES on GitHub: [lequal/i-CodeCNES](https://github.com/lequal/i-CodeCNES).
You can get i-Code CNES on GitHub: [cnescatlab/i-CodeCNES](https://github.com/cnescatlab/i-CodeCNES).

### Quickstart
- Setup a SonarQube instance.
- **[Optional]** Install i-Code command line application as described in [official documentation](https://github.com/lequal/i-CodeCNES/wiki/Installation-Manual).
- **[Optional]** Install i-Code command line application as described in [official documentation](https://github.com/cnescatlab/i-CodeCNES/wiki/Installation-Manual).
- Install `sonaricode-*.jar` in `<SONARQUBE_HOME>/extensions/plugins/`.
- **[Optional]** Run i-Code manually or configure auto-launch in plugin configuration.
- Run an analysis with *sonar-scanner*, *maven*, *gradle*, *msbuild*, etc.
Expand All @@ -33,30 +33,28 @@ Here is the compatibility matrix of the plugin:
| 2.0.2 | 4.1.0 | 7.9 -> 8.2 |

#### Run i-Code manually
If you need help to run i-Code please refer to the [official user manual](https://github.com/lequal/i-CodeCNES/wiki/User-Manual) or [i-Code issue tracker](https://github.com/lequal/i-CodeCNES/issues).
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).

#### Run a specific i-Code version through sonaricode plugin
If embedded version of i-Code does not match your need, you can set the execution of another installed version of i-Code through the following properties:
- `sonar.icode.launch`: Activate autolaunch for i-Code if `true`. Default: `false`.
- `sonar.icode.path`: Define i-Code CNES executable path to auto-launch it on analysis. Default: `${HOME}/icode-cnes/icode.exe`.

#### Other plugin's properties
- `sonar.icode.shell.file.suffixes`: List of suffixes for Shell files to analyze. Default: `.sh,.ksh,.bash`.
- `sonar.icode.f77.file.suffixes`: List of suffixes for F77 files to analyze. Default: `.f,.f77,.for,.fpp,.ftn,.F,.F77,.FOR,.FPP,.FTN`.
- `sonar.icode.f90.file.suffixes`: List of suffixes for F90 files to analyze. Default: `.f90,.F90`.
- `sonar.icode.reports.path`: Path to the i-Code reports. Multiple path can be provided. Default: `result.res`.

### Features
- Fortran 77 analysis
- Fortran 90 analysis
- Shell analysis
- Import i-Code results

#### Get i-Code help
Use `icode -h` to get the following help about i-Code:
````
usage: icode [<FILE> [...]] [-c <arg>] [-e] [-f <arg>] [-h] [-l] [-o <arg>] [-p <arg>] [-q <arg>] [-r] [-x <arg>]
Analyze Shell, F77 & F90 code to find defects & bugs.
Analyze F77 & F90 code to find defects & bugs.
-c,--checked-languages <arg> Comma separated list of languages checked during analysis. All by default.
-e,--exporters Display all available exporters.
Expand All @@ -70,20 +68,20 @@ Analyze Shell, F77 & F90 code to find defects & bugs.
-r,--rules Display all available rules.
-x,--excluded-rules <arg> Comma separated list of rules id to exclude from analysis. None by default.
Please report issues at https://github.com/lequal/i-CodeCNES/issues
Please report issues at https://github.com/leqcnescatlabual/i-CodeCNES/issues
````

### How to contribute
If you experienced a problem with the plugin please open an issue. Inside this issue please explain us how to reproduce this issue and paste the log.

If you want to do a PR, please put inside of it the reason of this pull request. If this pull request fix an issue please insert the number of the issue or explain inside of the PR how to reproduce this issue.

All details are available in [CONTRIBUTING](https://github.com/lequal/sonar-icode-cnes-plugin/CONTRIBUTING.md).
All details are available in [CONTRIBUTING](https://github.com/cnescatlab/sonar-icode-cnes-plugin/blob/master/CONTRIBUTING.md).

### Feedback and Support
Contact : [email protected]

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

### License
Licensed under the [GNU General Public License, Version 3.0](https://www.gnu.org/licenses/gpl.txt)
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<groupId>fr.cnes.sonar.plugins</groupId>
<artifactId>sonar-icode-cnes-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>2.0.2</version>
<version>3.0.0-SNAPSHOT</version>

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

<description>i-Code CNES plugin for SonarQube</description>
<url>https://github.com/lequal/sonar-icode-cnes-plugin</url>
<url>https://github.com/cnescatlab/sonar-icode-cnes-plugin</url>
<inceptionYear>2017</inceptionYear>

<licenses>
Expand All @@ -24,7 +24,7 @@

<organization>
<name>CNES</name>
<url>http://cnes.fr</url>
<url>https://cnes.fr</url>
</organization>

<developers>
Expand Down Expand Up @@ -61,12 +61,12 @@
<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.12</junit.version>
<junit.version>4.13.2</junit.version>
<jacoco.version>0.8.4</jacoco.version>
<sonar.pluginKey>icode</sonar.pluginKey>
<sonar.pluginClass>fr.cnes.sonar.plugins.icode.ICodePlugin</sonar.pluginClass>
<sonar.pluginUrl>https://github.com/lequal/sonar-icode-cnes-plugin</sonar.pluginUrl>
<sonar.pluginSourcesUrl>https://github.com/lequal/sonar-icode-cnes-plugin</sonar.pluginSourcesUrl>
<sonar.pluginUrl>https://github.com/cnescatlab/sonar-icode-cnes-plugin</sonar.pluginUrl>
<sonar.pluginSourcesUrl>https://github.com/cnescatlab/sonar-icode-cnes-plugin</sonar.pluginSourcesUrl>
<sonar.pluginOrganizationName>CNES</sonar.pluginOrganizationName>
<sonar.sources>src/main/java</sonar.sources>
<sonar.test>src/test/java</sonar.test>
Expand Down Expand Up @@ -106,7 +106,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -118,7 +117,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.11.1</version>
<version>1.4.18</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -214,4 +213,15 @@

</plugins>
</build>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
3 changes: 1 addition & 2 deletions src/main/java/fr/cnes/sonar/plugins/icode/ICodePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import fr.cnes.sonar.plugins.icode.languages.Fortran77Language;
import fr.cnes.sonar.plugins.icode.languages.Fortran90Language;
import fr.cnes.sonar.plugins.icode.languages.ICodeQualityProfiles;
import fr.cnes.sonar.plugins.icode.languages.ShellLanguage;
import fr.cnes.sonar.plugins.icode.measures.ICodeNestingMetric;
import fr.cnes.sonar.plugins.icode.rules.ICodeRulesDefinition;
import fr.cnes.sonar.plugins.icode.settings.ICodePluginProperties;
Expand All @@ -39,7 +38,7 @@ public class ICodePlugin implements Plugin {
@Override
public void define(Context context) {
// Setting plugin ICode
context.addExtensions(ShellLanguage.class, Fortran77Language.class, Fortran90Language.class);
context.addExtensions(Fortran77Language.class, Fortran90Language.class);
context.addExtension(ICodeQualityProfiles.class);
context.addExtensions(ICodePluginProperties.getProperties());

Expand Down
27 changes: 17 additions & 10 deletions src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import fr.cnes.sonar.plugins.icode.exceptions.ICodeException;
import fr.cnes.sonar.plugins.icode.languages.Fortran77Language;
import fr.cnes.sonar.plugins.icode.languages.Fortran90Language;
import fr.cnes.sonar.plugins.icode.languages.ShellLanguage;
import fr.cnes.sonar.plugins.icode.measures.ICodeMetricsProcessor;
import fr.cnes.sonar.plugins.icode.model.AnalysisFile;
import fr.cnes.sonar.plugins.icode.model.AnalysisProject;
Expand Down Expand Up @@ -63,6 +62,11 @@ public class ICodeSensor implements Sensor {
*/
private static final Logger LOGGER = Loggers.get(ICodeSensor.class);

/**
* Languages used by I-Code
*/
private final String[] languages = {Fortran77Language.KEY, Fortran90Language.KEY};

/**
* Give information about this sensor.
*
Expand All @@ -71,7 +75,7 @@ public class ICodeSensor implements Sensor {
@Override
public void describe(final SensorDescriptor sensorDescriptor) {
// Prevents sensor to be run during all analysis.
sensorDescriptor.onlyOnLanguages(ShellLanguage.KEY, Fortran77Language.KEY, Fortran90Language.KEY);
sensorDescriptor.onlyOnLanguages(languages);

// Defines sensor name
sensorDescriptor.name("Sonar i-Code");
Expand All @@ -80,10 +84,11 @@ public void describe(final SensorDescriptor sensorDescriptor) {
sensorDescriptor.onlyOnFileType(InputFile.Type.MAIN);

// This sensor is activated only if a rule from the following repo is activated.
sensorDescriptor.createIssuesForRuleRepositories(
ICodeRulesDefinition.getRepositoryKeyForLanguage(ShellLanguage.KEY),
ICodeRulesDefinition.getRepositoryKeyForLanguage(Fortran77Language.KEY),
ICodeRulesDefinition.getRepositoryKeyForLanguage(Fortran90Language.KEY));
for (String Lang : languages) {
sensorDescriptor.createIssuesForRuleRepositories(
ICodeRulesDefinition.getRepositoryKeyForLanguage(Lang));
}

}

/**
Expand Down Expand Up @@ -382,10 +387,12 @@ protected List<File> getReportFiles(final Configuration config, final FileSystem
* @return True if the rule is active and false if not or not exists.
*/
protected boolean isRuleActive(final ActiveRules activeRules, final String rule) {
final RuleKey ruleKeyShell = RuleKey.of(ICodeRulesDefinition.getRepositoryKeyForLanguage(ShellLanguage.KEY), rule);
final RuleKey ruleKeyF77 = RuleKey.of(ICodeRulesDefinition.getRepositoryKeyForLanguage(Fortran77Language.KEY), rule);
final RuleKey ruleKeyF90 = RuleKey.of(ICodeRulesDefinition.getRepositoryKeyForLanguage(Fortran90Language.KEY), rule);
return activeRules.find(ruleKeyShell)!=null || activeRules.find(ruleKeyF77)!=null || activeRules.find(ruleKeyF90)!=null;
boolean isActive = false;
for (String Lang : languages) {
RuleKey ruleKey = RuleKey.of(ICodeRulesDefinition.getRepositoryKeyForLanguage(Lang), rule);
isActive = activeRules.find(ruleKey)!=null || isActive;
}
return isActive;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;

/**
* Declared language i-Code as the parent language for Fortran 77, Fortran 90 & Shell.
* Declared language i-Code as the parent language for Fortran 77, Fortran 90.
*/
public abstract class ICodeLanguage extends AbstractLanguage {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public final class ICodeQualityProfiles implements BuiltInQualityProfilesDefinit
*/
@Override
public void define(final Context context) {
createBuiltInProfile(context, ShellLanguage.KEY, ICodeRulesDefinition.PATH_TO_SHELL_RULES_XML);
createBuiltInProfile(context, Fortran77Language.KEY, ICodeRulesDefinition.PATH_TO_F77_RULES_XML);
createBuiltInProfile(context, Fortran90Language.KEY, ICodeRulesDefinition.PATH_TO_F90_RULES_XML);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ 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 SHELL / F77 / F90 ncloc into account
// Take F77 / F90 ncloc into account
if (metricKey.contains("MET.LineOfCode")) {
saveSonarQubeNewMeasure(context, files, CoreMetrics.NCLOC, icodeMeasure);
}
// Take SHELL / F77 / F90 number of comment lines into account
// Take F77 / F90 number of comment lines into account
else if (metricKey.contains("MET.LineOfComment")) {
saveSonarQubeNewMeasure(context, files, CoreMetrics.COMMENT_LINES, icodeMeasure);
}
// Take SHELL complexity into account
else if (metricKey.contains("SH.MET.ComplexitySimplified")) {
saveSonarQubeNewMeasure(context, files, CoreMetrics.COMPLEXITY, icodeMeasure);
}
}

}
Expand Down Expand Up @@ -151,7 +147,7 @@ public static void saveExtraMeasures(final SensorContext context, final Map<Stri
}
}

// Compute nesting for shell and fortran.
// Compute nesting for Fortran.
computeNesting(context, scannedFiles, measures);
// Compute complexity for Fortran.
computeComplexity(context, scannedFiles, measures);
Expand Down Expand Up @@ -186,7 +182,7 @@ public static void saveExtraMeasures(final SensorContext context, final Map<Stri
}
}

// Compute nesting for shell and fortran.
// Compute nesting for Fortran.
computeNesting(context, scannedFiles, measures);
// Compute complexity for Fortran.
computeComplexity(context, scannedFiles, measures);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/fr/cnes/sonar/plugins/icode/model/XmlHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ public boolean shouldSerializeMember(final Class definedIn, final String fieldNa
}
};
xStream.processAnnotations(cls);

/*
See https://stackoverflow.com/a/67288175 for more informations about this.
In few words, It's a security feature,
We need to explicitly authorize class that uses XStream to avoid unwanted injections.
*/
xStream.allowTypesByWildcard(new String[] {
"fr.cnes.sonar.plugins.icode.model.**",
});
return xStream.fromXML(file);
}

}
}
Loading

0 comments on commit 4c5aa48

Please sign in to comment.