List of usage examples for org.dom4j Element remove
boolean remove(Text text);
Text
if the node is an immediate child of this element. From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java
License:Apache License
@com.thoughtworks.gauge.Step("Delete pipeline <pipelineName> - Configure cruise using api") public void deletePipeline(final String pipelineName) throws Exception { editPipelineGroup(new PipelineGroupEditAction() { public void applyEdit(Document group) { Element pipelineToRemove = (Element) group.selectSingleNode(String .format("//pipelines/pipeline[@name='%s']", scenarioState.pipelineNamed(pipelineName))); Element pipelines = (Element) group.selectSingleNode("//pipelines"); pipelines.remove(pipelineToRemove); }/*from ww w. j a v a 2 s .c om*/ }); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeLicense() { Element serverElement = serverTag(); Element licenseElement = (Element) serverElement.selectSingleNode("./license"); serverElement.remove(licenseElement); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void changeHgUrl(String newURL) { List<Element> hgs = root().selectNodes("//hg"); for (Element hg : hgs) { Element parent = hg.getParent(); parent.remove(hg); String dest = hg.attributeValue("dest"); Element newHg = new DefaultElement("hg"); if (!StringUtils.isEmpty(dest)) { newHg.addAttribute("dest", dest); }/* www. j a v a 2 s .co m*/ newHg.addAttribute("url", newURL); parent.add(newHg); } }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void setTaskForFirstStage(String pipelineName, SimpleCruiseConfigTag cruiseConfigTag) { Element pipelineElement = pipelineElement(pipelineName); // Element tasksElement = (Element) // pipelineElement.selectSingleNode("stage/jobs/job/tasks"); Element jobElement = (Element) pipelineElement.selectSingleNode("stage/jobs/job"); Element tasksElement = jobElement.element("tasks"); if (tasksElement == null) { tasksElement = new DefaultElement("tasks"); jobElement.add(tasksElement);/*from w w w . jav a 2 s . c o m*/ } List<Element> taskList = tasksElement.elements(); for (Element task : taskList) { tasksElement.remove(task); } tasksElement.add(cruiseConfigTag.convertToDomElement()); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
private void assignAgentToEnvironment(Element environment, String uuid) { Element physical = new DefaultElement("physical"); physical.addAttribute("uuid", uuid); Element envAgents = (Element) environment.selectSingleNode("agents"); if (envAgents == null) { Element envPipelines = (Element) environment.selectSingleNode("pipelines"); if (envPipelines != null) { environment.remove(envPipelines); }//from w ww.j ava 2s. com envAgents = new DefaultElement("agents"); environment.add(envAgents); if (envPipelines != null) { environment.add(envPipelines); } } envAgents.add(physical); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
private void deassignAgentToEnvironment(Element environment, String uuid) { Element physical = new DefaultElement("physical"); physical.addAttribute("uuid", uuid); Element envAgents = (Element) environment.selectSingleNode("agents"); if (envAgents == null) { Element envPipelines = (Element) environment.selectSingleNode("pipelines"); if (envPipelines != null) { environment.remove(envPipelines); }/*from w ww. jav a2s.c o m*/ envAgents = new DefaultElement("agents"); environment.remove(envAgents); if (envPipelines != null) { environment.add(envPipelines); } } envAgents.add(physical); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void setRunInstanceCountForJobTo(String pipelineName, String jobName, int runInstanceCount) { Element pipeline = pipelineWithName(pipelineName); List<Element> jobs = pipeline.selectNodes(String.format("stage/jobs/job[@name='%s']", jobName)); assertThat("Job " + jobName + " does not exist", jobs.isEmpty(), is(false)); for (Element job : jobs) { if (runInstanceCount == 0) { job.remove(job.attribute("runInstanceCount")); } else {/* w w w .java 2 s .c o m*/ job.addAttribute("runInstanceCount", Integer.toString(runInstanceCount)); } } }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public static Element findOrCreateAt(Element parent, int index, String childName) { Element found = (Element) parent.selectSingleNode(childName); if (found == null) { List<Element> children = parent.elements(); if (children.size() == 0) { found = new DefaultElement(childName); parent.add(found);/*from w ww . ja v a 2s . co m*/ return found; } for (Element child : children) { parent.remove(child); child.detach(); } for (int i = 0; i < children.size(); i++) { Element child = children.get(i); if (i == index) { found = new DefaultElement(childName); parent.add(found); } parent.add(child); } // Adding to the end if (found == null) { found = new DefaultElement(childName); parent.add(found); } } return found; }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeTimer(String pipelineName) { Element pipeline = pipelineWithName(pipelineName); Element timer = (Element) pipeline.selectSingleNode("timer"); if (timer != null) { pipeline.remove(timer); }//w w w . j av a 2 s . c om }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void enableAutoUpdate(String currentPipeline) { List<Element> materials = materialsForPipeline(currentPipeline); for (Element material : materials) { Attribute autoUpdate = material.attribute("autoUpdate"); if (autoUpdate != null) { material.remove(autoUpdate); }//from w w w . j a va2 s. c o m } }