aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-02 17:50:04 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-02 17:52:24 +0200
commita5d9aeea1d086bbffb8f2f864651416494abb0b4 (patch)
treefbe41af6757604f34540fafc0318c6d6cef3c620 /sonar-batch
parent2d60412e140a950436349f80f928c0e3a073c287 (diff)
downloadsonarqube-a5d9aeea1d086bbffb8f2f864651416494abb0b4.tar.gz
sonarqube-a5d9aeea1d086bbffb8f2f864651416494abb0b4.zip
SONAR-5643 Hide SVN password and rework logging
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameResult.java90
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java68
3 files changed, 104 insertions, 60 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameResult.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameResult.java
new file mode 100644
index 00000000000..64e8a77d48b
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameResult.java
@@ -0,0 +1,90 @@
+/*
+ * 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.batch.scm;
+
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.scm.BlameCommand.BlameResult;
+import org.sonar.api.batch.scm.BlameLine;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.PropertiesBuilder;
+import org.sonar.api.utils.DateUtils;
+
+import java.text.Normalizer;
+import java.util.List;
+import java.util.regex.Pattern;
+
+class DefaultBlameResult implements BlameResult {
+
+ private static final Pattern NON_ASCII_CHARS = Pattern.compile("[^\\x00-\\x7F]");
+ private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
+
+ private final SensorContext context;
+
+ DefaultBlameResult(SensorContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void add(InputFile file, List<BlameLine> lines) {
+
+ PropertiesBuilder<Integer, String> authors = propertiesBuilder(CoreMetrics.SCM_AUTHORS_BY_LINE);
+ PropertiesBuilder<Integer, String> dates = propertiesBuilder(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);
+ PropertiesBuilder<Integer, String> revisions = propertiesBuilder(CoreMetrics.SCM_REVISIONS_BY_LINE);
+
+ int lineNumber = 1;
+ for (BlameLine line : lines) {
+ authors.add(lineNumber, normalizeString(line.getAuthor()));
+ dates.add(lineNumber, DateUtils.formatDateTime(line.getDate()));
+ revisions.add(lineNumber, line.getRevision());
+
+ lineNumber++;
+ // SONARPLUGINS-3097 For some SCM blame is missing on last empty line
+ if (lineNumber > lines.size() && lineNumber == file.lines()) {
+ authors.add(lineNumber, normalizeString(line.getAuthor()));
+ dates.add(lineNumber, DateUtils.formatDateTime(line.getDate()));
+ revisions.add(lineNumber, line.getRevision());
+ }
+ }
+
+ ScmSensor.saveMeasures(context, file, authors.buildData(), dates.buildData(), revisions.buildData());
+
+ }
+
+ private String normalizeString(String inputString) {
+ String lowerCasedString = inputString.toLowerCase();
+ String stringWithoutAccents = removeAccents(lowerCasedString);
+ return removeNonAsciiCharacters(stringWithoutAccents);
+ }
+
+ private String removeAccents(String inputString) {
+ String unicodeDecomposedString = Normalizer.normalize(inputString, Normalizer.Form.NFD);
+ return ACCENT_CODES.matcher(unicodeDecomposedString).replaceAll("");
+ }
+
+ private String removeNonAsciiCharacters(String inputString) {
+ return NON_ASCII_CHARS.matcher(inputString).replaceAll("_");
+ }
+
+ private static PropertiesBuilder<Integer, String> propertiesBuilder(Metric metric) {
+ return new PropertiesBuilder<Integer, String>(metric);
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java
index 11e00d0964c..8ccfa2f4678 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java
@@ -57,7 +57,7 @@ public final class ScmConfiguration implements BatchComponent, Startable {
@Override
public void start() {
- if (!settings.getBoolean(CoreProperties.SCM_ENABLED_KEY)) {
+ if (isDisabled()) {
LOG.debug("SCM Step is disabled by configuration");
return;
}
@@ -92,6 +92,10 @@ public final class ScmConfiguration implements BatchComponent, Startable {
return provider;
}
+ public boolean isDisabled() {
+ return !settings.getBoolean(CoreProperties.SCM_ENABLED_KEY);
+ }
+
@Override
public void stop() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
index 8c729c605ec..2de113798e1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
@@ -25,33 +25,23 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
-import org.sonar.api.batch.scm.BlameCommand.BlameResult;
-import org.sonar.api.batch.scm.BlameLine;
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.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.PropertiesBuilder;
-import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectReferentials;
import java.nio.charset.Charset;
-import java.text.Normalizer;
import java.util.LinkedList;
import java.util.List;
-import java.util.regex.Pattern;
public final class ScmSensor implements Sensor {
private static final Logger LOG = LoggerFactory.getLogger(ScmSensor.class);
- private static final Pattern NON_ASCII_CHARS = Pattern.compile("[^\\x00-\\x7F]");
- private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
-
private final ProjectDefinition projectDefinition;
private final ScmConfiguration configuration;
private final FileSystem fs;
@@ -76,8 +66,12 @@ public final class ScmSensor implements Sensor {
@Override
public void execute(final SensorContext context) {
+ if (configuration.isDisabled()) {
+ LOG.info("SCM Sensor is disabled");
+ return;
+ }
if (configuration.provider() == null) {
- LOG.info("No SCM provider");
+ LOG.info("No SCM provider for this project");
return;
}
@@ -96,60 +90,16 @@ public final class ScmSensor implements Sensor {
filesToBlame.add(f);
}
}
- configuration.provider().blameCommand().blame(fs, filesToBlame, new BlameResult() {
-
- @Override
- public void add(InputFile file, List<BlameLine> lines) {
-
- PropertiesBuilder<Integer, String> authors = propertiesBuilder(CoreMetrics.SCM_AUTHORS_BY_LINE);
- PropertiesBuilder<Integer, String> dates = propertiesBuilder(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);
- PropertiesBuilder<Integer, String> revisions = propertiesBuilder(CoreMetrics.SCM_REVISIONS_BY_LINE);
-
- int lineNumber = 1;
- for (BlameLine line : lines) {
- authors.add(lineNumber, normalizeString(line.getAuthor()));
- dates.add(lineNumber, DateUtils.formatDateTime(line.getDate()));
- revisions.add(lineNumber, line.getRevision());
-
- lineNumber++;
- // SONARPLUGINS-3097 For some SCM blame is missing on last empty line
- if (lineNumber > lines.size() && lineNumber == file.lines()) {
- authors.add(lineNumber, normalizeString(line.getAuthor()));
- dates.add(lineNumber, DateUtils.formatDateTime(line.getDate()));
- revisions.add(lineNumber, line.getRevision());
- }
- }
-
- saveMeasures(context, file, authors.buildData(), dates.buildData(), revisions.buildData());
-
- }
- });
+ if (!filesToBlame.isEmpty()) {
+ configuration.provider().blameCommand().blame(fs, filesToBlame, new DefaultBlameResult(context));
+ }
profiler.stop();
}
- private String normalizeString(String inputString) {
- String lowerCasedString = inputString.toLowerCase();
- String stringWithoutAccents = removeAccents(lowerCasedString);
- return removeNonAsciiCharacters(stringWithoutAccents);
- }
-
- private String removeAccents(String inputString) {
- String unicodeDecomposedString = Normalizer.normalize(inputString, Normalizer.Form.NFD);
- return ACCENT_CODES.matcher(unicodeDecomposedString).replaceAll("");
- }
-
- private String removeNonAsciiCharacters(String inputString) {
- return NON_ASCII_CHARS.matcher(inputString).replaceAll("_");
- }
-
- private static PropertiesBuilder<Integer, String> propertiesBuilder(Metric metric) {
- return new PropertiesBuilder<Integer, String>(metric);
- }
-
/**
* This method is synchronized since it is allowed for plugins to compute blame in parallel.
*/
- private synchronized void saveMeasures(SensorContext context, InputFile f, String scmAuthorsByLine, String scmLastCommitDatetimesByLine, String scmRevisionsByLine) {
+ static synchronized void saveMeasures(SensorContext context, InputFile f, String scmAuthorsByLine, String scmLastCommitDatetimesByLine, String scmRevisionsByLine) {
((DefaultMeasure<String>) context.<String>newMeasure()
.onFile(f)
.forMetric(CoreMetrics.SCM_AUTHORS_BY_LINE)