mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-07-28 08:17:45 +02:00
Fix quality flaws
This commit is contained in:
parent
70eac6ea0e
commit
42f1728669
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@ -20,6 +21,18 @@
|
||||
<artifactId>sonar-plugin-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -19,8 +19,6 @@
|
||||
*/
|
||||
package org.sonar.plugins.l10n;
|
||||
|
||||
import org.sonar.api.Extension;
|
||||
|
||||
import org.sonar.api.SonarPlugin;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -28,7 +26,7 @@ import java.util.List;
|
||||
|
||||
public final class EnglishPackPlugin extends SonarPlugin {
|
||||
|
||||
public List<Class<? extends Extension>> getExtensions() {
|
||||
public List<?> getExtensions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Sonar, open source software quality management tool.
|
||||
* Copyright (C) 2008-2012 SonarSource
|
||||
* mailto:contact AT sonarsource DOT com
|
||||
*
|
||||
* Sonar 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.
|
||||
*
|
||||
* Sonar 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 Sonar; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
|
||||
*/
|
||||
package org.sonar.plugins.l10n;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
public class EnglishPackPluginTest {
|
||||
@Test
|
||||
public void no_extensions() {
|
||||
assertThat(new EnglishPackPlugin().getExtensions()).isEmpty();
|
||||
}
|
||||
}
|
@ -30,9 +30,17 @@ import org.sonar.api.batch.Event;
|
||||
import org.sonar.api.batch.SonarIndex;
|
||||
import org.sonar.api.database.model.ResourceModel;
|
||||
import org.sonar.api.design.Dependency;
|
||||
import org.sonar.api.measures.*;
|
||||
import org.sonar.api.measures.Measure;
|
||||
import org.sonar.api.measures.MeasuresFilter;
|
||||
import org.sonar.api.measures.MeasuresFilters;
|
||||
import org.sonar.api.measures.Metric;
|
||||
import org.sonar.api.measures.MetricFinder;
|
||||
import org.sonar.api.profiles.RulesProfile;
|
||||
import org.sonar.api.resources.*;
|
||||
import org.sonar.api.resources.Project;
|
||||
import org.sonar.api.resources.ProjectLink;
|
||||
import org.sonar.api.resources.Resource;
|
||||
import org.sonar.api.resources.ResourceUtils;
|
||||
import org.sonar.api.resources.Scopes;
|
||||
import org.sonar.api.rules.ActiveRule;
|
||||
import org.sonar.api.rules.Violation;
|
||||
import org.sonar.api.utils.SonarException;
|
||||
@ -42,7 +50,14 @@ import org.sonar.batch.ProjectTree;
|
||||
import org.sonar.batch.ResourceFilters;
|
||||
import org.sonar.batch.ViolationFilters;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultIndex extends SonarIndex {
|
||||
|
||||
@ -448,10 +463,10 @@ public class DefaultIndex extends SonarIndex {
|
||||
if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
|
||||
// not a project nor a library
|
||||
uid = new StringBuilder(ResourceModel.KEY_SIZE)
|
||||
.append(project.getKey())
|
||||
.append(':')
|
||||
.append(resource.getKey())
|
||||
.toString();
|
||||
.append(project.getKey())
|
||||
.append(':')
|
||||
.append(resource.getKey())
|
||||
.toString();
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
@ -540,10 +555,8 @@ public class DefaultIndex extends SonarIndex {
|
||||
}
|
||||
|
||||
private void checkLock(Resource resource) {
|
||||
if (lock.isLocked() && !ResourceUtils.isLibrary(resource)) {
|
||||
if (lock.isFailWhenLocked()) {
|
||||
throw new SonarException("Index is locked, resource can not be indexed: " + resource);
|
||||
}
|
||||
if (lock.isLocked() && !ResourceUtils.isLibrary(resource) && lock.isFailWhenLocked()) {
|
||||
throw new SonarException("Index is locked, resource can not be indexed: " + resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,11 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.sonar.api.utils.KeyValueFormat;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
|
||||
/**
|
||||
* @since 2.7
|
||||
@ -34,9 +38,9 @@ public final class CoverageMeasuresBuilder {
|
||||
* Metrics of generated measures
|
||||
*/
|
||||
public static final List<Metric> METRICS = Arrays.asList(
|
||||
CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA,
|
||||
CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE,
|
||||
CoreMetrics.COVERED_CONDITIONS_BY_LINE);
|
||||
CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA,
|
||||
CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE,
|
||||
CoreMetrics.COVERED_CONDITIONS_BY_LINE);
|
||||
|
||||
|
||||
private int totalCoveredLines = 0, totalConditions = 0, totalCoveredConditions = 0;
|
||||
@ -69,13 +73,11 @@ public final class CoverageMeasuresBuilder {
|
||||
}
|
||||
|
||||
public CoverageMeasuresBuilder setConditions(int lineId, int conditions, int coveredConditions) {
|
||||
if (!conditionsByLine.containsKey(lineId)) {
|
||||
if (conditions > 0) {
|
||||
totalConditions += conditions;
|
||||
totalCoveredConditions += coveredConditions;
|
||||
conditionsByLine.put(lineId, conditions);
|
||||
coveredConditionsByLine.put(lineId, coveredConditions);
|
||||
}
|
||||
if (conditions > 0 && !conditionsByLine.containsKey(lineId)) {
|
||||
totalConditions += conditions;
|
||||
totalCoveredConditions += coveredConditions;
|
||||
conditionsByLine.put(lineId, conditions);
|
||||
coveredConditionsByLine.put(lineId, coveredConditions);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -126,14 +128,14 @@ public final class CoverageMeasuresBuilder {
|
||||
|
||||
private Measure createCoveredConditionsByLine() {
|
||||
return new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE)
|
||||
.setData(KeyValueFormat.format(coveredConditionsByLine))
|
||||
.setPersistenceMode(PersistenceMode.DATABASE);
|
||||
.setData(KeyValueFormat.format(coveredConditionsByLine))
|
||||
.setPersistenceMode(PersistenceMode.DATABASE);
|
||||
}
|
||||
|
||||
private Measure createConditionsByLine() {
|
||||
return new Measure(CoreMetrics.CONDITIONS_BY_LINE)
|
||||
.setData(KeyValueFormat.format(conditionsByLine))
|
||||
.setPersistenceMode(PersistenceMode.DATABASE);
|
||||
.setData(KeyValueFormat.format(conditionsByLine))
|
||||
.setPersistenceMode(PersistenceMode.DATABASE);
|
||||
}
|
||||
|
||||
public static CoverageMeasuresBuilder create() {
|
||||
|
Loading…
Reference in New Issue
Block a user