diff options
36 files changed, 406 insertions, 288 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java index aae1beeb13c..74e4788460b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java @@ -20,27 +20,24 @@ package org.sonar.server.computation; -import org.sonar.batch.protocol.output.BatchOutputReader; +import org.sonar.batch.protocol.output.BatchOutput; import org.sonar.core.component.ComponentDto; import org.sonar.core.computation.db.AnalysisReportDto; - -import java.util.Date; +import org.sonar.server.computation.step.ParseReportStep; public class ComputationContext { private final AnalysisReportDto reportDto; private final ComponentDto project; - private final BatchOutputReader reportReader; /** * Cache of analysis date as it can be accessed several times */ - private Date analysisDate = null; + private BatchOutput.ReportMetadata reportMetadata = null; - public ComputationContext(AnalysisReportDto reportDto, ComponentDto project, BatchOutputReader reportReader) { + public ComputationContext(AnalysisReportDto reportDto, ComponentDto project) { this.reportDto = reportDto; this.project = project; - this.reportReader = reportReader; } public AnalysisReportDto getReportDto() { @@ -51,14 +48,14 @@ public class ComputationContext { return project; } - public BatchOutputReader getReportReader() { - return reportReader; + public BatchOutput.ReportMetadata getReportMetadata() { + if (reportMetadata == null) { + throw new IllegalStateException("Report metadata is available after execution of " + ParseReportStep.class); + } + return reportMetadata; } - public Date getAnalysisDate() { - if (analysisDate == null) { - analysisDate = new Date(reportReader.readMetadata().getAnalysisDate()); - } - return analysisDate; + public void setReportMetadata(BatchOutput.ReportMetadata m) { + this.reportMetadata = m; } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java index 4b127c9d5df..2f8f2cce6ca 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java @@ -21,14 +21,12 @@ package org.sonar.server.computation; import com.google.common.base.Throwables; -import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.api.utils.System2; -import org.sonar.api.utils.TempFolder; import org.sonar.api.utils.TimeProfiler; -import org.sonar.batch.protocol.output.BatchOutputReader; import org.sonar.core.activity.Activity; import org.sonar.core.component.ComponentDto; import org.sonar.core.computation.db.AnalysisReportDto; @@ -39,8 +37,6 @@ import org.sonar.server.computation.step.ComputationStep; import org.sonar.server.computation.step.ComputationSteps; import org.sonar.server.db.DbClient; -import java.io.File; - public class ComputationService implements ServerComponent { private static final Logger LOG = LoggerFactory.getLogger(ComputationService.class); @@ -48,14 +44,11 @@ public class ComputationService implements ServerComponent { private final DbClient dbClient; private final ComputationSteps steps; private final ActivityService activityService; - private final TempFolder tempFolder; - public ComputationService(DbClient dbClient, ComputationSteps steps, ActivityService activityService, - TempFolder tempFolder) { + public ComputationService(DbClient dbClient, ComputationSteps steps, ActivityService activityService) { this.dbClient = dbClient; this.steps = steps; this.activityService = activityService; - this.tempFolder = tempFolder; } public void process(AnalysisReportDto report) { @@ -63,14 +56,14 @@ public class ComputationService implements ServerComponent { "#%s - %s - processing analysis report", report.getId(), report.getProjectKey())); ComponentDto project = loadProject(report); - File reportDir = tempFolder.newDir(); try { - decompressReport(report, reportDir); - ComputationContext context = new ComputationContext(report, project, new BatchOutputReader(reportDir)); + ComputationContext context = new ComputationContext(report, project); for (ComputationStep step : steps.orderedSteps()) { - TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.getDescription()); - step.execute(context); - stepProfiler.stop(); + if (ArrayUtils.contains(step.supportedProjectQualifiers(), context.getProject().qualifier())) { + TimeProfiler stepProfiler = new TimeProfiler(LOG).start(step.getDescription()); + step.execute(context); + stepProfiler.stop(); + } } report.succeed(); @@ -79,7 +72,6 @@ public class ComputationService implements ServerComponent { throw Throwables.propagate(e); } finally { - FileUtils.deleteQuietly(reportDir); logActivity(report, project); profiler.stop(); } @@ -104,16 +96,4 @@ public class ComputationService implements ServerComponent { MyBatis.closeQuietly(session); } } - - private void decompressReport(AnalysisReportDto report, File toDir) { - long startTime = System.currentTimeMillis(); - DbSession session = dbClient.openSession(false); - try { - dbClient.analysisReportDao().selectAndDecompressToDir(session, report.getId(), toDir); - } finally { - MyBatis.closeQuietly(session); - } - long stopTime = System.currentTimeMillis(); - LOG.info("Analysis report loaded and uncompressed in " + (stopTime - startTime) + "ms (project=" + report.getProjectKey() + ")"); - } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java index ea34aa81760..5a64e542487 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java @@ -37,7 +37,12 @@ import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; import java.util.List; import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING; @@ -110,11 +115,12 @@ public class AnalysisReportDao implements DaoComponent { Connection connection = session.getConnection(); PreparedStatement ps = null; + ResultSet generatedIdRs = null; try { ps = connection.prepareStatement( "insert into analysis_reports " + " (project_key, snapshot_id, report_status, report_data, created_at, updated_at, started_at, finished_at)" + - " values (?, ?, ?, ?, ?, ?, ?, ?)"); + " values (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); ps.setString(1, report.getProjectKey()); ps.setLong(2, report.getSnapshotId()); ps.setString(3, report.getStatus().toString()); @@ -124,11 +130,16 @@ public class AnalysisReportDao implements DaoComponent { setLong(ps, 7, report.getStartedAt()); setLong(ps, 8, report.getFinishedAt()); - ps.executeUpdate(); + if (ps.executeUpdate() == 1) { + generatedIdRs = ps.getGeneratedKeys(); + generatedIdRs.next(); + report.setId(generatedIdRs.getLong(1)); + } connection.commit(); } catch (SQLException | IOException e) { throw new IllegalStateException(String.format("Failed to insert %s in the database", report), e); } finally { + DatabaseUtils.closeQuietly(generatedIdRs); DatabaseUtils.closeQuietly(ps); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java index 1717b91fd19..4a75701e905 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java @@ -77,7 +77,7 @@ public class IssueComputation { target.setDebt(issue.hasDebtInMinutes() ? Duration.create(issue.getDebtInMinutes()) : null); if (issue.hasDiffFields()) { FieldDiffs fieldDiffs = FieldDiffs.parse(issue.getDiffFields()); - fieldDiffs.setCreationDate(context.getAnalysisDate()); + fieldDiffs.setCreationDate(new Date(context.getReportMetadata().getAnalysisDate())); target.setCurrentChange(fieldDiffs); } target.setStatus(issue.getStatus()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ApplyPermissionsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ApplyPermissionsStep.java index 022ee3eb068..b43a7679bfa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ApplyPermissionsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ApplyPermissionsStep.java @@ -20,6 +20,7 @@ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.server.computation.ComputationContext; import org.sonar.server.issue.index.IssueAuthorizationIndexer; @@ -32,6 +33,11 @@ public class ApplyPermissionsStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT, Qualifiers.VIEW}; + } + + @Override public void execute(ComputationContext context) { indexer.index(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStep.java index 69e13111896..7f5577f8fcd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComputationStep.java @@ -27,6 +27,11 @@ import org.sonar.server.computation.ComputationContext; */ public interface ComputationStep { + /** + * Allows to distinguish standard projects from view projects + */ + String[] supportedProjectQualifiers(); + void execute(ComputationContext context); String getDescription(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java index 60d3f219759..aba41a433b2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexComponentsStep.java @@ -20,6 +20,7 @@ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.server.computation.ComputationContext; @@ -34,6 +35,11 @@ public class IndexComponentsStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT, Qualifiers.VIEW}; + } + + @Override public void execute(ComputationContext context) { resourceIndexerDao.indexProject(context.getProject().getId()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexIssuesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexIssuesStep.java index e1caae311ef..ac55607385a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexIssuesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexIssuesStep.java @@ -20,6 +20,7 @@ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.server.computation.ComputationContext; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.issue.index.IssueIndexer; @@ -35,6 +36,11 @@ public class IndexIssuesStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override public void execute(ComputationContext context) { authorizationIndexer.index(); indexer.index(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexSourceLinesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexSourceLinesStep.java index e5f3356cfeb..7746f78c72a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexSourceLinesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexSourceLinesStep.java @@ -19,6 +19,7 @@ */ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.server.computation.ComputationContext; import org.sonar.server.source.index.SourceLineIndexer; @@ -31,6 +32,11 @@ public class IndexSourceLinesStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override public void execute(ComputationContext context) { indexer.index(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexViewsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexViewsStep.java index b6dcd0774a3..1825f6c2466 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexViewsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/IndexViewsStep.java @@ -33,10 +33,13 @@ public class IndexViewsStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.VIEW}; + } + + @Override public void execute(ComputationContext context) { - if (context.getProject().qualifier().equals(Qualifiers.VIEW)) { - indexer.index(context.getProject().uuid()); - } + indexer.index(context.getProject().uuid()); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java index e83ec7c894c..c98359fa9f2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java @@ -20,33 +20,82 @@ package org.sonar.server.computation.step; -import org.sonar.batch.protocol.output.BatchOutputReader; +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.utils.TempFolder; import org.sonar.batch.protocol.output.BatchOutput; +import org.sonar.batch.protocol.output.BatchOutputReader; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.MyBatis; import org.sonar.server.computation.ComputationContext; import org.sonar.server.computation.issue.IssueComputation; +import org.sonar.server.db.DbClient; + +import java.io.File; public class ParseReportStep implements ComputationStep { + private static final Logger LOG = LoggerFactory.getLogger(ParseReportStep.class); + private final IssueComputation issueComputation; + private final DbClient dbClient; + private final TempFolder tempFolder; - public ParseReportStep(IssueComputation issueComputation) { + public ParseReportStep(IssueComputation issueComputation, DbClient dbClient, TempFolder tempFolder) { this.issueComputation = issueComputation; + this.dbClient = dbClient; + this.tempFolder = tempFolder; + } + + @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT, Qualifiers.VIEW}; } @Override public void execute(ComputationContext context) { - int rootComponentRef = context.getReportReader().readMetadata().getRootComponentRef(); - processComponent(context, rootComponentRef); - issueComputation.afterReportProcessing(); + File reportDir = tempFolder.newDir(); + try { + // extract compressed report from database and uncompress it in temporary directory + extractReport(context.getReportDto(), reportDir); + + // prepare parsing of report + BatchOutputReader reader = new BatchOutputReader(reportDir); + BatchOutput.ReportMetadata reportMetadata = reader.readMetadata(); + context.setReportMetadata(reportMetadata); + + // and parse! + int rootComponentRef = reportMetadata.getRootComponentRef(); + recursivelyProcessComponent(reader, context, rootComponentRef); + issueComputation.afterReportProcessing(); + + } finally { + FileUtils.deleteQuietly(reportDir); + } + } + + private void extractReport(AnalysisReportDto report, File toDir) { + long startTime = System.currentTimeMillis(); + DbSession session = dbClient.openSession(false); + try { + dbClient.analysisReportDao().selectAndDecompressToDir(session, report.getId(), toDir); + } finally { + MyBatis.closeQuietly(session); + } + long stopTime = System.currentTimeMillis(); + LOG.info(String.format("Report extracted in %dms | uncompressed size=%s | project=%s", + stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toDir)), report.getProjectKey())); } - private void processComponent(ComputationContext context, int componentRef) { - BatchOutputReader reader = context.getReportReader(); - BatchOutput.ReportComponent component = reader.readComponent(componentRef); - issueComputation.processComponentIssues(context, component.getUuid(), reader.readComponentIssues(componentRef)); + private void recursivelyProcessComponent(BatchOutputReader reportReader, ComputationContext context, int componentRef) { + BatchOutput.ReportComponent component = reportReader.readComponent(componentRef); + issueComputation.processComponentIssues(context, component.getUuid(), reportReader.readComponentIssues(componentRef)); for (Integer childRef : component.getChildRefsList()) { - processComponent(context, childRef); + recursivelyProcessComponent(reportReader, context, childRef); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java index 8f56637cfa5..569341eda11 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistIssuesStep.java @@ -24,6 +24,7 @@ import org.sonar.api.issue.IssueComment; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.System2; import org.sonar.core.issue.db.IssueChangeDto; import org.sonar.core.issue.db.IssueChangeMapper; @@ -57,6 +58,11 @@ public class PersistIssuesStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override public void execute(ComputationContext context) { DbSession session = dbClient.openSession(true); IssueMapper mapper = session.getMapper(IssueMapper.class); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java index 1f9725c7ff3..d9fa522e40f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java @@ -20,6 +20,7 @@ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.core.computation.dbcleaner.ProjectCleaner; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; @@ -38,6 +39,11 @@ public class PurgeDatastoresStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT, Qualifiers.VIEW}; + } + + @Override public void execute(ComputationContext context) { DbSession session = dbClient.openSession(true); try { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeRemovedViewsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeRemovedViewsStep.java index 4c652e5129f..3f0c7fe4e9d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeRemovedViewsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeRemovedViewsStep.java @@ -48,13 +48,12 @@ public class PurgeRemovedViewsStep implements ComputationStep { } @Override - public void execute(ComputationContext context) { - if (context.getProject().qualifier().equals(Qualifiers.VIEW)) { - purgeRemovedViews(); - } + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.VIEW}; } - private void purgeRemovedViews() { + @Override + public void execute(ComputationContext context) { DbSession session = dbClient.openSession(false); try { Set<String> viewUuidsInIndex = newHashSet(index.findAllViewUuids()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SendIssueNotificationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SendIssueNotificationsStep.java index f500f50030f..1d3fc613aad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SendIssueNotificationsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SendIssueNotificationsStep.java @@ -21,6 +21,7 @@ package org.sonar.server.computation.step; import com.google.common.collect.ImmutableSet; import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.api.resources.Qualifiers; import org.sonar.core.component.ComponentDto; import org.sonar.server.computation.ComputationContext; import org.sonar.server.computation.issue.IssueCache; @@ -30,6 +31,7 @@ import org.sonar.server.issue.notification.NewIssuesNotification; import org.sonar.server.notifications.NotificationService; import org.sonar.server.util.CloseableIterator; +import java.util.Date; import java.util.Set; /** @@ -54,6 +56,11 @@ public class SendIssueNotificationsStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override public void execute(ComputationContext context) { if (service.hasProjectSubscribersForTypes(context.getProject().uuid(), NOTIF_TYPES)) { doExecute(context); @@ -88,7 +95,7 @@ public class SendIssueNotificationsStep implements ComputationStep { ComponentDto project = context.getProject(); NewIssuesNotification notification = new NewIssuesNotification(); notification.setProject(project); - notification.setAnalysisDate(context.getAnalysisDate()); + notification.setAnalysisDate(new Date(context.getReportMetadata().getAnalysisDate())); notification.setStatistics(project, stats); service.deliver(notification); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java index 5d51fe0f5f0..1be36deb720 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java @@ -20,6 +20,7 @@ package org.sonar.server.computation.step; +import org.sonar.api.resources.Qualifiers; import org.sonar.core.component.SnapshotDto; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.persistence.DbSession; @@ -39,6 +40,11 @@ public class SwitchSnapshotStep implements ComputationStep { } @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT, Qualifiers.VIEW}; + } + + @Override public void execute(ComputationContext context) { DbSession session = dbClient.openSession(true); try { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java new file mode 100644 index 00000000000..d3ae3cb99b1 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java @@ -0,0 +1,106 @@ +/* + * 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.server.computation; + +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.resources.Qualifiers; +import org.sonar.core.activity.Activity; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.activity.ActivityService; +import org.sonar.server.component.db.ComponentDao; +import org.sonar.server.computation.step.ComputationStep; +import org.sonar.server.computation.step.ComputationSteps; +import org.sonar.server.db.DbClient; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + +public class ComputationServiceTest { + + @Rule + public DbTester dbTester = new DbTester(); + + ComputationStep projectStep1 = mockStep(Qualifiers.PROJECT); + ComputationStep projectStep2 = mockStep(Qualifiers.PROJECT); + ComputationStep viewStep = mockStep(Qualifiers.VIEW); + ComputationSteps steps = mock(ComputationSteps.class); + ActivityService activityService = mock(ActivityService.class); + + @Test + public void process_project() throws Exception { + // db contains project with key "PROJECT_KEY" + dbTester.prepareDbUnit(getClass(), "shared.xml"); + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao()); + + when(steps.orderedSteps()).thenReturn(Arrays.asList(projectStep1, projectStep2, viewStep)); + + // load report from db and parse it + ComputationService sut = new ComputationService(dbClient, steps, activityService); + AnalysisReportDto report = AnalysisReportDto.newForTests(1L); + report.setProjectKey("PROJECT_KEY"); + assertThat(report.getStatus()).isNull(); + sut.process(report); + + // status of report is set + assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.SUCCESS); + + // execute only the steps supporting the project qualifier + verify(projectStep1).execute(any(ComputationContext.class)); + verify(projectStep2).execute(any(ComputationContext.class)); + verify(viewStep, never()).execute(any(ComputationContext.class)); + verify(activityService).write(any(DbSession.class), eq(Activity.Type.ANALYSIS_REPORT), any(AnalysisReportLog.class)); + } + + @Test + public void fail_to_parse_report() throws Exception { + // db contains project with key "PROJECT_KEY" + dbTester.prepareDbUnit(getClass(), "shared.xml"); + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao()); + + when(steps.orderedSteps()).thenReturn(Arrays.asList(projectStep1)); + doThrow(new UnsupportedOperationException()).when(projectStep1).execute(any(ComputationContext.class)); + + // load report from db and parse it + ComputationService sut = new ComputationService(dbClient, steps, activityService); + AnalysisReportDto report = AnalysisReportDto.newForTests(1L); + report.setProjectKey("PROJECT_KEY"); + try { + sut.process(report); + fail(); + } catch (UnsupportedOperationException e) { + // status of report is set + assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.FAILED); + verify(activityService).write(any(DbSession.class), eq(Activity.Type.ANALYSIS_REPORT), any(AnalysisReportLog.class)); + } + } + + private ComputationStep mockStep(String... qualifiers) { + ComputationStep step = mock(ComputationStep.class); + when(step.supportedProjectQualifiers()).thenReturn(qualifiers); + return step; + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java index 9cab6044c2a..e0f74762a67 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java @@ -88,6 +88,9 @@ public class AnalysisReportDaoTest { session.commit(); db.assertDbUnit(getClass(), "insert-result.xml", "analysis_reports"); + // update dto with generated id + assertThat(report1.getId()).isNotNull(); + assertThat(report2.getId()).isNotNull(); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java index cc4a4878a6d..bd6fb0263d8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java @@ -22,7 +22,6 @@ package org.sonar.server.computation.step; import org.junit.Before; import org.junit.Test; -import org.sonar.batch.protocol.output.BatchOutputReader; import org.sonar.core.component.ComponentDto; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.resource.ResourceIndexerDao; @@ -47,7 +46,7 @@ public class IndexComponentsStepTest { public void call_indexProject_of_dao() throws IOException { ComponentDto project = mock(ComponentDto.class); when(project.getId()).thenReturn(123L); - ComputationContext context = new ComputationContext(mock(AnalysisReportDto.class), project, mock(BatchOutputReader.class)); + ComputationContext context = new ComputationContext(mock(AnalysisReportDto.class), project); sut.execute(context); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexViewsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexViewsStepTest.java index 0fca85963bb..8c8fbd5409f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexViewsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexViewsStepTest.java @@ -20,11 +20,7 @@ package org.sonar.server.computation.step; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.resources.Qualifiers; import org.sonar.server.component.ComponentTesting; import org.sonar.server.computation.ComputationContext; @@ -32,38 +28,19 @@ import org.sonar.server.view.index.ViewIndexer; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) public class IndexViewsStepTest { - @Mock - ComputationContext context; - - @Mock - ViewIndexer indexer; - - IndexViewsStep step; - - @Before - public void setUp() throws Exception { - step = new IndexViewsStep(indexer); - } + ComputationContext context = mock(ComputationContext.class); + ViewIndexer indexer = mock(ViewIndexer.class); + IndexViewsStep sut = new IndexViewsStep(indexer); @Test - public void index_view_on_view() throws Exception { + public void index_views() throws Exception { when(context.getProject()).thenReturn(ComponentTesting.newProjectDto("ABCD").setQualifier(Qualifiers.VIEW)); - step.execute(context); + sut.execute(context); verify(indexer).index("ABCD"); } - @Test - public void not_index_view_on_project() throws Exception { - when(context.getProject()).thenReturn(ComponentTesting.newProjectDto().setQualifier(Qualifiers.PROJECT)); - - step.execute(context); - - verifyZeroInteractions(indexer); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java new file mode 100644 index 00000000000..858edad447e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java @@ -0,0 +1,119 @@ +/* + * 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.server.computation.step; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.utils.ZipUtils; +import org.sonar.api.utils.internal.DefaultTempFolder; +import org.sonar.batch.protocol.Constants; +import org.sonar.batch.protocol.output.BatchOutput; +import org.sonar.batch.protocol.output.BatchOutputWriter; +import org.sonar.core.component.ComponentDto; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.computation.ComputationContext; +import org.sonar.server.computation.db.AnalysisReportDao; +import org.sonar.server.computation.issue.IssueComputation; +import org.sonar.server.db.DbClient; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class ParseReportStepTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Rule + public DbTester dbTester = new DbTester(); + + @Test + public void extract_report_from_db_and_browse_components() throws Exception { + AnalysisReportDto reportDto = prepareAnalysisReportInDb(); + + + IssueComputation issueComputation = mock(IssueComputation.class); + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new AnalysisReportDao()); + ParseReportStep step = new ParseReportStep(issueComputation, dbClient, new DefaultTempFolder(temp.newFolder())); + ComputationContext context = new ComputationContext(reportDto, mock(ComponentDto.class)); + step.execute(context); + + // verify that all components are processed (currently only for issues) + verify(issueComputation).processComponentIssues(context, "PROJECT_UUID", Collections.<BatchOutput.ReportIssue>emptyList()); + verify(issueComputation).processComponentIssues(context, "FILE1_UUID", Collections.<BatchOutput.ReportIssue>emptyList()); + verify(issueComputation).processComponentIssues(context, "FILE2_UUID", Collections.<BatchOutput.ReportIssue>emptyList()); + verify(issueComputation).afterReportProcessing(); + assertThat(context.getReportMetadata().getRootComponentRef()).isEqualTo(1); + } + + private AnalysisReportDto prepareAnalysisReportInDb() throws IOException { + File dir = temp.newFolder(); + // project and 2 files + BatchOutputWriter writer = new BatchOutputWriter(dir); + writer.writeMetadata(BatchOutput.ReportMetadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + writer.writeComponent(BatchOutput.ReportComponent.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("PROJECT_UUID") + .addChildRefs(2) + .addChildRefs(3) + .build()); + writer.writeComponent(BatchOutput.ReportComponent.newBuilder() + .setRef(2) + .setType(Constants.ComponentType.FILE) + .setUuid("FILE1_UUID") + .build()); + writer.writeComponent(BatchOutput.ReportComponent.newBuilder() + .setRef(3) + .setType(Constants.ComponentType.FILE) + .setUuid("FILE2_UUID") + .build()); + File zipFile = temp.newFile(); + ZipUtils.zipDir(dir, zipFile); + + AnalysisReportDto dto = new AnalysisReportDto(); + DbSession dbSession = dbTester.myBatis().openSession(false); + try { + dto.setProjectKey("PROJECT_KEY"); + dto.setCreatedAt(System.currentTimeMillis()); + dto.setSnapshotId(1L); + dto.setStatus(AnalysisReportDto.Status.PENDING); + dto.setData(new FileInputStream(zipFile)); + new AnalysisReportDao().insert(dbSession, dto); + dbSession.commit(); + } finally { + dbSession.close(); + } + return dto; + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java index 43601a875ec..a21e9b2955f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java @@ -95,7 +95,7 @@ public class PurgeDatastoresStepMediumTest { dbClient.propertiesDao().setProperty(new PropertyDto().setKey(DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS).setValue("52")); dbSession.commit(); - ComputationContext context = new ComputationContext(report, project, null); + ComputationContext context = new ComputationContext(report, project); // ACT sut.execute(context); @@ -134,7 +134,7 @@ public class PurgeDatastoresStepMediumTest { dbClient.propertiesDao().setProperty(new PropertyDto().setKey(DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS).setValue("4")); dbClient.propertiesDao().setProperty(new PropertyDto().setKey(DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS).setValue("1").setResourceId(project.getId())); dbSession.commit(); - ComputationContext context = new ComputationContext(report, project, null); + ComputationContext context = new ComputationContext(report, project); // ACT sut.execute(context); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java index f858ce7a2fc..a98bb1ddb00 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java @@ -25,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; -import org.sonar.batch.protocol.output.BatchOutputReader; import org.sonar.core.component.ComponentDto; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.computation.dbcleaner.ProjectCleaner; @@ -59,7 +58,7 @@ public class PurgeDatastoresStepTest { ComponentDto project = mock(ComponentDto.class); when(project.getId()).thenReturn(123L); when(project.uuid()).thenReturn("UUID-1234"); - ComputationContext context = new ComputationContext(mock(AnalysisReportDto.class), project, mock(BatchOutputReader.class)); + ComputationContext context = new ComputationContext(mock(AnalysisReportDto.class), project); sut.execute(context); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeRemovedViewsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeRemovedViewsStepTest.java index ed96ecb547d..0144eb0c648 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeRemovedViewsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeRemovedViewsStepTest.java @@ -94,23 +94,4 @@ public class PurgeRemovedViewsStepTest { List<String> viewUuids = esTester.getDocumentFields(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, ViewIndexDefinition.FIELD_UUID); assertThat(viewUuids).containsOnly("ABCD", "BCDE"); } - - @Test - public void nothing_to_do_when_not_analysing_view() throws Exception { - when(context.getProject()).thenReturn(ComponentTesting.newProjectDto("DBCA")); - - esTester.putDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, - new ViewDoc().setUuid("ABCD").getFields(), - // This vies does not exists in db... - new ViewDoc().setUuid("BCDE").getFields()); - - dbClient.componentDao().insert(session, ComponentTesting.newProjectDto("ABCD").setQualifier(Qualifiers.VIEW)); - session.commit(); - - step.execute(context); - - // ... But it should not be removed as the project of the context is not a view - assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW)).isEqualTo(2); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java index 273e14f4ec5..cf784e682d0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java @@ -27,6 +27,7 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.notifications.Notification; import org.sonar.api.rule.Severity; import org.sonar.api.utils.System2; +import org.sonar.batch.protocol.output.BatchOutput; import org.sonar.server.computation.ComputationContext; import org.sonar.server.computation.issue.IssueCache; import org.sonar.server.computation.issue.RuleCache; @@ -64,6 +65,7 @@ public class SendIssueNotificationsStepTest { issueCache.newAppender().append(new DefaultIssue().setSeverity(Severity.BLOCKER)).close(); when(context.getProject().uuid()).thenReturn("PROJECT_UUID"); + when(context.getReportMetadata()).thenReturn(BatchOutput.ReportMetadata.newBuilder().build()); when(notifService.hasProjectSubscribersForTypes("PROJECT_UUID", SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); SendIssueNotificationsStep step = new SendIssueNotificationsStep(issueCache, ruleCache, notifService); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java index 72758f31f04..8135e8cc343 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; -import org.sonar.batch.protocol.output.BatchOutputReader; import org.sonar.core.computation.db.AnalysisReportDto; import org.sonar.core.persistence.DbTester; import org.sonar.server.component.ComponentTesting; @@ -59,7 +58,7 @@ public class SwitchSnapshotStepTest { public void one_switch_with_a_snapshot_and_his_children() throws IOException { db.prepareDbUnit(getClass(), "snapshots.xml"); ComputationContext context = new ComputationContext(AnalysisReportDto.newForTests(1L).setSnapshotId(1L), - ComponentTesting.newProjectDto(), mock(BatchOutputReader.class)); + ComponentTesting.newProjectDto()); sut.execute(context); @@ -70,7 +69,7 @@ public class SwitchSnapshotStepTest { public void throw_IllegalStateException_when_not_finding_snapshot() throws IOException { db.prepareDbUnit(getClass(), "empty.xml"); ComputationContext context = new ComputationContext(AnalysisReportDto.newForTests(1L).setSnapshotId(1L), - ComponentTesting.newProjectDto(), mock(BatchOutputReader.class)); + ComponentTesting.newProjectDto()); sut.execute(context); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputationServiceTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputationServiceTest/shared.xml new file mode 100644 index 00000000000..d01512aa559 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputationServiceTest/shared.xml @@ -0,0 +1,3 @@ +<dataset> + <projects id="10" kee="PROJECT_KEY" qualifier="TRK"/> +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_fail_to_load_component_id_if_unknown_component.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_fail_to_load_component_id_if_unknown_component.xml deleted file mode 100644 index 5ed00ba028b..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_fail_to_load_component_id_if_unknown_component.xml +++ /dev/null @@ -1 +0,0 @@ -<dataset></dataset>
\ No newline at end of file diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues-result.xml deleted file mode 100644 index 458ce2553c2..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues-result.xml +++ /dev/null @@ -1,27 +0,0 @@ -<dataset> - <issues id="1" kee="ABCDE" resolution="OPEN" status="OPEN" severity="BLOCKER" manual_severity="[false]" - assignee="[null]" - author_login="[null]" - checksum="[null]" - effort_to_fix="[null]" - technical_debt="10" - message="[null]" - line="5000" - component_id="100" - root_component_id="10" - rule_id="200" - created_at="[null]" - updated_at="[null]" - reporter="emmerik" - issue_attributes="foo=bar" - tags="[null]" - action_plan_key="[null]" - issue_creation_date="2013-05-18" - issue_update_date="2013-05-18" - issue_close_date="2013-05-18" - /> - - <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" change_data="the comment" - created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]" /> - -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues.xml deleted file mode 100644 index 02899f1459d..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_insert_new_issues.xml +++ /dev/null @@ -1,4 +0,0 @@ -<dataset> - <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="ABCD"/> - <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="BCDE"/> -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_load_component_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_load_component_id_from_db.xml deleted file mode 100644 index 99098d271cc..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_load_component_id_from_db.xml +++ /dev/null @@ -1,3 +0,0 @@ -<dataset> - <projects id="123" kee="struts:Action.java" uuid="ABCD"/> -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates-result.xml deleted file mode 100644 index e421b224b5e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates-result.xml +++ /dev/null @@ -1,34 +0,0 @@ -<dataset> - <rules tags="[null]" system_tags="[null]" id="200" name="Avoid Cycles" plugin_rule_key="AvoidCycles" - plugin_config_key="[null]" plugin_name="squid"/> - - <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="ABCD"/> - <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="BCDE"/> - - <issues id="1" - kee="ABCDE" - resolution="FIXED" - status="RESOLVED" - severity="BLOCKER" - manual_severity="[false]" - assignee="winner" - author_login="[null]" - checksum="FFFFF" - effort_to_fix="[null]" - technical_debt="[null]" - message="[null]" - line="444" - component_id="100" - root_component_id="10" - rule_id="200" - reporter="[null]" - issue_attributes="JIRA=http://jira.com" - tags="[null]" - action_plan_key="[null]" - created_at="1400000000000" - updated_at="1400000000000" - issue_creation_date="2005-05-12 00:00:00.0" - issue_update_date="2013-05-18 00:00:00.0" - issue_close_date="[null]" - /> -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates.xml deleted file mode 100644 index 0ddfc4586ab..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_resolve_conflicts_on_updates.xml +++ /dev/null @@ -1,34 +0,0 @@ -<dataset> - - <rules tags="[null]" system_tags="[null]" id="200" name="Avoid Cycles" plugin_rule_key="AvoidCycles" - plugin_config_key="[null]" plugin_name="squid" /> - - <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="ABCD"/> - <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="BCDE"/> - - <issues id="1" - kee="ABCDE" - assignee="winner" - resolution="FIXED" - status="RESOLVED" - severity="MAJOR" - manual_severity="[false]" - author_login="[null]" - checksum="FFFFF" - effort_to_fix="[null]" - technical_debt="[null]" - message="[null]" - line="1" - component_id="100" - root_component_id="10" - rule_id="200" - reporter="[null]" - issue_attributes="" - action_plan_key="[null]" - created_at="1400000000000" - updated_at="1500000000000" - issue_creation_date="2005-05-12 00:00:00.0" - issue_update_date="2013-05-18 00:00:00.0" - issue_close_date="[null]" - /> -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues-result.xml deleted file mode 100644 index ba65e9df145..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues-result.xml +++ /dev/null @@ -1,33 +0,0 @@ -<dataset> - <issues id="1" - kee="ABCDE" - resolution="FIXED" - status="RESOLVED" - severity="BLOCKER" - manual_severity="[false]" - assignee="loic" - author_login="simon" - checksum="FFFFF" - effort_to_fix="[null]" - technical_debt="10" - message="[null]" - line="5000" - component_id="100" - root_component_id="10" - rule_id="200" - created_at="1400000000000" - updated_at="1400000000000" - reporter="emmerik" - issue_attributes="foo=bar" - tags="[null]" - action_plan_key="[null]" - issue_creation_date="2013-05-18 00:00:00.0" - issue_update_date="2013-05-18 00:00:00.0" - issue_close_date="2013-05-18 00:00:00.0" - /> - - <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" - change_data="the comment" created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/> - <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik" - change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]" issue_change_creation_date="[null]"/> -</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues.xml deleted file mode 100644 index 5fd4a9e813c..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ComputeEngineIssueStorageTest/should_update_issues.xml +++ /dev/null @@ -1,31 +0,0 @@ -<dataset> - - <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="ABCD"/> - <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="BCDE"/> - - <issues id="1" - kee="ABCDE" - resolution="OPEN" - status="OPEN" - severity="BLOCKER" - manual_severity="[false]" - assignee="loic" - author_login="simon" - checksum="FFFFF" - effort_to_fix="[null]" - technical_debt="[null]" - message="[null]" - line="3000" - component_id="100" - root_component_id="10" - rule_id="200" - created_at="1400000000000" - updated_at="1400000000000" - reporter="emmerik" - issue_attributes="foo=bar" - action_plan_key="[null]" - issue_creation_date="2010-01-01" - issue_update_date="2010-02-02" - issue_close_date="[null]" - /> -</dataset> diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java index bd21be2f473..4987652b89d 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java @@ -46,6 +46,10 @@ public class AnalysisReportDto { return report; } + public void setId(Long id) { + this.id = id; + } + public String getProjectKey() { return projectKey; } |