You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/02/10 11:02:22 UTC
[8/8] camel git commit: CAMEL-8197: Fixed CS
CAMEL-8197: Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/55d4f227
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/55d4f227
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/55d4f227
Branch: refs/heads/master
Commit: 55d4f227fa3bb953ba642e91b77f1db685b2cf27
Parents: bef145f
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Feb 10 10:57:07 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Feb 10 10:57:07 2015 +0100
----------------------------------------------------------------------
.../camel/maven/CamelSpringNamespace.java | 36 ++--
.../java/org/apache/camel/maven/Constants.java | 29 +--
.../camel/maven/DocumentationEnricher.java | 110 +++++------
.../java/org/apache/camel/maven/DomFinder.java | 24 +--
.../maven/EipDocumentationEnricherMojo.java | 192 +++++++++----------
.../org/apache/camel/maven/PackageHelper.java | 59 +++---
.../apache/camel/maven/PackageHelperTest.java | 46 +++--
7 files changed, 251 insertions(+), 245 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/CamelSpringNamespace.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/CamelSpringNamespace.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/CamelSpringNamespace.java
index 4466045..3daf1d3 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/CamelSpringNamespace.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/CamelSpringNamespace.java
@@ -16,32 +16,32 @@
*/
package org.apache.camel.maven;
-import javax.xml.namespace.NamespaceContext;
import java.util.Iterator;
+import javax.xml.namespace.NamespaceContext;
/**
* Default namespace for xsd schema.
*/
public class CamelSpringNamespace implements NamespaceContext {
- @Override
- public String getNamespaceURI(String prefix) {
- if (prefix == null) {
- throw new IllegalArgumentException("The prefix cannot be null.");
- }
- if ("xs".equals(prefix)) {
- return "http://www.w3.org/2001/XMLSchema";
+ @Override
+ public String getNamespaceURI(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("The prefix cannot be null.");
+ }
+ if ("xs".equals(prefix)) {
+ return "http://www.w3.org/2001/XMLSchema";
+ }
+ return null;
}
- return null;
- }
- @Override
- public String getPrefix(String namespaceURI) {
- throw new UnsupportedOperationException("Operation not supported");
- }
+ @Override
+ public String getPrefix(String namespaceURI) {
+ throw new UnsupportedOperationException("Operation not supported");
+ }
- @Override
- public Iterator getPrefixes(String namespaceURI) {
- throw new UnsupportedOperationException("Operation not supported");
- }
+ @Override
+ public Iterator getPrefixes(String namespaceURI) {
+ throw new UnsupportedOperationException("Operation not supported");
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
index 745026c..224e6a8 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java
@@ -20,20 +20,23 @@ package org.apache.camel.maven;
* Stores mojo related constants.
*/
public final class Constants {
- private Constants(){}
- // Camel core constants.
- public static final String PATH_TO_MODEL_DIR = "target/classes/org/apache/camel/model";
+ // Camel core constants.
+ public static final String PATH_TO_MODEL_DIR = "target/classes/org/apache/camel/model";
- // XML constants.
- public static final String NAME_ATTRIBUTE_NAME = "name";
- public static final String TYPE_ATTRIBUTE_NAME = "type";
- public static final String XS_ANNOTATION_ELEMENT_NAME = "xs:annotation";
- public static final String XS_DOCUMENTATION_ELEMENT_NAME = "xs:documentation";
+ // XML constants.
+ public static final String NAME_ATTRIBUTE_NAME = "name";
+ public static final String TYPE_ATTRIBUTE_NAME = "type";
+ public static final String XS_ANNOTATION_ELEMENT_NAME = "xs:annotation";
+ public static final String XS_DOCUMENTATION_ELEMENT_NAME = "xs:documentation";
+
+ // Json files constants.
+ public static final String PROPERTIES_ATTRIBUTE_NAME = "properties";
+ public static final String JSON_SUFIX = ".json";
+ public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
+ public static final String MODEL_ATTRIBUTE_NAME = "model";
+
+ private Constants() {
+ }
- // Json files constants.
- public static final String PROPERTIES_ATTRIBUTE_NAME = "properties";
- public static final String JSON_SUFIX = ".json";
- public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
- public static final String MODEL_ATTRIBUTE_NAME = "model";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
index 31ab995..7aa1d86 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java
@@ -16,84 +16,74 @@
*/
package org.apache.camel.maven;
-import org.apache.camel.util.JsonSchemaHelper;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.apache.camel.util.JsonSchemaHelper;
+
/**
* Enriches xml document with documentation from json files.
*/
public class DocumentationEnricher {
- public void enrichTopLevelElementsDocumentation(Document document,
- NodeList elements,
- Map<String, File> jsonFiles)
- throws IOException {
- for (int i = 0; i < elements.getLength(); i++) {
- Element item = (Element) elements.item(i);
- String name = item.getAttribute(Constants.NAME_ATTRIBUTE_NAME);
- if (jsonFiles.containsKey(name)) {
- addElementDocumentation(document, item, jsonFiles.get(name));
- }
+ public void enrichTopLevelElementsDocumentation(Document document, NodeList elements, Map<String, File> jsonFiles) throws IOException {
+ for (int i = 0; i < elements.getLength(); i++) {
+ Element item = (Element) elements.item(i);
+ String name = item.getAttribute(Constants.NAME_ATTRIBUTE_NAME);
+ if (jsonFiles.containsKey(name)) {
+ addElementDocumentation(document, item, jsonFiles.get(name));
+ }
+ }
}
- }
- public void enrichTypeAttributesDocumentation(Document document,
- NodeList attributeElements,
- File jsonFile) throws IOException {
- for (int j = 0; j < attributeElements.getLength(); j++) {
- Element item = (Element) attributeElements.item(j);
- addAttributeDocumentation(item, jsonFile, document);
+ public void enrichTypeAttributesDocumentation(Document document, NodeList attributeElements, File jsonFile) throws IOException {
+ for (int j = 0; j < attributeElements.getLength(); j++) {
+ Element item = (Element) attributeElements.item(j);
+ addAttributeDocumentation(item, jsonFile, document);
+ }
}
- }
- private void addElementDocumentation(Document document, Element item, File jsonFile)
- throws IOException {
- List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema
- (Constants.MODEL_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), false);
- for (Map<String, String> row : rows) {
- if (row.containsKey(Constants.DESCRIPTION_ATTRIBUTE_NAME)) {
- String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
- addDocumentation(document, item, descriptionText);
- break;
- }
+ private void addElementDocumentation(Document document, Element item, File jsonFile) throws IOException {
+ List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(Constants.MODEL_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), false);
+ for (Map<String, String> row : rows) {
+ if (row.containsKey(Constants.DESCRIPTION_ATTRIBUTE_NAME)) {
+ String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
+ addDocumentation(document, item, descriptionText);
+ break;
+ }
+ }
}
- }
- private void addAttributeDocumentation(Element item,
- File jsonFile,
- Document document)
- throws IOException {
- List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema
- (Constants.PROPERTIES_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), true);
- for (Map<String, String> row : rows) {
- if (item.getAttribute(Constants.NAME_ATTRIBUTE_NAME)
- .equals(row.get(Constants.NAME_ATTRIBUTE_NAME))){
- String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
- if (descriptionText != null) {
- addDocumentation(document, item, descriptionText);
- break;
+ private void addAttributeDocumentation(Element item, File jsonFile, Document document) throws IOException {
+ List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(Constants.PROPERTIES_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), true);
+ for (Map<String, String> row : rows) {
+ if (item.getAttribute(Constants.NAME_ATTRIBUTE_NAME)
+ .equals(row.get(Constants.NAME_ATTRIBUTE_NAME))) {
+ String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME);
+ if (descriptionText != null) {
+ addDocumentation(document, item, descriptionText);
+ break;
+ }
+ }
}
- }
}
- }
- private void addDocumentation(Document document, Element item, String textContent) {
- Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME);
- Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME);
- documentation.setAttribute("xml:lang", "en");
- documentation.setTextContent(textContent);
- annotation.appendChild(documentation);
- if (item.getFirstChild() != null){
- item.insertBefore(annotation, item.getFirstChild());
- } else {
- item.appendChild(annotation);
+ private void addDocumentation(Document document, Element item, String textContent) {
+ Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME);
+ Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME);
+ documentation.setAttribute("xml:lang", "en");
+ documentation.setTextContent(textContent);
+ annotation.appendChild(documentation);
+ if (item.getFirstChild() != null) {
+ item.insertBefore(annotation, item.getFirstChild());
+ } else {
+ item.appendChild(annotation);
+ }
}
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java
index c5c0aff..ea62849 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java
@@ -16,26 +16,26 @@
*/
package org.apache.camel.maven;
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
/**
* Finds xml elements where documentation can be added.
*/
public class DomFinder {
- public NodeList findElementsAndTypes(Document document, XPath xPath) throws XPathExpressionException {
- return (NodeList) xPath.compile("/xs:schema/xs:element")
- .evaluate(document, XPathConstants.NODESET);
- }
+ public NodeList findElementsAndTypes(Document document, XPath xPath) throws XPathExpressionException {
+ return (NodeList) xPath.compile("/xs:schema/xs:element")
+ .evaluate(document, XPathConstants.NODESET);
+ }
- public NodeList findAttributesElements(Document document, XPath xPath, String name) throws XPathExpressionException {
- return (NodeList) xPath.compile(
- "/xs:schema/xs:complexType[@name='" + name + "']//xs:attribute")
- .evaluate(document, XPathConstants.NODESET);
- }
+ public NodeList findAttributesElements(Document document, XPath xPath, String name) throws XPathExpressionException {
+ return (NodeList) xPath.compile(
+ "/xs:schema/xs:complexType[@name='" + name + "']//xs:attribute")
+ .evaluate(document, XPathConstants.NODESET);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java
index 4b4a967..4c2ddd0 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java
@@ -16,127 +16,127 @@
*/
package org.apache.camel.maven;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.*;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
/**
* Injects EIP documentation to camel schema.
*/
@Mojo(name = "eip-documentation-enricher", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresProject = true,
- defaultPhase = LifecyclePhase.PACKAGE)
+ defaultPhase = LifecyclePhase.PACKAGE)
public class EipDocumentationEnricherMojo extends AbstractMojo {
- /**
- * Path to camel EIP schema.
- */
- @Parameter(required = true)
- File inputCamelSchemaFile;
+ /**
+ * Path to camel EIP schema.
+ */
+ @Parameter(required = true)
+ File inputCamelSchemaFile;
- /**
- * Path to camel EIP schema with enriched documentation.
- */
- @Parameter(required = true)
- File outputCamelSchemaFile;
+ /**
+ * Path to camel EIP schema with enriched documentation.
+ */
+ @Parameter(required = true)
+ File outputCamelSchemaFile;
- /**
- * Path to camel core project root directory.
- */
- @Parameter(defaultValue = "${project.build.directory}/../../..//camel-core")
- File camelCoreDir;
+ /**
+ * Path to camel core project root directory.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/../../..//camel-core")
+ File camelCoreDir;
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- File rootDir = new File(camelCoreDir, Constants.PATH_TO_MODEL_DIR);
- DomFinder domFinder = new DomFinder();
- DocumentationEnricher documentationEnricher = new DocumentationEnricher();
- Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir);
- XPath xPath = buildXPath(new CamelSpringNamespace());
- try {
- Document document = buildNamespaceAwareDocument(inputCamelSchemaFile);
- NodeList elementsAndTypes = domFinder.findElementsAndTypes(document, xPath);
- documentationEnricher.enrichTopLevelElementsDocumentation
- (document, elementsAndTypes, jsonFiles);
- Map<String, String> typeToNameMap = buildTypeToNameMap(elementsAndTypes);
- for (Map.Entry<String, String> entry : typeToNameMap.entrySet()) {
- NodeList attributeElements = domFinder.findAttributesElements(document, xPath, entry.getKey());
- if (jsonFiles.containsKey(entry.getValue())){
- documentationEnricher.enrichTypeAttributesDocumentation
- (document, attributeElements, jsonFiles.get(entry.getValue()));
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ File rootDir = new File(camelCoreDir, Constants.PATH_TO_MODEL_DIR);
+ DomFinder domFinder = new DomFinder();
+ DocumentationEnricher documentationEnricher = new DocumentationEnricher();
+ Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir);
+ XPath xPath = buildXPath(new CamelSpringNamespace());
+ try {
+ Document document = buildNamespaceAwareDocument(inputCamelSchemaFile);
+ NodeList elementsAndTypes = domFinder.findElementsAndTypes(document, xPath);
+ documentationEnricher.enrichTopLevelElementsDocumentation(document, elementsAndTypes, jsonFiles);
+ Map<String, String> typeToNameMap = buildTypeToNameMap(elementsAndTypes);
+ for (Map.Entry<String, String> entry : typeToNameMap.entrySet()) {
+ NodeList attributeElements = domFinder.findAttributesElements(document, xPath, entry.getKey());
+ if (jsonFiles.containsKey(entry.getValue())) {
+ documentationEnricher.enrichTypeAttributesDocumentation(document, attributeElements, jsonFiles.get(entry.getValue()));
+ }
+ }
+ saveToFile(document, outputCamelSchemaFile, buildTransformer());
+ } catch (Exception e) {
+ getLog().error(e);
}
- }
- saveToFile(document, outputCamelSchemaFile, buildTransformer());
- } catch (Exception e) {
- getLog().error(e);
}
- }
- private Map<String, String> buildTypeToNameMap(NodeList elementsAndTypes) {
- Map<String, String> typeToNameMap = new HashMap<>();
- for (int i = 0; i < elementsAndTypes.getLength(); i++) {
- Element item = (Element) elementsAndTypes.item(i);
- String name = item.getAttribute(Constants.NAME_ATTRIBUTE_NAME);
- String type = item.getAttribute(Constants.TYPE_ATTRIBUTE_NAME);
- if (name != null && type != null) {
- type = type.replaceAll("tns:", "");
- if (getLog().isDebugEnabled()) {
- getLog().debug(String.format("Putting attributes type:'%s', name:'%s'", name, type));
+ private Map<String, String> buildTypeToNameMap(NodeList elementsAndTypes) {
+ Map<String, String> typeToNameMap = new HashMap<String, String>();
+ for (int i = 0; i < elementsAndTypes.getLength(); i++) {
+ Element item = (Element) elementsAndTypes.item(i);
+ String name = item.getAttribute(Constants.NAME_ATTRIBUTE_NAME);
+ String type = item.getAttribute(Constants.TYPE_ATTRIBUTE_NAME);
+ if (name != null && type != null) {
+ type = type.replaceAll("tns:", "");
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(String.format("Putting attributes type:'%s', name:'%s'", name, type));
+ }
+ typeToNameMap.put(type, name);
+ }
}
- typeToNameMap.put(type, name);
- }
+ return typeToNameMap;
}
- return typeToNameMap;
- }
- private XPath buildXPath(NamespaceContext namespaceContext) {
- XPath xPath = XPathFactory.newInstance().newXPath();
- xPath.setNamespaceContext(namespaceContext);
- return xPath;
- }
+ private XPath buildXPath(NamespaceContext namespaceContext) {
+ XPath xPath = XPathFactory.newInstance().newXPath();
+ xPath.setNamespaceContext(namespaceContext);
+ return xPath;
+ }
- private Transformer buildTransformer() throws TransformerConfigurationException {
- Transformer transformer =
- TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(
- "{http://xml.apache.org/xslt}indent-amount", "2");
- return transformer;
- }
+ private Transformer buildTransformer() throws TransformerConfigurationException {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ return transformer;
+ }
- public Document buildNamespaceAwareDocument(File xml) throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(xml);
- }
+ public Document buildNamespaceAwareDocument(File xml) throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(xml);
+ }
- private void saveToFile(Document document, File outputFile, Transformer transformer) throws IOException, TransformerException {
- StreamResult result =
- new StreamResult(new FileOutputStream(outputFile));
- DOMSource source = new DOMSource(document);
- transformer.transform(source, result);
- }
+ private void saveToFile(Document document, File outputFile, Transformer transformer) throws IOException, TransformerException {
+ StreamResult result = new StreamResult(new FileOutputStream(outputFile));
+ DOMSource source = new DOMSource(document);
+ transformer.transform(source, result);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/PackageHelper.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/PackageHelper.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/PackageHelper.java
index 2470098..6057a15 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/PackageHelper.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/PackageHelper.java
@@ -28,40 +28,41 @@ import java.util.Map;
/**
* Utility class to find, read json files.
*/
-public class PackageHelper {
- private PackageHelper() {}
+public final class PackageHelper {
- public static String fileToString(File file) throws IOException {
- byte[] encoded = Files.readAllBytes(Paths.get(file.toURI()));
- return new String(encoded, Charset.defaultCharset());
- }
+ private PackageHelper() {
+ }
- public static Map<String, File> findJsonFiles(File rootDir) {
- Map<String, File> results = new HashMap<>();
- findJsonFiles0(rootDir, results, new CamelComponentsModelFilter());
- return results;
- }
+ public static String fileToString(File file) throws IOException {
+ byte[] encoded = Files.readAllBytes(Paths.get(file.toURI()));
+ return new String(encoded, Charset.defaultCharset());
+ }
- private static void findJsonFiles0(File dir, Map<String, File> result, FileFilter filter) {
- File[] files = dir.listFiles(filter);
- if (files != null) {
- for (File file : files) {
- // skip files in root dirs as Camel does not store information there but others may do
- boolean jsonFile = file.isFile() && file.getName().endsWith(Constants.JSON_SUFIX);
- if (jsonFile) {
- result.put(file.getName().replaceAll("\\"+ Constants.JSON_SUFIX, ""), file);
- } else if (file.isDirectory()) {
- findJsonFiles0(file, result, filter);
+ public static Map<String, File> findJsonFiles(File rootDir) {
+ Map<String, File> results = new HashMap<String, File>();
+ findJsonFiles0(rootDir, results, new CamelComponentsModelFilter());
+ return results;
+ }
+
+ private static void findJsonFiles0(File dir, Map<String, File> result, FileFilter filter) {
+ File[] files = dir.listFiles(filter);
+ if (files != null) {
+ for (File file : files) {
+ // skip files in root dirs as Camel does not store information there but others may do
+ boolean jsonFile = file.isFile() && file.getName().endsWith(Constants.JSON_SUFIX);
+ if (jsonFile) {
+ result.put(file.getName().replaceAll("\\" + Constants.JSON_SUFIX, ""), file);
+ } else if (file.isDirectory()) {
+ findJsonFiles0(file, result, filter);
+ }
+ }
}
- }
}
- }
- private static class CamelComponentsModelFilter implements FileFilter {
- @Override
- public boolean accept(File pathname) {
- return pathname.isDirectory() ||
- pathname.getName().endsWith(Constants.JSON_SUFIX);
+ private static class CamelComponentsModelFilter implements FileFilter {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isDirectory() || pathname.getName().endsWith(Constants.JSON_SUFIX);
+ }
}
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/55d4f227/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
index 5e6f6ad..0d45deb 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/test/java/org/apache/camel/maven/PackageHelperTest.java
@@ -1,31 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.camel.maven;
-import org.junit.Assert;
-import org.junit.Test;
-
import java.io.File;
import java.util.Map;
+import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-
public class PackageHelperTest {
- @Test
- public void testFileToString() throws Exception {
- assertEquals("dk19i21)@+#(OR", PackageHelper.fileToString(new File(
- this.getClass().getClassLoader().getResource("filecontent/a.txt").getFile())));
- }
+ @Test
+ public void testFileToString() throws Exception {
+ assertEquals("dk19i21)@+#(OR", PackageHelper.fileToString(new File(this.getClass().getClassLoader().getResource("filecontent/a.txt").getFile())));
+ }
- @Test
- public void testFindJsonFiles() throws Exception {
- Map<String, File> jsonFiles = PackageHelper.findJsonFiles(new File(
- this.getClass().getClassLoader().getResource("json").getFile()));
+ @Test
+ public void testFindJsonFiles() throws Exception {
+ Map<String, File> jsonFiles = PackageHelper.findJsonFiles(new File(this.getClass().getClassLoader().getResource("json").getFile()));
- assertTrue("Files a.json must be found", jsonFiles.containsKey("a"));
- assertTrue("Files b.json must be found", jsonFiles.containsKey("b"));
- assertFalse("File c.txt must not be found", jsonFiles.containsKey("c"));
- }
+ assertTrue("Files a.json must be found", jsonFiles.containsKey("a"));
+ assertTrue("Files b.json must be found", jsonFiles.containsKey("b"));
+ assertFalse("File c.txt must not be found", jsonFiles.containsKey("c"));
+ }
}
\ No newline at end of file