@@ -26,27 +26,22 @@ import static java.util.Objects.requireNonNull; | |||
public class ProjectAttributes { | |||
private final String projectVersion; | |||
private final String codePeriodVersion; | |||
@Nullable | |||
private final String buildString; | |||
public ProjectAttributes(@Nullable String projectVersion, String codePeriodVersion, String buildString) { | |||
this.projectVersion = projectVersion; | |||
this.codePeriodVersion = requireNonNull(codePeriodVersion, "codePeriod version can't be null"); | |||
public ProjectAttributes(String projectVersion, @Nullable String buildString) { | |||
this.projectVersion = requireNonNull(projectVersion, "project version can't be null"); | |||
this.buildString = buildString; | |||
} | |||
public ProjectAttributes(ProjectAttributes projectAttributes) { | |||
this.projectVersion = projectAttributes.projectVersion; | |||
this.codePeriodVersion = projectAttributes.codePeriodVersion; | |||
this.buildString = projectAttributes.buildString; | |||
} | |||
public Optional<String> getProjectVersion() { | |||
return Optional.ofNullable(projectVersion); | |||
} | |||
public String getCodePeriodVersion() { | |||
return codePeriodVersion; | |||
public String getProjectVersion() { | |||
return projectVersion; | |||
} | |||
public Optional<String> getBuildString() { | |||
@@ -57,7 +52,6 @@ public class ProjectAttributes { | |||
public String toString() { | |||
return "ProjectAttributes{" + | |||
"projectVersion='" + projectVersion + '\'' + | |||
"codePeriodVersion='" + codePeriodVersion + '\'' + | |||
"buildString='" + buildString + '\'' + | |||
'}'; | |||
} |
@@ -111,23 +111,17 @@ public class BuildComponentTreeStep implements ComputationStep { | |||
} | |||
private static ProjectAttributes createProjectAttributes(ScannerReport.Metadata metadata, @Nullable SnapshotDto baseAnalysis) { | |||
String projectVersion = trimToNull(metadata.getProjectVersion()); | |||
String codePeriodVersion = computeCodePeriodVersion(metadata.getCodePeriodVersion(), projectVersion, baseAnalysis); | |||
String projectVersion = computeProjectVersion(trimToNull(metadata.getProjectVersion()), baseAnalysis); | |||
String buildString = trimToNull(metadata.getBuildString()); | |||
return new ProjectAttributes(projectVersion, codePeriodVersion, buildString); | |||
return new ProjectAttributes(projectVersion, buildString); | |||
} | |||
private static String computeCodePeriodVersion(String rawCodePeriodVersion, @Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) { | |||
String codePeriodVersion = trimToNull(rawCodePeriodVersion); | |||
if (codePeriodVersion != null) { | |||
return codePeriodVersion; | |||
} | |||
// support case (legacy but not forbidden) where only projectVersion is set | |||
private static String computeProjectVersion(@Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) { | |||
if (projectVersion != null) { | |||
return projectVersion; | |||
} | |||
if (baseAnalysis != null) { | |||
return firstNonNull(baseAnalysis.getCodePeriodVersion(), DEFAULT_PROJECT_VERSION); | |||
return firstNonNull(baseAnalysis.getProjectVersion(), DEFAULT_PROJECT_VERSION); | |||
} | |||
return DEFAULT_PROJECT_VERSION; | |||
} |
@@ -109,7 +109,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
} | |||
private Optional<Period> resolvePeriod(Component projectOrView) { | |||
String currentVersion = projectOrView.getProjectAttributes().getCodePeriodVersion(); | |||
String currentVersion = projectOrView.getProjectAttributes().getProjectVersion(); | |||
Optional<String> propertyValue = configRepository.getConfiguration().get(LEAK_PERIOD) | |||
.filter(t -> !t.isEmpty()); | |||
checkPeriodProperty(propertyValue.isPresent(), "", "property is undefined or value is empty"); |
@@ -102,12 +102,10 @@ public class PersistAnalysisStep implements ComputationStep { | |||
private SnapshotDto createAnalysis(String snapshotUuid, Component component) { | |||
String componentUuid = component.getUuid(); | |||
String codePeriodVersion = component.getType() == PROJECT ? component.getProjectAttributes().getCodePeriodVersion() : null; | |||
String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion().orElse(null) : null; | |||
String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion() : null; | |||
String buildString = component.getType() == PROJECT ? component.getProjectAttributes().getBuildString().orElse(null) : null; | |||
return new SnapshotDto() | |||
.setUuid(snapshotUuid) | |||
.setCodePeriodVersion(codePeriodVersion) | |||
.setProjectVersion(projectVersion) | |||
.setBuildString(buildString) | |||
.setComponentUuid(componentUuid) |
@@ -101,10 +101,10 @@ public class PersistEventsStep implements ComputationStep { | |||
} | |||
private void saveVersionEvent(DbSession session, Component component, Long analysisDate) { | |||
String codePeriodVersion = component.getProjectAttributes().getCodePeriodVersion(); | |||
deletePreviousEventsHavingSameVersion(session, codePeriodVersion, component); | |||
String projectVersion = component.getProjectAttributes().getProjectVersion(); | |||
deletePreviousEventsHavingSameVersion(session, projectVersion, component); | |||
dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate) | |||
.setName(codePeriodVersion) | |||
.setName(projectVersion) | |||
.setCategory(EventDto.CATEGORY_VERSION)); | |||
} | |||
@@ -132,7 +132,7 @@ public class QualityGateEventsStep implements ComputationStep { | |||
.setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label)) | |||
.setFieldValue("projectName", project.getName()) | |||
.setFieldValue("projectKey", project.getKey()) | |||
.setFieldValue("codePeriodVersion", project.getProjectAttributes().getCodePeriodVersion()) | |||
.setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion()) | |||
.setFieldValue("alertName", label) | |||
.setFieldValue("alertText", rawStatus.getText()) | |||
.setFieldValue("alertLevel", rawStatus.getStatus().toString()) |
@@ -165,7 +165,7 @@ public class SendIssueNotificationsStep implements ComputationStep { | |||
NewIssuesNotification notification = newIssuesNotificationFactory | |||
.newNewIssuesNotification() | |||
.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | |||
.setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion()) | |||
.setProjectVersion(project.getProjectAttributes().getProjectVersion()) | |||
.setAnalysisDate(new Date(analysisDate)) | |||
.setStatistics(project.getName(), globalStatistics) | |||
.setDebt(Duration.create(globalStatistics.effort().getOnLeak())); | |||
@@ -186,7 +186,7 @@ public class SendIssueNotificationsStep implements ComputationStep { | |||
.setAssignee(userDtoByUuid.get(assigneeUuid)); | |||
myNewIssuesNotification | |||
.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest()) | |||
.setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion()) | |||
.setProjectVersion(project.getProjectAttributes().getProjectVersion()) | |||
.setAnalysisDate(new Date(analysisDate)) | |||
.setStatistics(project.getName(), assigneeStatistics) | |||
.setDebt(Duration.create(assigneeStatistics.effort().getOnLeak())); |
@@ -249,7 +249,7 @@ public class ComponentImplTest { | |||
.setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build()); | |||
if (type == PROJECT) { | |||
String buildString = randomAlphabetic(15); | |||
builder.setProjectAttributes(new ProjectAttributes(null, "version_1", buildString)); | |||
builder.setProjectAttributes(new ProjectAttributes("version_1", buildString)); | |||
} | |||
return builder; | |||
} |
@@ -19,9 +19,6 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import java.util.EnumSet; | |||
import java.util.HashMap; | |||
@@ -31,12 +28,10 @@ import java.util.Objects; | |||
import java.util.Optional; | |||
import java.util.Random; | |||
import java.util.function.Function; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.ExternalResource; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.analysis.Branch; | |||
import org.sonar.core.component.ComponentKeys; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
@@ -58,7 +53,6 @@ import static org.sonar.scanner.protocol.output.ScannerReport.Component.Componen | |||
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED; | |||
import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; | |||
@RunWith(DataProviderRunner.class) | |||
public class ComponentTreeBuilderTest { | |||
private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_" | |||
@@ -70,8 +64,7 @@ public class ComponentTreeBuilderTest { | |||
private static final String NO_SCM_BASE_PATH = ""; | |||
// both no project as "" or null should be supported | |||
private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes( | |||
new Random().nextBoolean() ? null : randomAlphabetic(12), | |||
randomAlphabetic(20), randomAlphabetic(21)); | |||
randomAlphabetic(20), new Random().nextBoolean() ? null : randomAlphabetic(12)); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@@ -128,8 +121,7 @@ public class ComponentTreeBuilderTest { | |||
} | |||
@Test | |||
@UseDataProvider("projectVersionOrNull") | |||
public void by_default_project_fields_are_loaded_from_report(@Nullable String projectVersion) { | |||
public void by_default_project_fields_are_loaded_from_report() { | |||
String nameInReport = "the name"; | |||
String descriptionInReport = "the desc"; | |||
String buildString = randomAlphabetic(21); | |||
@@ -139,7 +131,7 @@ public class ComponentTreeBuilderTest { | |||
.setRef(42) | |||
.setName(nameInReport) | |||
.setDescription(descriptionInReport) | |||
.build(), NO_SCM_BASE_PATH, new ProjectAttributes(projectVersion, "6.5", buildString)); | |||
.build(), NO_SCM_BASE_PATH, new ProjectAttributes("6.5", buildString)); | |||
assertThat(root.getUuid()).isEqualTo("generated_K1_uuid"); | |||
assertThat(root.getDbKey()).isEqualTo("generated_K1"); | |||
@@ -149,24 +141,11 @@ public class ComponentTreeBuilderTest { | |||
assertThat(root.getShortName()).isEqualTo(nameInReport); | |||
assertThat(root.getDescription()).isEqualTo(descriptionInReport); | |||
assertThat(root.getReportAttributes().getRef()).isEqualTo(42); | |||
if (projectVersion == null) { | |||
assertThat(root.getProjectAttributes().getProjectVersion()).isEmpty(); | |||
} else { | |||
assertThat(root.getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||
} | |||
assertThat(root.getProjectAttributes().getCodePeriodVersion()).isEqualTo("6.5"); | |||
assertThat(root.getProjectAttributes().getProjectVersion()).contains("6.5"); | |||
assertThat(root.getProjectAttributes().getBuildString()).isEqualTo(Optional.of(buildString)); | |||
assertThatFileAttributesAreNotSet(root); | |||
} | |||
@DataProvider | |||
public static Object[][] projectVersionOrNull() { | |||
return new Object[][] { | |||
{null}, | |||
{randomAlphabetic(15)} | |||
}; | |||
} | |||
@Test | |||
public void project_name_is_loaded_from_db_if_absent_from_report() { | |||
Component root = call(newBuilder() |
@@ -43,7 +43,7 @@ public class ReportComponent implements Component { | |||
.setPublicKey("PUBLIC_PROJECT_KEY") | |||
.setUuid("PROJECT_UUID") | |||
.setName("Project Name") | |||
.setCodePeriodVersion("1.0-SNAPSHOT") | |||
.setProjectVersion("1.0-SNAPSHOT") | |||
.build(); | |||
private final Type type; | |||
@@ -69,8 +69,8 @@ public class ReportComponent implements Component { | |||
this.shortName = builder.shortName == null ? this.name : builder.shortName; | |||
this.description = builder.description; | |||
this.uuid = builder.uuid; | |||
this.projectAttributes = Optional.ofNullable(builder.codePeriodVersion) | |||
.map(t -> new ProjectAttributes(builder.projectVersion, t, builder.buildString)) | |||
this.projectAttributes = Optional.ofNullable(builder.projectVersion) | |||
.map(v -> new ProjectAttributes(v, builder.buildString)) | |||
.orElse(null); | |||
this.reportAttributes = ReportAttributes.newBuilder(builder.ref) | |||
.build(); | |||
@@ -205,7 +205,6 @@ public class ReportComponent implements Component { | |||
private String publicKey; | |||
private String name; | |||
private String shortName; | |||
private String codePeriodVersion; | |||
private String projectVersion; | |||
private String buildString; | |||
private String description; | |||
@@ -217,7 +216,7 @@ public class ReportComponent implements Component { | |||
this.type = type; | |||
this.ref = ref; | |||
if (type == Type.PROJECT) { | |||
this.codePeriodVersion = "toBeDefined"; | |||
this.projectVersion = "toBeDefined"; | |||
} | |||
} | |||
@@ -251,18 +250,14 @@ public class ReportComponent implements Component { | |||
return this; | |||
} | |||
public Builder setCodePeriodVersion(String s) { | |||
checkArgument(type != Type.PROJECT ^ s != null, "CodePeriod version must and can only be set on Project"); | |||
this.codePeriodVersion = s; | |||
return this; | |||
} | |||
public Builder setProjectVersion(@Nullable String projectVersion) { | |||
this.projectVersion = projectVersion; | |||
public Builder setProjectVersion(@Nullable String s) { | |||
checkProjectVersion(s); | |||
this.projectVersion = s; | |||
return this; | |||
} | |||
public Builder setBuildString(@Nullable String buildString) { | |||
checkBuildString(buildString); | |||
this.buildString = buildString; | |||
return this; | |||
} | |||
@@ -287,9 +282,17 @@ public class ReportComponent implements Component { | |||
} | |||
public ReportComponent build() { | |||
checkArgument(type != Type.PROJECT ^ this.codePeriodVersion != null, "CodePeriod version must and can only be set on Project"); | |||
checkArgument(type == Type.PROJECT || this.buildString == null, "BuildString can only be set on Project"); | |||
checkProjectVersion(this.projectVersion); | |||
checkBuildString(this.buildString); | |||
return new ReportComponent(this); | |||
} | |||
private void checkProjectVersion(@Nullable String s) { | |||
checkArgument(type != Type.PROJECT ^ s != null, "Project version must and can only be set on Project"); | |||
} | |||
private void checkBuildString(@Nullable String s) { | |||
checkArgument(type == Type.PROJECT || s == null, "BuildString can only be set on Project"); | |||
} | |||
} | |||
} |
@@ -66,7 +66,7 @@ import static org.sonar.scanner.protocol.output.ScannerReport.Component.Componen | |||
@RunWith(DataProviderRunner.class) | |||
public class BuildComponentTreeStepTest { | |||
private static final String NO_SCANNER_PROJECT_VERSION = null; | |||
private static final String NO_SCANNER_CODE_PERIOD_VERSION = null; | |||
private static final String NO_SCANNER_BUILD_STRING = null; | |||
private static final int ROOT_REF = 1; | |||
private static final int FILE_1_REF = 4; | |||
@@ -91,7 +91,7 @@ public class BuildComponentTreeStepTest { | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_CODE_PERIOD_VERSION)); | |||
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING)); | |||
@Rule | |||
public MutableTreeRootHolderRule treeRootHolder = new MutableTreeRootHolderRule(); | |||
@Rule | |||
@@ -322,161 +322,70 @@ public class BuildComponentTreeStepTest { | |||
} | |||
@Test | |||
public void set_codePeriodVersion_to_not_provided_when_both_codePeriod_and_project_version_are_not_set_on_first_analysis() { | |||
public void set_projectVersion_to_not_provided_when_not_set_on_first_analysis() { | |||
setAnalysisMetadataHolder(); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()).isEqualTo("not provided"); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEqualTo("not provided"); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_codePeriodVersion_to_previous_analysis_codePeriodVersion_when_both_codePeriod_and_project_version_are_not_set( | |||
@Nullable String previousAnalysisCodePeriodVersion) { | |||
public void set_projectVersion_to_previous_analysis_when_not_set(@Nullable String previousAnalysisProjectVersion) { | |||
setAnalysisMetadataHolder(); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||
insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
String codePeriodVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion(); | |||
if (previousAnalysisCodePeriodVersion == null) { | |||
assertThat(codePeriodVersion).isEqualTo("not provided"); | |||
String projectVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion(); | |||
if (previousAnalysisProjectVersion == null) { | |||
assertThat(projectVersion).isEqualTo("not provided"); | |||
} else { | |||
assertThat(codePeriodVersion).isEqualTo(previousAnalysisCodePeriodVersion); | |||
assertThat(projectVersion).isEqualTo(previousAnalysisProjectVersion); | |||
} | |||
} | |||
@Test | |||
public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_first_analysis() { | |||
public void set_projectVersion_when_it_is_set_on_first_analysis() { | |||
String scannerProjectVersion = randomAlphabetic(12); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION)); | |||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()) | |||
.isEqualTo(scannerProjectVersion); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_later_analysis( | |||
@Nullable String previousAnalysisCodePeriodVersion) { | |||
public void set_projectVersion_when_it_is_set_on_later_analysis(@Nullable String previousAnalysisProjectVersion) { | |||
String scannerProjectVersion = randomAlphabetic(12); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION)); | |||
reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||
insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()) | |||
.isEqualTo(scannerProjectVersion); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_first_analysis(@Nullable String projectVersion) { | |||
String scannerCodePeriodVersion = randomAlphabetic(12); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||
.isEqualTo(scannerCodePeriodVersion); | |||
} | |||
@Test | |||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||
public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_later_analysis(@Nullable String projectVersion, @Nullable String previousAnalysisCodePeriodVersion) { | |||
String scannerCodePeriodVersion = randomAlphabetic(12); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()) | |||
.isEqualTo(scannerCodePeriodVersion); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_projectVersion_to_null_when_projectVersion_is_unset_on_first_analysis(@Nullable String codePeriodVersion) { | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty(); | |||
} | |||
@Test | |||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||
public void set_projectVersion_to_null_when_projectVersion_is_unset_on_later_analysis(@Nullable String codePeriodVersion, @Nullable String previousAnalysisCodePeriodVersion) { | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty(); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_first_analysis(@Nullable String codePeriodVersion) { | |||
String projectVersion = randomAlphabetic(7); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||
} | |||
@Test | |||
@UseDataProvider("twoParametersNullNonNullCombinations") | |||
public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_later_analysis(@Nullable String codePeriodVersion, | |||
@Nullable String previousAnalysisCodePeriodVersion) { | |||
String projectVersion = randomAlphabetic(7); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion); | |||
} | |||
@Test | |||
@UseDataProvider("oneParameterNullNonNullCombinations") | |||
public void set_buildString(@Nullable String buildString) { | |||
String projectVersion = randomAlphabetic(7); | |||
String codePeriodVersion = randomAlphabetic(8); | |||
setAnalysisMetadataHolder(); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion, buildString)); | |||
reportReader.setMetadata(createReportMetadata(projectVersion, buildString)); | |||
reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
underTest.execute(new TestComputationStepContext()); | |||
@@ -492,16 +401,6 @@ public class BuildComponentTreeStepTest { | |||
}; | |||
} | |||
@DataProvider | |||
public static Object[][] twoParametersNullNonNullCombinations() { | |||
return new Object[][] { | |||
{null, null}, | |||
{randomAlphabetic(7), null}, | |||
{null, randomAlphabetic(8)}, | |||
{randomAlphabetic(9), randomAlphabetic(10)} | |||
}; | |||
} | |||
private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) { | |||
assertThat(component.getType()).isEqualTo(type); | |||
assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef); | |||
@@ -622,15 +521,10 @@ public class BuildComponentTreeStepTest { | |||
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY))); | |||
} | |||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion) { | |||
return createReportMetadata(projectVersion, scannerCodePeriodVersion, null); | |||
} | |||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion, @Nullable String buildString) { | |||
public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String buildString) { | |||
ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder() | |||
.setProjectKey(REPORT_PROJECT_KEY) | |||
.setRootComponentRef(ROOT_REF); | |||
ofNullable(scannerCodePeriodVersion).ifPresent(builder::setCodePeriodVersion); | |||
ofNullable(projectVersion).ifPresent(builder::setProjectVersion); | |||
ofNullable(buildString).ifPresent(builder::setBuildString); | |||
return builder.build(); |
@@ -156,7 +156,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
SnapshotDto analysis1 = dbTester.components() | |||
.insertSnapshot(project, snapshot -> snapshot.setStatus(STATUS_UNPROCESSED).setCreatedAt(1226379600000L).setLast(false));// 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, | |||
snapshot -> snapshot.setStatus(STATUS_PROCESSED).setCodePeriodVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29 | |||
snapshot -> snapshot.setStatus(STATUS_PROCESSED).setProjectVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | |||
dbTester.events().insertEvent(newEvent(analysis2).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | |||
when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime()); | |||
@@ -366,11 +366,11 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
@Test | |||
public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_and_codePeriod_version() { | |||
public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_version() { | |||
String version = randomAlphabetic(12); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(version).setProjectVersion(version)); | |||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(version).setProjectVersion(version)); | |||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | |||
setupRoot(project); | |||
@@ -382,24 +382,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
@Test | |||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_other_codePeriod_version() { | |||
String codePeriodVersion = randomAlphabetic(12); | |||
String projectVersion = randomAlphabetic(15); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion)); | |||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | |||
setupRoot(project); | |||
settings.setProperty("sonar.leak.period", "ignored"); | |||
underTest.execute(new TestComputationStepContext()); | |||
assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid()); | |||
} | |||
@Test | |||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_no_codePeriod_version() { | |||
public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version() { | |||
String projectVersion = randomAlphabetic(15); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
@@ -415,13 +398,12 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
@Test | |||
@UseDataProvider("projectAndCodePeriodVersionsCombinations") | |||
public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one_over_any_other_version( | |||
@Nullable String codePeriodVersion, @Nullable String projectVersion) { | |||
@UseDataProvider("projectVersionNullOrNot") | |||
public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one(@Nullable String projectVersion) { | |||
String eventVersion = randomAlphabetic(15); | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion)); | |||
SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(projectVersion)); | |||
dbTester.events().insertEvent(EventTesting.newEvent(manualBaselineAnalysis).setCategory(CATEGORY_VERSION).setName(eventVersion)); | |||
dbTester.components().setManualBaseline(project, manualBaselineAnalysis); | |||
when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project)); | |||
@@ -434,15 +416,10 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
@DataProvider | |||
public static Object[][] projectAndCodePeriodVersionsCombinations() { | |||
String codePeriodVersion = randomAlphabetic(12); | |||
String projectVersion = randomAlphabetic(15); | |||
public static Object[][] projectVersionNullOrNot() { | |||
return new Object[][] { | |||
{null, null}, | |||
{codePeriodVersion, null}, | |||
{codePeriodVersion, projectVersion}, | |||
{projectVersion, projectVersion}, | |||
{null, projectVersion} | |||
{null}, | |||
{randomAlphabetic(15)}, | |||
}; | |||
} | |||
@@ -614,11 +591,11 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void fail_with_MessageException_if_string_is_not_an_existing_version_event(String propertyValue) { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | |||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | |||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | |||
@@ -717,11 +694,11 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_previous_version() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt())); | |||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt())); | |||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt())); | |||
@@ -743,9 +720,9 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_previous_version_with_previous_version_deleted() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | |||
// The "1.0" version was deleted from the history | |||
dbTester.events().insertEvent(newEvent(analysis3).setName("1.1").setCategory(CATEGORY_VERSION)); | |||
@@ -765,8 +742,8 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("1.1").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.1").setCategory(CATEGORY_VERSION)); | |||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | |||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | |||
@@ -785,7 +762,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11 | |||
SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11 | |||
dbTester.events().insertEvent(newEvent(analysis).setName("0.9").setCategory(CATEGORY_VERSION)); | |||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | |||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | |||
@@ -803,11 +780,11 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_version() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11 | |||
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12 | |||
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20 | |||
SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22 | |||
SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | |||
dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION)); | |||
dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION)); | |||
@@ -831,7 +808,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
public void feed_period_by_version_with_only_one_existing_version() { | |||
OrganizationDto organization = dbTester.organizations().insert(); | |||
ComponentDto project = dbTester.components().insertMainBranch(organization); | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11 | |||
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11 | |||
dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION)); | |||
when(system2Mock.now()).thenReturn(november30th2008.getTime()); | |||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false); | |||
@@ -878,7 +855,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
private void setupRoot(ComponentDto project, String version) { | |||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setCodePeriodVersion(version).build()); | |||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setProjectVersion(version).build()); | |||
when(configurationRepository.getConfiguration()).thenReturn(settings.asConfig()); | |||
} | |||
@@ -58,7 +58,7 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
private static final long NOW = 1225630680000L; | |||
private static final ReportComponent ROOT = builder(PROJECT, 1) | |||
.setUuid("ABCD") | |||
.setCodePeriodVersion("version_1") | |||
.setProjectVersion("version_1") | |||
.addChildren( | |||
builder(DIRECTORY, 2) | |||
.setUuid("BCDE") | |||
@@ -107,7 +107,7 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
when(system2.now()).thenReturn(NOW); | |||
Component project = builder(PROJECT, 1) | |||
.setUuid("ABCD") | |||
.setCodePeriodVersion("1.0") | |||
.setProjectVersion("1.0") | |||
.addChildren( | |||
builder(DIRECTORY, 2) | |||
.setUuid("BCDE") | |||
@@ -197,7 +197,7 @@ public class PersistEventsStepTest extends BaseStepTest { | |||
Component project = builder(PROJECT, 1) | |||
.setUuid(projectDto.uuid()) | |||
.setCodePeriodVersion("1.5-SNAPSHOT") | |||
.setProjectVersion("1.5-SNAPSHOT") | |||
.addChildren( | |||
builder(DIRECTORY, 2) | |||
.setUuid("BCDE") |
@@ -60,12 +60,12 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR; | |||
import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK; | |||
public class QualityGateEventsStepTest { | |||
private static final String PROJECT_VERSION = new Random().nextBoolean() ? null : randomAlphabetic(19); | |||
private static final String PROJECT_VERSION = randomAlphabetic(19); | |||
private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1) | |||
.setUuid("uuid 1") | |||
.setKey("key 1") | |||
.setCodePeriodVersion("V1.9") | |||
.setProjectVersion(PROJECT_VERSION) | |||
.setBuildString("V1.9") | |||
.addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).build()) | |||
.build(); | |||
private static final String INVALID_ALERT_STATUS = "trololo"; | |||
@@ -182,7 +182,7 @@ public class QualityGateEventsStepTest { | |||
assertThat(notification.getType()).isEqualTo("alerts"); | |||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | |||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | |||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||
assertThat(notification.getFieldValue("branch")).isNull(); | |||
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name()); | |||
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | |||
@@ -233,7 +233,7 @@ public class QualityGateEventsStepTest { | |||
assertThat(notification.getType()).isEqualTo("alerts"); | |||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | |||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | |||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||
assertThat(notification.getFieldValue("branch")).isNull(); | |||
assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name()); | |||
assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel); | |||
@@ -263,7 +263,7 @@ public class QualityGateEventsStepTest { | |||
assertThat(notification.getType()).isEqualTo("alerts"); | |||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | |||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | |||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||
assertThat(notification.getFieldValue("branch")).isEqualTo(branchName); | |||
reset(measureRepository, eventRepository, notificationService); | |||
@@ -285,7 +285,7 @@ public class QualityGateEventsStepTest { | |||
assertThat(notification.getType()).isEqualTo("alerts"); | |||
assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey()); | |||
assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); | |||
assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion()); | |||
assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion()); | |||
assertThat(notification.getFieldValue("branch")).isEqualTo(null); | |||
reset(measureRepository, eventRepository, notificationService); |
@@ -19,16 +19,11 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.step; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
@@ -56,7 +51,6 @@ import static org.mockito.Mockito.when; | |||
import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION; | |||
@RunWith(DataProviderRunner.class) | |||
public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
private static final String PROJECT_KEY = "PROJECT_KEY"; | |||
@@ -101,8 +95,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
} | |||
@Test | |||
@UseDataProvider("projectVersionOrNull") | |||
public void persist_analysis(@Nullable String projectVersion) { | |||
public void persist_analysis() { | |||
String projectVersion = randomAlphabetic(10); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
@@ -120,7 +114,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1) | |||
.setUuid("ABCD") | |||
.setKey(PROJECT_KEY) | |||
.setCodePeriodVersion("1.0") | |||
.setProjectVersion(projectVersion) | |||
.setBuildString(buildString) | |||
.addChildren(directory) | |||
@@ -138,7 +131,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); | |||
assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | |||
assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid()); | |||
assertThat(projectSnapshot.getCodePeriodVersion()).isEqualTo("1.0"); | |||
assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion); | |||
assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString); | |||
assertThat(projectSnapshot.getLast()).isFalse(); | |||
@@ -150,14 +142,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId()); | |||
} | |||
@DataProvider | |||
public static Object[][] projectVersionOrNull() { | |||
return new Object[][] { | |||
{null}, | |||
{randomAlphabetic(17)} | |||
}; | |||
} | |||
@Test | |||
public void persist_snapshots_with_leak_period() { | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); |
@@ -96,7 +96,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
private static final Component FILE = builder(Type.FILE, 11).build(); | |||
private static final Component PROJECT = builder(Type.PROJECT, 1) | |||
.setCodePeriodVersion(randomAlphanumeric(10)) | |||
.setProjectVersion(randomAlphanumeric(10)) | |||
.addChildren(FILE).build(); | |||
@Rule | |||
@@ -509,7 +509,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
private NewIssuesNotification createNewIssuesNotificationMock() { | |||
NewIssuesNotification notification = mock(NewIssuesNotification.class); | |||
when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | |||
when(notification.setCodePeriodVersion(any())).thenReturn(notification); | |||
when(notification.setProjectVersion(any())).thenReturn(notification); | |||
when(notification.setAnalysisDate(any())).thenReturn(notification); | |||
when(notification.setStatistics(any(), any())).thenReturn(notification); | |||
when(notification.setDebt(any())).thenReturn(notification); | |||
@@ -520,7 +520,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class); | |||
when(notification.setAssignee(any(UserDto.class))).thenReturn(notification); | |||
when(notification.setProject(any(), any(), any(), any())).thenReturn(notification); | |||
when(notification.setCodePeriodVersion(any())).thenReturn(notification); | |||
when(notification.setProjectVersion(any())).thenReturn(notification); | |||
when(notification.setAnalysisDate(any())).thenReturn(notification); | |||
when(notification.setStatistics(any(), any())).thenReturn(notification); | |||
when(notification.setDebt(any())).thenReturn(notification); |
@@ -111,7 +111,6 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { | |||
SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); | |||
assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); | |||
assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); | |||
assertThat(viewSnapshot.getCodePeriodVersion()).isNull(); | |||
assertThat(viewSnapshot.getProjectVersion()).isNull(); | |||
assertThat(viewSnapshot.getLast()).isFalse(); | |||
assertThat(viewSnapshot.getStatus()).isEqualTo("U"); |
@@ -24,6 +24,7 @@ import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.apache.commons.lang.StringUtils.trimToNull; | |||
public final class SnapshotDto { | |||
@@ -33,6 +34,7 @@ public final class SnapshotDto { | |||
public static final String STATUS_UNPROCESSED = "U"; | |||
public static final String STATUS_PROCESSED = "P"; | |||
public static final int MAX_VERSION_LENGTH = 100; | |||
public static final int MAX_BUILD_STRING_LENGTH = 100; | |||
private Long id; | |||
private String uuid; | |||
@@ -41,7 +43,7 @@ public final class SnapshotDto { | |||
private Long buildDate; | |||
private String status = STATUS_UNPROCESSED; | |||
private Boolean last; | |||
private String codePeriodVersion; | |||
// maps to "version" column in the table | |||
private String projectVersion; | |||
private String buildString; | |||
private String periodMode; | |||
@@ -102,36 +104,15 @@ public final class SnapshotDto { | |||
return this; | |||
} | |||
/** | |||
* Version is only available on projects and modules | |||
*/ | |||
@CheckForNull | |||
public String getCodePeriodVersion() { | |||
return codePeriodVersion; | |||
} | |||
public SnapshotDto setCodePeriodVersion(@Nullable String codePeriodVersion) { | |||
checkVersion(codePeriodVersion, "codePeriodVersion"); | |||
this.codePeriodVersion = codePeriodVersion; | |||
return this; | |||
} | |||
private static void checkVersion(@Nullable String version, String versionLabel) { | |||
if (version != null) { | |||
checkArgument(version.length() <= MAX_VERSION_LENGTH, | |||
"%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", versionLabel, version.length(), MAX_VERSION_LENGTH, version); | |||
private static void checkLength(int maxLength, @Nullable String s, String label) { | |||
if (s != null) { | |||
checkArgument(s.length() <= maxLength, | |||
"%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", label, s.length(), maxLength, s); | |||
} | |||
} | |||
/** | |||
* Used by MyBatis | |||
*/ | |||
private void setRawCodePeriodVersion(@Nullable String codePeriodVersion) { | |||
this.codePeriodVersion = codePeriodVersion; | |||
} | |||
public SnapshotDto setProjectVersion(@Nullable String projectVersion) { | |||
checkVersion(projectVersion, "projectVersion"); | |||
checkLength(MAX_VERSION_LENGTH, projectVersion, "projectVersion"); | |||
this.projectVersion = projectVersion; | |||
return this; | |||
} | |||
@@ -145,7 +126,7 @@ public final class SnapshotDto { | |||
* Used by MyBatis | |||
*/ | |||
private void setRawProjectVersion(@Nullable String projectVersion) { | |||
this.projectVersion = projectVersion; | |||
this.projectVersion = trimToNull(projectVersion); | |||
} | |||
@CheckForNull | |||
@@ -154,10 +135,18 @@ public final class SnapshotDto { | |||
} | |||
public SnapshotDto setBuildString(@Nullable String buildString) { | |||
checkLength(MAX_BUILD_STRING_LENGTH, buildString, "buildString"); | |||
this.buildString = buildString; | |||
return this; | |||
} | |||
/** | |||
* Used by MyBatis | |||
*/ | |||
private void setRawBuildString(@Nullable String buildString) { | |||
this.buildString = trimToNull(buildString); | |||
} | |||
public SnapshotDto setPeriodMode(@Nullable String p) { | |||
periodMode = p; | |||
return this; | |||
@@ -216,8 +205,8 @@ public final class SnapshotDto { | |||
Objects.equals(buildDate, that.buildDate) && | |||
Objects.equals(status, that.status) && | |||
Objects.equals(last, that.last) && | |||
Objects.equals(codePeriodVersion, that.codePeriodVersion) && | |||
Objects.equals(projectVersion, that.projectVersion) && | |||
Objects.equals(buildString, that.buildString) && | |||
Objects.equals(periodMode, that.periodMode) && | |||
Objects.equals(periodParam, that.periodParam) && | |||
Objects.equals(periodDate, that.periodDate); | |||
@@ -225,7 +214,7 @@ public final class SnapshotDto { | |||
@Override | |||
public int hashCode() { | |||
return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, codePeriodVersion, projectVersion, periodMode, periodParam, periodDate); | |||
return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate); | |||
} | |||
@Override | |||
@@ -238,8 +227,8 @@ public final class SnapshotDto { | |||
", buildDate=" + buildDate + | |||
", status='" + status + '\'' + | |||
", last=" + last + | |||
", codePeriodVersion='" + codePeriodVersion + '\'' + | |||
", projectVersion='" + projectVersion + '\'' + | |||
", buildString='" + buildString + '\'' + | |||
", periodMode='" + periodMode + '\'' + | |||
", periodParam='" + periodParam + '\'' + | |||
", periodDate=" + periodDate + |
@@ -46,7 +46,7 @@ public final class SnapshotQuery { | |||
private Long createdAfter; | |||
private Long createdBefore; | |||
private String status; | |||
private String codePeriodVersion; | |||
private String projectVersion; | |||
private Boolean isLast; | |||
private String sortField; | |||
private String sortOrder; | |||
@@ -108,12 +108,12 @@ public final class SnapshotQuery { | |||
} | |||
@CheckForNull | |||
public String getCodePeriodVersion() { | |||
return codePeriodVersion; | |||
public String getProjectVersion() { | |||
return projectVersion; | |||
} | |||
public SnapshotQuery setCodePeriodVersion(@Nullable String codePeriodVersion) { | |||
this.codePeriodVersion = codePeriodVersion; | |||
public SnapshotQuery setProjectVersion(@Nullable String projectVersion) { | |||
this.projectVersion = projectVersion; | |||
return this; | |||
} | |||
@@ -10,8 +10,7 @@ | |||
s.build_date as buildDate, | |||
s.status as status, | |||
s.islast as last, | |||
s.version as rawCodePeriodVersion, | |||
s.project_version as rawProjectVersion, | |||
s.version as rawProjectVersion, | |||
s.build_string as buildString, | |||
s.period1_mode as periodMode, | |||
s.period1_param as periodParam, | |||
@@ -73,8 +72,8 @@ | |||
<if test="query.status != null"> | |||
AND s.status=#{query.status,jdbcType=VARCHAR} | |||
</if> | |||
<if test="query.codePeriodVersion != null"> | |||
AND s.version=#{query.codePeriodVersion,jdbcType=VARCHAR} | |||
<if test="query.projectVersion != null"> | |||
AND s.version=#{query.projectVersion,jdbcType=VARCHAR} | |||
</if> | |||
<if test="query.isLast != null"> | |||
AND s.islast=#{query.isLast} | |||
@@ -152,7 +151,7 @@ | |||
<update id="update" parameterType="Snapshot"> | |||
update snapshots | |||
set version = #{codePeriodVersion, jdbcType=VARCHAR}, | |||
set version = #{projectVersion, jdbcType=VARCHAR}, | |||
status = #{status, jdbcType=VARCHAR} | |||
where uuid = #{uuid,jdbcType=VARCHAR} | |||
</update> | |||
@@ -166,7 +165,6 @@ | |||
status, | |||
islast, | |||
version, | |||
project_version, | |||
build_string, | |||
period1_mode, | |||
period1_param, | |||
@@ -179,7 +177,6 @@ | |||
#{buildDate, jdbcType=BIGINT}, | |||
#{status, jdbcType=VARCHAR}, | |||
#{last, jdbcType=BOOLEAN}, | |||
#{codePeriodVersion, jdbcType=VARCHAR}, | |||
#{projectVersion, jdbcType=VARCHAR}, | |||
#{buildString, jdbcType=VARCHAR}, | |||
#{periodMode, jdbcType=VARCHAR}, |
@@ -19,14 +19,19 @@ | |||
*/ | |||
package org.sonar.db.component; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbClient; | |||
@@ -43,6 +48,7 @@ import static java.util.Collections.singletonList; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.apache.commons.lang.math.RandomUtils.nextLong; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.fail; | |||
import static org.assertj.core.groups.Tuple.tuple; | |||
import static org.sonar.db.ce.CeActivityDto.Status.CANCELED; | |||
import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS; | |||
@@ -54,6 +60,7 @@ import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
@RunWith(DataProviderRunner.class) | |||
public class SnapshotDaoTest { | |||
@Rule | |||
@@ -76,8 +83,8 @@ public class SnapshotDaoTest { | |||
.setPeriodMode("days") | |||
.setPeriodParam("30") | |||
.setPeriodDate(1500000000001L) | |||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||
.setProjectVersion("2.1.0.2336") | |||
.setProjectVersion("2.1.0") | |||
.setBuildString("2.1.0.2336") | |||
.setBuildDate(1500000000006L) | |||
.setCreatedAt(1403042400000L)); | |||
@@ -87,14 +94,13 @@ public class SnapshotDaoTest { | |||
assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); | |||
assertThat(result.getStatus()).isEqualTo("P"); | |||
assertThat(result.getLast()).isTrue(); | |||
assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||
assertThat(result.getProjectVersion()).isEqualTo("2.1.0.2336"); | |||
assertThat(result.getProjectVersion()).isEqualTo("2.1.0"); | |||
assertThat(result.getBuildString()).isEqualTo("2.1.0.2336"); | |||
assertThat(result.getPeriodMode()).isEqualTo("days"); | |||
assertThat(result.getPeriodModeParameter()).isEqualTo("30"); | |||
assertThat(result.getPeriodDate()).isEqualTo(1500000000001L); | |||
assertThat(result.getBuildDate()).isEqualTo(1500000000006L); | |||
assertThat(result.getCreatedAt()).isEqualTo(1403042400000L); | |||
assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||
assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse(); | |||
} | |||
@@ -152,14 +158,14 @@ public class SnapshotDaoTest { | |||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery())).hasSize(6); | |||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC))) | |||
.extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion) | |||
.extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString) | |||
.containsOnly( | |||
tuple(1L, "2.0-SNAPSHOT", "2.0.0.2363"), | |||
tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | |||
tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869") | |||
); | |||
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC))) | |||
.extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion) | |||
.extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString) | |||
.containsOnly( | |||
tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869"), | |||
tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"), | |||
@@ -300,7 +306,7 @@ public class SnapshotDaoTest { | |||
.setPeriodMode("days") | |||
.setPeriodParam("30") | |||
.setPeriodDate(1500000000001L) | |||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||
.setProjectVersion("2.1-SNAPSHOT") | |||
.setBuildDate(1500000000006L) | |||
.setCreatedAt(1403042400000L)); | |||
@@ -314,8 +320,36 @@ public class SnapshotDaoTest { | |||
assertThat(dto.getPeriodDate()).isEqualTo(1500000000001L); | |||
assertThat(dto.getBuildDate()).isEqualTo(1500000000006L); | |||
assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L); | |||
assertThat(dto.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT"); | |||
assertThat(dto.getProjectVersion()).isEqualTo("2.1-SNAPSHOT"); | |||
} | |||
@Test | |||
@UseDataProvider("nullAndEmptyNonEmptyStrings") | |||
public void insert_with_null_and_empty_and_non_empty_projectVersion(@Nullable String projectVersion) { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setProjectVersion(projectVersion)); | |||
assertThat(dto.getProjectVersion()).isEqualTo(projectVersion); | |||
} | |||
@Test | |||
@UseDataProvider("nullAndEmptyNonEmptyStrings") | |||
public void insert_with_null_and_empty_and_non_empty_buildString(@Nullable String buildString) { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setBuildString(buildString)); | |||
assertThat(dto.getBuildString()).isEqualTo(buildString); | |||
} | |||
@DataProvider | |||
public static Object[][] nullAndEmptyNonEmptyStrings() { | |||
return new Object[][] { | |||
{null}, | |||
{""}, | |||
{randomAlphanumeric(7)}, | |||
}; | |||
} | |||
@Test | |||
@@ -386,31 +420,17 @@ public class SnapshotDaoTest { | |||
db.commit(); | |||
analysis | |||
.setComponentUuid("P42") | |||
.setCodePeriodVersion("5.6.3") | |||
.setProjectVersion("5.6.3") | |||
.setStatus(STATUS_UNPROCESSED); | |||
underTest.update(dbSession, analysis); | |||
SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get(); | |||
assertThat(result.getCodePeriodVersion()).isEqualTo("5.6.3"); | |||
assertThat(result.getProjectVersion()).isEqualTo("5.6.3"); | |||
assertThat(result.getStatus()).isEqualTo(STATUS_UNPROCESSED); | |||
assertThat(result.getComponentUuid()).isEqualTo("P1"); | |||
} | |||
@Test | |||
public void snashotDto_can_hold_version_larger_than_100_read_from_database() { | |||
SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false); | |||
db.commit(); | |||
String tooLongVersion = StringUtils.repeat("d", 200); | |||
db.executeUpdateSql("update snapshots set version='" + tooLongVersion + "' where uuid='" + analysis.getUuid() + "'"); | |||
db.commit(); | |||
assertThat(underTest.selectByUuid(dbSession, analysis.getUuid()) | |||
.map(SnapshotDto::getCodePeriodVersion)) | |||
.contains(tooLongVersion); | |||
} | |||
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) { | |||
SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid)) | |||
.setLast(isLastFlag) | |||
@@ -432,7 +452,7 @@ public class SnapshotDaoTest { | |||
.setComponentUuid("uuid_3") | |||
.setStatus("P") | |||
.setLast(true) | |||
.setCodePeriodVersion("2.1-SNAPSHOT") | |||
.setProjectVersion("2.1-SNAPSHOT") | |||
.setPeriodMode("days1") | |||
.setPeriodParam("30") | |||
.setPeriodDate(1_500_000_000_001L) |
@@ -39,7 +39,8 @@ public class SnapshotDtoTest { | |||
.setBuildDate(parseDate("2014-07-02").getTime()) | |||
.setComponentUuid("uuid_21") | |||
.setLast(true) | |||
.setCodePeriodVersion("1.0") | |||
.setProjectVersion("1.0") | |||
.setBuildString("1.0.1.123") | |||
.setPeriodMode("mode1") | |||
.setPeriodParam("param1") | |||
.setPeriodDate(parseDate("2014-06-01").getTime()); | |||
@@ -48,24 +49,40 @@ public class SnapshotDtoTest { | |||
assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime()); | |||
assertThat(snapshotDto.getComponentUuid()).isEqualTo("uuid_21"); | |||
assertThat(snapshotDto.getLast()).isTrue(); | |||
assertThat(snapshotDto.getCodePeriodVersion()).isEqualTo("1.0"); | |||
assertThat(snapshotDto.getProjectVersion()).isEqualTo("1.0"); | |||
assertThat(snapshotDto.getBuildString()).isEqualTo("1.0.1.123"); | |||
assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1"); | |||
assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1"); | |||
assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime()); | |||
} | |||
@Test | |||
public void fail_if_version_name_is_longer_then_100_characters() { | |||
public void fail_if_projectVersion_is_longer_then_100_characters() { | |||
SnapshotDto snapshotDto = new SnapshotDto(); | |||
snapshotDto.setCodePeriodVersion(null); | |||
snapshotDto.setCodePeriodVersion("1.0"); | |||
snapshotDto.setCodePeriodVersion(repeat("a", 100)); | |||
snapshotDto.setProjectVersion(null); | |||
snapshotDto.setProjectVersion("1.0"); | |||
snapshotDto.setProjectVersion(repeat("a", 100)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("codePeriodVersion" + | |||
expectedException.expectMessage("projectVersion" + | |||
" length (101) is longer than the maximum authorized (100). " + | |||
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); | |||
snapshotDto.setCodePeriodVersion(repeat("a", 101)); | |||
snapshotDto.setProjectVersion(repeat("a", 101)); | |||
} | |||
@Test | |||
public void fail_if_buildString_is_longer_then_100_characters() { | |||
SnapshotDto snapshotDto = new SnapshotDto(); | |||
snapshotDto.setBuildString(null); | |||
snapshotDto.setBuildString("1.0"); | |||
snapshotDto.setBuildString(repeat("a", 100)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("buildString" + | |||
" length (101) is longer than the maximum authorized (100). " + | |||
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided."); | |||
snapshotDto.setBuildString(repeat("a", 101)); | |||
} | |||
} |
@@ -33,7 +33,7 @@ public class SnapshotQueryTest { | |||
.setComponentUuid("abcd") | |||
.setIsLast(true) | |||
.setStatus("P") | |||
.setCodePeriodVersion("1.0") | |||
.setProjectVersion("1.0") | |||
.setCreatedAfter(10L) | |||
.setCreatedBefore(20L) | |||
.setSort(BY_DATE, ASC); | |||
@@ -41,7 +41,7 @@ public class SnapshotQueryTest { | |||
assertThat(query.getComponentUuid()).isEqualTo("abcd"); | |||
assertThat(query.getIsLast()).isTrue(); | |||
assertThat(query.getStatus()).isEqualTo("P"); | |||
assertThat(query.getCodePeriodVersion()).isEqualTo("1.0"); | |||
assertThat(query.getProjectVersion()).isEqualTo("1.0"); | |||
assertThat(query.getCreatedAfter()).isEqualTo(10L); | |||
assertThat(query.getCreatedBefore()).isEqualTo(20L); | |||
assertThat(query.getSortField()).isEqualTo("created_at"); |
@@ -399,7 +399,7 @@ public class PurgeDaoTest { | |||
.setComponentUuid(PROJECT_UUID) | |||
.setStatus(STATUS_PROCESSED) | |||
.setLast(false) | |||
.setCodePeriodVersion("V5") | |||
.setProjectVersion("V5") | |||
}; | |||
db.components().insertSnapshots(analyses); | |||
db.events().insertEvent(EventTesting.newEvent(analyses[4]) |
@@ -47,7 +47,7 @@ | |||
created_at="1228172400001" | |||
build_date="1317247200000" | |||
version="2.0-SNAPSHOT" | |||
project_version="2.0.0.2363" | |||
build_string="2.0.0.2363" | |||
/> | |||
<snapshots id="2" | |||
uuid="u2" | |||
@@ -73,7 +73,7 @@ | |||
created_at="1228172400002" | |||
build_date="1317247200000" | |||
version="2.1-SNAPSHOT" | |||
project_version="2.1.0.11" | |||
build_string="2.1.0.11" | |||
/> | |||
<snapshots id="3" | |||
uuid="u3" | |||
@@ -99,7 +99,7 @@ | |||
created_at="1228172400003" | |||
build_date="1317247200000" | |||
version="2.2-SNAPSHOT" | |||
project_version="2.2.0.8869" | |||
build_string="2.2.0.8869" | |||
/> | |||
<!-- PROJECT_ID = 2 --> | |||
@@ -148,7 +148,7 @@ | |||
created_at="1228172400000" | |||
build_date="1317247200000" | |||
version="2.1-SNAPSHOT" | |||
project_version="2.1.0.66" | |||
build_string="2.1.0.66" | |||
/> | |||
<!-- Unprocessed snapshot --> | |||
<snapshots organization_uuid="org1" | |||
@@ -176,7 +176,7 @@ | |||
created_at="1228172400000" | |||
build_date="1317247200000" | |||
version="2.1-SNAPSHOT" | |||
project_version="2.1.0.1" | |||
build_string="2.1.0.1" | |||
/> | |||
<!-- PROJECT_ID = 3 - no last snapshot --> | |||
@@ -225,7 +225,7 @@ | |||
created_at="1228172400000" | |||
build_date="1317247200000" | |||
version="2.1-SNAPSHOT" | |||
project_version="2.1.0.5586" | |||
build_string="2.1.0.5586" | |||
/> | |||
<!-- PROJECT_ID = 4 - no snapshot --> |
@@ -51,7 +51,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { | |||
static final String FIELD_PROJECT_NAME = "projectName"; | |||
static final String FIELD_PROJECT_KEY = "projectKey"; | |||
static final String FIELD_PROJECT_DATE = "projectDate"; | |||
static final String FIELD_CODE_PERIOD_VERSION = "codePeriodVersion"; | |||
static final String FIELD_PROJECT_VERSION = "projectVersion"; | |||
static final String FIELD_ASSIGNEE = "assignee"; | |||
static final String FIELD_BRANCH = "branch"; | |||
static final String FIELD_PULL_REQUEST = "pullRequest"; | |||
@@ -89,7 +89,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { | |||
if (pullRequest!= null) { | |||
message.append("Pull request: ").append(pullRequest).append(NEW_LINE); | |||
} | |||
String version = notification.getFieldValue(FIELD_CODE_PERIOD_VERSION); | |||
String version = notification.getFieldValue(FIELD_PROJECT_VERSION); | |||
if (version != null) { | |||
message.append("Version: ").append(version).append(NEW_LINE); | |||
} |
@@ -47,7 +47,7 @@ import org.sonar.server.issue.notification.NewIssuesStatistics.Metric; | |||
import static java.util.stream.Collectors.toMap; | |||
import static java.util.stream.Collectors.toSet; | |||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_BRANCH; | |||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION; | |||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PROJECT_VERSION; | |||
import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PULL_REQUEST; | |||
import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE; | |||
import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY; | |||
@@ -92,9 +92,9 @@ public class NewIssuesNotification extends Notification { | |||
return this; | |||
} | |||
public NewIssuesNotification setCodePeriodVersion(@Nullable String version) { | |||
public NewIssuesNotification setProjectVersion(@Nullable String version) { | |||
if (version != null) { | |||
setFieldValue(FIELD_CODE_PERIOD_VERSION, version); | |||
setFieldValue(FIELD_PROJECT_VERSION, version); | |||
} | |||
return this; | |||
} |
@@ -50,7 +50,7 @@ public class AlertsEmailTemplate extends EmailTemplate { | |||
String projectId = notification.getFieldValue("projectId"); | |||
String projectKey = notification.getFieldValue("projectKey"); | |||
String projectName = notification.getFieldValue("projectName"); | |||
String projectVersion = notification.getFieldValue("codePeriodVersion"); | |||
String projectVersion = notification.getFieldValue("projectVersion"); | |||
String branchName = notification.getFieldValue("branch"); | |||
String alertName = notification.getFieldValue("alertName"); | |||
String alertText = notification.getFieldValue("alertText"); |
@@ -120,7 +120,7 @@ public class MyNewIssuesEmailTemplateTest { | |||
@Test | |||
public void format_email_with_no_assignees_tags_nor_components() { | |||
Notification notification = newNotification(32) | |||
.setFieldValue("codePeriodVersion", "52.0"); | |||
.setFieldValue("projectVersion", "52.0"); | |||
EmailMessage message = underTest.format(notification); | |||
@@ -140,7 +140,7 @@ public class MyNewIssuesEmailTemplateTest { | |||
@Test | |||
public void format_email_with_issue_on_branch() { | |||
Notification notification = newNotification(32) | |||
.setFieldValue("codePeriodVersion", "52.0") | |||
.setFieldValue("projectVersion", "52.0") | |||
.setFieldValue("branch", "feature1"); | |||
EmailMessage message = underTest.format(notification); |
@@ -88,7 +88,7 @@ public class NewIssuesEmailTemplateTest { | |||
@Test | |||
public void format_email_with_all_fields_filled() { | |||
Notification notification = newNotification(32) | |||
.setFieldValue("codePeriodVersion", "42.1.1"); | |||
.setFieldValue("projectVersion", "42.1.1"); | |||
addAssignees(notification); | |||
addRules(notification); | |||
addTags(notification); | |||
@@ -179,7 +179,7 @@ public class NewIssuesEmailTemplateTest { | |||
public void format_email_with_issue_on_branch_with_version() { | |||
Notification notification = newNotification(32) | |||
.setFieldValue("branch", "feature1") | |||
.setFieldValue("codePeriodVersion", "42.1.1"); | |||
.setFieldValue("projectVersion", "42.1.1"); | |||
EmailMessage message = template.format(notification); | |||
@@ -85,16 +85,16 @@ public class NewIssuesNotificationTest { | |||
public void set_project_version() { | |||
String version = randomAlphanumeric(5); | |||
underTest.setCodePeriodVersion(version); | |||
underTest.setProjectVersion(version); | |||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isEqualTo(version); | |||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isEqualTo(version); | |||
} | |||
@Test | |||
public void set_project_version_supports_null() { | |||
underTest.setCodePeriodVersion(null); | |||
underTest.setProjectVersion(null); | |||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isNull(); | |||
assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isNull(); | |||
} | |||
@Test |
@@ -71,7 +71,7 @@ class ComponentDtoToWsComponent { | |||
analysis -> { | |||
wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())); | |||
ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak))); | |||
ofNullable(analysis.getCodePeriodVersion()).ifPresent(wsComponent::setVersion); | |||
ofNullable(analysis.getProjectVersion()).ifPresent(wsComponent::setVersion); | |||
}); | |||
if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) { | |||
wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate())); |
@@ -127,7 +127,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction { | |||
private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) { | |||
EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis)); | |||
if (VERSION.equals(request.getCategory())) { | |||
analysis.setCodePeriodVersion(request.getName()); | |||
analysis.setProjectVersion(request.getName()); | |||
dbClient.snapshotDao().update(dbSession, analysis); | |||
} | |||
dbSession.commit(); |
@@ -92,7 +92,7 @@ public class DeleteEventAction implements ProjectAnalysesWsAction { | |||
SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid()) | |||
.orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid()))); | |||
checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis"); | |||
analysis.setCodePeriodVersion(null); | |||
analysis.setProjectVersion(null); | |||
dbClient.snapshotDao().update(dbSession, analysis); | |||
} | |||
dbClient.eventDao().delete(dbSession, dbEvent.getUuid()); |
@@ -83,7 +83,6 @@ class SearchResponseBuilder { | |||
.setKey(dbAnalysis.getUuid()) | |||
.setDate(formatDateTime(dbAnalysis.getCreatedAt())) | |||
.setManualNewCodePeriodBaseline(searchData.getManualBaseline().filter(dbAnalysis.getUuid()::equals).isPresent()); | |||
ofNullable(dbAnalysis.getCodePeriodVersion()).ifPresent(builder::setCodePeriodVersion); | |||
ofNullable(dbAnalysis.getProjectVersion()).ifPresent(builder::setProjectVersion); | |||
ofNullable(dbAnalysis.getBuildString()).ifPresent(builder::setBuildString); | |||
@@ -119,7 +119,7 @@ public class UpdateEventAction implements ProjectAnalysesWsAction { | |||
dbClient.eventDao().update(dbSession, event.getUuid(), event.getName(), event.getDescription()); | |||
if (VERSION.getLabel().equals(event.getCategory())) { | |||
SnapshotDto analysis = getAnalysis(dbSession, event); | |||
analysis.setCodePeriodVersion(event.getName()); | |||
analysis.setProjectVersion(event.getName()); | |||
dbClient.snapshotDao().update(dbSession, analysis); | |||
} | |||
dbSession.commit(); |
@@ -229,7 +229,7 @@ public class ComponentAction implements NavigationWsAction { | |||
List<Page> pages = pageRepository.getComponentPages(false, component.qualifier()); | |||
writeExtensions(json, component, pages); | |||
if (analysis != null) { | |||
json.prop("version", analysis.getCodePeriodVersion()) | |||
json.prop("version", analysis.getProjectVersion()) | |||
.prop("analysisDate", formatDateTime(new Date(analysis.getCreatedAt()))); | |||
} | |||
} |
@@ -276,7 +276,7 @@ public class ShowActionTest { | |||
ComponentDto module = db.components().insertComponent(newModuleDto(project)); | |||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | |||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | |||
db.components().insertSnapshot(project, s -> s.setCodePeriodVersion("1.1")); | |||
db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1")); | |||
userSession.addProjectPermission(USER, project); | |||
ShowWsResponse response = newRequest(null, file.getDbKey()); | |||
@@ -296,7 +296,7 @@ public class ShowActionTest { | |||
ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | |||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | |||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | |||
db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1")); | |||
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1")); | |||
ShowWsResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, file.getKey()) | |||
@@ -322,7 +322,7 @@ public class ShowActionTest { | |||
ComponentDto module = db.components().insertComponent(newModuleDto(branch)); | |||
ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); | |||
ComponentDto file = db.components().insertComponent(newFileDto(directory)); | |||
db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1")); | |||
db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1")); | |||
ShowWsResponse response = ws.newRequest() | |||
.setParam(PARAM_COMPONENT, file.getKey()) | |||
@@ -448,7 +448,7 @@ public class ShowActionTest { | |||
.setQualifier(Qualifiers.PROJECT) | |||
.setTagsString("language, plugin")); | |||
db.components().insertSnapshot(project, snapshot -> snapshot | |||
.setCodePeriodVersion("1.1") | |||
.setProjectVersion("1.1") | |||
.setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime()) | |||
.setPeriodDate(parseDateTime("2017-01-01T11:39:03+0100").getTime())); | |||
ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl") |
@@ -128,7 +128,7 @@ public class AlertsEmailTemplateTest { | |||
@Test | |||
public void shouldFormatNewAlertWithoutVersion() { | |||
Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true") | |||
.setFieldValue("codePeriodVersion", null); | |||
.setFieldValue("projectVersion", null); | |||
EmailMessage message = template.format(notification); | |||
assertThat(message.getMessageId(), is("alerts/45")); | |||
@@ -200,7 +200,7 @@ public class AlertsEmailTemplateTest { | |||
.setFieldValue("projectName", "Foo") | |||
.setFieldValue("projectKey", "org.sonar.foo:foo") | |||
.setFieldValue("projectId", "45") | |||
.setFieldValue("codePeriodVersion", "V1-SNAP") | |||
.setFieldValue("projectVersion", "V1-SNAP") | |||
.setFieldValue("alertName", alertName) | |||
.setFieldValue("alertText", alertText) | |||
.setFieldValue("alertLevel", alertLevel) |
@@ -144,7 +144,7 @@ public class CreateEventActionTest { | |||
call(VERSION.name(), "5.6.3", analysis.getUuid()); | |||
Optional<SnapshotDto> newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()); | |||
assertThat(newAnalysis.get().getCodePeriodVersion()).isEqualTo("5.6.3"); | |||
assertThat(newAnalysis.get().getProjectVersion()).isEqualTo("5.6.3"); | |||
} | |||
@Test | |||
@@ -156,7 +156,7 @@ public class CreateEventActionTest { | |||
CreateEventResponse result = call(OTHER.name(), "Project Import", analysis.getUuid()); | |||
SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | |||
assertThat(analysis.getCodePeriodVersion()).isEqualTo(newAnalysis.getCodePeriodVersion()); | |||
assertThat(analysis.getProjectVersion()).isEqualTo(newAnalysis.getProjectVersion()); | |||
ProjectAnalyses.Event wsEvent = result.getEvent(); | |||
assertThat(wsEvent.getKey()).isNotEmpty(); | |||
assertThat(wsEvent.getCategory()).isEqualTo(OTHER.name()); |
@@ -76,20 +76,20 @@ public class DeleteEventActionTest { | |||
@Test | |||
public void delete_version_event() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(false)); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(false)); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | |||
logInAsProjectAdministrator(project); | |||
call("E1"); | |||
SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | |||
assertThat(newAnalysis.getCodePeriodVersion()).isNull(); | |||
assertThat(newAnalysis.getProjectVersion()).isNull(); | |||
} | |||
@Test | |||
public void fail_if_version_for_last_analysis() { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(true)); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(true)); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); | |||
logInAsProjectAdministrator(project); | |||
@@ -121,7 +121,7 @@ public class UpdateEventActionTest { | |||
call("E1", "6.3"); | |||
SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | |||
assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("6.3"); | |||
assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("6.3"); | |||
} | |||
@Test | |||
@@ -132,7 +132,7 @@ public class UpdateEventActionTest { | |||
call("E1", "6.3"); | |||
SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); | |||
assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("5.6"); | |||
assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("5.6"); | |||
} | |||
@Test | |||
@@ -256,7 +256,7 @@ public class UpdateEventActionTest { | |||
private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) { | |||
ComponentDto project = db.components().insertPrivateProject(); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion(version)); | |||
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion(version)); | |||
logInAsProjectAdministrator(project); | |||
return analysis; | |||
} |
@@ -157,7 +157,7 @@ public class ComponentActionTest { | |||
ComponentDto project = insertOrganizationAndProject(); | |||
db.components().insertSnapshot(project, snapshot -> snapshot | |||
.setCreatedAt(parseDateTime("2015-04-22T11:44:00+0200").getTime()) | |||
.setCodePeriodVersion("3.14")); | |||
.setProjectVersion("3.14")); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
init(); | |||
@@ -530,7 +530,7 @@ public class ComponentActionTest { | |||
componentDbTester.insertComponent(project); | |||
SnapshotDto analysis = newAnalysis(project) | |||
.setCreatedAt(parseDateTime("2016-12-06T11:44:00+0200").getTime()) | |||
.setCodePeriodVersion("6.3") | |||
.setProjectVersion("6.3") | |||
.setLast(true); | |||
componentDbTester.insertSnapshot(analysis); | |||
when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); |
@@ -146,7 +146,6 @@ public interface CoreProperties { | |||
@Deprecated | |||
String PROJECT_BRANCH_PROPERTY = "sonar.branch"; | |||
String PROJECT_VERSION_PROPERTY = "sonar.projectVersion"; | |||
String CODE_PERIOD_VERSION_PROPERTY = "sonar.codePeriodVersion"; | |||
String BUILD_STRING_PROPERTY = "sonar.buildString"; | |||
/** |
@@ -32,7 +32,6 @@ import org.sonar.api.utils.MessageException; | |||
import static java.lang.String.format; | |||
import static org.sonar.api.CoreProperties.BUILD_STRING_PROPERTY; | |||
import static org.sonar.api.CoreProperties.CODE_PERIOD_VERSION_PROPERTY; | |||
import static org.sonar.api.CoreProperties.PROJECT_VERSION_PROPERTY; | |||
/** | |||
@@ -46,7 +45,6 @@ public class ProjectInfo implements Startable { | |||
private Date analysisDate; | |||
private String projectVersion; | |||
private String codePeriodVersion; | |||
private String buildString; | |||
public ProjectInfo(Configuration settings, Clock clock) { | |||
@@ -62,10 +60,6 @@ public class ProjectInfo implements Startable { | |||
return Optional.ofNullable(projectVersion); | |||
} | |||
public Optional<String> getCodePeriodVersion() { | |||
return Optional.ofNullable(codePeriodVersion); | |||
} | |||
public Optional<String> getBuildString() { | |||
return Optional.ofNullable(buildString); | |||
} | |||
@@ -96,10 +90,6 @@ public class ProjectInfo implements Startable { | |||
.map(StringUtils::trimToNull) | |||
.filter(validateLengthLimit("project version")) | |||
.orElse(null); | |||
this.codePeriodVersion = settings.get(CODE_PERIOD_VERSION_PROPERTY) | |||
.map(StringUtils::trimToNull) | |||
.filter(validateLengthLimit("codePeriod version")) | |||
.orElse(projectVersion); | |||
this.buildString = settings.get(BUILD_STRING_PROPERTY) | |||
.map(StringUtils::trimToNull) | |||
.filter(validateLengthLimit("buildString")) |
@@ -89,7 +89,6 @@ public class MetadataPublisher implements ReportPublisherStep { | |||
.setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()) | |||
.setRootComponentRef(rootProject.scannerId()); | |||
projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion); | |||
projectInfo.getCodePeriodVersion().ifPresent(builder::setCodePeriodVersion); | |||
projectInfo.getBuildString().ifPresent(builder::setBuildString); | |||
properties.organizationKey().ifPresent(builder::setOrganizationKey); |
@@ -112,54 +112,54 @@ public class ProjectInfoTest { | |||
} | |||
@Test | |||
@UseDataProvider("projectVersions") | |||
public void getCodePeriodVersion_has_value_of_projectVersion_if_property_is_unset(@Nullable String projectVersion) { | |||
@UseDataProvider("emptyOrNullString") | |||
public void getProjectVersion_is_empty_if_property_is_empty_or_null(@Nullable String projectVersion) { | |||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | |||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | |||
underTest.start(); | |||
if (projectVersion == null) { | |||
assertThat(underTest.getCodePeriodVersion()).isEmpty(); | |||
} else { | |||
assertThat(underTest.getCodePeriodVersion()).contains(projectVersion); | |||
} | |||
assertThat(underTest.getProjectVersion()).isEmpty(); | |||
} | |||
@Test | |||
@UseDataProvider("projectVersions") | |||
public void getCodePeriodVersion_is_empty_if_property_is_empty(@Nullable String projectVersion) { | |||
public void getProjectVersion_contains_value_of_property() { | |||
String value = RandomStringUtils.randomAlphabetic(10); | |||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | |||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | |||
settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, ""); | |||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, value); | |||
underTest.start(); | |||
if (projectVersion == null) { | |||
assertThat(underTest.getCodePeriodVersion()).isEmpty(); | |||
} else { | |||
assertThat(underTest.getCodePeriodVersion()).contains(projectVersion); | |||
} | |||
assertThat(underTest.getProjectVersion()).contains(value); | |||
} | |||
@Test | |||
@UseDataProvider("projectVersions") | |||
public void getCodePeriodVersion_contains_value_of_property(@Nullable String projectVersion) { | |||
String version = RandomStringUtils.randomAlphabetic(10); | |||
@UseDataProvider("emptyOrNullString") | |||
public void getBuildString_is_empty_if_property_is_empty_or_null(@Nullable String buildString) { | |||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | |||
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion); | |||
settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, version); | |||
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString); | |||
underTest.start(); | |||
assertThat(underTest.getBuildString()).isEmpty(); | |||
} | |||
@Test | |||
public void getBuildString_contains_value_of_property() { | |||
String value = RandomStringUtils.randomAlphabetic(10); | |||
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); | |||
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, value); | |||
underTest.start(); | |||
assertThat(underTest.getCodePeriodVersion()).contains(version); | |||
assertThat(underTest.getBuildString()).contains(value); | |||
} | |||
@DataProvider | |||
public static Object[][] projectVersions() { | |||
public static Object[][] emptyOrNullString() { | |||
return new Object[][] { | |||
{""}, | |||
{null}, | |||
{randomAlphabetic(12)} | |||
}; | |||
} | |||
} |
@@ -215,33 +215,6 @@ public class MetadataPublisherTest { | |||
}; | |||
} | |||
@Test | |||
@UseDataProvider("codePeriodVersions") | |||
public void write_codePeriod_version(@Nullable String codePeriodVersion, String expected) throws Exception { | |||
when(projectInfo.getCodePeriodVersion()).thenReturn(Optional.ofNullable(codePeriodVersion)); | |||
when(properties.organizationKey()).thenReturn(Optional.of("SonarSource")); | |||
File outputDir = temp.newFolder(); | |||
ScannerReportWriter writer = new ScannerReportWriter(outputDir); | |||
underTest.publish(writer); | |||
ScannerReportReader reader = new ScannerReportReader(outputDir); | |||
ScannerReport.Metadata metadata = reader.readMetadata(); | |||
assertThat(metadata.getCodePeriodVersion()).isEqualTo(expected); | |||
} | |||
@DataProvider | |||
public static Object[][] codePeriodVersions() { | |||
String randomVersion = randomAlphabetic(15); | |||
return new Object[][] { | |||
{null, ""}, | |||
{"", ""}, | |||
{"5.6.3", "5.6.3"}, | |||
{randomVersion, randomVersion} | |||
}; | |||
} | |||
@Test | |||
@UseDataProvider("buildStrings") | |||
public void write_buildString(@Nullable String buildString, String expected) throws Exception { |
@@ -50,8 +50,7 @@ message Metadata { | |||
map<string, string> modules_project_relative_path_by_key = 15; | |||
string projectVersion = 16; | |||
string codePeriodVersion = 17; | |||
string buildString = 18; | |||
string buildString = 17; | |||
message QProfile { | |||
string key = 1; |
@@ -56,10 +56,9 @@ message Analysis { | |||
optional string key = 1; | |||
optional string date = 2; | |||
repeated Event events = 3; | |||
optional string codePeriodVersion = 4; | |||
optional string projectVersion = 5; | |||
optional string projectVersion = 4; | |||
optional string buildString = 5; | |||
optional bool manualNewCodePeriodBaseline = 6; | |||
optional string buildString = 7; | |||
} | |||
message QualityGate { |