Browse Source

Fix some quality flaws

tags/5.2-RC1
Julien HENRY 8 years ago
parent
commit
e2daa5befa
39 changed files with 313 additions and 459 deletions
  1. 5
    6
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
  2. 5
    6
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java
  3. 1
    1
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java
  4. 26
    15
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java
  5. 1
    1
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java
  6. 1
    1
      plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java
  7. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java
  8. 9
    10
      server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java
  9. 12
    18
      server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
  10. 9
    11
      server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
  11. 0
    38
      sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.java
  12. 0
    28
      sonar-batch/src/main/java/org/sonar/batch/index/Data.java
  13. 0
    34
      sonar-batch/src/main/java/org/sonar/batch/index/ResourceNotPersistedException.java
  14. 0
    40
      sonar-batch/src/main/java/org/sonar/batch/index/StringData.java
  15. 3
    2
      sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java
  16. 146
    141
      sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java
  17. 6
    8
      sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
  18. 6
    6
      sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java
  19. 1
    1
      sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java
  20. 0
    4
      sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
  21. 0
    2
      sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
  22. 5
    5
      sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
  23. 3
    3
      sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
  24. 2
    2
      sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
  25. 2
    2
      sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
  26. 10
    12
      sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
  27. 6
    7
      sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java
  28. 1
    1
      sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java
  29. 2
    2
      sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java
  30. 5
    7
      sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java
  31. 6
    6
      sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java
  32. 1
    4
      sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java
  33. 14
    11
      sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java
  34. 3
    4
      sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
  35. 1
    1
      sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java
  36. 1
    1
      sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java
  37. 3
    3
      sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
  38. 2
    2
      sonar-db/src/main/java/org/sonar/db/version/SelectImpl.java
  39. 13
    11
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java

+ 5
- 6
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java View File

@@ -20,6 +20,10 @@
package org.sonar.xoo.lang;

import com.google.common.base.Splitter;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.sonar.api.batch.fs.InputFile;
@@ -33,11 +37,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
* Parse files *.xoo.symbol
*/
@@ -79,7 +78,7 @@ public class SymbolReferencesSensor implements Sensor {
}
}

private void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) {
private static void processLine(File symbolFile, int lineNumber, Symbolizable.SymbolTableBuilder symbolTableBuilder, String line) {
try {
Iterator<String> split = Splitter.on(",").split(line).iterator();
int startOffset = Integer.parseInt(split.next());

+ 5
- 6
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SyntaxHighlightingSensor.java View File

@@ -20,6 +20,10 @@
package org.sonar.xoo.lang;

import com.google.common.base.Splitter;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.sonar.api.batch.fs.InputFile;
@@ -32,11 +36,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
* Parse files *.xoo.highlighting
*/
@@ -69,7 +68,7 @@ public class SyntaxHighlightingSensor implements Sensor {
}
}

private void processLine(File highlightingFile, int lineNumber, NewHighlighting highlightingBuilder, String line) {
private static void processLine(File highlightingFile, int lineNumber, NewHighlighting highlightingBuilder, String line) {
try {
Iterator<String> split = Splitter.on(":").split(line).iterator();
int startOffset = Integer.parseInt(split.next());

+ 1
- 1
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java View File

@@ -51,7 +51,7 @@ public class CreateIssueByInternalKeySensor implements Sensor {
}
}

private void createIssues(InputFile file, SensorContext context) {
private static void createIssues(InputFile file, SensorContext context) {
ActiveRule rule = context.activeRules().findByInternalKey(XooRulesDefinition.XOO_REPOSITORY,
context.settings().getString(INTERNAL_KEY_PROPERTY));
if (rule != null) {

+ 26
- 15
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/MultilineIssuesSensor.java View File

@@ -61,13 +61,38 @@ public class MultilineIssuesSensor implements Sensor {
}
}

private void createIssues(InputFile file, SensorContext context) {
private static void createIssues(InputFile file, SensorContext context) {
Pattern startPattern = Pattern.compile(START_ISSUE_PATTERN);
Pattern endPattern = Pattern.compile(END_ISSUE_PATTERN);
Map<Integer, Map<Integer, TextPointer>> startPositions = new HashMap<>();
Map<Integer, Map<Integer, TextPointer>> endPositions = new HashMap<>();

RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
parse(file, context, startPattern, endPattern, startPositions, endPositions);
createIssues(file, context, startPositions, endPositions, ruleKey);
}

private static void createIssues(InputFile file, SensorContext context, Map<Integer, Map<Integer, TextPointer>> startPositions,
Map<Integer, Map<Integer, TextPointer>> endPositions,
RuleKey ruleKey) {
for (Map.Entry<Integer, Map<Integer, TextPointer>> entry : startPositions.entrySet()) {
NewIssue newIssue = context.newIssue().forRule(ruleKey);
for (Map.Entry<Integer, TextPointer> location : entry.getValue().entrySet()) {
NewIssueLocation newLocation = newIssue.newLocation()
.on(file)
.at(file.newRange(location.getValue(), endPositions.get(entry.getKey()).get(location.getKey())));
if (location.getKey() == 1) {
newIssue.at(newLocation.message("Primary location"));
} else {
newIssue.addLocation(newLocation.message("Location #" + location.getKey()));
}
}
newIssue.save();
}
}

private static void parse(InputFile file, SensorContext context, Pattern startPattern, Pattern endPattern, Map<Integer, Map<Integer, TextPointer>> startPositions,
Map<Integer, Map<Integer, TextPointer>> endPositions) {
int currentLine = 0;
try {
for (String lineStr : Files.readAllLines(file.path(), context.fileSystem().encoding())) {
@@ -98,20 +123,6 @@ public class MultilineIssuesSensor implements Sensor {
} catch (IOException e) {
throw new IllegalStateException("Unable to read file", e);
}
for (Map.Entry<Integer, Map<Integer, TextPointer>> entry : startPositions.entrySet()) {
NewIssue newIssue = context.newIssue().forRule(ruleKey);
for (Map.Entry<Integer, TextPointer> location : entry.getValue().entrySet()) {
NewIssueLocation newLocation = newIssue.newLocation()
.on(file)
.at(file.newRange(location.getValue(), endPositions.get(entry.getKey()).get(location.getKey())));
if (location.getKey() == 1) {
newIssue.at(newLocation.message("Primary location"));
} else {
newIssue.addLocation(newLocation.message("Location #" + location.getKey()));
}
}
newIssue.save();
}
}

}

+ 1
- 1
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java View File

@@ -47,7 +47,7 @@ public class OneIssueOnDirPerFileSensor implements Sensor {
}
}

private void createIssues(InputFile file, SensorContext context) {
private static void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
InputDir inputDir = context.fileSystem().inputDir(file.file().getParentFile());
if (inputDir != null) {

+ 1
- 1
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java View File

@@ -61,7 +61,7 @@ public class RandomAccessSensor implements Sensor {
}
}

private void createIssues(InputFile file, SensorContext context) {
private static void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
NewIssue newIssue = context.newIssue();
newIssue

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/batch/IssuesAction.java View File

@@ -86,7 +86,7 @@ public class IssuesAction implements BatchWsAction {
Map<String, String> keysByUUid = keysByUUid(session, component);

BatchInput.ServerIssue.Builder issueBuilder = BatchInput.ServerIssue.newBuilder();
for (Iterator<IssueDoc> issueDocIterator = issueIndex.selectIssuesForBatch(component); issueDocIterator.hasNext(); ) {
for (Iterator<IssueDoc> issueDocIterator = issueIndex.selectIssuesForBatch(component); issueDocIterator.hasNext();) {
handleIssue(issueDocIterator.next(), issueBuilder, keysByUUid, response.stream().output());
}
} finally {
@@ -94,7 +94,7 @@ public class IssuesAction implements BatchWsAction {
}
}

private void handleIssue(IssueDoc issue, BatchInput.ServerIssue.Builder issueBuilder, Map<String, String> keysByUUid, OutputStream out) {
private static void handleIssue(IssueDoc issue, BatchInput.ServerIssue.Builder issueBuilder, Map<String, String> keysByUUid, OutputStream out) {
issueBuilder.setKey(issue.key());
issueBuilder.setModuleKey(keysByUUid.get(issue.moduleUuid()));
String path = issue.filePath();

+ 9
- 10
server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java View File

@@ -77,7 +77,7 @@ public class ProjectRepositoryLoader {
private final UserSession userSession;

public ProjectRepositoryLoader(DbClient dbClient, QProfileFactory qProfileFactory, QProfileLoader qProfileLoader, RuleService ruleService,
Languages languages, UserSession userSession) {
Languages languages, UserSession userSession) {
this.dbClient = dbClient;
this.qProfileFactory = qProfileFactory;
this.qProfileLoader = qProfileLoader;
@@ -117,9 +117,8 @@ public class ProjectRepositoryLoader {
TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, modulesTree, modulesTreeSettings, module);

addSettingsToChildrenModules(ref, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm, session);
List<FilePathWithHashDto> files = module.isRootProject() ?
dbClient.componentDao().selectEnabledFilesFromProject(session, module.uuid()) :
dbClient.componentDao().selectEnabledDescendantFiles(session, module.uuid());
List<FilePathWithHashDto> files = module.isRootProject() ? dbClient.componentDao().selectEnabledFilesFromProject(session, module.uuid())
: dbClient.componentDao().selectEnabledDescendantFiles(session, module.uuid());
addFileData(session, ref, modulesTree, files);

// FIXME need real value but actually only used to know if there is a previous analysis in local issue tracking mode so any value is
@@ -170,7 +169,7 @@ public class ProjectRepositoryLoader {
}

private void addSettingsToChildrenModules(ProjectRepositories ref, String moduleKey, Map<String, String> parentProperties, TreeModuleSettings treeModuleSettings,
boolean hasScanPerm, DbSession session) {
boolean hasScanPerm, DbSession session) {
Map<String, String> currentParentProperties = newHashMap();
currentParentProperties.putAll(parentProperties);
currentParentProperties.putAll(getPropertiesMap(treeModuleSettings.findModuleSettings(moduleKey), hasScanPerm));
@@ -182,7 +181,7 @@ public class ProjectRepositoryLoader {
}
}

private void addSettings(ProjectRepositories ref, String module, Map<String, String> properties) {
private static void addSettings(ProjectRepositories ref, String module, Map<String, String> properties) {
if (!properties.isEmpty()) {
ref.addSettings(module, properties);
}
@@ -241,10 +240,10 @@ public class ProjectRepositoryLoader {
// Load all rules of the profile language (only needed fields are loaded)
Map<RuleKey, Rule> languageRules = ruleByRuleKey(ruleService.search(new RuleQuery().setLanguages(newArrayList(qProfile.language())),
new QueryContext(userSession).setLimit(100).setFieldsToReturn(newArrayList(
RuleNormalizer.RuleField.KEY.field(), RuleNormalizer.RuleField.NAME.field(), RuleNormalizer.RuleField.INTERNAL_KEY.field(), RuleNormalizer.RuleField.TEMPLATE_KEY.field()
)).setScroll(true))
RuleNormalizer.RuleField.KEY.field(), RuleNormalizer.RuleField.NAME.field(), RuleNormalizer.RuleField.INTERNAL_KEY.field(),
RuleNormalizer.RuleField.TEMPLATE_KEY.field())).setScroll(true))
.scroll());
for (Iterator<ActiveRule> activeRuleIterator = qProfileLoader.findActiveRulesByProfile(qProfile.key()); activeRuleIterator.hasNext(); ) {
for (Iterator<ActiveRule> activeRuleIterator = qProfileLoader.findActiveRulesByProfile(qProfile.key()); activeRuleIterator.hasNext();) {
ActiveRule activeRule = activeRuleIterator.next();
Rule rule = languageRules.get(activeRule.key().ruleKey());
if (rule == null) {
@@ -339,7 +338,7 @@ public class ProjectRepositoryLoader {
private Multimap<String, ComponentDto> moduleChildrenByModuleUuid;

private TreeModuleSettings(Map<String, String> moduleUuidsByKey, Map<String, Long> moduleIdsByKey, List<ComponentDto> moduleChildren,
List<PropertyDto> moduleChildrenSettings, ComponentDto module) {
List<PropertyDto> moduleChildrenSettings, ComponentDto module) {
this.moduleIdsByKey = moduleIdsByKey;
this.moduleUuidsByKey = moduleUuidsByKey;
propertiesByModuleId = ArrayListMultimap.create();

+ 12
- 18
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java View File

@@ -67,8 +67,8 @@ import org.sonar.api.resources.Scopes;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.core.util.NonNullInputFunction;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.es.BaseIndex;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.EsUtils;
@@ -92,7 +92,6 @@ import static com.google.common.collect.Lists.newArrayList;
*/
public class IssueIndex extends BaseIndex {


private static final String SUBSTRING_MATCH_REGEXP = ".*%s.*";

public static final List<String> SUPPORTED_FACETS = ImmutableList.of(
@@ -326,7 +325,7 @@ public class IssueIndex extends BaseIndex {
return String.format("%s%s%s", IssueIndexDefinition.TYPE_ISSUE, viewUuid, ViewIndexDefinition.TYPE_VIEW);
}

private FilterBuilder createAuthorizationFilter(boolean checkAuthorization, @Nullable String userLogin, Set<String> userGroups) {
private static FilterBuilder createAuthorizationFilter(boolean checkAuthorization, @Nullable String userLogin, Set<String> userGroups) {
if (checkAuthorization) {
OrFilterBuilder groupsAndUser = FilterBuilders.orFilter();
if (userLogin != null) {
@@ -340,8 +339,7 @@ public class IssueIndex extends BaseIndex {
QueryBuilders.matchAllQuery(),
FilterBuilders.boolFilter()
.must(groupsAndUser)
.cache(true))
);
.cache(true)));
} else {
return FilterBuilders.matchAllFilter();
}
@@ -533,8 +531,7 @@ public class IssueIndex extends BaseIndex {
facetTopAggregation.subAggregation(
addDebtAggregationIfNeeded(query, AggregationBuilders
.missing(facetName + FACET_SUFFIX_MISSING)
.field(fieldName))
);
.field(fieldName)));

return AggregationBuilders
.global(facetName)
@@ -543,11 +540,11 @@ public class IssueIndex extends BaseIndex {

private Collection<String> escapeValuesForFacetInclusion(@Nullable Collection<String> values) {
return values == null ? Arrays.<String>asList() : Collections2.transform(values, new Function<String, String>() {
@Override
public String apply(String input) {
return Pattern.quote(input);
}
});
@Override
public String apply(String input) {
return Pattern.quote(input);
}
});
}

private void addAssignedToMeFacetIfNeeded(SearchRequestBuilder builder, SearchOptions options, IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder queryBuilder) {
@@ -591,8 +588,7 @@ public class IssueIndex extends BaseIndex {
facetTopAggregation.subAggregation(
addDebtAggregationIfNeeded(query, AggregationBuilders
.missing(facetName + FACET_SUFFIX_MISSING)
.field(fieldName))
);
.field(fieldName)));

return AggregationBuilders
.global(facetName)
@@ -616,8 +612,7 @@ public class IssueIndex extends BaseIndex {
facetTopAggregation.subAggregation(
addDebtAggregationIfNeeded(query, AggregationBuilders
.missing(facetName + FACET_SUFFIX_MISSING)
.field(fieldName))
);
.field(fieldName)));

return AggregationBuilders
.global(facetName)
@@ -711,8 +706,7 @@ public class IssueIndex extends BaseIndex {
FilterBuilder dateFilter = FilterBuilders.rangeFilter(IssueIndexDefinition.FIELD_ISSUE_FUNC_CLOSED_AT).lt(beforeDate.getTime());
QueryBuilder queryBuilder = QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(),
FilterBuilders.andFilter(projectFilter, dateFilter)
);
FilterBuilders.andFilter(projectFilter, dateFilter));

getClient().prepareDeleteByQuery(IssueIndexDefinition.INDEX).setQuery(queryBuilder).get();
}

+ 9
- 11
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java View File

@@ -21,25 +21,23 @@
package org.sonar.server.permission;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.server.ServerSide;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.permission.PermissionTemplateDao;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.permission.PermissionTemplateDao;
import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDao;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.sonar.server.user.UserSession;

/**
@@ -188,7 +186,7 @@ public class PermissionTemplateService {
}
}

private void validateKeyPattern(@Nullable String keyPattern) {
private static void validateKeyPattern(@Nullable String keyPattern) {
if (StringUtils.isEmpty(keyPattern)) {
return;
}

+ 0
- 38
sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.java View File

@@ -1,38 +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.batch;

import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;

/**
* This interface is implemented by the views plugin!!
*
* @deprecated in 4.2
*/
@Deprecated
public interface ProfileLoader {

/**
* Loads quality profile for specified project.
*/
RulesProfile load(Settings settings);

}

+ 0
- 28
sonar-batch/src/main/java/org/sonar/batch/index/Data.java View File

@@ -1,28 +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.batch.index;

import java.io.Serializable;

public interface Data extends Serializable {

String writeString();

}

+ 0
- 34
sonar-batch/src/main/java/org/sonar/batch/index/ResourceNotPersistedException.java View File

@@ -1,34 +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.batch.index;

import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;

/**
* @since 2.6
*/
public final class ResourceNotPersistedException extends SonarException {

public ResourceNotPersistedException(Resource resource) {
super(resource.toString());
}

}

+ 0
- 40
sonar-batch/src/main/java/org/sonar/batch/index/StringData.java View File

@@ -1,40 +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.batch.index;

public class StringData implements Data {
private String data = null;

public StringData() {
}

public StringData(String s) {
this.data = s;
}

public String data() {
return data;
}

@Override
public String writeString() {
return data;
}
}

+ 3
- 2
sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java View File

@@ -20,6 +20,7 @@
package org.sonar.batch.issue;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -142,7 +143,7 @@ public class DeprecatedIssueWrapper implements Issue {

@Override
public List<IssueComment> comments() {
return null;
return Collections.emptyList();
}

@Override
@@ -172,7 +173,7 @@ public class DeprecatedIssueWrapper implements Issue {

@Override
public Collection<String> tags() {
return null;
return Collections.emptyList();
}

}

+ 146
- 141
sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java View File

@@ -37,181 +37,186 @@ import org.sonar.batch.protocol.output.BatchReport;
@BatchSide
public class IssueFilters {

private final org.sonar.api.issue.IssueFilter[] exclusionFilters;
private final IssueFilter[] filters;
private final Project project;
private static final class IssueAdapterForFilter implements Issue {
private final Project project;
private final org.sonar.batch.protocol.output.BatchReport.Issue rawIssue;
private final String componentKey;

private IssueAdapterForFilter(Project project, org.sonar.batch.protocol.output.BatchReport.Issue rawIssue, String componentKey) {
this.project = project;
this.rawIssue = rawIssue;
this.componentKey = componentKey;
}

public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters, IssueFilter[] filters) {
this.project = project;
this.exclusionFilters = exclusionFilters;
this.filters = filters;
}
@Override
public String key() {
throw unsupported();
}

public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters) {
this(project, exclusionFilters, new IssueFilter[0]);
}
@Override
public String componentKey() {
return componentKey;
}

public IssueFilters(Project project, IssueFilter[] filters) {
this(project, new org.sonar.api.issue.IssueFilter[0], filters);
}
@Override
public RuleKey ruleKey() {
return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey());
}

public IssueFilters(Project project) {
this(project, new org.sonar.api.issue.IssueFilter[0], new IssueFilter[0]);
}
@Override
public String language() {
throw unsupported();
}

public boolean accept(String componentKey, BatchReport.Issue rawIssue) {
Issue issue = toIssueForIssueFilter(componentKey, rawIssue);
if (new DefaultIssueFilterChain(filters).accept(issue)) {
// Apply deprecated rules only if filter chain accepts the current issue
for (org.sonar.api.issue.IssueFilter filter : exclusionFilters) {
if (!filter.accept(issue)) {
return false;
}
}
return true;
} else {
return false;
@Override
public String severity() {
return rawIssue.getSeverity().name();
}
}

private Issue toIssueForIssueFilter(final String componentKey, final BatchReport.Issue rawIssue) {
return new Issue() {
@Override
public String message() {
return rawIssue.getMsg();
}

@Override
public String key() {
throw unsupported();
}
@Override
public Integer line() {
return rawIssue.hasLine() ? rawIssue.getLine() : null;
}

@Override
public String componentKey() {
return componentKey;
}
@Override
public Double effortToFix() {
return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null;
}

@Override
public RuleKey ruleKey() {
return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey());
}
@Override
public String status() {
return Issue.STATUS_OPEN;
}

@Override
public String language() {
throw unsupported();
}
@Override
public String resolution() {
return null;
}

@Override
public String severity() {
return rawIssue.getSeverity().name();
}
@Override
public String reporter() {
throw unsupported();
}

@Override
public String message() {
return rawIssue.getMsg();
}
@Override
public String assignee() {
return null;
}

@Override
public Integer line() {
return rawIssue.hasLine() ? rawIssue.getLine() : null;
}
@Override
public Date creationDate() {
return project.getAnalysisDate();
}

@Override
public Double effortToFix() {
return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null;
}
@Override
public Date updateDate() {
return null;
}

@Override
public String status() {
return Issue.STATUS_OPEN;
}
@Override
public Date closeDate() {
return null;
}

@Override
public String resolution() {
return null;
}
@Override
public String attribute(String key) {
return attributes().get(key);
}

@Override
public String reporter() {
throw unsupported();
}
@Override
public Map<String, String> attributes() {
return rawIssue.hasAttributes() ? KeyValueFormat.parse(rawIssue.getAttributes()) : Collections.<String, String>emptyMap();
}

@Override
public String assignee() {
return null;
}
@Override
public String authorLogin() {
throw unsupported();
}

@Override
public Date creationDate() {
return project.getAnalysisDate();
}
@Override
public String actionPlanKey() {
throw unsupported();
}

@Override
public Date updateDate() {
return null;
}
@Override
public List<IssueComment> comments() {
throw unsupported();
}

@Override
public Date closeDate() {
return null;
}
@Override
public boolean isNew() {
throw unsupported();
}

@Override
public String attribute(String key) {
return attributes().get(key);
}
@Override
public Duration debt() {
throw unsupported();
}

@Override
public Map<String, String> attributes() {
return rawIssue.hasAttributes() ? KeyValueFormat.parse(rawIssue.getAttributes()) : Collections.<String, String>emptyMap();
}
@Override
public String projectKey() {
return project.getEffectiveKey();
}

@Override
public String authorLogin() {
throw unsupported();
}
@Override
public String projectUuid() {
throw unsupported();
}

@Override
public String actionPlanKey() {
throw unsupported();
}
@Override
public String componentUuid() {
throw unsupported();
}

@Override
public List<IssueComment> comments() {
throw unsupported();
}
@Override
public Collection<String> tags() {
throw unsupported();
}

@Override
public boolean isNew() {
throw unsupported();
}
private static UnsupportedOperationException unsupported() {
return new UnsupportedOperationException("Not available for issues filters");
}
}

@Override
public Duration debt() {
throw unsupported();
}
private final org.sonar.api.issue.IssueFilter[] exclusionFilters;
private final IssueFilter[] filters;
private final Project project;

@Override
public String projectKey() {
return project.getEffectiveKey();
}
public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters, IssueFilter[] filters) {
this.project = project;
this.exclusionFilters = exclusionFilters;
this.filters = filters;
}

@Override
public String projectUuid() {
throw unsupported();
}
public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters) {
this(project, exclusionFilters, new IssueFilter[0]);
}

@Override
public String componentUuid() {
throw unsupported();
}
public IssueFilters(Project project, IssueFilter[] filters) {
this(project, new org.sonar.api.issue.IssueFilter[0], filters);
}

@Override
public Collection<String> tags() {
throw unsupported();
}
public IssueFilters(Project project) {
this(project, new org.sonar.api.issue.IssueFilter[0], new IssueFilter[0]);
}

private UnsupportedOperationException unsupported() {
return new UnsupportedOperationException("Not available for issues filters");
public boolean accept(String componentKey, BatchReport.Issue rawIssue) {
Issue issue = new IssueAdapterForFilter(project, rawIssue, componentKey);
if (new DefaultIssueFilterChain(filters).accept(issue)) {
// Apply deprecated rules only if filter chain accepts the current issue
for (org.sonar.api.issue.IssueFilter filter : exclusionFilters) {
if (!filter.accept(issue)) {
return false;
}
}

};

return true;
} else {
return false;
}
}
}

+ 6
- 8
sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java View File

@@ -20,8 +20,8 @@
package org.sonar.batch.issue;

import com.google.common.base.Strings;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.Rule;
@@ -63,8 +63,8 @@ public class ModuleIssues {
}

public boolean initAndAddIssue(Issue issue) {
String key = ((DefaultInputComponent) issue.primaryLocation().inputComponent()).key();
BatchComponent component = componentCache.get(key);
InputComponent inputComponent = issue.primaryLocation().inputComponent();
BatchComponent component = componentCache.get(inputComponent);

Rule rule = validateRule(issue);
ActiveRule activeRule = activeRules.find(issue.ruleKey());
@@ -102,7 +102,7 @@ public class ModuleIssues {
applyExecutionFlows(issue);
BatchReport.Issue rawIssue = builder.build();

if (filters.accept(key, rawIssue)) {
if (filters.accept(inputComponent.key(), rawIssue)) {
write(component, rawIssue);
return true;
}
@@ -112,8 +112,7 @@ public class ModuleIssues {
private void applyAdditionalLocations(Issue issue) {
for (org.sonar.api.batch.sensor.issue.IssueLocation additionalLocation : issue.locations()) {
locationBuilder.clear();
String locationComponentKey = ((DefaultInputComponent) additionalLocation.inputComponent()).key();
locationBuilder.setComponentRef(componentCache.get(locationComponentKey).batchId());
locationBuilder.setComponentRef(componentCache.get(additionalLocation.inputComponent()).batchId());
String message = additionalLocation.message();
if (message != null) {
locationBuilder.setMsg(message);
@@ -128,8 +127,7 @@ public class ModuleIssues {
flowBuilder.clear();
for (org.sonar.api.batch.sensor.issue.IssueLocation location : executionFlow.locations()) {
locationBuilder.clear();
String locationComponentKey = ((DefaultInputComponent) location.inputComponent()).key();
locationBuilder.setComponentRef(componentCache.get(locationComponentKey).batchId());
locationBuilder.setComponentRef(componentCache.get(location.inputComponent()).batchId());
String message = location.message();
if (message != null) {
locationBuilder.setMsg(message);

+ 6
- 6
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java View File

@@ -226,7 +226,7 @@ public class IssueTracking {
return rawIssuesByLines;
}

private Multimap<Integer, ServerIssue> lastIssuesByLines(Collection<ServerIssue> previousIssues, IssueTrackingBlocksRecognizer rec) {
private static Multimap<Integer, ServerIssue> lastIssuesByLines(Collection<ServerIssue> previousIssues, IssueTrackingBlocksRecognizer rec) {
Multimap<Integer, ServerIssue> previousIssuesByLines = LinkedHashMultimap.create();
for (ServerIssue previousIssue : previousIssues) {
if (rec.isValidLineInReference(previousIssue.line())) {
@@ -272,15 +272,15 @@ public class IssueTracking {
}

@CheckForNull
private Integer line(BatchReport.Issue rawIssue) {
private static Integer line(BatchReport.Issue rawIssue) {
return rawIssue.hasLine() ? rawIssue.getLine() : null;
}

private boolean isNotAlreadyMapped(ServerIssue previousIssue, IssueTrackingResult result) {
private static boolean isNotAlreadyMapped(ServerIssue previousIssue, IssueTrackingResult result) {
return result.unmatched().contains(previousIssue);
}

private boolean isNotAlreadyMapped(BatchReport.Issue rawIssue, IssueTrackingResult result) {
private static boolean isNotAlreadyMapped(BatchReport.Issue rawIssue, IssueTrackingResult result) {
return !result.isMatched(rawIssue);
}

@@ -297,11 +297,11 @@ public class IssueTracking {
}

@CheckForNull
private String message(BatchReport.Issue rawIssue) {
private static String message(BatchReport.Issue rawIssue) {
return rawIssue.hasMsg() ? rawIssue.getMsg() : null;
}

private void mapIssue(BatchReport.Issue rawIssue, @Nullable ServerIssue ref, IssueTrackingResult result) {
private static void mapIssue(BatchReport.Issue rawIssue, @Nullable ServerIssue ref, IssueTrackingResult result) {
if (ref != null) {
result.setMatch(rawIssue, ref);
}

+ 1
- 1
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java View File

@@ -92,7 +92,7 @@ class IssueTrackingResult {
unmatchedForRuleAndLine.put(checksumNotNull, i);
}

private Integer lineNotNull(ServerIssue i) {
private static Integer lineNotNull(ServerIssue i) {
Integer line = i.line();
return line != null ? line : 0;
}

+ 0
- 4
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java View File

@@ -29,8 +29,6 @@ import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.ActiveRule;
@@ -57,8 +55,6 @@ import org.sonar.core.util.CloseableIterator;
@BatchSide
public class LocalIssueTracking {

private static final Logger LOG = LoggerFactory.getLogger(LocalIssueTracking.class);

private final IssueCache issueCache;
private final IssueTracking tracking;
private final ServerLineHashesLoader lastLineHashes;

+ 0
- 2
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java View File

@@ -20,9 +20,7 @@
package org.sonar.batch.issue.tracking;

import com.google.common.base.Function;

import javax.annotation.Nullable;

import org.sonar.api.batch.BatchSide;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.utils.log.Logger;

+ 5
- 5
sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java View File

@@ -112,7 +112,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
}
}

private String getVersion(ProjectDefinition def) {
private static String getVersion(ProjectDefinition def) {
String version = def.getVersion();
return StringUtils.isNotBlank(version) ? version : getVersion(def.getParent());
}
@@ -130,7 +130,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
}
}

private void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp,
private static void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp,
ComponentLinkType linkType) {
String link = def.properties().get(linkProp);
if (StringUtils.isNotBlank(link)) {
@@ -142,19 +142,19 @@ public class ComponentsPublisher implements ReportPublisherStep {
}

@CheckForNull
private String getLanguageKey(Resource r) {
private static String getLanguageKey(Resource r) {
Language language = r.getLanguage();
return ResourceUtils.isFile(r) && language != null ? language.getKey() : null;
}

@CheckForNull
private String getName(Resource r) {
private static String getName(Resource r) {
// Don't return name for directories and files since it can be guessed from the path
return (ResourceUtils.isFile(r) || ResourceUtils.isDirectory(r)) ? null : r.getName();
}

@CheckForNull
private String getDescription(Resource r) {
private static String getDescription(Resource r) {
// Only for projets and modules
return ResourceUtils.isProject(r) ? r.getDescription() : null;
}

+ 3
- 3
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java View File

@@ -52,7 +52,7 @@ public class RulesProfileProvider extends ProviderAdapter {
return singleton;
}

private RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) {
private static RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) {
QProfile qProfile = qProfiles.findByLanguage(language);
if (qProfile != null) {
return new RulesProfileWrapper(select(qProfile, activeRules));
@@ -60,7 +60,7 @@ public class RulesProfileProvider extends ProviderAdapter {
return new RulesProfileWrapper(Lists.<RulesProfile>newArrayList());
}

private RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) {
private static RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) {
Collection<RulesProfile> dtos = Lists.newArrayList();
for (QProfile qProfile : qProfiles.findAll()) {
dtos.add(select(qProfile, activeRules));
@@ -68,7 +68,7 @@ public class RulesProfileProvider extends ProviderAdapter {
return new RulesProfileWrapper(dtos);
}

private RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
RulesProfile deprecatedProfile = new RulesProfile();
// TODO deprecatedProfile.setVersion(qProfile.version());
deprecatedProfile.setName(qProfile.getName());

+ 2
- 2
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java View File

@@ -125,7 +125,7 @@ public class ProjectReactorBuilder {
return new ProjectReactor(rootProject);
}

private Map<String, Map<String, String>> extractPropertiesByModule(String currentModuleId, Map<String, String> parentProperties) {
private static Map<String, Map<String, String>> extractPropertiesByModule(String currentModuleId, Map<String, String> parentProperties) {
Map<String, String> allProperties = new HashMap<>();
allProperties.putAll(parentProperties);
Map<String, String> currentModuleProperties = new HashMap<>();
@@ -202,7 +202,7 @@ public class ProjectReactorBuilder {
}

@CheckForNull
private File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) {
private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) {
String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR);
if (StringUtils.isBlank(buildDir)) {
return null;

+ 2
- 2
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java View File

@@ -62,7 +62,7 @@ public class ProjectReactorValidator {
}
}

private void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) {
private static void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) {
if (!ComponentKeys.isValidModuleKey(moduleDef.getKey())) {
validationMessages.add(String.format("\"%s\" is not a valid project or module key. "
+ "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey()));
@@ -75,7 +75,7 @@ public class ProjectReactorValidator {
}
}

private void validateBranch(List<String> validationMessages, @Nullable String branch) {
private static void validateBranch(List<String> validationMessages, @Nullable String branch) {
if (StringUtils.isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) {
validationMessages.add(String.format("\"%s\" is not a valid branch name. "
+ "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch));

+ 10
- 12
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java View File

@@ -24,6 +24,14 @@ import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.FilePredicate;
@@ -34,16 +42,6 @@ import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.utils.MessageException;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
* @since 3.5
*/
@@ -121,7 +119,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
return testDirsOrFiles;
}

private List<File> keepOnlyDirs(List<File> dirsOrFiles) {
private static List<File> keepOnlyDirs(List<File> dirsOrFiles) {
List<File> result = new ArrayList<>();
for (File f : dirsOrFiles) {
if (f.isDirectory()) {
@@ -173,7 +171,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
throw modificationNotPermitted();
}

private UnsupportedOperationException modificationNotPermitted() {
private static UnsupportedOperationException modificationNotPermitted() {
return new UnsupportedOperationException("Modifications of the file system are not permitted");
}


+ 6
- 7
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java View File

@@ -20,17 +20,16 @@
package org.sonar.batch.scan.filesystem;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.scan.filesystem.PathResolver;

import java.io.File;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.scan.filesystem.PathResolver;

@BatchSide
public class FileSystemLogger {
@@ -63,7 +62,7 @@ public class FileSystemLogger {
}
}

private void logPaths(Logger logger, String label, File baseDir, List<File> paths) {
private static void logPaths(Logger logger, String label, File baseDir, List<File> paths) {
if (!paths.isEmpty()) {
PathResolver resolver = new PathResolver();
StringBuilder sb = new StringBuilder(label);

+ 1
- 1
sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java View File

@@ -58,7 +58,7 @@ class MeasureValueCoder implements ValueCoder {
value.putString(persistenceMode != null ? persistenceMode.name() : null);
}

private void putUTFOrNull(Value value, @Nullable String utfOrNull) {
private static void putUTFOrNull(Value value, @Nullable String utfOrNull) {
if (utfOrNull != null) {
value.putUTF(utfOrNull);
} else {

+ 2
- 2
sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java View File

@@ -25,12 +25,12 @@ import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.config.Settings;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.issue.DefaultIssue;

@Properties({
@Property(key = ConsoleReport.CONSOLE_REPORT_ENABLED_KEY, name = "Enable console report", description = "Set this to true to generate a report in console output",
@@ -135,7 +135,7 @@ public class ConsoleReport implements Reporter {
}
}

private void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) {
private static void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) {
if (issueCount > 0) {
sb.append(StringUtils.leftPad("+" + issueCount, LEFT_PAD)).append(" ").append(severityLabel).append("\n");
}

+ 5
- 7
sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java View File

@@ -19,14 +19,13 @@
*/
package org.sonar.batch.scan.report;

import org.sonar.api.batch.rule.Rule;

import org.sonar.api.batch.rule.Rules;
import javax.annotation.CheckForNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
import org.sonar.api.issue.Issue;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.resources.Project;
import org.sonar.api.rules.RulePriority;
import org.sonar.batch.DefaultProjectTree;
@@ -34,8 +33,7 @@ import org.sonar.batch.index.BatchComponent;
import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.scan.filesystem.InputPathCache;

import javax.annotation.CheckForNull;
import org.sonar.core.issue.DefaultIssue;

@BatchSide
public class IssuesReportBuilder {
@@ -84,7 +82,7 @@ public class IssuesReportBuilder {
}
}

private boolean validate(Issue issue, Rule rule, BatchComponent resource) {
private static boolean validate(Issue issue, Rule rule, BatchComponent resource) {
if (rule == null) {
LOG.warn("Unknow rule for issue {}", issue);
return false;

+ 6
- 6
sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java View File

@@ -38,27 +38,27 @@ public class RuleReportComparator implements Comparator<RuleReport>, Serializabl
}
}

private int compareByRuleSeverityAndName(RuleReport o1, RuleReport o2) {
private static int compareByRuleSeverityAndName(RuleReport o1, RuleReport o2) {
return o1.getReportRuleKey().compareTo(o2.getReportRuleKey());
}

private boolean sameNewIssueCount(RuleReport o1, RuleReport o2) {
private static boolean sameNewIssueCount(RuleReport o1, RuleReport o2) {
return o2.getTotal().getNewIssuesCount() == o1.getTotal().getNewIssuesCount();
}

private boolean sameSeverity(RuleReport o1, RuleReport o2) {
private static boolean sameSeverity(RuleReport o1, RuleReport o2) {
return o1.getSeverity().equals(o2.getSeverity());
}

private int compareNewIssueCount(RuleReport o1, RuleReport o2) {
private static int compareNewIssueCount(RuleReport o1, RuleReport o2) {
return o2.getTotal().getNewIssuesCount() - o1.getTotal().getNewIssuesCount();
}

private boolean bothHaveNewIssues(RuleReport o1, RuleReport o2) {
private static boolean bothHaveNewIssues(RuleReport o1, RuleReport o2) {
return o1.getTotal().getNewIssuesCount() > 0 && o2.getTotal().getNewIssuesCount() > 0;
}

private boolean bothHaveNoNewIssue(RuleReport o1, RuleReport o2) {
private static boolean bothHaveNoNewIssue(RuleReport o1, RuleReport o2) {
return o1.getTotal().getNewIssuesCount() == 0 && o2.getTotal().getNewIssuesCount() == 0;
}
}

+ 1
- 4
sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java View File

@@ -31,17 +31,14 @@ import org.sonar.api.batch.BatchSide;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.batch.index.BatchComponent;
import org.sonar.batch.scan.filesystem.InputPathCache;

@BatchSide
public class SourceProvider {

private static final Logger LOG = LoggerFactory.getLogger(SourceProvider.class);
private final InputPathCache inputPathCache;
private final FileSystem fs;

public SourceProvider(InputPathCache inputPathCache, FileSystem fs) {
this.inputPathCache = inputPathCache;
public SourceProvider(FileSystem fs) {
this.fs = fs;
}


+ 14
- 11
sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java View File

@@ -20,6 +20,16 @@
package org.sonar.batch.scm;

import com.google.common.base.Preconditions;
import java.text.Normalizer;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,13 +43,6 @@ import org.sonar.batch.protocol.output.BatchReport.Changesets.Builder;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.util.ProgressReport;

import javax.annotation.Nullable;

import java.text.Normalizer;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

class DefaultBlameOutput implements BlameOutput {

private static final Logger LOG = LoggerFactory.getLogger(DefaultBlameOutput.class);
@@ -99,7 +102,7 @@ class DefaultBlameOutput implements BlameOutput {
progressReport.message(count + "/" + total + " files analyzed, last one was " + file.absolutePath());
}

private void addChangeset(Builder scmBuilder, BlameLine line) {
private static void addChangeset(Builder scmBuilder, BlameLine line) {
BatchReport.Changesets.Changeset.Builder changesetBuilder = BatchReport.Changesets.Changeset.newBuilder();
if (StringUtils.isNotBlank(line.revision())) {
changesetBuilder.setRevision(line.revision());
@@ -114,7 +117,7 @@ class DefaultBlameOutput implements BlameOutput {
scmBuilder.addChangeset(changesetBuilder.build());
}

private String normalizeString(@Nullable String inputString) {
private static String normalizeString(@Nullable String inputString) {
if (inputString == null) {
return "";
}
@@ -123,12 +126,12 @@ class DefaultBlameOutput implements BlameOutput {
return removeNonAsciiCharacters(stringWithoutAccents);
}

private String removeAccents(String inputString) {
private static String removeAccents(String inputString) {
String unicodeDecomposedString = Normalizer.normalize(inputString, Normalizer.Form.NFD);
return ACCENT_CODES.matcher(unicodeDecomposedString).replaceAll("");
}

private String removeNonAsciiCharacters(String inputString) {
private static String removeNonAsciiCharacters(String inputString) {
return NON_ASCII_CHARS.matcher(inputString).replaceAll("_");
}


+ 3
- 4
sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java View File

@@ -19,6 +19,8 @@
*/
package org.sonar.batch.scm;

import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
@@ -35,9 +37,6 @@ import org.sonar.batch.protocol.input.ProjectRepositories;
import org.sonar.batch.report.ReportPublisher;
import org.sonar.batch.scan.filesystem.InputPathCache;

import java.util.LinkedList;
import java.util.List;

public final class ScmSensor implements Sensor {

private static final Logger LOG = LoggerFactory.getLogger(ScmSensor.class);
@@ -105,7 +104,7 @@ public final class ScmSensor implements Sensor {
return filesToBlame;
}

private void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) {
private static void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) {
if (!f.isEmpty()) {
filesToBlame.add(f);
}

+ 1
- 1
sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java View File

@@ -124,7 +124,7 @@ public class CoverageExclusions {
log("Excluded sources for coverage: ", resourcePatterns);
}

private void log(String title, Collection<WildcardPattern> patterns) {
private static void log(String title, Collection<WildcardPattern> patterns) {
if (!patterns.isEmpty()) {
LOG.info(title);
for (WildcardPattern pattern : patterns) {

+ 1
- 1
sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java View File

@@ -79,7 +79,7 @@ public class DefaultTestable implements MutableTestable {
throw unsupported();
}

private UnsupportedOperationException unsupported() {
private static UnsupportedOperationException unsupported() {
return new UnsupportedOperationException("No more available since SQ 5.2");
}


+ 3
- 3
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java View File

@@ -342,7 +342,7 @@ public class DefaultIssue implements Issue, Trackable {

public DefaultIssue setCreationDate(Date d) {
// d is not marked as Nullable but we still allow null parameter for unit testing.
this.creationDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
this.creationDate = d != null ? DateUtils.truncate(d, Calendar.SECOND) : null;
return this;
}

@@ -353,7 +353,7 @@ public class DefaultIssue implements Issue, Trackable {
}

public DefaultIssue setUpdateDate(@Nullable Date d) {
this.updateDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
this.updateDate = d != null ? DateUtils.truncate(d, Calendar.SECOND) : null;
return this;
}

@@ -364,7 +364,7 @@ public class DefaultIssue implements Issue, Trackable {
}

public DefaultIssue setCloseDate(@Nullable Date d) {
this.closeDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null);
this.closeDate = d != null ? DateUtils.truncate(d, Calendar.SECOND) : null;
return this;
}


+ 2
- 2
sonar-db/src/main/java/org/sonar/db/version/SelectImpl.java View File

@@ -28,7 +28,7 @@ import java.util.List;
import org.apache.commons.dbutils.DbUtils;
import org.sonar.db.Database;

class SelectImpl extends BaseSqlStatement<Select> implements Select {
class SelectImpl extends BaseSqlStatement<Select>implements Select {

private SelectImpl(PreparedStatement pstmt) {
super(pstmt);
@@ -85,7 +85,7 @@ class SelectImpl extends BaseSqlStatement<Select> implements Select {
}
}

private IllegalStateException newExceptionWithRowDetails(Select.Row row, Exception e) {
private static IllegalStateException newExceptionWithRowDetails(Select.Row row, Exception e) {
return new IllegalStateException("Error during processing of row: [" + row + "]", e);
}


+ 13
- 11
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java View File

@@ -40,6 +40,18 @@ import org.sonar.api.rule.RuleKey;

public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {

private static final class ToExecutionFlow implements Function<List<IssueLocation>, ExecutionFlow> {
@Override
public ExecutionFlow apply(final List<IssueLocation> input) {
return new ExecutionFlow() {
@Override
public List<IssueLocation> locations() {
return ImmutableList.copyOf(input);
}
};
}
}

private RuleKey ruleKey;
private Double effortToFix;
private Severity overriddenSeverity;
@@ -141,17 +153,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {

@Override
public List<ExecutionFlow> executionFlows() {
return Lists.transform(this.executionFlows, new Function<List<IssueLocation>, ExecutionFlow>() {
@Override
public ExecutionFlow apply(final List<IssueLocation> input) {
return new ExecutionFlow() {
@Override
public List<IssueLocation> locations() {
return ImmutableList.copyOf(input);
}
};
}
});
return Lists.transform(this.executionFlows, new ToExecutionFlow());
}

@Override

Loading…
Cancel
Save