Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…plugin.git into Cyrille-dev
  • Loading branch information
Aurore Dupuis committed Dec 15, 2017
2 parents 5a8f60a + 3bcb4a3 commit 7ae3609
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,31 @@ private String[] filterEmptyStrings(String[] stringArray) {
}
return nonEmptyStrings.toArray(new String[nonEmptyStrings.size()]);
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((settings == null) ? 0 : settings.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
FramaCLanguage other = (FramaCLanguage) obj;
if (settings == null) {
if (other.settings != null)
return false;
} else if (!settings.equals(other.settings))
return false;
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public final class FramaCQualityProfile extends ProfileDefinition {

@Override
public RulesProfile createProfile(ValidationMessages validation) {
RulesProfile profile = RulesProfile.create(FRAMA_C_RULES_PROFILE_NAME, FramaCLanguage.KEY);

return profile;
return RulesProfile.create(FRAMA_C_RULES_PROFILE_NAME, FramaCLanguage.KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public class ComputePluginErrors implements MeasureComputer {

@Override
public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
return defContext.newDefinitionBuilder()
.setInputMetrics(new String[] {FramaCMetrics.NUMBER_OF_ERRORS.key(), FramaCMetrics.REPORT_FILES_ERROR.key()})
.setOutputMetrics(new String[] {FramaCMetrics.NUMBER_OF_ERRORS.key(), FramaCMetrics.REPORT_FILES_ERROR.key()})
String[] metricTab = new String[] {FramaCMetrics.NUMBER_OF_ERRORS.key(), FramaCMetrics.REPORT_FILES_ERROR.key()};
return defContext.newDefinitionBuilder()
.setInputMetrics(metricTab)
.setOutputMetrics(metricTab)
.build();
}

Expand All @@ -56,11 +57,6 @@ public void compute(MeasureComputerContext context) {
}
context.addMeasure(FramaCMetrics.NUMBER_OF_ERRORS.key(), sum);

int sumOfReportFiles = 0;
for (Measure child : context.getChildrenMeasures(FramaCMetrics.REPORT_FILES_ERROR.key())) {
sumOfReportFiles++;
}

context.addMeasure(FramaCMetrics.REPORT_FILES_ERROR.key(), SEE_REPORT_FILES_ERROR_MESSAGES);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public class ComputeProjectCyclomaticStatistics implements MeasureComputer {
@Override
public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {

return defContext.newDefinitionBuilder()
.setInputMetrics(new String[] {CyclomaticMetrics.CYCLOMATIC.key(),CyclomaticMetrics.CYCLOMATIC_MEAN.key(),CyclomaticMetrics.CYCLOMATIC_MIN.key(),CyclomaticMetrics.CYCLOMATIC_MAX.key()})
.setOutputMetrics(new String[] {CyclomaticMetrics.CYCLOMATIC.key(),CyclomaticMetrics.CYCLOMATIC_MEAN.key(),CyclomaticMetrics.CYCLOMATIC_MIN.key(),CyclomaticMetrics.CYCLOMATIC_MAX.key()})
String[] metricTab = new String[] {CyclomaticMetrics.CYCLOMATIC.key(),CyclomaticMetrics.CYCLOMATIC_MEAN.key(),CyclomaticMetrics.CYCLOMATIC_MIN.key(),CyclomaticMetrics.CYCLOMATIC_MAX.key()};
return defContext.newDefinitionBuilder()
.setInputMetrics(metricTab)
.setOutputMetrics(metricTab)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public class ComputeProjectLocStatistics implements MeasureComputer {
@Override
public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {

return defContext.newDefinitionBuilder()
.setInputMetrics(new String[] {CyclomaticMetrics.SLOC.key(),CyclomaticMetrics.SLOC_MEAN.key(),CyclomaticMetrics.SLOC_MIN.key(),CyclomaticMetrics.SLOC_MAX.key()})
.setOutputMetrics(new String[] {CyclomaticMetrics.SLOC.key(),CyclomaticMetrics.SLOC_MEAN.key(),CyclomaticMetrics.SLOC_MIN.key(),CyclomaticMetrics.SLOC_MAX.key()})
String[] metricTab = new String[] {CyclomaticMetrics.SLOC.key(),CyclomaticMetrics.SLOC_MEAN.key(),CyclomaticMetrics.SLOC_MIN.key(),CyclomaticMetrics.SLOC_MAX.key()};
return defContext.newDefinitionBuilder()
.setInputMetrics(metricTab)
.setOutputMetrics(metricTab)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@
*/
package fr.cnes.sonarqube.plugins.framac.measures;

import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;

Expand Down Expand Up @@ -64,7 +57,7 @@ public class CyclomaticMetrics implements Metrics {

public static final String DOMAIN = FramaCMetrics.DOMAIN;

private static final Map<String,Pattern> mapMetricsPattern = new HashMap<String, Pattern>();
private static final Map<String,Pattern> mapMetricsPattern = new HashMap<>();

public static Map<String, Pattern> getMapMetricsPattern() {
if(mapMetricsPattern.isEmpty()){
Expand All @@ -73,7 +66,7 @@ public static Map<String, Pattern> getMapMetricsPattern() {
return mapMetricsPattern;
}

public final static Pattern METRICS_PATTERN = Pattern.compile("Global metrics");
public static final Pattern METRICS_PATTERN = Pattern.compile("Global metrics");

/** Metric for number of lines of code (assuming one C statement equals one line of code): Sloc */
public static final Metric<Integer> SLOC = new Metric.Builder(
Expand Down Expand Up @@ -251,7 +244,7 @@ public List<Metric> getMetrics() {

initMapMetricsPattern();

ArrayList<Metric> res=new ArrayList<Metric>();
ArrayList<Metric> res=new ArrayList<>();
res.addAll(Arrays.asList(
DECISION_POINTS,
NUMBER_OF_GLOBAL_VARIABLES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*/
package fr.cnes.sonarqube.plugins.framac.measures;

import org.sonar.api.measures.Metrics;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;

/**
* General metrics of Frama-C plugin for sonar.
Expand Down Expand Up @@ -77,7 +76,7 @@ public class FramaCMetrics implements Metrics {

@SuppressWarnings({ "rawtypes" })
public List<Metric> getMetrics() {
ArrayList<Metric> res=new ArrayList<Metric>();
ArrayList<Metric> res=new ArrayList<>();
res.addAll(Arrays.asList(
NUMBER_OF_WARNINGS,
NUMBER_OF_ERRORS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,18 @@ MetricsModuleMeasure getGlobalMetrics() {

@Override
public ReportModuleRuleInterface getModuleCyclomaticMeasure() {
// TODO Auto-generated method stub
return this.globalMetrics;
}

@Override
public ReportFunctionRuleInterface[] getCyclomaticMeasureByFunction() {
// TODO Auto-generated method stub
return new ReportFunctionRuleInterface[0];
}

@Override
public ErrorInterface[] getErrors() {
if(this.errors == null){
this.errors = new ArrayList<FramaCError>();
this.errors = new ArrayList<>();
}
ErrorInterface[] res = new ErrorInterface[this.errors.size()];
res = this.errors.toArray(res);
Expand All @@ -66,7 +64,7 @@ public ErrorInterface[] getErrors() {

public void addError(FramaCError err) {
if(this.errors == null){
this.errors = new ArrayList<FramaCError>();
this.errors = new ArrayList<>();
}
this.errors.add(err);
}
Expand All @@ -90,13 +88,11 @@ class MetricsModuleMeasure implements ReportModuleRuleInterface{

@Override
public String getLoc() {
// TODO Auto-generated method stub
return this.sloc;
}

@Override
public String getComplexity() {
// TODO Auto-generated method stub
return this.cyclomaticComplexity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class FramaCReportReader {
public static final Pattern PATTERN_KERNEL = Pattern.compile(WORD_KERNEL);
public static final Pattern PATTERN_VALUE = Pattern.compile(WORD_VALUE);

protected static final Map<String,Pattern> mapRulePattern = new HashMap<String, Pattern>();
protected static final Map<String,Pattern> mapRulePattern = new HashMap<>();

public FramaCReportReader() {
super();
Expand Down Expand Up @@ -106,7 +106,7 @@ private void valueRulesMatchingPatterns() {
}
}

private final static Charset ENCODING = StandardCharsets.UTF_8;
private static final Charset ENCODING = StandardCharsets.UTF_8;

/**
* Parse a XML report file.
Expand Down Expand Up @@ -181,8 +181,8 @@ private void searchIssues(AnalysisProject res, Matcher kernelMatcher, Matcher va

private FramaCError searchError(String line, String ruleModuleKey) {
FramaCError err = null;
String rule0_Key = ruleModuleKey+".0";
Pattern pValue0 = mapRulePattern.get(rule0_Key);
String rule0Key = ruleModuleKey+".0";
Pattern pValue0 = mapRulePattern.get(rule0Key);
Matcher mValue0 = pValue0.matcher(line);
if (mValue0.find()) {
int index = 1;
Expand All @@ -204,8 +204,8 @@ private FramaCError searchError(String line, String ruleModuleKey) {
}
}
if (!ruleFind) {
err = parseError(rule0_Key, mValue0, line);
LOGGER.info("Rule = " + rule0_Key);
err = parseError(rule0Key, mValue0, line);
LOGGER.info("Rule = " + rule0Key);
}

}
Expand Down Expand Up @@ -237,15 +237,12 @@ private FramaCError parseError(
}
}

FramaCError error = new FramaCError(externalRuleKey, description, filePath, lineNb);

return error;
return new FramaCError(externalRuleKey, description, filePath, lineNb);
}

private void readGlobalMetrics(AnalysisProject res, Scanner scanner) {
// Skip next line
scanner.nextLine();
Metric<?> metric = null;

// Read sloc value
readSloc(res, scanner);
Expand Down Expand Up @@ -289,7 +286,7 @@ private void readCyclomatic(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.CYCLOMATIC;
String cyclomatic = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (cyclomatic != null) {
res.getGlobalMetrics().setCyclomaticComplexity(cyclomatic.toString());
res.getGlobalMetrics().setCyclomaticComplexity(cyclomatic);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -300,7 +297,7 @@ private void readNumberOfDereferencings(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_POINTER_DEREFERENCINGS;
String pd = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (pd != null) {
res.getGlobalMetrics().setPointerDereferencing(pd.toString());
res.getGlobalMetrics().setPointerDereferencing(pd);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -311,7 +308,7 @@ private void readNumberOfCalls(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_FUNCTION_CALLS;
String fc = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (fc != null) {
res.getGlobalMetrics().setFunctionCall(fc.toString());
res.getGlobalMetrics().setFunctionCall(fc);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -322,7 +319,7 @@ private void readNumberOfFunctions(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_FUNCTIONS_DECLARED;
String fd = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (fd != null) {
res.getGlobalMetrics().setFunction(fd.toString());
res.getGlobalMetrics().setFunction(fd);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -333,7 +330,7 @@ private void readNumberOfExitPoints(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_EXIT_POINT_STATEMENTS;
String ep = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (ep != null) {
res.getGlobalMetrics().setExitPoint(ep.toString());
res.getGlobalMetrics().setExitPoint(ep);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -344,7 +341,7 @@ private void readNumberOfAssignment(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_ASSIGNMENT_STATEMENTS;
String assignment = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (assignment != null) {
res.getGlobalMetrics().setAssignmentStatements(assignment.toString());
res.getGlobalMetrics().setAssignmentStatements(assignment);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -355,7 +352,7 @@ private void readNumberOfGotos(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_GOTO_STATEMENTS;
String gotoStatements = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (gotoStatements != null) {
res.getGlobalMetrics().setGotoStatements(gotoStatements.toString());
res.getGlobalMetrics().setGotoStatements(gotoStatements);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -366,7 +363,7 @@ private void readNumberOfLoops(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_LOOP_STATEMENTS;
String loopStatements = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (loopStatements != null) {
res.getGlobalMetrics().setLoopStatements(loopStatements.toString());
res.getGlobalMetrics().setLoopStatements(loopStatements);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -377,7 +374,7 @@ private void readIfStatements(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_IF_STATEMENTS;
String ifStatements = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (ifStatements != null) {
res.getGlobalMetrics().setIfStatements(ifStatements.toString());
res.getGlobalMetrics().setIfStatements(ifStatements);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -388,7 +385,7 @@ private void readGlobalVariables(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.NUMBER_OF_GLOBAL_VARIABLES;
String gv = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (gv != null) {
res.getGlobalMetrics().setGlobalVariables(gv.toString());
res.getGlobalMetrics().setGlobalVariables(gv);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand All @@ -399,7 +396,7 @@ private void readDecisionPoints(AnalysisProject res, Scanner scanner) {
metric = CyclomaticMetrics.DECISION_POINTS;
String dp = scanMetricValue(scanner, CyclomaticMetrics.getMapMetricsPattern(), metric);
if (dp != null) {
res.getGlobalMetrics().setDecisionPoint(dp.toString());
res.getGlobalMetrics().setDecisionPoint(dp);
} else {
LOGGER.warn(NO_EXPECTED_VALUE_FOR_METRICS + metric.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;

import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
Expand All @@ -43,15 +42,13 @@ public class FramaCRulesDefinition implements RulesDefinition {
public static final String REPO_KEY = FramaCLanguage.KEY + "-" + KEY;
protected static final String REPO_NAME = FramaCLanguage.NAME;

private NewRepository repository;

protected String rulesDefinitionFilePath() {
return PATH_TO_RULES_XML;
}

private void defineRulesForLanguage(Context context, String repositoryKey, String repositoryName,
String languageKey) {
repository = context.createRepository(repositoryKey, languageKey).setName(repositoryName);
NewRepository repository = context.createRepository(repositoryKey, languageKey).setName(repositoryName);

InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath());
if (rulesXml != null) {
Expand Down
Loading

0 comments on commit 7ae3609

Please sign in to comment.