Search in sources :

Example 11 with PluggableSCMMaterialConfig

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

the class ConfigConverterTest method shouldConvertPluggableScmMaterialWithIncludelist.

@Test
void shouldConvertPluggableScmMaterialWithIncludelist() {
    SCM myscm = new SCM("scmid", new PluginConfiguration(), new Configuration());
    SCMs scms = new SCMs(myscm);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setSCMs(scms);
    when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
    CRPluggableScmMaterial crPluggableScmMaterial = new CRPluggableScmMaterial("name", "scmid", "directory", filter, false);
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) configConverter.toMaterialConfig(crPluggableScmMaterial, context, scms);
    assertThat(pluggableSCMMaterialConfig.getName().toLower()).isEqualTo("name");
    assertThat(pluggableSCMMaterialConfig.getSCMConfig()).isEqualTo(myscm);
    assertThat(pluggableSCMMaterialConfig.getScmId()).isEqualTo("scmid");
    assertThat(pluggableSCMMaterialConfig.getFolder()).isEqualTo("directory");
    assertThat(pluggableSCMMaterialConfig.getFilterAsString()).isEqualTo("filter");
}
Also used : SCMs(com.thoughtworks.go.domain.scm.SCMs) SCM(com.thoughtworks.go.domain.scm.SCM) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 12 with PluggableSCMMaterialConfig

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

the class CruiseConfigTestBase method shouldReturnAllUniqueSchedulableScmMaterials.

@Test
public void shouldReturnAllUniqueSchedulableScmMaterials() {
    final MaterialConfig svnMaterialConfig = svn("http://svn_url_1", "username", "password", false);
    svnMaterialConfig.setAutoUpdate(false);
    final MaterialConfig svnMaterialConfigWithAutoUpdate = svn("http://svn_url_2", "username", "password", false);
    svnMaterialConfigWithAutoUpdate.setAutoUpdate(true);
    final MaterialConfig hgMaterialConfig = hg("http://hg_url", null);
    hgMaterialConfig.setAutoUpdate(false);
    final MaterialConfig gitMaterialConfig = git("http://git_url");
    gitMaterialConfig.setAutoUpdate(false);
    final MaterialConfig tfsMaterialConfig = tfs(mock(GoCipher.class), new UrlArgument("http://tfs_url"), "username", "domain", "password", "project_path");
    tfsMaterialConfig.setAutoUpdate(false);
    final MaterialConfig p4MaterialConfig = p4("http://p4_url", "view", "username");
    p4MaterialConfig.setAutoUpdate(false);
    final MaterialConfig dependencyMaterialConfig = MaterialConfigsMother.dependencyMaterialConfig();
    final PluggableSCMMaterialConfig pluggableSCMMaterialConfig = MaterialConfigsMother.pluggableSCMMaterialConfig("scm-id-1", null, null);
    pluggableSCMMaterialConfig.getSCMConfig().setAutoUpdate(false);
    final PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1", new MaterialConfigs(svnMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p2 = PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(svnMaterialConfig, gitMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p3 = PipelineConfigMother.pipelineConfig("pipeline3", new MaterialConfigs(hgMaterialConfig, dependencyMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p4 = PipelineConfigMother.pipelineConfig("pipeline4", new MaterialConfigs(p4MaterialConfig, pluggableSCMMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    final PipelineConfig p5 = PipelineConfigMother.pipelineConfig("pipeline5", new MaterialConfigs(svnMaterialConfigWithAutoUpdate, tfsMaterialConfig), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
    cruiseConfig.getGroups().add(new BasicPipelineConfigs(p1, p2, p3, p4, p5));
    final Set<MaterialConfig> materials = cruiseConfig.getAllUniquePostCommitSchedulableMaterials();
    assertThat(materials.size(), is(6));
    assertThat(materials, hasItems(svnMaterialConfig, hgMaterialConfig, gitMaterialConfig, tfsMaterialConfig, p4MaterialConfig, pluggableSCMMaterialConfig));
    assertThat(materials, not(hasItem(svnMaterialConfigWithAutoUpdate)));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GoCipher(com.thoughtworks.go.security.GoCipher) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) ScmMaterialConfig(com.thoughtworks.go.config.materials.ScmMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 13 with PluggableSCMMaterialConfig

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

the class CruiseConfigTestBase method shouldDecideIfPluggableSCMMaterialCanBeDeleted_BasedOnPluggableSCMMaterialBeingUsedByPipelines.

@Test
public void shouldDecideIfPluggableSCMMaterialCanBeDeleted_BasedOnPluggableSCMMaterialBeingUsedByPipelines() throws Exception {
    SCM scmConfigOne = SCMMother.create("scm-id-1");
    SCM scmConfigTwo = SCMMother.create("scm-id-2");
    cruiseConfig.getSCMs().addAll(Arrays.asList(scmConfigOne, scmConfigTwo));
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfig("pipeline");
    pipeline.addMaterialConfig(new PluggableSCMMaterialConfig(null, scmConfigOne, null, null, false));
    cruiseConfig.addPipeline("existing_group", pipeline);
    assertThat(cruiseConfig.canDeletePluggableSCMMaterial(scmConfigOne), is(false));
    assertThat(cruiseConfig.canDeletePluggableSCMMaterial(scmConfigTwo), is(true));
}
Also used : SCM(com.thoughtworks.go.domain.scm.SCM) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 14 with PluggableSCMMaterialConfig

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

the class MaterialRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, MaterialConfig materialConfig) {
    if (!materialConfig.errors().isEmpty()) {
        jsonWriter.addChild("errors", errorWriter -> {
            HashMap<String, String> errorMapping = new HashMap<>();
            errorMapping.put("materialName", "name");
            errorMapping.put("folder", "destination");
            errorMapping.put("autoUpdate", "auto_update");
            errorMapping.put("filterAsString", "filter");
            errorMapping.put("checkexternals", "check_externals");
            errorMapping.put("serverAndPort", "port");
            errorMapping.put("useTickets", "use_tickets");
            errorMapping.put("pipelineName", "pipeline");
            errorMapping.put("stageName", "stage");
            errorMapping.put("pipelineStageName", "pipeline");
            errorMapping.put("packageId", "ref");
            errorMapping.put("scmId", "ref");
            errorMapping.put("encryptedPassword", "encrypted_password");
            new ErrorGetter(errorMapping).toJSON(errorWriter, materialConfig);
        });
    }
    jsonWriter.add("type", classToTypeMap.get(materialConfig.getClass()));
    switch(classToTypeMap.get(materialConfig.getClass())) {
        case "git":
            jsonWriter.addChild("attributes", attributeWriter -> GitMaterialRepresenter.toJSON(attributeWriter, (GitMaterialConfig) materialConfig));
            break;
        case "hg":
            jsonWriter.addChild("attributes", attributeWriter -> HgMaterialRepresenter.toJSON(attributeWriter, (HgMaterialConfig) materialConfig));
            break;
        case "svn":
            jsonWriter.addChild("attributes", attributeWriter -> SvnMaterialRepresenter.toJSON(attributeWriter, (SvnMaterialConfig) materialConfig));
            break;
        case "p4":
            jsonWriter.addChild("attributes", attributeWriter -> PerforceMaterialRepresenter.toJSON(attributeWriter, (P4MaterialConfig) materialConfig));
            break;
        case "tfs":
            jsonWriter.addChild("attributes", attributeWriter -> TfsMaterialRepresenter.toJSON(attributeWriter, (TfsMaterialConfig) materialConfig));
            break;
        case "dependency":
            jsonWriter.addChild("attributes", attributeWriter -> DependencyMaterialRepresenter.toJSON(attributeWriter, (DependencyMaterialConfig) materialConfig));
            break;
        case "package":
            jsonWriter.addChild("attributes", attributeWriter -> PackageMaterialRepresenter.toJSON(attributeWriter, (PackageMaterialConfig) materialConfig));
            break;
        case "plugin":
            jsonWriter.addChild("attributes", attributeWriter -> PluggableScmMaterialRepresenter.toJSON(attributeWriter, (PluggableSCMMaterialConfig) materialConfig));
            break;
    }
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) HashMap(java.util.HashMap) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)

Example 15 with PluggableSCMMaterialConfig

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

the class PluggableScmMaterialRepresenter method fromJSON.

@Override
public PluggableSCMMaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) {
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig();
    CruiseConfig cruiseConfig = options.getCruiseConfig();
    if (cruiseConfig != null) {
        String ref = jsonReader.getString("ref");
        pluggableSCMMaterialConfig.setSCMConfig(cruiseConfig.getSCMs().find(ref));
        pluggableSCMMaterialConfig.setScmId(ref);
    }
    jsonReader.readStringIfPresent("destination", pluggableSCMMaterialConfig::setFolder);
    jsonReader.optJsonObject("filter").ifPresent(filterReader -> {
        pluggableSCMMaterialConfig.setFilter(FilterRepresenter.fromJSON(filterReader));
    });
    return pluggableSCMMaterialConfig;
}
Also used : CruiseConfig(com.thoughtworks.go.config.CruiseConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)

Aggregations

PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)36 Test (org.junit.jupiter.api.Test)25 SCM (com.thoughtworks.go.domain.scm.SCM)14 SCMs (com.thoughtworks.go.domain.scm.SCMs)11 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)8 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)7 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)5 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)4 GoConfigHolder (com.thoughtworks.go.config.GoConfigHolder)3 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)3 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)3 ErrorGetter (com.thoughtworks.go.api.representers.ErrorGetter)2 Filter (com.thoughtworks.go.config.materials.Filter)2