本文整理汇总了Java中io.fabric8.utils.DomHelper类的典型用法代码示例。如果您正苦于以下问题:Java DomHelper类的具体用法?Java DomHelper怎么用?Java DomHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DomHelper类属于io.fabric8.utils包,在下文中一共展示了DomHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setGitHubOrgJobOwnerAndRepo
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private void setGitHubOrgJobOwnerAndRepo(Document doc, String gitOwnerName, String gitRepoName) {
Element githubNavigator = getGitHubScmNavigatorElement(doc);
if (githubNavigator == null) {
throw new IllegalArgumentException("No element <" + GITHUB_SCM_NAVIGATOR_ELEMENT + "> found in the github organisation job!");
}
Element repoOwner = DomUtils.mandatoryFirstChild(githubNavigator, "repoOwner");
Element pattern = DomHelper.firstChild(githubNavigator, "pattern");
if (pattern == null) {
// lets check for the new plugin XML
Element traitsElement = DomHelper.firstChild(githubNavigator, "traits");
if (traitsElement != null) {
Element sourceFilterElement = DomHelper.firstChild(traitsElement, REGEX_SCM_SOURCE_FILTER_TRAIT_ELEMENT);
if (sourceFilterElement != null) {
pattern = DomHelper.firstChild(sourceFilterElement, "regex");
}
}
}
if (pattern == null) {
throw new IllegalArgumentException("No <pattern> or <traits><" + REGEX_SCM_SOURCE_FILTER_TRAIT_ELEMENT + "><regex> found in element <" + GITHUB_SCM_NAVIGATOR_ELEMENT + "> for the github organisation job!");
}
String newPattern = combineJobPattern(pattern.getTextContent(), gitRepoName);
DomUtils.setElementText(repoOwner, gitOwnerName);
DomUtils.setElementText(pattern, newPattern);
}
示例2: ensureSpaceLabelAddedToPom
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private static boolean ensureSpaceLabelAddedToPom(Document document, String spaceId) {
if (document != null && Strings.isNotBlank(spaceId)) {
NodeList plugins = document.getElementsByTagName("plugin");
if (plugins != null) {
for (int i = 0, size = plugins.getLength(); i < size; i++) {
Node item = plugins.item(i);
if (item instanceof Element) {
Element element = (Element) item;
if ("fabric8-maven-plugin".equals(DomHelper.firstChildTextContent(element, "artifactId"))) {
String indent = "\n ";
Element configuration = getOrCreateChild(element, "configuration", indent);
Element resources = getOrCreateChild(configuration, "resources", indent + " ");
Element labels = getOrCreateChild(resources, "labels", indent + " ");
Element all = getOrCreateChild(labels, "all", indent + " ");
Element space = getOrCreateChild(all, "space", indent + " ");
if (!spaceId.equals(space.getTextContent())) {
space.setTextContent(spaceId);
return true;
}
}
}
}
}
}
return false;
}
示例3: addModuleNameIfMissing
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected boolean addModuleNameIfMissing(Element modules, String moduleName) {
NodeList childNodes = modules.getChildNodes();
if (childNodes != null) {
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item instanceof Element) {
Element property = (Element) item;
if (moduleName.equals(property.getTextContent())) {
return false;
}
}
}
}
modules.appendChild(modules.getOwnerDocument().createTextNode("\n "));
DomHelper.addChildElement(modules, "module", moduleName);
return true;
}
示例4: updateFirstChild
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private static boolean updateFirstChild(Element parentElement, String elementName, String value) {
if (parentElement != null) {
Element element = DomHelper.firstChild(parentElement, elementName);
if (element != null) {
String textContent = element.getTextContent();
if (textContent == null || !value.equals(textContent)) {
element.setTextContent(value);
return true;
}
}
}
return false;
}
示例5: mandatoryFirstChild
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
/**
* Returns the first child of the given element with the name or throws an exception
*/
public static Element mandatoryFirstChild(Element element, String name) {
Element child = DomHelper.firstChild(element, name);
if (child == null) {
throw new IllegalArgumentException("The element <" + element.getTagName() + "> should have at least one child called <" + name + ">");
}
return child;
}
示例6: firstElementText
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private static String firstElementText(Element element, String name) {
Element child = DomHelper.firstChild(element, name);
if (child != null) {
return child.getTextContent();
}
return null;
}
示例7: updateDocument
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected void updateDocument(File file, Document doc) throws FileNotFoundException, TransformerException {
LOG.info("Updating the pom " + file);
try {
DomHelper.save(doc, file);
} catch (Exception e) {
LOG.error("Failed to update pom " + file + ". " + e, e);
throw e;
}
}
示例8: getOrCreateFirstChild
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected Element getOrCreateFirstChild(Element element, String elementName) {
Element answer = DomHelper.firstChild(element, elementName);
if (answer != null) {
return answer;
}
return DomHelper.addChildElement(element, elementName);
}
示例9: isFunktionProject
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected static boolean isFunktionProject(Document doc) {
Element parent = DomHelper.firstChild(doc.getDocumentElement(), "parent");
if (parent != null) {
Element groupId = DomHelper.firstChild(parent, "groupId");
if (groupId != null) {
String text = groupId.getTextContent();
return Objects.equals("io.fabric8.funktion.starter", text);
}
}
return false;
}
示例10: ensureMavenDependency
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected static boolean ensureMavenDependency(Document doc, String groupId, String artifactId, String scope) {
Element dependences = DomHelper.firstChild(doc.getDocumentElement(), "dependencies");
if (dependences == null) {
dependences = DomHelper.addChildElement(doc.getDocumentElement(), "dependencies");
}
NodeList childNodes = dependences.getChildNodes();
for (int i = 0, size = childNodes.getLength(); i < size; i++) {
Node item = childNodes.item(i);
if (item instanceof Element) {
Element child = (Element) item;
if (firstChildTextContent(child, "groupId", groupId) &&
firstChildTextContent(child, "artifactId", artifactId)) {
return false;
}
}
}
dependences.appendChild(doc.createTextNode("\n "));
Element dependency = DomHelper.addChildElement(dependences, "dependency");
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "groupId", groupId);
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "artifactId", artifactId);
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "scope", scope);
dependency.appendChild(doc.createTextNode("\n "));
dependences.appendChild(doc.createTextNode("\n "));
return true;
}
示例11: ensureMavenDependencyBOM
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected static boolean ensureMavenDependencyBOM(Document doc, String groupId, String artifactId, String version) {
Element dependencyManagement = DomHelper.firstChild(doc.getDocumentElement(), "dependencyManagement");
if (dependencyManagement == null) {
dependencyManagement = DomHelper.addChildElement(doc.getDocumentElement(), "dependencyManagement");
}
Element dependences = DomHelper.firstChild(dependencyManagement, "dependencies");
if (dependences == null) {
dependences = DomHelper.addChildElement(dependencyManagement, "dependencies");
}
NodeList childNodes = dependences.getChildNodes();
for (int i = 0, size = childNodes.getLength(); i < size; i++) {
Node item = childNodes.item(i);
if (item instanceof Element) {
Element child = (Element) item;
if (firstChildTextContent(child, "groupId", groupId) &&
firstChildTextContent(child, "artifactId", artifactId)) {
return false;
}
}
}
dependences.appendChild(doc.createTextNode("\n "));
Element dependency = DomHelper.addChildElement(dependences, "dependency");
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "groupId", groupId);
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "artifactId", artifactId);
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "version", version);
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "type", "pom");
dependency.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(dependency, "scope", "import");
dependency.appendChild(doc.createTextNode("\n "));
dependences.appendChild(doc.createTextNode("\n "));
return true;
}
示例12: firstChildTextContent
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private static boolean firstChildTextContent(Element element, String name, String textContent) {
Element child = DomHelper.firstChild(element, name);
if (child != null) {
String actual = child.getTextContent();
if (textContent.equals(actual)) {
return true;
}
}
return false;
}
示例13: updateDocument
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
public PomFileXml updateDocument(Document document) throws FileNotFoundException, TransformerException {
DomHelper.save(document, file);
return new PomFileXml(file, document);
}
示例14: assertArchetypeCreated
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
private void assertArchetypeCreated(String artifactId, String groupId, String version, File archetypejar) throws Exception {
artifactId = Strings.stripSuffix(artifactId, "-archetype");
artifactId = Strings.stripSuffix(artifactId, "-example");
File outDir = new File(projectsOutputFolder, artifactId);
LOG.info("Creating Archetype " + groupId + ":" + artifactId + ":" + version);
Map<String, String> properties = new ArchetypeHelper(archetypejar, outDir, groupId, artifactId, version, null, null).parseProperties();
LOG.info("Has preferred properties: " + properties);
ArchetypeHelper helper = new ArchetypeHelper(archetypejar, outDir, groupId, artifactId, version, null, null);
helper.setPackageName(packageName);
// lets override some properties
HashMap<String, String> overrideProperties = new HashMap<String, String>();
// for camel-archetype-component
overrideProperties.put("scheme", "mycomponent");
helper.setOverrideProperties(overrideProperties);
// this is where the magic happens
helper.execute();
LOG.info("Generated archetype " + artifactId);
// expected pom file
File pom = new File(outDir, "pom.xml");
// this archetype might not be a maven project
if (!pom.isFile()) {
return;
}
String pomText = Files.toString(pom);
String badText = "${camel-";
if (pomText.contains(badText)) {
if (verbose) {
LOG.info(pomText);
}
fail("" + pom + " contains " + badText);
}
// now lets ensure we have the necessary test dependencies...
boolean updated = false;
Document doc = XmlUtils.parseDoc(pom);
boolean funktion = isFunktionProject(doc);
LOG.debug("Funktion project: " + funktion);
if (!funktion) {
if (ensureMavenDependency(doc, "io.fabric8", "fabric8-arquillian", "test")) {
updated = true;
}
if (ensureMavenDependency(doc, "org.jboss.arquillian.junit", "arquillian-junit-container", "test")) {
updated = true;
}
if (ensureMavenDependency(doc, "org.jboss.shrinkwrap.resolver", "shrinkwrap-resolver-impl-maven", "test")) {
updated = true;
}
if (ensureMavenDependencyBOM(doc, "io.fabric8", "fabric8-project-bom-with-platform-deps", fabric8Version)) {
updated = true;
}
}
if (ensureFailsafePlugin(doc)) {
updated = true;
}
if (updated) {
DomHelper.save(doc, pom);
}
// lets generate the system test
if (!hasGoodSystemTest(new File(outDir, "src/test/java"))) {
File systemTest = new File(outDir, "src/test/java/io/fabric8/systests/KubernetesIntegrationKT.java");
systemTest.getParentFile().mkdirs();
String javaFileName = "KubernetesIntegrationKT.java";
URL javaUrl = getClass().getClassLoader().getResource(javaFileName);
assertNotNull("Could not load resource on the classpath: " + javaFileName, javaUrl);
IOHelpers.copy(javaUrl.openStream(), new FileOutputStream(systemTest));
}
outDirs.add(outDir.getPath());
}
示例15: ensureFailsafePlugin
import io.fabric8.utils.DomHelper; //导入依赖的package包/类
protected boolean ensureFailsafePlugin(Document doc) {
String artifactId = "maven-failsafe-plugin";
Element build = DomHelper.firstChild(doc.getDocumentElement(), "build");
if (build == null) {
build = DomHelper.addChildElement(doc.getDocumentElement(), "build");
}
Element plugins = DomHelper.firstChild(build, "plugins");
if (plugins == null) {
plugins = DomHelper.addChildElement(build, "plugins");
}
NodeList childNodes = plugins.getChildNodes();
for (int i = 0, size = childNodes.getLength(); i < size; i++) {
Node item = childNodes.item(i);
if (item instanceof Element) {
Element child = (Element) item;
if (firstChildTextContent(child, "artifactId", artifactId)) {
return false;
}
}
}
plugins.appendChild(doc.createTextNode("\n "));
Element plugin = DomHelper.addChildElement(plugins, "plugin");
plugin.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(plugin, "artifactId", artifactId);
plugin.appendChild(doc.createTextNode("\n "));
DomHelper.addChildElement(plugin, "version", failsafeVersion);
plugin.appendChild(doc.createTextNode("\n "));
Element configuration = DomHelper.addChildElement(plugin, "configuration");
configuration.appendChild(doc.createTextNode("\n "));
Element includes = DomHelper.addChildElement(configuration, "includes");
includes.appendChild(doc.createTextNode("\n "));
Element include = DomHelper.addChildElement(includes, "include", "**/*KT.*");
includes.appendChild(doc.createTextNode("\n "));
configuration.appendChild(doc.createTextNode("\n "));
plugin.appendChild(doc.createTextNode("\n "));
plugins.appendChild(doc.createTextNode("\n "));
return true;
}