Map<String, ScannerPlugin> getScannerPluginsByKey();
/**
- * Scm Revision id of the analysed code
+ * Scm Revision of the analysed code
*/
- Optional<String> getScmRevisionId();
+ Optional<String> getScmRevision();
}
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import static org.apache.commons.lang.StringUtils.defaultIfBlank;
public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
private static final String BRANCH_NOT_SET = "Branch has not been set";
private final InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
private final InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>();
private final InitializedProperty<Map<String, ScannerPlugin>> pluginsByKey = new InitializedProperty<>();
- private final InitializedProperty<String> scmRevisionId = new InitializedProperty<>();
+ private final InitializedProperty<String> scmRevision = new InitializedProperty<>();
@Override
public MutableAnalysisMetadataHolder setOrganizationsEnabled(boolean isOrganizationsEnabled) {
}
@Override
- public MutableAnalysisMetadataHolder setScmRevisionId(String scmRevisionId) {
- checkState(!this.scmRevisionId.isInitialized(), "ScmRevisionId has already been set");
- this.scmRevisionId.setProperty(scmRevisionId);
+ public MutableAnalysisMetadataHolder setScmRevision(@Nullable String s) {
+ checkState(!this.scmRevision.isInitialized(), "ScmRevision has already been set");
+ this.scmRevision.setProperty(defaultIfBlank(s, null));
return this;
}
@Override
- public Optional<String> getScmRevisionId() {
- if (!scmRevisionId.isInitialized()) {
+ public Optional<String> getScmRevision() {
+ if (!scmRevision.isInitialized()) {
return Optional.empty();
}
- return Optional.of(scmRevisionId.getProperty());
+ return Optional.ofNullable(scmRevision.getProperty());
}
@Override
/**
* @throws IllegalStateException if scm revision id has already been set
*/
- MutableAnalysisMetadataHolder setScmRevisionId(String scmRevisionId);
+ MutableAnalysisMetadataHolder setScmRevision(String scmRevisionId);
}
Long analysisDate = getAnalysisDate();
if (analysisDate != null) {
- return of(new AnalysisImpl(analysisMetadataHolder.getUuid(), analysisDate, analysisMetadataHolder.getScmRevisionId()));
+ return of(new AnalysisImpl(analysisMetadataHolder.getUuid(), analysisDate, analysisMetadataHolder.getScmRevision()));
}
return empty();
}
analysisMetadata.setAnalysisDate(reportMetadata.getAnalysisDate());
analysisMetadata.setRootComponentRef(reportMetadata.getRootComponentRef());
analysisMetadata.setCrossProjectDuplicationEnabled(reportMetadata.getCrossProjectDuplicationActivated());
- analysisMetadata.setScmRevisionId(reportMetadata.getScmRevisionId());
+ analysisMetadata.setScmRevision(reportMetadata.getScmRevisionId());
}
/**
*/
package org.sonar.ce.task.projectanalysis.analysis;
-import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
}
@Test
- public void setScmRevisionId_throws_ISE_when_called_twice() {
+ public void setScmRevision_throws_ISE_when_called_twice() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setScmRevisionId("scm_revision_id1");
+ underTest.setScmRevision("bd56dab");
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("ScmRevisionId has already been set");
- underTest.setScmRevisionId("scm_revision_id1");
+ expectedException.expectMessage("ScmRevision has already been set");
+ underTest.setScmRevision("bd56dab");
}
@Test
- public void getScmRevisionId_returns_empty_if_scmRevisionId_is_not_initialized() {
+ public void getScmRevision_returns_empty_if_scmRevision_is_not_initialized() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- assertThat(underTest.getScmRevisionId()).isNotPresent();
+ assertThat(underTest.getScmRevision()).isNotPresent();
}
@Test
- public void getScmRevisionId_returns_scmRevisionId_if_scmRevisionId_is_initialized() {
+ public void getScmRevision_returns_scmRevision_if_scmRevision_is_initialized() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setScmRevisionId("scm_revision_id");
- assertThat(underTest.getScmRevisionId()).isEqualTo(Optional.of("scm_revision_id"));
+ underTest.setScmRevision("bd56dab");
+ assertThat(underTest.getScmRevision()).hasValue("bd56dab");
+ }
+
+ @Test
+ public void getScmRevision_does_not_return_empty_string() {
+ AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+ underTest.setScmRevision("");
+ assertThat(underTest.getScmRevision()).isEmpty();
+ }
+
+ @Test
+ public void getScmRevision_does_not_return_blank_string() {
+ AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+ underTest.setScmRevision(" ");
+ assertThat(underTest.getScmRevision()).isEmpty();
}
}
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import static org.apache.commons.lang.StringUtils.defaultIfBlank;
public class AnalysisMetadataHolderRule extends ExternalResource implements MutableAnalysisMetadataHolder {
private final InitializedProperty<Map<String, ScannerPlugin>> pluginsByKey = new InitializedProperty<>();
- private final InitializedProperty<String> scmRevisionId = new InitializedProperty<>();
+ private final InitializedProperty<String> scmRevision = new InitializedProperty<>();
@Override
public AnalysisMetadataHolderRule setOrganizationsEnabled(boolean isOrganizationsEnabled) {
}
@Override
- public MutableAnalysisMetadataHolder setScmRevisionId(String scmRevisionId) {
- checkState(!this.scmRevisionId.isInitialized(), "ScmRevisionId has already been set");
- this.scmRevisionId.setProperty(scmRevisionId);
+ public MutableAnalysisMetadataHolder setScmRevision(@Nullable String s) {
+ checkState(!this.scmRevision.isInitialized(), "ScmRevisionId has already been set");
+ this.scmRevision.setProperty(defaultIfBlank(s, null));
return this;
}
@Override
- public Optional<String> getScmRevisionId() {
- if (!scmRevisionId.isInitialized()) {
+ public Optional<String> getScmRevision() {
+ if (!scmRevision.isInitialized()) {
return Optional.empty();
}
- return Optional.of(scmRevisionId.getProperty());
+ return Optional.ofNullable(scmRevision.getProperty());
}
@Override
@Override
- public MutableAnalysisMetadataHolder setScmRevisionId(String scmRevisionId) {
- delegate.setScmRevisionId(scmRevisionId);
+ public MutableAnalysisMetadataHolder setScmRevision(String scmRevisionId) {
+ delegate.setScmRevision(scmRevisionId);
return this;
}
@Override
- public Optional<String> getScmRevisionId() {
- return delegate.getScmRevisionId();
+ public Optional<String> getScmRevision() {
+ return delegate.getScmRevision();
}
@Override
public void persist_should_stores_sonarDotAnalysisDot_and_sonarDotPullRequestDot_properties() {
when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(PROPERTIES.iterator()));
when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);
- when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID));
+ when(analysisMetadataHolder.getScmRevision()).thenReturn(Optional.of(SCM_REV_ID));
underTest.execute(new TestComputationStepContext());
@Test
public void persist_filtering_of_properties_is_case_sensitive() {
- when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID));
+ when(analysisMetadataHolder.getScmRevision()).thenReturn(Optional.of(SCM_REV_ID));
when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(ImmutableList.of(
newContextProperty("sonar.ANALYSIS.foo", "foo"),
newContextProperty("sonar.anaLysis.bar", "bar"),
@Test
public void persist_should_store_nothing_if_there_are_no_context_properties() {
- when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID));
+ when(analysisMetadataHolder.getScmRevision()).thenReturn(Optional.of(SCM_REV_ID));
when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.emptyCloseableIterator());
when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);
analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
analysisMetadataHolder.setUuid(ANALYSIS_UUID);
analysisMetadataHolder.setAnalysisDate(analysisDate);
- analysisMetadataHolder.setScmRevisionId(REVISION_ID);
+ analysisMetadataHolder.setScmRevision(REVISION_ID);
dbIdsRepository = new DbIdsRepositoryImpl();
now = DateUtils.parseDateQuietly("2015-06-02").getTime();
* @deprecated in 7.8, replaced by {@code Analysis#getRevision()}
* @see #getAnalysis()
*/
+ @Deprecated
String getScmRevisionId();
}
}