Java Code Examples for io.fabric8.utils.IOHelpers#copy()
The following examples show how to use
io.fabric8.utils.IOHelpers#copy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchetypeHelper.java From ipaas-quickstarts with Apache License 2.0 | 5 votes |
/** * Extracts properties declared in "META-INF/maven/archetype-metadata.xml" file */ protected void parseReplaceProperties(InputStream zip, Map<String, String> replaceProperties) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOHelpers.copy(zip, bos); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource inputSource = new InputSource(new ByteArrayInputStream(bos.toByteArray())); Document document = db.parse(inputSource); XPath xpath = XPathFactory.newInstance().newXPath(); SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.registerMapping("ad", archetypeDescriptorUri); xpath.setNamespaceContext(nsContext); NodeList properties = (NodeList) xpath.evaluate(requiredPropertyXPath, document, XPathConstants.NODESET); for (int p = 0; p < properties.getLength(); p++) { Element requiredProperty = (Element) properties.item(p); String key = requiredProperty.getAttribute("key"); NodeList children = requiredProperty.getElementsByTagNameNS(archetypeDescriptorUri, "defaultValue"); String value = ""; if (children.getLength() == 1 && children.item(0).hasChildNodes()) { value = children.item(0).getTextContent(); } else { if ("name".equals(key) && value.isEmpty()) { value = "HelloWorld"; } } replaceProperties.put(key, value); } }
Example 2
Source File: ArchetypeTest.java From ipaas-quickstarts with Apache License 2.0 | 4 votes |
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()); }