From b99cd6861da25440322c4bd5ed15bd2e626851dc Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 26 Sep 2014 10:22:14 +0200 Subject: Revert "SONAR-5644, SONAR-5473 Create new SCM extension point and fetch SCM data using WS" This reverts commit 78fbdc2a8445e9131a10d2210b88d0e4d9927a14. --- .../java/org/sonar/plugins/core/CorePlugin.java | 106 ++----------------- .../java/org/sonar/plugins/cpd/JavaCpdEngine.java | 16 ++- .../src/main/java/org/sonar/xoo/XooPlugin.java | 6 +- .../java/org/sonar/xoo/lang/ScmActivitySensor.java | 112 +++++++++++++++++++++ .../java/org/sonar/xoo/lang/XooScmProvider.java | 102 ------------------- 5 files changed, 129 insertions(+), 213 deletions(-) create mode 100644 plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java delete mode 100644 plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java (limited to 'plugins') 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) context.newMeasure() + context.newMeasure() .forMetric(CoreMetrics.DUPLICATED_FILES) .onFile(inputFile) - .withValue(1)) - .setFromCore() + .withValue(1) .save(); - ((DefaultMeasure) context.newMeasure() + context.newMeasure() .forMetric(CoreMetrics.DUPLICATED_LINES) .onFile(inputFile) - .withValue(duplicatedLines.size())) - .setFromCore() + .withValue(duplicatedLines.size()) .save(); - ((DefaultMeasure) context.newMeasure() + context.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/ScmActivitySensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java new file mode 100644 index 00000000000..12663b0b697 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/ScmActivitySensor.java @@ -0,0 +1,112 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.xoo.lang; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Charsets; +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.utils.DateUtils; +import org.sonar.xoo.Xoo; + +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.List; + +public class ScmActivitySensor implements Sensor { + + private static final Logger LOG = LoggerFactory.getLogger(ScmActivitySensor.class); + + private static final String SCM_EXTENSION = ".scm"; + + private final FileSystem fs; + private final FileLinesContextFactory fileLinesContextFactory; + + public ScmActivitySensor(FileLinesContextFactory fileLinesContextFactory, FileSystem fileSystem) { + this.fs = fileSystem; + this.fileLinesContextFactory = fileLinesContextFactory; + } + + @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); + } + + @Override + public void execute(SensorContext context) { + for (InputFile inputFile : fs.inputFiles(fs.predicates().hasLanguage(Xoo.KEY))) { + processFile(inputFile); + } + + } + + @VisibleForTesting + protected void processFile(InputFile inputFile) { + 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; + } + + FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile); + try { + List lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name()); + int lineNumber = 0; + for (String line : lines) { + lineNumber++; + if (StringUtils.isNotBlank(line)) { + // revision,author,dateTime + String[] fields = StringUtils.split(line, ','); + if (fields.length < 3) { + throw new IllegalStateException("Not enough fields on line " + lineNumber); + } + String revision = fields[0]; + String author = fields[1]; + // 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)); + } + } + } catch (IOException e) { + throw new IllegalStateException(e); + } + fileLinesContext.save(); + } +} 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/XooScmProvider.java deleted file mode 100644 index 71582efc3ef..00000000000 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooScmProvider.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.xoo.lang; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; -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.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.utils.DateUtils; - -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 { - - private static final Logger LOG = LoggerFactory.getLogger(XooScmProvider.class); - - private static final String SCM_EXTENSION = ".scm"; - - private final Settings settings; - - public XooScmProvider(Settings settings) { - this.settings = settings; - } - - @Override - public String key() { - return "xoo"; - } - - @Override - public boolean supports(File baseDir) { - return false; - } - - @Override - public void blame(Iterable files, BlameResultHandler handler) { - for (InputFile inputFile : files) { - processFile(inputFile, handler); - } - } - - @VisibleForTesting - 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()) { - throw new IllegalStateException("Missing file " + scmDataFile); - } - - try { - List lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name()); - List blame = new ArrayList(lines.size()); - int lineNumber = 0; - for (String line : lines) { - lineNumber++; - if (StringUtils.isNotBlank(line)) { - // revision,author,dateTime - String[] fields = StringUtils.split(line, ','); - if (fields.length < 3) { - throw new IllegalStateException("Not enough fields on line " + lineNumber); - } - String revision = fields[0]; - String author = fields[1]; - // 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)); - } - } - handler.handle(inputFile, blame); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } -} -- cgit v1.2.3