use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class AbstractMaterialTestController method testConnection.
public String testConnection(Request request, Response response) {
JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
String type = jsonReader.getString("type");
String pipelineName = jsonReader.getStringOrDefault("pipeline_name", "");
String pipelineGroupName = jsonReader.getStringOrDefault("pipeline_group", "");
haltIfMaterialTypeIsInvalid(type);
haltIfMaterialTypeDoesNotSupportsCheckConnection(type);
ScmMaterialConfig scmMaterialConfig = buildSCMMaterialFromRequestBody(request);
validateMaterialConfig(scmMaterialConfig, pipelineName, pipelineGroupName);
if (!scmMaterialConfig.errors().isEmpty()) {
List<String> errorsList = new ArrayList<>();
scmMaterialConfig.errors().forEach((key, errors) -> errorsList.add(String.format("- %s: %s", key, StringUtils.join(errors, ", "))));
response.status(422);
return MessageJson.create(String.format("There was an error with the material configuration.\n%s", StringUtils.join(errorsList, "\n")), jsonWriter(scmMaterialConfig));
}
performParamExpansion(scmMaterialConfig, pipelineName);
Material material = materialConfigConverter.toMaterial(scmMaterialConfig);
resolveSecrets(pipelineGroupName, material);
ValidationBean validationBean = material.checkConnection(new CheckConnectionSubprocessExecutionContext(systemEnvironment));
return handleValidationBeanResponse(validationBean, response);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MaterialXmlRepresenter method populate.
public final void populate(ElementBuilder builder, XmlWriterContext ctx) {
Material material = materialRevision.getMaterial();
builder.node("material", materialBuilder -> populateMaterial(ctx, material, materialBuilder));
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class PipelineConfigDependencyGraph method isRevisionsOfSharedMaterialsIgnored.
public boolean isRevisionsOfSharedMaterialsIgnored(MaterialRevisions revisions) {
MaterialConfigs unsharedScmMaterialConfigs = unsharedMaterialConfigs();
List<PipelineConfigQueueEntry> queue = new ArrayList<>(buildQueue());
for (MaterialRevision revision : revisions) {
Material material = revision.getMaterial();
MaterialConfig materialConfig = material.config();
if (unsharedScmMaterialConfigs.hasMaterialWithFingerprint(materialConfig) || revision.isDependencyMaterialRevision()) {
continue;
}
if (isThisMaterialIgnored(queue, revision, materialConfig)) {
return true;
}
}
return false;
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class ConfigRepositoryInitializerTest method shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain.
@Test
void shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain() {
GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
File folder = new File("repo-folder");
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
// config changes..
configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class ConfigRepositoryInitializerTest method shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded.
@Test
void shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded() {
// add another config repo using another plugin id
ConfigRepoConfig repoConfig2 = new ConfigRepoConfig();
repoConfig2.setId("repo2");
repoConfig2.setPluginId(JSON_PLUGIN_ID);
repoConfig2.setRepo(MaterialConfigsMother.git("git-repo"));
repoConfigs.add(repoConfig2);
GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
File folder = new File("repo-folder");
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
// initialize config
configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
// load yaml plugin
configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
// verify the config repo is initialized once all the in use plugins are loaded
verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
// load json plugin
configRepositoryInitializer.pluginLoaded(jsonPluginDescriptor);
// verify the config repo is initialized once all the in use plugins are loaded
verify(goConfigRepoConfigDataSource, times(2)).onCheckoutComplete(gitMaterialConfig, folder, modification);
// load groovy plugin
configRepositoryInitializer.pluginLoaded(groovyPluginDescriptor);
// verify nothing happens on more plugin load
verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Aggregations