diff --git a/pom.xml b/pom.xml index 4221eca..81306cb 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ UTF-8 1.8 1.8 - 6.7.6 + 7.6 1.4.1 diff --git a/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java b/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java index 61c73d2..8f43114 100644 --- a/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java +++ b/src/main/java/com/stepstone/sonar/plugin/coldfusion/ColdFusionSensor.java @@ -26,7 +26,7 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -38,6 +38,7 @@ 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; @@ -46,10 +47,10 @@ public class ColdFusionSensor implements Sensor { private final FileSystem fs; - private final RulesProfile ruleProfile; + private final ActiveRules ruleProfile; private final Logger LOGGER = Loggers.get(ColdFusionSensor.class); - public ColdFusionSensor(FileSystem fs, RulesProfile ruleProfile) { + public ColdFusionSensor(FileSystem fs, ActiveRules ruleProfile) { Preconditions.checkNotNull(fs); Preconditions.checkNotNull(ruleProfile); @@ -87,7 +88,7 @@ private void analyze(SensorContext context) throws IOException, XMLStreamExcepti private File generateCflintConfig() throws IOException, XMLStreamException { final File configFile = new File(fs.workDir(), "cflint-config.xml"); - new CFlintConfigExporter(ruleProfile).save(configFile); + new CFlintConfigExporter(ruleProfile.findByRepository(ColdFusionPlugin.REPOSITORY_KEY)).save(configFile); return configFile; } diff --git a/src/main/java/com/stepstone/sonar/plugin/coldfusion/cflint/CFlintConfigExporter.java b/src/main/java/com/stepstone/sonar/plugin/coldfusion/cflint/CFlintConfigExporter.java index 270ace3..f579f55 100644 --- a/src/main/java/com/stepstone/sonar/plugin/coldfusion/cflint/CFlintConfigExporter.java +++ b/src/main/java/com/stepstone/sonar/plugin/coldfusion/cflint/CFlintConfigExporter.java @@ -17,8 +17,7 @@ package com.stepstone.sonar.plugin.coldfusion.cflint; import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; +import org.sonar.api.batch.rule.ActiveRule; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; @@ -27,18 +26,19 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.util.Collection; public class CFlintConfigExporter { - private final RulesProfile ruleProfile; + private final Collection ruleProfiles; private final String repositoryKey; - public CFlintConfigExporter(RulesProfile ruleProfile) { + public CFlintConfigExporter(Collection ruleProfile) { this(ruleProfile, ColdFusionPlugin.REPOSITORY_KEY); } - public CFlintConfigExporter(RulesProfile ruleProfile, String repositoryKey) { - this.ruleProfile = ruleProfile; + public CFlintConfigExporter(Collection ruleProfile, String repositoryKey) { + this.ruleProfiles = ruleProfile; this.repositoryKey = repositoryKey; } @@ -57,9 +57,9 @@ public void save(Writer writer) throws IOException, XMLStreamException { xtw.writeStartDocument(); xtw.writeStartElement("config"); - for (ActiveRule activeRule : ruleProfile.getActiveRulesByRepository(repositoryKey)) { + for (ActiveRule activeRule : ruleProfiles) { xtw.writeStartElement("includes"); - xtw.writeAttribute("code", activeRule.getRuleKey()); + xtw.writeAttribute("code", activeRule.ruleKey().toString()); xtw.writeEndElement(); } diff --git a/src/main/java/com/stepstone/sonar/plugin/coldfusion/profile/ColdFusionProfileExporter.java b/src/main/java/com/stepstone/sonar/plugin/coldfusion/profile/ColdFusionProfileExporter.java index 97970cd..4fafc51 100644 --- a/src/main/java/com/stepstone/sonar/plugin/coldfusion/profile/ColdFusionProfileExporter.java +++ b/src/main/java/com/stepstone/sonar/plugin/coldfusion/profile/ColdFusionProfileExporter.java @@ -20,6 +20,7 @@ import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin; import com.stepstone.sonar.plugin.coldfusion.cflint.CFlintConfigExporter; import org.sonar.api.profiles.ProfileExporter; +import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.profiles.RulesProfile; import javax.xml.stream.XMLStreamException; @@ -35,9 +36,16 @@ public ColdFusionProfileExporter() { @Override public void exportProfile(RulesProfile ruleProfile, Writer writer) { + try { + new CFlintConfigExporter(ruleProfile.getActiveRulesByRepository(ColdFusionPlugin.REPOSITORY_KEY)).save(writer); + } catch (IOException | XMLStreamException e) { + Throwables.propagate(e); + } + } + public void exportProfile(ActiveRules activeRules, Writer writer) { try { - new CFlintConfigExporter(ruleProfile).save(writer); + new CFlintConfigExporter(activeRules.findByRepository(ColdFusionPlugin.REPOSITORY_KEY)).save(writer); } catch (IOException | XMLStreamException e) { Throwables.propagate(e); } diff --git a/src/test/java/com/wellsky/ColdfusionPluginTest.java b/src/test/java/com/wellsky/ColdfusionPluginTest.java index 9e01e11..176731c 100644 --- a/src/test/java/com/wellsky/ColdfusionPluginTest.java +++ b/src/test/java/com/wellsky/ColdfusionPluginTest.java @@ -12,12 +12,12 @@ public class ColdfusionPluginTest { - private static final Version VERSION_6_5 = Version.create(6, 5); + private static final Version VERSION_7_6 = Version.create(7, 6); @Test public void testExtensions() { ColdFusionPlugin plugin = new ColdFusionPlugin(); - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_6_5, SonarQubeSide.SERVER); + SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_7_6, SonarQubeSide.SERVER); Plugin.Context context = new Plugin.Context(runtime); plugin.define(context); diff --git a/src/test/java/com/wellsky/ColdfusionSensorTest.java b/src/test/java/com/wellsky/ColdfusionSensorTest.java index 555c53e..a7673d0 100644 --- a/src/test/java/com/wellsky/ColdfusionSensorTest.java +++ b/src/test/java/com/wellsky/ColdfusionSensorTest.java @@ -19,7 +19,8 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.FileLinesContext; import org.sonar.api.measures.FileLinesContextFactory; -import org.sonar.api.profiles.RulesProfile; +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; @@ -33,7 +34,7 @@ public class ColdfusionSensorTest { - private RulesProfile rulesProfile = RulesProfile.create(RulesProfile.SONAR_WAY_NAME, ColdFusionPlugin.LANGUAGE_NAME); + private ActiveRules rulesProfile = new ActiveRulesBuilder().build(); private File baseDir = new File("src/test/resources").getAbsoluteFile(); private SensorContextTester context = SensorContextTester.create(baseDir); @@ -47,7 +48,7 @@ public void testBasicCFMAnalysis() { fileSystem.setWorkDir(tmpFolder.getRoot().toPath()); context.setFileSystem(fileSystem); - context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER)); + context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SCANNER)); context.settings().appendProperty("sonar.projectBaseDir", baseDir.getPath()); addFilesToFs();