Search in sources :

Example 26 with PluggableSCMMaterial

use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.

the class PluggableSCMMaterialAgent method prepare.

@Override
public void prepare() {
    PluggableSCMMaterial material = (PluggableSCMMaterial) revision.getMaterial();
    Modification latestModification = revision.getLatestModification();
    SCMRevision scmRevision = new SCMRevision(latestModification.getRevision(), latestModification.getModifiedTime(), null, null, latestModification.getAdditionalDataMap(), null);
    File destinationFolder = material.workingDirectory(workingDirectory);
    Result result = scmExtension.checkout(material.getScmConfig().getPluginConfiguration().getId(), buildSCMPropertyConfigurations(material.getScmConfig()), destinationFolder.getAbsolutePath(), scmRevision);
    if (!result.isSuccessful()) {
    // handle
    }
// handle messages
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) File(java.io.File) Result(com.thoughtworks.go.plugin.api.response.Result)

Example 27 with PluggableSCMMaterial

use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.

the class PluggableSCMMaterialAgentTest method shouldTalkToPluginCheckoutForPrepare.

@Test
public void shouldTalkToPluginCheckoutForPrepare() {
    PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
    pluggableSCMMaterial.setFolder("destination-folder");
    Modification modification = ModificationsMother.oneModifiedFile("r1");
    Map<String, String> additionalData = new HashMap<>();
    additionalData.put("a1", "v1");
    additionalData.put("a2", "v2");
    modification.setAdditionalData(new Gson().toJson(additionalData));
    MaterialRevision revision = new MaterialRevision(pluggableSCMMaterial, modification);
    String pipelineFolder = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
    String destinationFolder = new File(pipelineFolder, "destination-folder").getAbsolutePath();
    PluggableSCMMaterialAgent pluggableSCMMaterialAgent = new PluggableSCMMaterialAgent(scmExtension, revision, new File(pipelineFolder));
    when(scmExtension.checkout(eq("pluginid"), scmConfiguration.capture(), eq(destinationFolder), scmRevision.capture())).thenReturn(new Result());
    pluggableSCMMaterialAgent.prepare();
    verify(scmExtension).checkout(any(String.class), any(SCMPropertyConfiguration.class), any(String.class), any(SCMRevision.class));
    assertThat(scmConfiguration.getValue().size(), is(2));
    assertThat(scmConfiguration.getValue().get("k1").getValue(), is("v1"));
    assertThat(scmConfiguration.getValue().get("k2").getValue(), is("v2"));
    assertThat(scmRevision.getValue().getRevision(), is("r1"));
    assertThat(scmRevision.getValue().getTimestamp(), is(modification.getModifiedTime()));
    assertThat(scmRevision.getValue().getData().size(), is(2));
    assertThat(scmRevision.getValue().getDataFor("a1"), is("v1"));
    assertThat(scmRevision.getValue().getDataFor("a2"), is("v2"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Gson(com.google.gson.Gson) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) File(java.io.File) Result(com.thoughtworks.go.plugin.api.response.Result) Test(org.junit.Test)

Example 28 with PluggableSCMMaterial

use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.

the class PluggableSCMMaterialInstanceTest method shouldCorrectlyCopyConfigurationValue.

@Test
public void shouldCorrectlyCopyConfigurationValue() {
    PluggableSCMMaterialInstance materialInstance = (PluggableSCMMaterialInstance) MaterialsMother.pluggableSCMMaterial().createMaterialInstance();
    materialInstance.setId(10L);
    PluggableSCMMaterial latestMaterial = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1"));
    PluggableSCMMaterialInstance newPluggableSCMMaterialInstance = (PluggableSCMMaterialInstance) latestMaterial.createMaterialInstance();
    materialInstance.upgradeTo(newPluggableSCMMaterialInstance);
    assertThat(materialInstance.getId(), is(10L));
    assertThat(materialInstance.getConfiguration(), is(newPluggableSCMMaterialInstance.getConfiguration()));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) Test(org.junit.Test)

Example 29 with PluggableSCMMaterial

use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.

the class PluggableSCMMaterialInstanceTest method shouldConvertMaterialInstanceToMaterial.

@Test
public void shouldConvertMaterialInstanceToMaterial() {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    SCM scmConfig = material.getScmConfig();
    PluggableSCMMaterialInstance materialInstance = new PluggableSCMMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
    materialInstance.setId(1L);
    PluggableSCMMaterial constructedMaterial = (PluggableSCMMaterial) materialInstance.toOldMaterial(null, null, null);
    assertThat(constructedMaterial.getId(), is(1L));
    assertThat(constructedMaterial.getScmConfig().getPluginConfiguration().getId(), is(scmConfig.getPluginConfiguration().getId()));
    assertThat(constructedMaterial.getScmConfig().getConfiguration(), is(scmConfig.getConfiguration()));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.Test)

Example 30 with PluggableSCMMaterial

use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.

the class PluggableSCMMaterialInstanceTest method shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial.

@Test
public void shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial() {
    String fingerprint = "fingerprint";
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    PluggableSCMMaterialInstance materialInstance = new PluggableSCMMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
    ReflectionUtil.setField(materialInstance, "fingerprint", fingerprint);
    materialInstance.setId(1L);
    PluggableSCMMaterial constructedMaterial = (PluggableSCMMaterial) materialInstance.toOldMaterial(null, null, null);
    assertThat(constructedMaterial.getFingerprint(), is(fingerprint));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) Test(org.junit.Test)

Aggregations

PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)63 Test (org.junit.Test)55 SCM (com.thoughtworks.go.domain.scm.SCM)24 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)18 File (java.io.File)13 Modification (com.thoughtworks.go.domain.materials.Modification)11 Modifications (com.thoughtworks.go.domain.materials.Modifications)10 Date (java.util.Date)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)9 HashMap (java.util.HashMap)8 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)7 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)7 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)7 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)6 Map (java.util.Map)6 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)5 Material (com.thoughtworks.go.domain.materials.Material)5 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)5 LinkedHashMap (java.util.LinkedHashMap)5 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)4