Skip to content

Commit

Permalink
Sonar 5.0 support
Browse files Browse the repository at this point in the history
Removed deprecations
  • Loading branch information
Gilles Grousset committed Jan 19, 2015
1 parent d7339ea commit 7632e96
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 38 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/sonar/plugins/objectivec/core/ObjectiveC.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.AbstractLanguage;
import org.sonar.plugins.objectivec.ObjectiveCPlugin;

Expand All @@ -32,15 +32,16 @@ public class ObjectiveC extends AbstractLanguage {

public static final String KEY = "objc";

private Configuration configuration;
private Settings settings;

public ObjectiveC(Settings settings) {

public ObjectiveC(Configuration configuration) {
super(KEY, "Objective-C");
this.configuration = configuration;
this.settings = settings;
}

public String[] getFileSuffixes() {
String[] suffixes = filterEmptyStrings(configuration.getStringArray(ObjectiveCPlugin.FILE_SUFFIXES_KEY));
String[] suffixes = filterEmptyStrings(settings.getStringArray(ObjectiveCPlugin.FILE_SUFFIXES_KEY));
if (suffixes == null || suffixes.length == 0) {
suffixes = StringUtils.split(ObjectiveCPlugin.FILE_SUFFIXES_DEFVALUE, ",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoverageMeasuresBuilder;
import org.sonar.api.resources.Project;
Expand All @@ -42,17 +43,20 @@ public final class CoberturaSensor implements Sensor {
private final ReportFilesFinder reportFilesFinder;
private final CoberturaParser parser = new CoberturaParser();

public CoberturaSensor() {
this(null);
}
private final Settings conf;
private final FileSystem fileSystem;

public CoberturaSensor(final FileSystem fileSystem, final Settings config) {

public CoberturaSensor(final Settings config) {
reportFilesFinder = new ReportFilesFinder(config, REPORT_PATTERN_KEY,
DEFAULT_REPORT_PATTERN);
this.conf = config;
this.fileSystem = fileSystem;

reportFilesFinder = new ReportFilesFinder(config, REPORT_PATTERN_KEY, DEFAULT_REPORT_PATTERN);
}

public boolean shouldExecuteOnProject(final Project project) {
return ObjectiveC.KEY.equals(project.getLanguageKey());

return project.isRoot() && fileSystem.languages().contains(ObjectiveC.KEY);
}

public void analyse(final Project project, final SensorContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,30 @@
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.Violation;
import org.sonar.plugins.objectivec.ObjectiveCPlugin;
import org.sonar.plugins.objectivec.core.ObjectiveC;
import org.sonar.plugins.objectivec.violations.OCLintParser;

public final class OCLintSensor implements Sensor {
public static final String REPORT_PATH_KEY = ObjectiveCPlugin.PROPERTY_PREFIX
+ ".oclint.report";
public static final String DEFAULT_REPORT_PATH = "sonar-reports/oclint.xml";
private final Settings conf;

public OCLintSensor() {
this(null);
}
private final Settings conf;
private final FileSystem fileSystem;

public OCLintSensor(final Settings config) {
conf = config;
public OCLintSensor(final FileSystem moduleFileSystem, final Settings config) {
this.conf = config;
this.fileSystem = moduleFileSystem;
}

public boolean shouldExecuteOnProject(final Project project) {
return ObjectiveC.KEY.equals(project.getLanguageKey());

return project.isRoot() && fileSystem.languages().contains(ObjectiveC.KEY);

}

public void analyse(final Project project, final SensorContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,54 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.plugins.objectivec.core.ObjectiveC;

import java.util.SortedSet;
import java.util.TreeSet;

public final class CoberturaSensorTest {

private Settings settings;

@Before
public void setUp() {
settings = new Settings();
}

@Test
public void shouldExecuteOnProjectShouldBeTrueWhenProjectIsObjc() {
final Project project = new Project("Test");
final CoberturaSensor testedSensor = new CoberturaSensor();
final PropertiesConfiguration config = new PropertiesConfiguration();
config.addProperty("sonar.language", ObjectiveC.KEY);
project.setConfiguration(config);

FileSystem fileSystem = mock(FileSystem.class);
SortedSet<String> languages = new TreeSet<String>();
languages.add(ObjectiveC.KEY);
when(fileSystem.languages()).thenReturn(languages);

final CoberturaSensor testedSensor = new CoberturaSensor(fileSystem, settings);

assertTrue(testedSensor.shouldExecuteOnProject(project));
}

@Test
public void shouldExecuteOnProjectShouldBeFalseWhenProjectIsSomethingElse() {
final Project project = new Project("Test");
final CoberturaSensor testedSensor = new CoberturaSensor();
final PropertiesConfiguration config = new PropertiesConfiguration();
config.addProperty("sonar.language", "Test");
project.setConfiguration(config);
settings.setProperty("sonar.language", "Test");

FileSystem fileSystem = mock(FileSystem.class);
SortedSet<String> languages = new TreeSet<String>();
languages.add("Test");
when(fileSystem.languages()).thenReturn(languages);

final CoberturaSensor testedSensor = new CoberturaSensor(fileSystem, settings);

assertFalse(testedSensor.shouldExecuteOnProject(project));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,52 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.plugins.objectivec.core.ObjectiveC;

import java.util.SortedSet;
import java.util.TreeSet;

public final class OCLintSensorTest {

private Settings settings;

@Before
public void setUp() {
settings = new Settings();
}

@Test
public void shouldExecuteOnProjectShouldBeTrueWhenProjectIsObjc() {
final Project project = new Project("Test");
final OCLintSensor testedSensor = new OCLintSensor();
final PropertiesConfiguration config = new PropertiesConfiguration();
config.addProperty("sonar.language", ObjectiveC.KEY);
project.setConfiguration(config);

FileSystem fileSystem = mock(FileSystem.class);
SortedSet<String> languages = new TreeSet<String>();
languages.add(ObjectiveC.KEY);
when(fileSystem.languages()).thenReturn(languages);

final OCLintSensor testedSensor = new OCLintSensor(fileSystem, settings);

assertTrue(testedSensor.shouldExecuteOnProject(project));
}

@Test
public void shouldExecuteOnProjectShouldBeFalseWhenProjectIsSomethingElse() {
final Project project = new Project("Test");
final OCLintSensor testedSensor = new OCLintSensor();
final PropertiesConfiguration config = new PropertiesConfiguration();
config.addProperty("sonar.language", "Test");
project.setConfiguration(config);

FileSystem fileSystem = mock(FileSystem.class);
SortedSet<String> languages = new TreeSet<String>();
languages.add("Test");
when(fileSystem.languages()).thenReturn(languages);

final OCLintSensor testedSensor = new OCLintSensor(fileSystem, settings);

assertFalse(testedSensor.shouldExecuteOnProject(project));
}
Expand Down

0 comments on commit 7632e96

Please sign in to comment.