Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

In this page you can find the example usage for org.dom4j Element attribute.

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private void replacePipelineInFetchArtifact(String initial, String replaced) {
    List<Element> selectNodes = (List<Element>) root().selectNodes("//fetchartifact");
    for (Element fetchArtifactElem : selectNodes) {
        Attribute pathFromAncestorAttr = fetchArtifactElem.attribute("pipeline");
        if (pathFromAncestorAttr != null) {
            String pathFromAncestor = pathFromAncestorAttr.getStringValue();
            String[] individualPipelineNames = pathFromAncestor.split("/");
            for (String pipelineName : individualPipelineNames) {
                if (pipelineName.equals(initial)) {
                    fetchArtifactElem.addAttribute("pipeline", pathFromAncestor.replace(initial, replaced));
                    break;
                }//from w  ww.ja v  a 2 s .c  o  m
            }
        }
    }

}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private Set<String> addAgentsToEnvironment(int numberOfAgents, String environmentName, List<String> idleAgents,
        List<Element> possibleAgents) {
    Element environment = environment(environmentName);
    removeAgentsAlreadyInEnvironment(possibleAgents,
            (List<Element>) environment.selectNodes("//agents/physical"));

    if (idleAgents.size() < numberOfAgents) {
        throw new IllegalArgumentException(String.format("There are not enough idle agents (%s) to assign (%s)",
                idleAgents.size(), numberOfAgents));
    }//from   w  ww  . ja  v  a 2s  . c om
    if (possibleAgents.size() < numberOfAgents) {
        throw new IllegalArgumentException(
                String.format("Total number of matching agents (%s) is less than requested number (%s)",
                        possibleAgents.size(), numberOfAgents));
    }

    Set<String> selectedUuids = new HashSet<String>();
    for (Element possibleAgent : possibleAgents) {
        if (idleAgents.contains(possibleAgent.attribute("uuid").getValue())) {
            selectedUuids.add(possibleAgent.attributeValue("uuid"));
            if (selectedUuids.size() >= numberOfAgents) {
                break;
            }
        }
    }

    for (String uuid : selectedUuids) {
        assignAgentToEnvironment(environment, uuid);
    }

    if (selectedUuids.size() < numberOfAgents) {
        throw new RuntimeException("Could not add " + numberOfAgents + " to environment " + environmentName
                + " from agents " + possibleAgents + "selecting from " + idleAgents
                + " number of selected uuids = " + selectedUuids.size());
    }
    return selectedUuids;
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private Set<String> removeAgentsFromEnvironment(int numberOfAgents, String environmentName,
        List<String> idleAgents, List<Element> possibleAgents) {
    Element environment = environment(environmentName);
    removeAgentsAlreadyInEnvironment(possibleAgents,
            (List<Element>) environment.selectNodes("//agents/physical"));

    if (idleAgents.size() < numberOfAgents) {
        throw new IllegalArgumentException(String.format("There are not enough idle agents (%s) to assign (%s)",
                idleAgents.size(), numberOfAgents));
    }//from ww w .  ja v  a2 s .  co  m
    if (possibleAgents.size() < numberOfAgents) {
        throw new IllegalArgumentException(
                String.format("Total number of matching agents (%s) is less than requested number (%s)",
                        possibleAgents.size(), numberOfAgents));
    }

    Set<String> selectedUuids = new HashSet<String>();
    for (Element possibleAgent : possibleAgents) {
        if (idleAgents.contains(possibleAgent.attribute("uuid").getValue())) {
            selectedUuids.add(possibleAgent.attributeValue("uuid"));
            if (selectedUuids.size() >= numberOfAgents) {
                break;
            }
        }
    }

    for (String uuid : selectedUuids) {
        deassignAgentToEnvironment(environment, uuid);
    }

    if (selectedUuids.size() < numberOfAgents) {
        throw new RuntimeException("Could not add " + numberOfAgents + " to environment " + environmentName
                + " from agents " + possibleAgents + "selecting from " + idleAgents);
    }
    return selectedUuids;
}

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  . ja  v  a  2  s  .co m*/
            job.addAttribute("runInstanceCount", Integer.toString(runInstanceCount));
        }
    }
}

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  ww w.j av a  2 s .c  o m
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void pipelineAutoUpdate(String pipelineName) {
    List<Element> materials = materialsForPipeline(pipelineName);
    for (Element material : materials) {
        Attribute autoUpdate = material.attribute("autoUpdate");
        if (autoUpdate == null) {
            material.add(new DefaultAttribute("autoUpdate", "true"));
        } else {/*from  w  ww . j a v  a  2  s . c  o m*/
            autoUpdate.setValue("true");
        }
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void removeExternalsFor(String pipelineName, String materialName) {
    Element material = material(pipelineName, materialName);
    if (material.attribute("checkexternals") != null) {
        material.remove(material.attribute("checkexternals"));
    }/*  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 makeMaterialNonExistantMaterial(String pipelineName) {
    Element material = materialsForPipeline(pipelineName).get(0);
    material.attribute("url").setText("non-existant");
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void makeAllMaterialsNonExistantMAterials(String pipelineName) {
    int numberOfMaterials = materialsForPipeline(pipelineName).size();
    for (int i = 0; i < numberOfMaterials; i++) {
        Element material = materialsForPipeline(pipelineName).get(i);
        if (material.getName().equalsIgnoreCase("p4")) {
            material.attribute("port").setText("nonexistant:6578");
        } else {/* www  .  ja  va2 s .  c om*/
            material.attribute("url").setText("non-existant");
        }

    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void changeArtifactLocation(String artifactLocation) {
    Element artifact = (Element) root().selectSingleNode("/cruise/server");
    artifact.attribute("artifactsdir").setText(artifactLocation);
}