public Stage createClone() { return CLONER.deepClone(this); }
public ParamResolver applyOver(ParamResolver enclosingScope) { return enclosingScope.override(CLONER.deepClone(params)); }
public void usingTemplate(PipelineTemplateConfig pipelineTemplate) { this.addAll(CLONER.deepClone(pipelineTemplate)); this.templateApplied = true; }
public AgentConfig deepClone() { return new Cloner().deepClone(this); }
/** * Make copy of InsnNode object. */ public InsnNode copy() { if (this.getClass() == InsnNode.class) { return copyCommonParams(new InsnNode(insnType, getArgsCount())); } return INSN_CLONER.deepClone(this); } }
@Override public CruiseConfig cloneForValidation() { Cloner cloner = new Cloner(); BasicCruiseConfig configForValidation = cloner.deepClone(BasicCruiseConfig.this); // This needs to be done clear the cached fields else the cloned object will all get them. configForValidation.resetAllPipelineConfigsCache(); return configForValidation; }
public PipelineConfig duplicate() { PipelineConfig clone = CLONER.deepClone(this); clone.name = new CaseInsensitiveString(""); clearSelfPipelineNameInFetchTask(clone); return clone; }
private void cacheActiveJob(ActiveJob activeJob) { goCache.put(cacheKeyForActiveJob(activeJob.getId()), cloner.deepClone(activeJob));//TODO: we should clone while serving the object out, and not while adding it to cache }
public JobInstance buildByIdWithTransitions(long buildInstanceId) { String cacheKey = cacheKeyForJobInstanceWithTransitions(buildInstanceId); synchronized (cacheKey) { JobInstance instance = (JobInstance) goCache.get(cacheKey); if (instance == null) { instance = job(buildInstanceId, "buildByIdWithTransitions"); goCache.put(cacheKey, instance); } return cloner.deepClone(instance); } }
public static PipelineConfig renamePipeline(PipelineConfig oldConfig, String newPipelineName) { PipelineConfig newConfig = new Cloner().deepClone(oldConfig); HashMap attributes = new HashMap(); attributes.put(PipelineConfig.NAME, newPipelineName); newConfig.setConfigAttributes(attributes); return newConfig; }
public EnvironmentConfig getEnvironmentForEdit(String environmentName) { return cloner.deepClone(goConfigService.getConfigForEditing().getEnvironments().find(new CaseInsensitiveString(environmentName))); }
@Before public void before() { original = CLONER.deepClone(System.getProperties()); systemEnvironment = new SystemEnvironment(); }
@Test public void shouldNotUpdateAnythingForNullAttributes() { EnvironmentConfig beforeUpdate = new Cloner().deepClone(environmentConfig); environmentConfig.setConfigAttributes(null); assertThat(environmentConfig, is(beforeUpdate)); }
public ParamsConfig referredParams() { ParamReferenceCollectorFactory paramHandlerFactory = new ParamReferenceCollectorFactory(); new ParamResolver(paramHandlerFactory, FIELD_CACHE).resolve(CLONER.deepClone(this)); ParamsConfig paramsConfig = new ParamsConfig(); for (String param : paramHandlerFactory.referredParams()) { paramsConfig.add(new ParamConfig(param, null)); } return paramsConfig; }
public ConfigElementForEdit<EnvironmentConfig> getMergedEnvironmentforDisplay(String environmentName, HttpLocalizedOperationResult result) { ConfigElementForEdit<EnvironmentConfig> edit = null; try { CruiseConfig config = goConfigService.getMergedConfigForEditing(); EnvironmentConfig env = environments.named(new CaseInsensitiveString(environmentName)); edit = new ConfigElementForEdit<>(cloner.deepClone(env), config.getMd5()); } catch (NoSuchEnvironmentException e) { result.badRequest(resourceNotFound("Environment", environmentName)); } return edit; }
@Test public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() { //we need this case because cloning has proven to be problematic with complex object graph in merged config BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1"); PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2"); partialConfig.setOrigin(new RepoConfigOrigin()); CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig); Cloner CLONER = new Cloner(); CruiseConfig cloned = CLONER.deepClone(config); List<ConfigErrors> allErrors = cloned.validateAfterPreprocess(); assertThat(allErrors.size(), is(2)); assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]")); assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]")); }
@Test public void shouldBeAbleToCreateACopyOfItself() { Resource existingResource = new Resource("some-name"); existingResource.setId(2); existingResource.setBuildId(10); assertThat(existingResource, equalTo(new Resource(existingResource))); assertThat(existingResource, equalTo(new Cloner().deepClone(existingResource))); } }
public Stages getAllRunsOfStageForPipelineInstance(String pipelineName, Integer pipelineCounter, String stageName) { String cacheKeyForAllStages = cacheKeyForAllStageOfPipeline(pipelineName, pipelineCounter, stageName); synchronized (cacheKeyForAllStages) { List<Stage> stages = (List<Stage>) goCache.get(cacheKeyForAllStages); if (stages == null) { Map<String, Object> toGet = arguments("pipelineName", pipelineName).and("pipelineCounter", pipelineCounter).and("stageName", stageName).asMap(); stages = (List<Stage>) getSqlMapClientTemplate().queryForList("getAllRunsOfStageForPipelineInstance", toGet); goCache.put(cacheKeyForAllStages, stages); } return new Stages(cloner.deepClone(stages)); } }
@Test public void shouldWalkCruiseConfigObjectsParallelly() { CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("bad pipeline name"); CruiseConfig rawCruiseConfig = new Cloner().deepClone(cruiseConfig); MagicalGoConfigXmlLoader.validate(cruiseConfig); cruiseConfig.copyErrorsTo(rawCruiseConfig); assertThat(rawCruiseConfig.pipelineConfigByName(new CaseInsensitiveString("bad pipeline name")).errors(), is(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("bad pipeline name")).errors())); }
@Test public void shouldCopyErrorsForFieldsOnPipelineConfig(){ PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline", MaterialConfigsMother.defaultMaterialConfigs(), new JobConfigs(JobConfigMother.createJobConfigWithJobNameAndEmptyResources())); pipelineConfig.setVariables(new EnvironmentVariablesConfig(asList(new EnvironmentVariableConfig("name", "value")))); PipelineConfig pipelineWithErrors = new Cloner().deepClone(pipelineConfig); pipelineWithErrors.getVariables().get(0).addError("name", "error on environment variable"); pipelineWithErrors.first().addError("name", "error on stage"); pipelineWithErrors.first().getJobs().first().addError("name", "error on job"); BasicCruiseConfig.copyErrors(pipelineWithErrors, pipelineConfig); assertThat(pipelineConfig.getVariables().get(0).errors().on("name"), is("error on environment variable")); assertThat(pipelineConfig.first().errors().on("name"), is("error on stage")); assertThat(pipelineConfig.first().getJobs().first().errors().on("name"), is("error on job")); }