diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-26 10:22:14 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-26 10:22:14 +0200 |
commit | b99cd6861da25440322c4bd5ed15bd2e626851dc (patch) | |
tree | 3859097d3aa9f5a5943b7355c74c2adfb9171e1c /plugins | |
parent | c9fbb6a04bc2001bd9fb8519cb127c6c1ed56d29 (diff) | |
download | sonarqube-b99cd6861da25440322c4bd5ed15bd2e626851dc.tar.gz sonarqube-b99cd6861da25440322c4bd5ed15bd2e626851dc.zip |
Revert "SONAR-5644, SONAR-5473 Create new SCM extension point and fetch SCM data using WS"
This reverts commit 78fbdc2a8445e9131a10d2210b88d0e4d9927a14.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java | 106 | ||||
-rw-r--r-- | plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/JavaCpdEngine.java | 16 | ||||
-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/ScmActivitySensor.java (renamed from plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java) | 58 |
4 files changed, 51 insertions, 135 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index dbf7b8af7d1..1476e9aefe7 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -20,11 +20,7 @@ package org.sonar.plugins.core; import com.google.common.collect.ImmutableList; -import org.sonar.api.CoreProperties; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.PropertyType; -import org.sonar.api.SonarPlugin; +import org.sonar.api.*; import org.sonar.api.checks.NoSonarFilter; import org.sonar.core.timemachine.Periods; import org.sonar.plugins.core.batch.IndexProjectPostJob; @@ -36,81 +32,17 @@ import org.sonar.plugins.core.dashboards.GlobalDefaultDashboard; import org.sonar.plugins.core.dashboards.ProjectDefaultDashboard; import org.sonar.plugins.core.dashboards.ProjectIssuesDashboard; import org.sonar.plugins.core.dashboards.ProjectTimeMachineDashboard; -import org.sonar.plugins.core.issue.CountFalsePositivesDecorator; -import org.sonar.plugins.core.issue.CountUnresolvedIssuesDecorator; -import org.sonar.plugins.core.issue.InitialOpenIssuesSensor; -import org.sonar.plugins.core.issue.InitialOpenIssuesStack; -import org.sonar.plugins.core.issue.IssueHandlers; -import org.sonar.plugins.core.issue.IssueTracking; -import org.sonar.plugins.core.issue.IssueTrackingDecorator; -import org.sonar.plugins.core.issue.notification.ChangesOnMyIssueNotificationDispatcher; -import org.sonar.plugins.core.issue.notification.IssueChangesEmailTemplate; -import org.sonar.plugins.core.issue.notification.NewFalsePositiveNotificationDispatcher; -import org.sonar.plugins.core.issue.notification.NewIssuesEmailTemplate; -import org.sonar.plugins.core.issue.notification.NewIssuesNotificationDispatcher; -import org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob; +import org.sonar.plugins.core.issue.*; +import org.sonar.plugins.core.issue.notification.*; import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; import org.sonar.plugins.core.measurefilters.ProjectFilter; import org.sonar.plugins.core.notifications.alerts.NewAlerts; import org.sonar.plugins.core.security.ApplyProjectRolesDecorator; -import org.sonar.plugins.core.sensors.BranchCoverageDecorator; -import org.sonar.plugins.core.sensors.CommentDensityDecorator; -import org.sonar.plugins.core.sensors.CoverageDecorator; -import org.sonar.plugins.core.sensors.CoverageMeasurementFilter; -import org.sonar.plugins.core.sensors.DirectoriesDecorator; -import org.sonar.plugins.core.sensors.FileHashSensor; -import org.sonar.plugins.core.sensors.FilesDecorator; -import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator; -import org.sonar.plugins.core.sensors.ItCoverageDecorator; -import org.sonar.plugins.core.sensors.ItLineCoverageDecorator; -import org.sonar.plugins.core.sensors.LineCoverageDecorator; -import org.sonar.plugins.core.sensors.ManualMeasureDecorator; -import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator; -import org.sonar.plugins.core.sensors.OverallCoverageDecorator; -import org.sonar.plugins.core.sensors.OverallLineCoverageDecorator; -import org.sonar.plugins.core.sensors.ProjectLinksSensor; -import org.sonar.plugins.core.sensors.UnitTestDecorator; -import org.sonar.plugins.core.sensors.VersionEventsSensor; -import org.sonar.plugins.core.timemachine.NewCoverageAggregator; -import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer; -import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer; -import org.sonar.plugins.core.timemachine.NewOverallCoverageFileAnalyzer; -import org.sonar.plugins.core.timemachine.TendencyDecorator; -import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister; -import org.sonar.plugins.core.timemachine.VariationDecorator; -import org.sonar.plugins.core.widgets.AlertsWidget; -import org.sonar.plugins.core.widgets.BubbleChartWidget; -import org.sonar.plugins.core.widgets.ComplexityWidget; -import org.sonar.plugins.core.widgets.CoverageWidget; -import org.sonar.plugins.core.widgets.CustomMeasuresWidget; -import org.sonar.plugins.core.widgets.DebtOverviewWidget; -import org.sonar.plugins.core.widgets.DescriptionWidget; -import org.sonar.plugins.core.widgets.DocumentationCommentsWidget; -import org.sonar.plugins.core.widgets.DuplicationsWidget; -import org.sonar.plugins.core.widgets.EventsWidget; -import org.sonar.plugins.core.widgets.HotspotMetricWidget; -import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget; -import org.sonar.plugins.core.widgets.ItCoverageWidget; -import org.sonar.plugins.core.widgets.ProjectFileCloudWidget; -import org.sonar.plugins.core.widgets.SizeWidget; -import org.sonar.plugins.core.widgets.TechnicalDebtPyramidWidget; -import org.sonar.plugins.core.widgets.TimeMachineWidget; -import org.sonar.plugins.core.widgets.TimelineWidget; -import org.sonar.plugins.core.widgets.TreemapWidget; -import org.sonar.plugins.core.widgets.WelcomeWidget; -import org.sonar.plugins.core.widgets.issues.ActionPlansWidget; -import org.sonar.plugins.core.widgets.issues.FalsePositiveIssuesWidget; -import org.sonar.plugins.core.widgets.issues.IssueFilterWidget; -import org.sonar.plugins.core.widgets.issues.IssuesWidget; -import org.sonar.plugins.core.widgets.issues.MyUnresolvedIssuesWidget; -import org.sonar.plugins.core.widgets.issues.UnresolvedIssuesPerAssigneeWidget; -import org.sonar.plugins.core.widgets.issues.UnresolvedIssuesStatusesWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterAsBubbleChartWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterAsCloudWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterAsHistogramWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterAsPieChartWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterAsTreemapWidget; -import org.sonar.plugins.core.widgets.measures.MeasureFilterListWidget; +import org.sonar.plugins.core.sensors.*; +import org.sonar.plugins.core.timemachine.*; +import org.sonar.plugins.core.widgets.*; +import org.sonar.plugins.core.widgets.issues.*; +import org.sonar.plugins.core.widgets.measures.*; import java.util.List; @@ -254,27 +186,7 @@ import java.util.List; global = false, defaultValue = "admin", type = PropertyType.STRING, - multiValues = true), - @Property( - key = CoreProperties.SCM_ENABLED_KEY, - defaultValue = "true", - name = "Activation of the SCM Activity step", - description = "This property can be set to false in order to deactivate the SCM Activity step.", - module = false, - project = true, - global = true, - type = PropertyType.BOOLEAN - ), - @Property( - key = CoreProperties.SCM_PROVIDER_KEY, - defaultValue = "", - name = "Key of the SCM provider for this project", - description = "Force the provider to be used to get SCM information for this project. By default auto-detection is done. Exemple: svn, git.", - module = false, - project = true, - global = false, - type = PropertyType.BOOLEAN - ) + multiValues = true) }) public final class CorePlugin extends SonarPlugin { diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/JavaCpdEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/JavaCpdEngine.java index f8baa2ce642..5dfff7e3dcd 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/JavaCpdEngine.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/JavaCpdEngine.java @@ -33,7 +33,6 @@ import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.duplication.DuplicationBuilder; import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplicationBuilder; -import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.config.Settings; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.FileLinesContext; @@ -207,23 +206,20 @@ public class JavaCpdEngine extends CpdEngine { } linesContext.save(); // Save - ((DefaultMeasure<Integer>) context.<Integer>newMeasure() + context.<Integer>newMeasure() .forMetric(CoreMetrics.DUPLICATED_FILES) .onFile(inputFile) - .withValue(1)) - .setFromCore() + .withValue(1) .save(); - ((DefaultMeasure<Integer>) context.<Integer>newMeasure() + context.<Integer>newMeasure() .forMetric(CoreMetrics.DUPLICATED_LINES) .onFile(inputFile) - .withValue(duplicatedLines.size())) - .setFromCore() + .withValue(duplicatedLines.size()) .save(); - ((DefaultMeasure<Integer>) context.<Integer>newMeasure() + context.<Integer>newMeasure() .forMetric(CoreMetrics.DUPLICATED_BLOCKS) .onFile(inputFile) - .withValue(duplicatedBlocks)) - .setFromCore() + .withValue(duplicatedBlocks) .save(); DuplicationBuilder builder = context.duplicationBuilder(inputFile); 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 e1988ac37ab..c7e43d9e0ab 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,11 +51,9 @@ 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/XooScmProvider.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java index 71582efc3ef..12663b0b697 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java @@ -25,58 +25,66 @@ 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.scm.BlameLine; -import org.sonar.api.batch.scm.ScmProvider; -import org.sonar.api.config.Settings; +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.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 XooScmProvider implements ScmProvider { +public class ScmActivitySensor implements Sensor { - private static final Logger LOG = LoggerFactory.getLogger(XooScmProvider.class); + private static final Logger LOG = LoggerFactory.getLogger(ScmActivitySensor.class); private static final String SCM_EXTENSION = ".scm"; - private final Settings settings; + private final FileSystem fs; + private final FileLinesContextFactory fileLinesContextFactory; - public XooScmProvider(Settings settings) { - this.settings = settings; + public ScmActivitySensor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) { + this.fs = fileSystem; + this.fileLinesContextFactory = fileLinesContextFactory; } @Override - public String key() { - return "xoo"; + 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); } @Override - public boolean supports(File baseDir) { - return false; - } - - @Override - public void blame(Iterable<InputFile> files, BlameResultHandler handler) { - for (InputFile inputFile : files) { - processFile(inputFile, handler); + public void execute(SensorContext context) { + for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) { + processFile(inputFile); } + } @VisibleForTesting - protected void processFile(InputFile inputFile, BlameResultHandler handler) { + protected void processFile(InputFile inputFile) { File ioFile = inputFile.file(); File scmDataFile = new java.io.File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION); if (!scmDataFile.exists()) { - throw new IllegalStateException("Missing file " + scmDataFile); + LOG.debug("Skipping SCM data injection for " + inputFile.relativePath()); + return; } + 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++; @@ -91,12 +99,14 @@ public class XooScmProvider implements ScmProvider { // Will throw an exception, when date is not in format "yyyy-MM-dd" Date date = DateUtils.parseDate(fields[2]); - blame.add(new BlameLine(date, revision, author)); + 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)); } } - handler.handle(inputFile, blame); } catch (IOException e) { throw new IllegalStateException(e); } + fileLinesContext.save(); } } |