Skip to content

Commit

Permalink
Merge pull request #30 from stepstone-tech/sonar-7.6
Browse files Browse the repository at this point in the history
Sonar 7.6 compatibility
  • Loading branch information
tommywo authored Oct 20, 2021
2 parents 7e0d374 + 8595dd2 commit 5e85a2f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ Many thanks for the people, who created or improved this project:
- Tomek Stec
- Michał Paluchowski
- Nicolas Bihan
- Gareth Edwards

## License

Copyright 2016-2019 StepStone GmbH
and contibutors
and contributors


Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,35 @@

package com.stepstone.sonar.plugin.coldfusion;

import com.stepstone.sonar.plugin.coldfusion.cflint.CFLintAnalysisResultImporter;
import com.google.common.base.Preconditions;
import com.stepstone.sonar.plugin.coldfusion.cflint.CFLintAnalyzer;
import com.stepstone.sonar.plugin.coldfusion.cflint.CFLintAnalysisResultImporter;
import com.stepstone.sonar.plugin.coldfusion.cflint.CFLintConfigExporter;

import com.google.common.base.Preconditions;

import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

import javax.xml.stream.XMLStreamException;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.stream.XMLStreamException;

public class ColdFusionSensor implements Sensor {

Expand Down Expand Up @@ -120,7 +119,7 @@ private void measureProcessor(SensorContext context) {
for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(ColdFusionPlugin.LANGUAGE_KEY))) {
Callable<Integer> callableTask = () -> {
try {
metricsLinesCounter(inputFile, context);
metricsCounter(inputFile, context);
return 1;
} catch (IOException e) {
return 0;
Expand All @@ -142,17 +141,19 @@ private void measureProcessor(SensorContext context) {

//Very basic and naive line of code counter for Coldfusion
//Might count a line of code as comment
private void metricsLinesCounter(InputFile inputFile, SensorContext context) throws IOException {
private void metricsCounter(InputFile inputFile, SensorContext context) throws IOException {
String currentLine;
int commentLines = 0;
int blankLines = 0;
int lines = 0;
int complexity = 1;


try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputFile.inputStream()))) {
if (inputFile.inputStream() != null) {
while ((currentLine = reader.readLine()) != null) {
lines++;

if (currentLine.contains("<!--")) {
commentLines++;
if (currentLine.contains("-->")) {
Expand All @@ -166,6 +167,7 @@ private void metricsLinesCounter(InputFile inputFile, SensorContext context) thr
}
} else if (currentLine.trim().isEmpty()) {
blankLines++;
continue;
}

complexity = getLineComplexity(currentLine, complexity);
Expand All @@ -176,7 +178,6 @@ private void metricsLinesCounter(InputFile inputFile, SensorContext context) thr
// every 100 lines of code add 1 to the content's complexity
complexity = complexity + (linesOfCode / 100);


context.<Integer>newMeasure().forMetric(CoreMetrics.COMMENT_LINES).on(inputFile).withValue(commentLines).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.NCLOC).on(inputFile).withValue(linesOfCode).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.LINES).on(inputFile).withValue(lines).save();
Expand Down Expand Up @@ -220,6 +221,5 @@ private int countRegexOccurrences(String str, String regex) {
}
return matches;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
package com.stepstone.sonar.plugin.coldfusion.cflint;

import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin;

import org.sonar.api.batch.rule.ActiveRule;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class CFLintConfigExporter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

package com.stepstone.sonar.plugin.coldfusion.profile;

import com.google.common.base.Throwables;
import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin;
import com.stepstone.sonar.plugin.coldfusion.cflint.CFLintConfigExporter;

import com.google.common.base.Throwables;

import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.profiles.RulesProfile;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.Writer;
import javax.xml.stream.XMLStreamException;

public class ColdFusionProfileExporter extends ProfileExporter {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.stepstone.sonar.plugin.coldfusion;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -11,18 +9,20 @@
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.internal.apachecommons.codec.Charsets;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.utils.Version;
import org.sonar.api.utils.command.CommandExecutor;

import java.io.File;

import static org.assertj.core.api.Assertions.assertThat;

public class ColdfusionSensorTest {

private ActiveRules rulesProfile = new ActiveRulesBuilder().build();
Expand Down Expand Up @@ -71,6 +71,7 @@ public void testBasicCFMAnalysis() {
assertThat(nloc).isEqualTo(56);
assertThat(comments).isEqualTo(9);
assertThat(complexity).isEqualTo(10);

}

private void addFilesToFs() {
Expand Down

0 comments on commit 5e85a2f

Please sign in to comment.