import java.util.Set;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.util.CloseableIterator;
-import org.sonar.server.computation.batch.BatchReportReader;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.TreeRootHolder;
import org.sonar.server.computation.issue.IssueCache;
private final RuleRepository rules;
private final TreeRootHolder treeRootHolder;
private final NotificationService service;
- private final BatchReportReader reportReader;
+ private final AnalysisMetadataHolder analysisMetadataHolder;
private NewIssuesNotificationFactory newIssuesNotificationFactory;
public SendIssueNotificationsStep(IssueCache issueCache, RuleRepository rules, TreeRootHolder treeRootHolder,
- NotificationService service, BatchReportReader reportReader,
+ NotificationService service, AnalysisMetadataHolder analysisMetadataHolder,
NewIssuesNotificationFactory newIssuesNotificationFactory) {
this.issueCache = issueCache;
this.rules = rules;
this.treeRootHolder = treeRootHolder;
this.service = service;
- this.reportReader = reportReader;
+ this.analysisMetadataHolder = analysisMetadataHolder;
this.newIssuesNotificationFactory = newIssuesNotificationFactory;
}
issues.close();
}
if (newIssuesStats.hasIssues()) {
- long analysisDate = reportReader.readMetadata().getAnalysisDate();
+ long analysisDate = analysisMetadataHolder.getAnalysisDate().getTime();
sendNewIssuesNotification(newIssuesStats, project, analysisDate);
sendNewIssuesNotificationToAssignees(newIssuesStats, project, analysisDate);
}
import java.util.Map;
import javax.annotation.CheckForNull;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.component.ComponentKeys;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.batch.BatchReportReader;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.ComponentVisitor;
private final DbClient dbClient;
private final BatchReportReader reportReader;
private final TreeRootHolder treeRootHolder;
+ private final AnalysisMetadataHolder analysisMetadataHolder;
- public ValidateProjectStep(DbClient dbClient, BatchReportReader reportReader, TreeRootHolder treeRootHolder) {
+ public ValidateProjectStep(DbClient dbClient, BatchReportReader reportReader, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder) {
this.dbClient = dbClient;
this.reportReader = reportReader;
this.treeRootHolder = treeRootHolder;
+ this.analysisMetadataHolder = analysisMetadataHolder;
}
@Override
private void validateAnalysisDate(Optional<ComponentDto> baseProject) {
if (baseProject.isPresent()) {
SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentId(session, baseProject.get().getId());
- long currentAnalysisDate = reportReader.readMetadata().getAnalysisDate();
+ long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate().getTime();
Long lastAnalysisDate = snapshotDto != null ? snapshotDto.getCreatedAt() : null;
if (lastAnalysisDate != null && currentAnalysisDate <= snapshotDto.getCreatedAt()) {
validationMessages.add(String.format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " +
@CheckForNull
private void validateBranch() {
- BatchReport.Metadata metadata = reportReader.readMetadata();
- if (!metadata.hasBranch()) {
+ String branch = analysisMetadataHolder.getBranch();
+ if (branch == null) {
return;
}
- String branch = metadata.getBranch();
if (!ComponentKeys.isValidBranch(branch)) {
validationMessages.add(String.format("\"%s\" is not a valid branch name. "
+ "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch));
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.System2;
-import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.server.computation.batch.BatchReportReaderRule;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.Component.Type;
static final Component PROJECT = builder(Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).setName(PROJECT_NAME).build();
- @Rule
- public BatchReportReaderRule reportReader = new BatchReportReaderRule();
-
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
.setRoot(PROJECT);
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
+ .setAnalysisDate(new Date(ANALYSE_DATE));
+
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Before
public void setUp() throws Exception {
issueCache = new IssueCache(temp.newFile(), System2.INSTANCE);
- underTest = new SendIssueNotificationsStep(issueCache, mock(RuleRepository.class), treeRootHolder, notificationService, reportReader, newIssuesNotificationFactory);
+ underTest = new SendIssueNotificationsStep(issueCache, mock(RuleRepository.class), treeRootHolder, notificationService, analysisMetadataHolder,
+ newIssuesNotificationFactory);
when(newIssuesNotificationFactory.newNewIssuesNotication()).thenReturn(newIssuesNotificationMock);
when(newIssuesNotificationFactory.newMyNewIssuesNotification()).thenReturn(myNewIssuesNotificationMock);
-
- reportReader.setMetadata(BatchReport.Metadata.newBuilder()
- .setRootComponentRef(1)
- .setAnalysisDate(ANALYSE_DATE)
- .build());
}
@Test
package org.sonar.server.computation.step;
+import java.util.Date;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.batch.protocol.Constants;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotTesting;
+import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.batch.BatchReportReaderRule;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.Component;
@Category(DbTests.class)
public class ValidateProjectStepTest {
- private static long DEFAULT_ANALYSIS_TIME = 1433131200000L; // 2015-06-01
- private static final String PROJECT_KEY = "PROJECT_KEY";
- private static final String MODULE_KEY = "MODULE_KEY";
+ static long DEFAULT_ANALYSIS_TIME = 1433131200000L; // 2015-06-01
+ static final String PROJECT_KEY = "PROJECT_KEY";
+ static final String MODULE_KEY = "MODULE_KEY";
+ static final String DEFAULT_BRANCH = "origin/master";
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
+ .setAnalysisDate(new Date(DEFAULT_ANALYSIS_TIME))
+ .setBranch(DEFAULT_BRANCH);
+
DbClient dbClient = dbTester.getDbClient();
- ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder);
+ ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
@Before
public void setUp() {
@Test
public void not_fail_on_valid_branch() {
- reportReader.setMetadata(BatchReport.Metadata.newBuilder()
- .setAnalysisDate(DEFAULT_ANALYSIS_TIME)
- .setBranch("origin/master")
- .build());
+ analysisMetadataHolder.setBranch(DEFAULT_BRANCH);
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
thrown.expectMessage("Validation of project failed:\n" +
" o \"bran#ch\" is not a valid branch name. Allowed characters are alphanumeric, '-', '_', '.' and '/'.");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder()
- .setAnalysisDate(DEFAULT_ANALYSIS_TIME)
- .setBranch("bran#ch")
- .build());
+ analysisMetadataHolder.setBranch("bran#ch");
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
" o \"Project\\Key\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.\n" +
" o \"Module$Key\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
"If you really want to stop directly analysing project \"" + MODULE_KEY + "\", please first delete it from SonarQube and then relaunch the analysis of project \""
+ PROJECT_KEY + "\".");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
thrown.expectMessage("Validation of project failed:\n" +
" o Module \"" + MODULE_KEY + "\" is already part of project \"" + anotherProjectKey + "\"");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
"If you really want to stop directly analysing project \"" + anotherProjectKey + "\", please first delete it from SonarQube and then relaunch the analysis of project \""
+ PROJECT_KEY + "\".");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
@Test
public void not_fail_if_analysis_date_is_after_last_analysis() {
- reportReader.setMetadata(BatchReport.Metadata.newBuilder()
- .setAnalysisDate(DEFAULT_ANALYSIS_TIME) // 2015-06-01
- .build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
thrown.expectMessage("Date of analysis cannot be older than the date of the last known analysis on this project. Value: ");
thrown.expectMessage("Latest analysis: ");
- reportReader.setMetadata(BatchReport.Metadata.newBuilder()
- .setAnalysisDate(1420088400000L) // 2015-01-01
- .build());
+ analysisMetadataHolder.setAnalysisDate(DateUtils.parseDate("2015-01-01"));
+
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)