Browse Source

Fix some quality flaws

tags/4.4-RC1
Julien HENRY 10 years ago
parent
commit
d0569c1ebf

+ 13
- 13
sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java View File

@@ -48,7 +48,7 @@ import java.util.Set;
public class DefaultDecoratorContext implements DecoratorContext {

private static final String SAVE_MEASURE_METHOD = "saveMeasure";
private SonarIndex index;
private SonarIndex sonarIndex;
private Resource resource;
private MeasurementFilters measurementFilters;
private boolean readOnly = false;
@@ -63,7 +63,7 @@ public class DefaultDecoratorContext implements DecoratorContext {
SonarIndex index,
List<DecoratorContext> childrenContexts,
MeasurementFilters measurementFilters, MeasureCache measureCache, MetricFinder metricFinder) {
this.index = index;
this.sonarIndex = index;
this.resource = resource;
this.childrenContexts = childrenContexts;
this.measurementFilters = measurementFilters;
@@ -88,7 +88,7 @@ public class DefaultDecoratorContext implements DecoratorContext {
}

public Project getProject() {
return index.getProject();
return sonarIndex.getProject();
}

public List<DecoratorContext> getChildren() {
@@ -181,50 +181,50 @@ public class DefaultDecoratorContext implements DecoratorContext {
* {@inheritDoc}
*/
public List<Violation> getViolations(ViolationQuery violationQuery) {
return index.getViolations(violationQuery);
return sonarIndex.getViolations(violationQuery);
}

/**
* {@inheritDoc}
*/
public List<Violation> getViolations() {
return index.getViolations(resource);
return sonarIndex.getViolations(resource);
}

public Dependency saveDependency(Dependency dependency) {
checkReadOnly("addDependency");
return index.addDependency(dependency);
return sonarIndex.addDependency(dependency);
}

public Set<Dependency> getDependencies() {
return index.getDependencies();
return sonarIndex.getDependencies();
}

public Collection<Dependency> getIncomingDependencies() {
return index.getIncomingEdges(resource);
return sonarIndex.getIncomingEdges(resource);
}

public Collection<Dependency> getOutgoingDependencies() {
return index.getOutgoingEdges(resource);
return sonarIndex.getOutgoingEdges(resource);
}

public List<Event> getEvents() {
return index.getEvents(resource);
return sonarIndex.getEvents(resource);
}

public Event createEvent(String name, String description, String category, Date date) {
return index.addEvent(resource, name, description, category, date);
return sonarIndex.addEvent(resource, name, description, category, date);
}

public void deleteEvent(Event event) {
index.deleteEvent(event);
sonarIndex.deleteEvent(event);
}

public DefaultDecoratorContext saveViolation(Violation violation, boolean force) {
if (violation.getResource() == null) {
violation.setResource(resource);
}
index.addViolation(violation, force);
sonarIndex.addViolation(violation, force);
return this;
}


+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/events/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch.events;

import javax.annotation.ParametersAreNonnullByDefault;

+ 1
- 2
sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java View File

@@ -183,11 +183,10 @@ public class ResourceKeyMigration implements BatchComponent {
}

private List<ResourceModel> loadEnabledResources(int moduleId, StringBuilder hql) {
List<ResourceModel> resources = session.createQuery(hql.toString())
return session.createQuery(hql.toString())
.setParameter("rootId", moduleId)
.setParameter("enabled", true)
.getResultList();
return resources;
}

private Map<String, ResourceModel> loadDisabledResources(int moduleId, StringBuilder hql) {

+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/index/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch.index;

import javax.annotation.ParametersAreNonnullByDefault;

+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/language/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch.language;

import javax.annotation.ParametersAreNonnullByDefault;

+ 1
- 0
sonar-batch/src/main/java/org/sonar/batch/languages/package-info.java View File

@@ -17,4 +17,5 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.batch.languages;

+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch;

import javax.annotation.ParametersAreNonnullByDefault;

+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch.phases;

import javax.annotation.ParametersAreNonnullByDefault;

+ 1
- 1
sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java View File

@@ -40,7 +40,7 @@ public class QProfileDecorator implements Decorator {
}

public boolean shouldExecuteOnProject(Project project) {
return project.getModules().size() > 0;
return !project.getModules().isEmpty();
}

@Override

+ 23
- 0
sonar-batch/src/main/java/org/sonar/batch/scan/maven/package-info.java View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
@ParametersAreNonnullByDefault
package org.sonar.batch.scan.maven;

import javax.annotation.ParametersAreNonnullByDefault;

+ 16
- 10
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigration.java View File

@@ -85,14 +85,8 @@ public class MeasureDataMigration implements DatabaseMigration {

@Override
public boolean update(Connection connection) throws SQLException {
if (ids.size() > 0) {
String deleteSql = new StringBuilder().append("DELETE FROM measure_data WHERE id IN (")
.append(StringUtils.repeat("?", ",", ids.size())).append(")").toString();
PreparedStatement s = connection.prepareStatement(deleteSql);
int i = 1;
for (Long id : ids) {
s.setLong(i++, id);
}
if (!ids.isEmpty()) {
PreparedStatement s = prepareDeleteQuery(ids, connection);
s.executeUpdate();
s.close();
ids.clear();
@@ -100,9 +94,21 @@ public class MeasureDataMigration implements DatabaseMigration {
}
return false;
}
});
}

}
);
private PreparedStatement prepareDeleteQuery(final List<Long> ids, Connection connection) throws SQLException {
String deleteSql = new StringBuilder()
.append("DELETE FROM measure_data WHERE id IN (")
.append(StringUtils.repeat("?", ",", ids.size()))
.append(")").toString();
PreparedStatement s = connection.prepareStatement(deleteSql);
int i = 1;
for (Long id : ids) {
s.setLong(i, id);
i++;
}
return s;
}

private static class Row {

Loading…
Cancel
Save