diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-23 10:51:34 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-02 17:52:23 +0200 |
commit | 043c278c2844bd09ce9bd5add89d67eb7311a21f (patch) | |
tree | d519ff02c813daa9f96df73e89b2bc94712d4ccc /plugins/sonar-xoo-plugin/src | |
parent | 833e747cee8e1927972a1d30bd1fd9d16d9e55ba (diff) | |
download | sonarqube-043c278c2844bd09ce9bd5add89d67eb7311a21f.tar.gz sonarqube-043c278c2844bd09ce9bd5add89d67eb7311a21f.zip |
SONAR-5644, SONAR-5473 Create new SCM extension point and fetch SCM data using WS
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java | 6 | ||||
-rw-r--r-- | plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java (renamed from plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java) | 58 |
2 files changed, 28 insertions, 36 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index c7e43d9e0ab..e1988ac37ab 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -22,10 +22,10 @@ package org.sonar.xoo; import org.sonar.api.SonarPlugin; import org.sonar.xoo.lang.CoveragePerTestSensor; import org.sonar.xoo.lang.MeasureSensor; -import org.sonar.xoo.lang.ScmActivitySensor; import org.sonar.xoo.lang.SymbolReferencesSensor; import org.sonar.xoo.lang.SyntaxHighlightingSensor; import org.sonar.xoo.lang.TestCaseSensor; +import org.sonar.xoo.lang.XooScmProvider; import org.sonar.xoo.lang.XooTokenizerSensor; import org.sonar.xoo.rule.CreateIssueByInternalKeySensor; import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor; @@ -51,9 +51,11 @@ public class XooPlugin extends SonarPlugin { XooRulesDefinition.class, XooQualityProfile.class, + // SCM + XooScmProvider.class, + // sensors MeasureSensor.class, - ScmActivitySensor.class, SyntaxHighlightingSensor.class, SymbolReferencesSensor.class, XooTokenizerSensor.class, diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java index 12663b0b697..71582efc3ef 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java @@ -25,66 +25,58 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; -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.measures.FileLinesContext; -import org.sonar.api.measures.FileLinesContextFactory; +import org.sonar.api.batch.scm.BlameLine; +import org.sonar.api.batch.scm.ScmProvider; +import org.sonar.api.config.Settings; import org.sonar.api.utils.DateUtils; -import org.sonar.xoo.Xoo; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Date; import java.util.List; -public class ScmActivitySensor implements Sensor { +public class XooScmProvider implements ScmProvider { - private static final Logger LOG = LoggerFactory.getLogger(ScmActivitySensor.class); + private static final Logger LOG = LoggerFactory.getLogger(XooScmProvider.class); private static final String SCM_EXTENSION = ".scm"; - private final FileSystem fs; - private final FileLinesContextFactory fileLinesContextFactory; + private final Settings settings; - public ScmActivitySensor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) { - this.fs = fileSystem; - this.fileLinesContextFactory = fileLinesContextFactory; + public XooScmProvider(Settings settings) { + this.settings = settings; } @Override - public void describe(SensorDescriptor descriptor) { - descriptor - .name(this.getClass().getSimpleName()) - .provides(CoreMetrics.SCM_AUTHORS_BY_LINE, - CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE, - CoreMetrics.SCM_REVISIONS_BY_LINE) - .workOnLanguages(Xoo.KEY); + public String key() { + return "xoo"; } @Override - public void execute(SensorContext context) { - for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) { - processFile(inputFile); - } + public boolean supports(File baseDir) { + return false; + } + @Override + public void blame(Iterable<InputFile> files, BlameResultHandler handler) { + for (InputFile inputFile : files) { + processFile(inputFile, handler); + } } @VisibleForTesting - protected void processFile(InputFile inputFile) { + protected void processFile(InputFile inputFile, BlameResultHandler handler) { File ioFile = inputFile.file(); File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION); if (!scmDataFile.exists()) { - LOG.debug("Skipping SCM data injection for " + inputFile.relativePath()); - return; + throw new IllegalStateException("Missing file " + scmDataFile); } - FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile); try { List<String> lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name()); + List<BlameLine> blame = new ArrayList<BlameLine>(lines.size()); int lineNumber = 0; for (String line : lines) { lineNumber++; @@ -99,14 +91,12 @@ public class ScmActivitySensor implements Sensor { // Will throw an exception, when date is not in format "yyyy-MM-dd" Date date = DateUtils.parseDate(fields[2]); - fileLinesContext.setStringValue(CoreMetrics.SCM_REVISIONS_BY_LINE_KEY, lineNumber, revision); - fileLinesContext.setStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, lineNumber, author); - fileLinesContext.setStringValue(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, lineNumber, DateUtils.formatDateTime(date)); + blame.add(new BlameLine(date, revision, author)); } } + handler.handle(inputFile, blame); } catch (IOException e) { throw new IllegalStateException(e); } - fileLinesContext.save(); } } |