import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
+import java.util.NoSuchElementException;
public class PreviousIssueHelper {
}
public <G> void streamIssues(Writer out, Iterable<G> issues, Function<G, PreviousIssue> converter) {
- Gson gson = GsonHelper.create();
try {
JsonWriter writer = new JsonWriter(out);
writer.setIndent(" ");
@Override
public PreviousIssue next() {
+ try {
+ if (!jsonreader.hasNext()) {
+ throw new NoSuchElementException();
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to iterate over JSON file ", e);
+ }
return gson.fromJson(jsonreader, PreviousIssue.class);
}
--- /dev/null
+/*
+ * 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.protocol.input.issues;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
*/
package org.sonar.batch.protocol.output;
-import org.sonar.batch.protocol.output.component.ReportComponents;
-
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
+import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.sonar.batch.protocol.GsonHelper;
+import org.sonar.batch.protocol.output.component.ReportComponents;
import org.sonar.batch.protocol.output.issue.ReportIssue;
import java.io.BufferedInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Iterator;
+import java.util.NoSuchElementException;
public class ReportHelper {
}
public void saveIssues(long componentBatchId, Iterable<ReportIssue> issues) {
- Gson gson = GsonHelper.create();
File issuesFile = getIssuesFile(componentBatchId);
try (OutputStreamWriter out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(issuesFile)), "UTF-8")) {
public ReportIssueIterator(File issuesFile) {
try {
- reader = new JsonReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(issuesFile))));
+ reader = new JsonReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(issuesFile)), Charsets.UTF_8));
reader.beginArray();
} catch (IOException e) {
throw new IllegalStateException("Unable to read " + issuesFile, e);
@Override
public ReportIssue next() {
+ try {
+ if (!reader.hasNext()) {
+ throw new NoSuchElementException();
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to iterate over JSON file ", e);
+ }
return gson.fromJson(reader, ReportIssue.class);
}
--- /dev/null
+/*
+ * 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.protocol.output;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import javax.annotation.CheckForNull;
private static final Logger LOG = LoggerFactory.getLogger(TimeMachineConfiguration.class);
private final DatabaseSession session;
- private Project project;
private final PeriodsDefinition periodsDefinition;
private List<Period> periods;
private List<PastSnapshot> modulePastSnapshots;
- public TimeMachineConfiguration(DatabaseSession session, Project project, PeriodsDefinition periodsDefinition) {
+ public TimeMachineConfiguration(DatabaseSession session, PeriodsDefinition periodsDefinition) {
this.session = session;
- this.project = project;
this.periodsDefinition = periodsDefinition;
initModulePastSnapshots();
}
return;
}
BatchResource parentBatchResource = batchResource.parent();
+ Snapshot s;
if (parentBatchResource != null) {
persist(parentBatchResource);
+ s = persist(findModule(parentBatchResource), batchResource.resource(), parentBatchResource.resource());
+ } else {
+ // Root project
+ s = persistProject((Project) batchResource.resource(), null);
}
- Snapshot s = persist(findParentModule(batchResource), batchResource.resource(), parentBatchResource != null ? parentBatchResource.resource() : null);
batchResource.setSnapshot(s);
if (ResourceUtils.isPersistable(batchResource.resource())) {
graph.addComponent(batchResource.resource(), batchResource.snapshotId());
}
@CheckForNull
- private Project findParentModule(BatchResource batchResource) {
- if (batchResource != null && batchResource.parent() != null) {
- if (batchResource.parent().resource() instanceof Project) {
- return (Project) batchResource.parent().resource();
- } else {
- return findParentModule(batchResource.parent());
- }
+ private Project findModule(BatchResource batchResource) {
+ if (batchResource.resource() instanceof Project) {
+ return (Project) batchResource.resource();
+ } else {
+ return findModule(batchResource.parent());
}
- return null;
}
private Snapshot persistProject(Project project, @Nullable Project parent) {
if (resource instanceof Project) {
// should not occur, please use the method saveProject()
snapshot = persistProject((Project) resource, (Project) parent);
-
- } else if (resource instanceof Library) {
- snapshot = persistLibrary(project.getAnalysisDate(), (Library) resource);
-
} else {
snapshot = persistFileOrDirectory(project, resource, parent);
}
return snapshot;
}
- private Snapshot persistLibrary(Date analysisDate, Library library) {
+ Snapshot persistLibrary(Date analysisDate, Library library) {
ResourceModel model = findOrCreateModel(library, null);
model = session.save(model);
// TODO to be removed
public final class DefaultPhaseExecutor implements PhaseExecutor {
- public static final Logger LOGGER = LoggerFactory.getLogger(DefaultPhaseExecutor.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPhaseExecutor.class);
private final EventBus eventBus;
private final Phases phases;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
-import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.events.BatchStepEvent;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
public final class PreviewPhaseExecutor implements PhaseExecutor {
- public static final Logger LOGGER = LoggerFactory.getLogger(PreviewPhaseExecutor.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(PreviewPhaseExecutor.class);
private final EventBus eventBus;
private final Phases phases;
private final DefaultModuleFileSystem fs;
private final QProfileVerifier profileVerifier;
private final IssueExclusionsLoader issueExclusionsLoader;
- private final AnalysisMode analysisMode;
private final JsonReport jsonReport;
public PreviewPhaseExecutor(Phases phases,
SensorsExecutor sensorsExecutor,
SensorContext sensorContext, DefaultIndex index,
EventBus eventBus, ProjectInitializer pi, FileSystemLogger fsLogger, JsonReport jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
- IssueExclusionsLoader issueExclusionsLoader, AnalysisMode analysisMode) {
+ IssueExclusionsLoader issueExclusionsLoader) {
this.phases = phases;
this.mavenPluginsConfigurator = mavenPluginsConfigurator;
this.initializersExecutor = initializersExecutor;
this.fs = fs;
this.profileVerifier = profileVerifier;
this.issueExclusionsLoader = issueExclusionsLoader;
- this.analysisMode = analysisMode;
}
/**
}
private void preventAutomaticProjectCreationIfNeeded(ProjectReactor reactor) {
- if (resourceDao != null) {
- if (settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION)) {
- String projectKey = reactor.getRoot().getKeyWithBranch();
- if (resourceDao.findByKey(projectKey) == null) {
- throw new SonarException(String.format("Unable to scan non-existing project \"%s\"", projectKey));
- }
+ if (resourceDao != null && settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION)) {
+ String projectKey = reactor.getRoot().getKeyWithBranch();
+ if (resourceDao.findByKey(projectKey) == null) {
+ throw new SonarException(String.format("Unable to scan non-existing project \"%s\"", projectKey));
}
}
}
private final MetricFinder metricFinder;
private final TechnicalDebtModel techDebtModel;
- public MeasureValueCoder(MetricFinder metricFinder, TechnicalDebtModel techDebtModel) {
+ public MeasureValueCoder(MetricFinder metricFinder, @Nullable TechnicalDebtModel techDebtModel) {
this.metricFinder = metricFinder;
this.techDebtModel = techDebtModel;
}
org.sonar.api.measures.Measure measureToSave = new org.sonar.api.measures.Measure(m);
setValueAccordingToMetricType(newMeasure, m, measureToSave);
measureToSave.setFromCore(measure.isFromCore());
- if (newMeasure.inputFile() != null) {
+ InputFile inputFile = newMeasure.inputFile();
+ if (inputFile != null) {
Formula formula = newMeasure.metric() instanceof org.sonar.api.measures.Metric ?
((org.sonar.api.measures.Metric) newMeasure.metric()).getFormula() : null;
if (formula instanceof SumChildDistributionFormula
&& !Scopes.isHigherThanOrEquals(Scopes.FILE, ((SumChildDistributionFormula) formula).getMinimumScopeToPersist())) {
measureToSave.setPersistenceMode(PersistenceMode.MEMORY);
}
- File sonarFile = getFile(newMeasure.inputFile());
+ File sonarFile = getFile(inputFile);
if (coverageExclusions.accept(sonarFile, measureToSave)) {
sonarIndex.addMeasure(sonarFile, measureToSave);
}
public class CoverageConstants {
+ private CoverageConstants() {
+ }
+
public static final Collection<Metric> COVERAGE_METRICS = ImmutableList.<Metric>of(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
--- /dev/null
+/*
+ * 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.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.batch.sensor.coverage;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Date;
when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), (Project) new Project("my:project"), periodsDefinition);
+ TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
assertThat(timeMachineConfiguration.periods()).hasSize(1);
assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull();
assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), (Project) new Project("my:module"), periodsDefinition);
+ TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
assertThat(timeMachineConfiguration.periods()).hasSize(1);
assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNotNull();
assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), (Project) new Project("my:project").setId(1), periodsDefinition);
+ TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
assertThat(timeMachineConfiguration.getProjectPastSnapshots()).hasSize(1);
assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getProjectSnapshot().getId()).isEqualTo(1010);
assertThat(timeMachineConfiguration.getProjectPastSnapshots().get(0).getIndex()).isEqualTo(1);
when(periodsDefinition.getRootProjectPastSnapshots()).thenReturn(newArrayList(projectPastSnapshot));
- TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), new Project("my:project"), periodsDefinition);
+ TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), periodsDefinition);
assertThat(timeMachineConfiguration.periods()).hasSize(1);
assertThat(timeMachineConfiguration.periods().get(0).getDate()).isNull();
}
setupData("shared");
persister.persist(null, singleProject, null);
- persister.persist(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"), null);
- persister.persist(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"), null);// do nothing, already
- // saved
- persister.persist(singleProject, new Library("junit:junit", "3.2").setEffectiveKey("junit:junit"), null);
+ persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));
+ persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));// do
+ // nothing,
+ // already
+ // saved
+ persister.persistLibrary(singleProject.getAnalysisDate(), (Library) new Library("junit:junit", "3.2").setEffectiveKey("junit:junit"));
checkTables("shouldSaveNewLibrary", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
"projects", "snapshots");