use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPoller method checkout.
@Override
public void checkout(PluggableSCMMaterial material, File baseDir, Revision revision, SubprocessExecutionContext execCtx) {
SCMPropertyConfiguration scmPropertyConfiguration = buildSCMPropertyConfigurations(material.getScmConfig());
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
PluggableSCMMaterialRevision pluggableSCMMaterialRevision = (PluggableSCMMaterialRevision) revision;
SCMRevision scmRevision = new SCMRevision(pluggableSCMMaterialRevision.getRevision(), pluggableSCMMaterialRevision.getTimestamp(), null, null, pluggableSCMMaterialRevision.getData(), null);
Result result = scmExtension.checkout(material.getPluginId(), scmPropertyConfiguration, baseDir.getAbsolutePath(), scmRevision);
if (!result.isSuccessful())
throw new RuntimeException("Failed to perform checkout on pluggable SCM");
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPoller method modificationsSince.
@Override
public List<Modification> modificationsSince(final PluggableSCMMaterial material, File baseDir, final Revision revision, SubprocessExecutionContext execCtx) {
SCMPropertyConfiguration scmPropertyConfiguration = buildSCMPropertyConfigurations(material.getScmConfig());
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
PluggableSCMMaterialRevision pluggableSCMMaterialRevision = (PluggableSCMMaterialRevision) revision;
SCMRevision previouslyKnownRevision = new SCMRevision(pluggableSCMMaterialRevision.getRevision(), pluggableSCMMaterialRevision.getTimestamp(), null, null, pluggableSCMMaterialRevision.getData(), null);
MaterialPollResult pollResult = scmExtension.latestModificationSince(material.getPluginId(), scmPropertyConfiguration, materialInstance.getAdditionalDataMap(), baseDir.getAbsolutePath(), previouslyKnownRevision);
final Map<String, String> materialData = pollResult.getMaterialData();
if (materialInstance.requiresUpdate(materialData)) {
updateAdditionalData(materialInstance.getId(), materialData);
}
List<SCMRevision> scmRevisions = pollResult.getRevisions();
return getModifications(scmRevisions);
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPollerTest method shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromTheSCMRevision.
@Test
public void shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromTheSCMRevision() {
String previousRevision = "rev-122";
Date timestamp = new Date();
Map<String, String> dataInPreviousRevision = new HashMap<>();
dataInPreviousRevision.put("1", "one");
PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision(previousRevision, timestamp, dataInPreviousRevision);
ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
Map<String, String> data = new HashMap<>();
String dataKey = "2";
String dataValue = "two";
data.put(dataKey, dataValue);
SCMRevision latestRevision = new SCMRevision("rev-123", timestamp, "user", "comment-123", data, null);
MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(latestRevision));
when(scmExtension.latestModificationSince(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath), knownSCMRevision.capture())).thenReturn(materialPollResult);
List<Modification> modifications = poller.modificationsSince(material, new File(flyweightFolderPath), knownRevision, null);
assertThat(knownSCMRevision.getValue().getRevision(), is(previousRevision));
assertThat(knownSCMRevision.getValue().getTimestamp(), is(timestamp));
assertThat(knownSCMRevision.getValue().getData(), is(notNullValue()));
assertThat(knownSCMRevision.getValue().getData().size(), is(dataInPreviousRevision.size()));
assertThat(knownSCMRevision.getValue().getData().get("1"), is(dataInPreviousRevision.get("1")));
HashMap<String, String> expected = new HashMap<>();
expected.put(dataKey, dataValue);
Modification firstModification = modifications.get(0);
assertThat(firstModification.getRevision(), is("rev-123"));
assertThat(firstModification.getModifiedTime(), is(timestamp));
assertThat(firstModification.getUserName(), is("user"));
assertThat(firstModification.getComment(), is("comment-123"));
assertThat(firstModification.getAdditionalData(), is(JsonHelper.toJsonString(expected)));
assertThat(firstModification.getModifiedFiles().isEmpty(), is(true));
assertThat(materialData.getValue().size(), is(1));
assertThat(materialData.getValue().get("mk-1"), is("mv-1"));
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPollerTest method shouldReturnEmptyModificationWhenSCMRevisionIsNullFor_latestModificationSince.
@Test
public void shouldReturnEmptyModificationWhenSCMRevisionIsNullFor_latestModificationSince() {
PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision("rev-122", new Date());
ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
when(scmExtension.latestModificationSince(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath), knownSCMRevision.capture())).thenReturn(new MaterialPollResult());
List<Modification> modifications = poller.modificationsSince(material, new File(flyweightFolderPath), knownRevision, null);
assertThat(modifications, is(notNullValue()));
assertThat(modifications.isEmpty(), is(true));
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetModificationsSinceAGivenRevision.
@Test
public void shouldTalkToPlugInToGetModificationsSinceAGivenRevision() {
Date timestamp = new Date();
PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision("rev-122", timestamp);
ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
SCMRevision latestRevision = new SCMRevision("rev-123", timestamp, "user", null, null, null);
MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(latestRevision));
when(scmExtension.latestModificationSince(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath), knownSCMRevision.capture())).thenReturn(materialPollResult);
List<Modification> modifications = poller.modificationsSince(material, new File(flyweightFolderPath), knownRevision, null);
assertThat(modifications.get(0).getRevision(), is("rev-123"));
assertThat(modifications.get(0).getModifiedTime(), is(timestamp));
assertThat(modifications.get(0).getUserName(), is("user"));
assertThat(modifications.get(0).getComment(), is(nullValue()));
assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
assertThat(knownSCMRevision.getValue().getRevision(), is("rev-122"));
assertThat(knownSCMRevision.getValue().getTimestamp(), is(timestamp));
assertThat(materialData.getValue().size(), is(1));
assertThat(materialData.getValue().get("mk-1"), is("mv-1"));
}
Aggregations