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/03/08 09:04:30 UTC
[1/3] camel git commit: Moving dependencies to class level attributes
to reduce number of parameters in methods.
Repository: camel
Updated Branches:
refs/heads/master cfab63a58 -> 5aae60e44
Moving dependencies to class level attributes to reduce number of parameters in methods.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f4d3ab25
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f4d3ab25
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f4d3ab25
Branch: refs/heads/master
Commit: f4d3ab259a95af4b7f7a6913a75b690c867c2488
Parents: 785efef
Author: nkukhar <ku...@gmail.com>
Authored: Sat Mar 7 18:11:48 2015 -0800
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 8 08:51:38 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/camel/maven/Constants.java | 2 +-
.../camel/maven/DocumentationEnricher.java | 38 +++++++++++---------
.../java/org/apache/camel/maven/DomFinder.java | 13 +++++--
.../maven/EipDocumentationEnricherMojo.java | 24 ++++++-------
4 files changed, 43 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/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 e6e3fbe..ebfd846 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
@@ -38,5 +38,5 @@ public final class Constants {
public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
public static final String MODEL_ATTRIBUTE_NAME = "model";
- private Constants() {}
+ private Constants() { }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/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 c7054e6..6e2db2c 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,68 +16,74 @@
*/
package org.apache.camel.maven;
-import org.apache.camel.util.JsonSchemaHelper;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.WordUtils;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import org.apache.camel.util.JsonSchemaHelper;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.WordUtils;
/**
* Enriches xml document with documentation from json files.
*/
public class DocumentationEnricher {
+ private final Document document;
+
+ public DocumentationEnricher(Document document) {
+ this.document = document;
+ }
- public void enrichTopLevelElementsDocumentation(Document document, NodeList elements, Map<String, File> jsonFiles) throws IOException {
+ public void enrichTopLevelElementsDocumentation(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));
+ addElementDocumentation(item, jsonFiles.get(name));
}
}
}
- public void enrichTypeAttributesDocumentation(Document document, NodeList attributeElements, File jsonFile) throws IOException {
+ public void enrichTypeAttributesDocumentation(NodeList attributeElements, File jsonFile) throws IOException {
for (int j = 0; j < attributeElements.getLength(); j++) {
Element item = (Element) attributeElements.item(j);
- addAttributeDocumentation(item, jsonFile, document);
+ addAttributeDocumentation(item, jsonFile);
}
}
- private void addElementDocumentation(Document document, Element item, File jsonFile) throws IOException {
+ private void addElementDocumentation(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);
+ addDocumentation(item, descriptionText);
break;
}
}
}
- private void addAttributeDocumentation(Element item, File jsonFile, Document document) throws IOException {
+ private void addAttributeDocumentation(Element item, File jsonFile) 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);
+ addDocumentation(item, descriptionText);
break;
}
}
}
}
- private void addDocumentation(Document document, Element item, String textContent) {
+ private void addDocumentation(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");
http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/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 5c4fe47..64b4a20 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
@@ -27,19 +27,26 @@ import org.w3c.dom.NodeList;
* Finds xml elements where documentation can be added.
*/
public class DomFinder {
+ private final Document document;
+ private final XPath xPath;
- public NodeList findElementsAndTypes(Document document, XPath xPath) throws XPathExpressionException {
+ public DomFinder(Document document, XPath xPath) {
+ this.document = document;
+ this.xPath = xPath;
+ }
+
+ public NodeList findElementsAndTypes() 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 {
+ public NodeList findAttributesElements(String name) throws XPathExpressionException {
return (NodeList) xPath.compile(
"/xs:schema/xs:complexType[@name='" + name + "']//xs:attribute")
.evaluate(document, XPathConstants.NODESET);
}
- public String findBaseType(Document document, XPath xPath, String name) throws XPathExpressionException {
+ public String findBaseType(String name) throws XPathExpressionException {
return (String) xPath.compile(
"/xs:schema/xs:complexType[@name='" + name + "']//xs:extension/@base")
.evaluate(document, XPathConstants.STRING);
http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/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 aebd0b1..db6ae1f 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
@@ -81,14 +81,14 @@ public class EipDocumentationEnricherMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
Set<String> injectedTypes = new HashSet<String>();
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());
Document document = buildNamespaceAwareDocument(inputCamelSchemaFile);
+ XPath xPath = buildXPath(new CamelSpringNamespace());
+ DomFinder domFinder = new DomFinder(document, xPath);
+ DocumentationEnricher documentationEnricher = new DocumentationEnricher(document);
+ Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir);
try {
- NodeList elementsAndTypes = domFinder.findElementsAndTypes(document, xPath);
- documentationEnricher.enrichTopLevelElementsDocumentation(document, elementsAndTypes, jsonFiles);
+ NodeList elementsAndTypes = domFinder.findElementsAndTypes();
+ documentationEnricher.enrichTopLevelElementsDocumentation(elementsAndTypes, jsonFiles);
Map<String, String> typeToNameMap = buildTypeToNameMap(elementsAndTypes);
for (Map.Entry<String, String> entry : typeToNameMap.entrySet()) {
String elementType = entry.getKey();
@@ -97,8 +97,6 @@ public class EipDocumentationEnricherMojo extends AbstractMojo {
injectAttributesDocumentation(domFinder,
documentationEnricher,
jsonFiles.get(elementName),
- xPath,
- document,
elementType,
injectedTypes);
}
@@ -119,18 +117,16 @@ public class EipDocumentationEnricherMojo extends AbstractMojo {
private void injectAttributesDocumentation(DomFinder domFinder,
DocumentationEnricher documentationEnricher,
File jsonFile,
- XPath xPath,
- Document document,
String type,
Set<String> injectedTypes) throws XPathExpressionException, IOException {
- NodeList attributeElements = domFinder.findAttributesElements(document, xPath, type);
+ NodeList attributeElements = domFinder.findAttributesElements(type);
if (attributeElements.getLength() > 0) {
- documentationEnricher.enrichTypeAttributesDocumentation(document, attributeElements, jsonFile);
+ documentationEnricher.enrichTypeAttributesDocumentation(attributeElements, jsonFile);
injectedTypes.add(type);
- String baseType = domFinder.findBaseType(document, xPath, type);
+ String baseType = domFinder.findBaseType(type);
baseType = truncateTypeNamespace(baseType);
if (baseType != null && !injectedTypes.contains(baseType)) {
- injectAttributesDocumentation(domFinder, documentationEnricher, jsonFile, xPath, document, baseType, injectedTypes);
+ injectAttributesDocumentation(domFinder, documentationEnricher, jsonFile, baseType, injectedTypes);
}
}
}
[2/3] camel git commit: [CAMEL-8381] Wraps documentation for easier
read in raw file.
Posted by da...@apache.org.
[CAMEL-8381] Wraps documentation for easier read in raw file.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/785efef1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/785efef1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/785efef1
Branch: refs/heads/master
Commit: 785efef16a2d87b9e07b4b6a49cf5a004ee77b01
Parents: cfab63a
Author: nkukhar <ku...@gmail.com>
Authored: Sat Mar 7 18:08:15 2015 -0800
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 8 08:51:38 2015 +0100
----------------------------------------------------------------------
.../pom.xml | 5 +++
.../java/org/apache/camel/maven/Constants.java | 6 ++--
.../camel/maven/DocumentationEnricher.java | 37 ++++++++++++++++----
3 files changed, 38 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
index 19574cc..68295ea 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
@@ -68,6 +68,11 @@
<artifactId>maven-artifact</artifactId>
<version>2.2.1</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.3.2</version>
+ </dependency>
<!-- add some logging to the classpath -->
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/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 224e6a8..e6e3fbe 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
@@ -23,6 +23,8 @@ public final class Constants {
// Camel core constants.
public static final String PATH_TO_MODEL_DIR = "target/classes/org/apache/camel/model";
+ public static final String DEFAULT_XML_INTEMSION = " ";
+ public static final int WRAP_LENGTH = 80;
// XML constants.
public static final String NAME_ATTRIBUTE_NAME = "name";
@@ -36,7 +38,5 @@ public final class Constants {
public static final String DESCRIPTION_ATTRIBUTE_NAME = "description";
public static final String MODEL_ATTRIBUTE_NAME = "model";
- private Constants() {
- }
-
+ private Constants() {}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/785efef1/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 7aa1d86..c7054e6 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,16 +16,19 @@
*/
package org.apache.camel.maven;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
+import org.apache.camel.util.JsonSchemaHelper;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.WordUtils;
+import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.apache.camel.util.JsonSchemaHelper;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
/**
* Enriches xml document with documentation from json files.
@@ -78,7 +81,8 @@ public class DocumentationEnricher {
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);
+ CDATASection cdataDocumentationText = document.createCDATASection(formatTextContent(item, textContent));
+ documentation.appendChild(cdataDocumentationText);
annotation.appendChild(documentation);
if (item.getFirstChild() != null) {
item.insertBefore(annotation, item.getFirstChild());
@@ -86,4 +90,23 @@ public class DocumentationEnricher {
item.appendChild(annotation);
}
}
+
+ private String formatTextContent(Element item, String textContent) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(System.lineSeparator())
+ .append(WordUtils.wrap(textContent, Constants.WRAP_LENGTH))
+ .append(System.lineSeparator())
+ // Fix closing tag intention.
+ .append(StringUtils.repeat(Constants.DEFAULT_XML_INTEMSION, getNodeDepth(item)));
+ return stringBuilder.toString();
+ }
+
+ private int getNodeDepth(Node item) {
+ int depth = 1;
+ while (item.getParentNode() != null) {
+ depth++;
+ item = item.getParentNode();
+ }
+ return depth;
+ }
}
[3/3] camel git commit: CAMEL-8381: Polished
Posted by da...@apache.org.
CAMEL-8381: Polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5aae60e4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5aae60e4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5aae60e4
Branch: refs/heads/master
Commit: 5aae60e4444775e80a16da04e8af0b4448859853
Parents: f4d3ab2
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Mar 8 08:52:37 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 8 08:52:37 2015 +0100
----------------------------------------------------------------------
.../maven/camel-eip-documentation-enricher-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5aae60e4/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
index 68295ea..177c5dc 100644
--- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
+++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/pom.xml
@@ -71,7 +71,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
- <version>3.3.2</version>
+ <version>${commons-lang3-version}</version>
</dependency>
<!-- add some logging to the classpath -->