use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldConvertPluggableScmMaterialWithNewSCMPluginVersionShouldDefaultToEmptyString.
@Test
void shouldConvertPluggableScmMaterialWithNewSCMPluginVersionShouldDefaultToEmptyString() {
SCM s = new SCM("an_id", new PluginConfiguration(), new Configuration());
s.setName("aname");
SCMs scms = new SCMs(s);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setSCMs(scms);
when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
Configuration config = new Configuration();
config.addNewConfigurationWithValue("url", "url", false);
SCM myscm = new SCM("scmid", new PluginConfiguration("plugin_id", ""), config);
myscm.setName("name");
CRPluggableScmMaterial crPluggableScmMaterial = new CRPluggableScmMaterial("name", "scmid", "directory", filter, false);
crPluggableScmMaterial.setPluginConfiguration(new CRPluginConfiguration("plugin_id", null));
crPluggableScmMaterial.getConfiguration().add(new CRConfigurationProperty("url", "url"));
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");
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class GoConfigServiceTest method shouldBeAbleToListAllSCMMaterialConfigs.
@Test
public void shouldBeAbleToListAllSCMMaterialConfigs() {
BasicCruiseConfig config = mock(BasicCruiseConfig.class);
DependencyMaterialConfig dependencyMaterialConfig = MaterialConfigsMother.dependencyMaterialConfig();
SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig();
PluggableSCMMaterialConfig pluggableSCMMaterialConfig = MaterialConfigsMother.pluggableSCMMaterialConfig();
HashSet<MaterialConfig> materialConfigs = new HashSet<>(Arrays.asList(dependencyMaterialConfig, svnMaterialConfig, pluggableSCMMaterialConfig));
when(goConfigService.getCurrentConfig()).thenReturn(config);
when(config.getAllUniqueMaterialsBelongingToAutoPipelinesAndConfigRepos()).thenReturn(materialConfigs);
Set<MaterialConfig> schedulableDependencyMaterials = goConfigService.getSchedulableSCMMaterials();
assertThat(schedulableDependencyMaterials.size(), is(2));
assertTrue(schedulableDependencyMaterials.contains(svnMaterialConfig));
assertTrue(schedulableDependencyMaterials.contains(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;
}
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;
}
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig in project gocd by gocd.
the class PluggableScmMaterialRepresenter method fromJSON.
public static 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;
}
Aggregations