Skip to content

Commit

Permalink
Merge pull request #1 from ghedwards/sonar-7.6
Browse files Browse the repository at this point in the history
Sonar 7.6
  • Loading branch information
ghedwards authored Mar 19, 2019
2 parents 140b913 + ed09e1f commit a1c7b90
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.version>6.7.6</sonar.version>
<sonar.version>7.6</sonar.version>
<cflint.version>1.4.1</cflint.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ActiveRule> 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;
}

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/wellsky/ColdfusionPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/wellsky/ColdfusionSensorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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();
Expand Down

0 comments on commit a1c7b90

Please sign in to comment.