Search in sources :

Example 6 with SCMRevision

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");
}
Also used : SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Result(com.thoughtworks.go.plugin.api.response.Result) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)

Example 7 with SCMRevision

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);
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 8 with SCMRevision

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"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 9 with SCMRevision

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));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 10 with SCMRevision

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"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)22 Test (org.junit.Test)16 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)15 File (java.io.File)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 ModifiedFile (com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile)7 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)5 Date (java.util.Date)4 Map (java.util.Map)4 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 Result (com.thoughtworks.go.plugin.api.response.Result)3 SimpleDateFormat (java.text.SimpleDateFormat)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)2