Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Make archetype-builder generate tokens for special versions we want t…
Browse files Browse the repository at this point in the history
…o be able to configure from archetype. Part of fabric8io/ipaas-quickstarts#989
  • Loading branch information
davsclaus authored and fusesource-ci committed Nov 24, 2015
1 parent 24fe12e commit 6068fe5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -191,10 +192,6 @@ public Document parseXml(InputSource inputSource) {

/**
* Serializes the Document to a File.
*
* @param document
* @param file
* @throws IOException
*/
public void writeXmlDocument(Document document, File file) throws IOException {
try {
Expand All @@ -209,6 +206,24 @@ public void writeXmlDocument(Document document, File file) throws IOException {
}
}

/**
* Serializes the Document to a String.
*/
public String writeXmlDocumentAsString(Document document) throws IOException {
try {
Transformer tr = transformerFactory.newTransformer();
tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tr.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
tr.transform(new DOMSource(document), result);
return writer.toString();
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
}

public String firstElementText(Element root, String elementName, String defaultValue) {
// prefer direct children first
String answer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ private void createArchetypeDescriptors(File projectPom, File archetypeDir, File
for (int cn = 0; cn < children.getLength(); cn++) {
Node e = children.item(cn);
if (e instanceof Element) {
//val text = e.childrenText
String cText = e.getTextContent();
String prefix = "${";
if (cText.startsWith(prefix)) {
Expand All @@ -442,6 +441,8 @@ private void createArchetypeDescriptors(File projectPom, File archetypeDir, File
if (value == null) {
value = versionProperties.get(name);
}
// lets use dash instead of dot
name = name.replace('.', '-');
propertyNameSet.put(name, value);
}
}
Expand All @@ -452,7 +453,12 @@ private void createArchetypeDescriptors(File projectPom, File archetypeDir, File
String value = e.getTextContent();
if (value != null) {
value = value.trim();
// lets use dash instead of dot
cName = cName.replace('.', '-');
propertyNameSet.put(cName, value);
// and use a placeholder token in its place, so we can allow to specify the version dynamically in the archetype
String token = "${" + cName + "}";
e.setTextContent(token);
}
}
}
Expand Down

0 comments on commit 6068fe5

Please sign in to comment.