use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigValidationTest method shouldAllowDependenciesFromMultiplePipelinesToTheSamePipeline.
@Test
public void shouldAllowDependenciesFromMultiplePipelinesToTheSamePipeline() throws Exception {
pipeline.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage")));
PipelineConfig pipeline3 = config.pipelineConfigByName(new CaseInsensitiveString("pipeline3"));
pipeline3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage")));
pipeline.validate(validationContext);
assertThat(pipeline.errors().isEmpty(), is(true));
pipeline3.validate(validationContext);
assertThat(pipeline3.errors().isEmpty(), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class FetchTask method validatePathFromAncestor.
private void validatePathFromAncestor(PipelineConfig currentPipeline, ValidationContext validationContext) {
List<CaseInsensitiveString> parentPipelineNames = pipelineName.pathIncludingAncestor();
PipelineConfig pipeline = currentPipeline;
CaseInsensitiveString dependencyStage = null;
for (CaseInsensitiveString parentPipelineName : parentPipelineNames) {
if (validationContext.getPipelineConfigByName(parentPipelineName) == null) {
addError(FetchTask.PIPELINE_NAME, String.format("Pipeline named '%s' which is declared ancestor of '%s' through path '%s' does not exist.", parentPipelineName, currentPipeline.name(), pipelineName.getPath()));
return;
}
DependencyMaterialConfig matchingDependencyMaterial = findMatchingDependencyMaterial(pipeline, parentPipelineName);
if (matchingDependencyMaterial != null) {
dependencyStage = matchingDependencyMaterial.getStageName();
pipeline = validationContext.getPipelineConfigByName(matchingDependencyMaterial.getPipelineName());
} else {
addError(FetchTask.PIPELINE_NAME, String.format("Pipeline named '%s' exists, but is not an ancestor of '%s' as declared in '%s'.", parentPipelineName, currentPipeline.name(), pipelineName.getPath()));
return;
}
}
boolean foundStageAtOrBeforeDependency = dependencyStage.equals(stage);
if (!foundStageAtOrBeforeDependency) {
for (StageConfig stageConfig : pipeline.allStagesBefore(dependencyStage)) {
foundStageAtOrBeforeDependency = stage.equals(stageConfig.name());
if (foundStageAtOrBeforeDependency) {
break;
}
}
}
if (!foundStageAtOrBeforeDependency) {
addStageMayNotCompleteBeforeDownstreamError(currentPipeline, validationContext);
}
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class BasicCruiseConfig method generatePipelineVsDownstreamMap.
@Override
public Map<String, List<PipelineConfig>> generatePipelineVsDownstreamMap() {
List<PipelineConfig> pipelineConfigs = getAllPipelineConfigs();
Map<String, List<PipelineConfig>> result = new HashMap<>();
for (PipelineConfig currentPipeline : pipelineConfigs) {
String currentPipelineName = currentPipeline.name().toString();
if (!result.containsKey(currentPipelineName)) {
result.put(currentPipelineName, new ArrayList<>());
}
for (MaterialConfig materialConfig : currentPipeline.materialConfigs()) {
if (materialConfig instanceof DependencyMaterialConfig) {
String pipelineWhichTriggersMe = ((DependencyMaterialConfig) materialConfig).getPipelineName().toString();
if (!result.containsKey(pipelineWhichTriggersMe)) {
result.put(pipelineWhichTriggersMe, new ArrayList<>());
}
result.get(pipelineWhichTriggersMe).add(currentPipeline);
}
}
}
return result;
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class BasicCruiseConfig method getStagesUsedAsMaterials.
@Override
public Set<StageConfig> getStagesUsedAsMaterials(PipelineConfig pipelineConfig) {
Set<String> stagesUsedAsMaterials = new HashSet<>();
for (MaterialConfig materialConfig : getAllUniqueMaterials()) {
if (materialConfig instanceof DependencyMaterialConfig) {
DependencyMaterialConfig dep = (DependencyMaterialConfig) materialConfig;
stagesUsedAsMaterials.add(dep.getPipelineName() + "|" + dep.getStageName());
}
}
Set<StageConfig> stages = new HashSet<>();
for (StageConfig stage : pipelineConfig) {
if (stagesUsedAsMaterials.contains(pipelineConfig.name() + "|" + stage.name())) {
stages.add(stage);
}
}
return stages;
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class BasicCruiseConfig method getUniqueMaterials.
private Set<MaterialConfig> getUniqueMaterials(boolean ignoreManualPipelines, boolean ignoreConfigRepos) {
Set<MaterialConfig> materialConfigs = new HashSet<>();
Set<Map> uniqueMaterials = new HashSet<>();
for (PipelineConfig pipelineConfig : pipelinesFromAllGroups()) {
for (MaterialConfig materialConfig : pipelineConfig.materialConfigs()) {
if (!uniqueMaterials.contains(materialConfig.getSqlCriteria())) {
boolean shouldSkipPolling = !materialConfig.isAutoUpdate();
boolean scmOrPackageMaterial = !(materialConfig instanceof DependencyMaterialConfig);
if (ignoreManualPipelines && scmOrPackageMaterial && shouldSkipPolling) {
continue;
}
materialConfigs.add(materialConfig);
uniqueMaterials.add(materialConfig.getSqlCriteria());
}
}
}
if (!ignoreConfigRepos) {
for (ConfigRepoConfig configRepo : this.configRepos) {
MaterialConfig materialConfig = configRepo.getMaterialConfig();
if (!uniqueMaterials.contains(materialConfig.getSqlCriteria())) {
materialConfigs.add(materialConfig);
uniqueMaterials.add(materialConfig.getSqlCriteria());
}
}
}
return materialConfigs;
}
Aggregations