Search in sources :

Example 56 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 57 with PluggableSCMMaterial

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

the class MaterialInstanceTest method shouldAnswerRequiresUpdate.

@Test
public void shouldAnswerRequiresUpdate() {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    // null
    materialInstance.setAdditionalData(null);
    assertThat(materialInstance.requiresUpdate(null), is(false));
    assertThat(materialInstance.requiresUpdate(new HashMap<>()), is(false));
    // empty
    materialInstance.setAdditionalData(JsonHelper.toJsonString(new HashMap<String, String>()));
    assertThat(materialInstance.requiresUpdate(null), is(false));
    assertThat(materialInstance.requiresUpdate(new HashMap<>()), is(false));
    // with data
    Map<String, String> data = new HashMap<>();
    data.put("k1", "v1");
    data.put("k2", "v2");
    materialInstance.setAdditionalData(JsonHelper.toJsonString(data));
    assertThat(materialInstance.requiresUpdate(null), is(true));
    assertThat(materialInstance.requiresUpdate(new HashMap<>()), is(true));
    assertThat(materialInstance.requiresUpdate(data), is(false));
    // missing key-value
    Map<String, String> dataWithMissingKey = new HashMap<>(data);
    dataWithMissingKey.remove("k1");
    assertThat(materialInstance.requiresUpdate(dataWithMissingKey), is(true));
    // extra key-value
    Map<String, String> dataWithExtraKey = new HashMap<>(data);
    dataWithExtraKey.put("k3", "v3");
    assertThat(materialInstance.requiresUpdate(dataWithExtraKey), is(true));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 58 with PluggableSCMMaterial

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

the class PluggableSCMPostCommitHookImplementer method prune.

@Override
public Set<Material> prune(Set<Material> materials, Map params) {
    HashSet<Material> prunedCollection = new HashSet<>();
    String paramSCMName = (String) params.get(SCM_NAME);
    if (StringUtils.isNotBlank(paramSCMName)) {
        for (Material material : materials) {
            if (material instanceof PluggableSCMMaterial && paramSCMName.equalsIgnoreCase(((PluggableSCMMaterial) material).getScmConfig().getName())) {
                prunedCollection.add(material);
            }
        }
    }
    return prunedCollection;
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) Material(com.thoughtworks.go.domain.materials.Material) HashSet(java.util.HashSet)

Example 59 with PluggableSCMMaterial

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

the class JsonMessageHandler2_0_Test method createPipeline.

private Pipeline createPipeline() throws Exception {
    Pipeline pipeline = PipelineMother.pipelineWithAllTypesOfMaterials("pipeline-name", "stage-name", "job-name", "1");
    List<MaterialRevision> materialRevisions = pipeline.getMaterialRevisions().getRevisions();
    PackageDefinition packageDefinition = ((PackageMaterial) materialRevisions.get(6).getMaterial()).getPackageDefinition();
    packageDefinition.getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true);
    packageDefinition.getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false);
    packageDefinition.getConfiguration().get(1).handleSecureValueConfiguration(true);
    SCM scm = ((PluggableSCMMaterial) materialRevisions.get(7).getMaterial()).getScmConfig();
    scm.getConfiguration().get(1).handleSecureValueConfiguration(true);
    Stage stage = pipeline.getFirstStage();
    stage.setId(1L);
    stage.setPipelineId(1L);
    stage.setCreatedTime(new Timestamp(getFixedDate().getTime()));
    stage.setLastTransitionedTime(new Timestamp(getFixedDate().getTime()));
    JobInstance job = stage.getJobInstances().get(0);
    job.setScheduledDate(getFixedDate());
    job.getTransition(JobState.Assigned).setStateChangeTime(getFixedDate());
    job.getTransition(JobState.Completed).setStateChangeTime(getFixedDate());
    return pipeline;
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) SCM(com.thoughtworks.go.domain.scm.SCM) Timestamp(java.sql.Timestamp)

Example 60 with PluggableSCMMaterial

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

the class PluggableSCMMaterialInstance method toOldMaterial.

@Override
public Material toOldMaterial(String name, String folder, String password) {
    PluggableSCMMaterial pluggableSCMMaterial = JsonHelper.fromJson(configuration, PluggableSCMMaterial.class);
    pluggableSCMMaterial.setName(new CaseInsensitiveString(name));
    pluggableSCMMaterial.setId(id);
    pluggableSCMMaterial.setFolder(folder);
    pluggableSCMMaterial.setFingerprint(getFingerprint());
    return pluggableSCMMaterial;
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)64 Test (org.junit.Test)55 SCM (com.thoughtworks.go.domain.scm.SCM)25 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 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)6 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)6 Map (java.util.Map)6 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