How do I run a java method against all files of a type within a gradle project?
up vote
1
down vote
favorite
I have a java application that generates xqDoc (similar to JavaDoc) against an XQuery (*.xqy) source file.
I have a maven project at: https://github.com/lcahlander/xqdoc-core.git
That I want to run the following java code against all .xqy
files in src/main/ml-modules/root/**/*.xqy
and place the results respectively in xqDoc/**/*.xml
:
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
InputStream is = Files.newInputStream(Paths.get(cmd.getOptionValue("f")));
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
XQDocPayload payload = controller.process(is, "");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isOut = new InputSource();
isOut.setCharacterStream(new StringReader(payload.getXQDocXML()));
Document doc = db.parse(isOut);
The xqDoc parser could also be run from the command line as
java -jar xqdoc-core-0.8-jar-with-dependencies.jar -Dfn=http://www.w3.org/2003/05/xpath-functions -Dxdmp=http://marklogic.com/xdmp -f filepath
I want to create the gradle task generateXQDoc
java maven gradle build.gradle xquery
add a comment |
up vote
1
down vote
favorite
I have a java application that generates xqDoc (similar to JavaDoc) against an XQuery (*.xqy) source file.
I have a maven project at: https://github.com/lcahlander/xqdoc-core.git
That I want to run the following java code against all .xqy
files in src/main/ml-modules/root/**/*.xqy
and place the results respectively in xqDoc/**/*.xml
:
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
InputStream is = Files.newInputStream(Paths.get(cmd.getOptionValue("f")));
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
XQDocPayload payload = controller.process(is, "");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isOut = new InputSource();
isOut.setCharacterStream(new StringReader(payload.getXQDocXML()));
Document doc = db.parse(isOut);
The xqDoc parser could also be run from the command line as
java -jar xqdoc-core-0.8-jar-with-dependencies.jar -Dfn=http://www.w3.org/2003/05/xpath-functions -Dxdmp=http://marklogic.com/xdmp -f filepath
I want to create the gradle task generateXQDoc
java maven gradle build.gradle xquery
1
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a java application that generates xqDoc (similar to JavaDoc) against an XQuery (*.xqy) source file.
I have a maven project at: https://github.com/lcahlander/xqdoc-core.git
That I want to run the following java code against all .xqy
files in src/main/ml-modules/root/**/*.xqy
and place the results respectively in xqDoc/**/*.xml
:
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
InputStream is = Files.newInputStream(Paths.get(cmd.getOptionValue("f")));
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
XQDocPayload payload = controller.process(is, "");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isOut = new InputSource();
isOut.setCharacterStream(new StringReader(payload.getXQDocXML()));
Document doc = db.parse(isOut);
The xqDoc parser could also be run from the command line as
java -jar xqdoc-core-0.8-jar-with-dependencies.jar -Dfn=http://www.w3.org/2003/05/xpath-functions -Dxdmp=http://marklogic.com/xdmp -f filepath
I want to create the gradle task generateXQDoc
java maven gradle build.gradle xquery
I have a java application that generates xqDoc (similar to JavaDoc) against an XQuery (*.xqy) source file.
I have a maven project at: https://github.com/lcahlander/xqdoc-core.git
That I want to run the following java code against all .xqy
files in src/main/ml-modules/root/**/*.xqy
and place the results respectively in xqDoc/**/*.xml
:
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
InputStream is = Files.newInputStream(Paths.get(cmd.getOptionValue("f")));
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
XQDocPayload payload = controller.process(is, "");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource isOut = new InputSource();
isOut.setCharacterStream(new StringReader(payload.getXQDocXML()));
Document doc = db.parse(isOut);
The xqDoc parser could also be run from the command line as
java -jar xqdoc-core-0.8-jar-with-dependencies.jar -Dfn=http://www.w3.org/2003/05/xpath-functions -Dxdmp=http://marklogic.com/xdmp -f filepath
I want to create the gradle task generateXQDoc
java maven gradle build.gradle xquery
java maven gradle build.gradle xquery
asked Nov 10 at 12:53
Loren Cahlander
534314
534314
1
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47
add a comment |
1
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47
1
1
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Some thing like this should work (untested). You can adjust the hard-coded paths to use project properties, but should be enough to demonstrate how to iterate over each file in the fileset and execute
task generateXQDoc {
description = 'Generate XQDocs'
doLast {
def sourceDir = 'src/main/ml-modules'
File targetDir = new File('xqDoc')
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
def xqueryFiles = fileTree(dir: sourceDir, include: '**/*.xq*')
xqueryFiles.each { file ->
InputStream is = Files.newInputStream(file));
XQDocPayload payload = controller.process(is, "");
String relativePath = new File(sourceDir).toURI().relativize(file.toURI()).getPath();
File outputFile = new File(targetDir, relativePath)
outputFile.parentFile.mkdirs()
outputFile.write(payload.getXQDocXML())
}
}
}
add a comment |
up vote
0
down vote
This is what I ended up developing using the filtered copy task.
import org.apache.tools.ant.filters.BaseFilterReader
buildscript {
repositories {
jcenter()
}
dependencies {
classpath files('lib/xqdoc-1.9-jar-with-dependencies.jar')
}
}
plugins {
id "net.saliman.properties" version "1.4.6"
id "com.marklogic.ml-gradle" version "3.6.0"
}
repositories {
jcenter()
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}
configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}
dependencies {
mlcp "com.marklogic:mlcp:9.0.6"
mlcp files("marklogic/lib")
}
class XQDocFilter extends BaseFilterReader {
XQDocFilter(Reader input) {
super(new StringReader(new org.exquery.xqdoc.MarkLogicProcessor().process(input.text)))
}
}
/**
* Generate the xqDoc files from the XQuery source code
*/
task generateXQDocs(type: Copy) {
into 'xqDoc'
from 'src/main/ml-modules/root'
include '**/*.xqy'
rename { it - '.xqy' + '.xml' }
includeEmptyDirs = false
filter XQDocFilter
}
/**
* Deploy the xqDoc files to the content repository
*/
task importXQDoc(type: com.marklogic.gradle.task.MlcpTask) {
classpath = configurations.mlcp
command = "IMPORT"
database = "emh-accelerator-content"
input_file_path = "xqDoc"
output_collections = "xqdoc"
output_uri_replace = ".*xqDoc,'/xqDoc'"
document_type = "mixed"
}
And here is the Java class being called.
public class MarkLogicProcessor {
public String process(String txt) throws XQDocException, ParserConfigurationException, IOException, SAXException {
HashMap uriMap = new HashMap();
uriMap.put("fn", "http://www.w3.org/2003/05/xpath-functions");
uriMap.put("cts", "http://marklogic.com/cts"); // MarkLogic Server search functions (Core Text Services)
uriMap.put("dav", "DAV:"); // Used with WebDAV
uriMap.put("dbg", "http://marklogic.com/xdmp/debug"); // Debug Built-In functions
uriMap.put("dir", "http://marklogic.com/xdmp/directory"); // MarkLogic Server directory XML
uriMap.put("err", "http://www.w3.org/2005/xqt-errors"); // namespace for XQuery and XPath errors
uriMap.put("error", "http://marklogic.com/xdmp/error"); // MarkLogic Server error namespace
uriMap.put("local", "http://www.w3.org/2005/xquery-local-functions"); // local namespace for functions defined in main modules
uriMap.put("lock", "http://marklogic.com/xdmp/lock"); // MarkLogic Server locks
uriMap.put("map", "http://marklogic.com/xdmp/map"); // MarkLogic Server maps
uriMap.put("math", "http://marklogic.com/xdmp/math"); // math Built-In functions
uriMap.put("prof", "http://marklogic.com/xdmp/profile"); // profile Built-In functions
uriMap.put("prop", "http://marklogic.com/xdmp/property"); // MarkLogic Server properties
uriMap.put("sec", "http://marklogic.com/xdmp/security"); // security Built-In functions
uriMap.put("sem", "http://marklogic.com/semantics"); // semantic Built-In functions
uriMap.put("spell", "http://marklogic.com/xdmp/spell"); // spelling correction functions
uriMap.put("xdmp", "http://marklogic.com/xdmp"); // MarkLogic Server Built-In functions
uriMap.put("xml", "http://www.w3.org/XML/1998/namespace"); // XML namespace
uriMap.put("xmlns", "http://www.w3.org/2000/xmlns/"); // xmlns namespace
uriMap.put("xqe", "http://marklogic.com/xqe"); // deprecated MarkLogic Server xqe namespace
uriMap.put("xqterr", "http://www.w3.org/2005/xqt-errors"); // XQuery test suite errors (same as err)
uriMap.put("xs", "http://www.w3.org/2001/XMLSchema"); // XML Schema namespace
ANTLRInputStream inputStream = new ANTLRInputStream(txt);
XQueryLexer markupLexer = new XQueryLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(markupLexer);
XQueryParser markupParser = new XQueryParser(commonTokenStream);
XQueryParser.ModuleContext fileContext = markupParser.module();
StringBuffer buffer = new StringBuffer();
XQueryVisitor visitor = new XQueryVisitor(buffer, uriMap);
visitor.visit(fileContext);
return DocumentUtility.getStringFromDoc(DocumentUtility.getDocumentFromBuffer(buffer));
}
}
The xqDoc codebase is here https://github.com/lcahlander/xqdoc
The code to display the xqDoc documents is here https://github.com/lcahlander/marklogic-xqdoc-display
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Some thing like this should work (untested). You can adjust the hard-coded paths to use project properties, but should be enough to demonstrate how to iterate over each file in the fileset and execute
task generateXQDoc {
description = 'Generate XQDocs'
doLast {
def sourceDir = 'src/main/ml-modules'
File targetDir = new File('xqDoc')
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
def xqueryFiles = fileTree(dir: sourceDir, include: '**/*.xq*')
xqueryFiles.each { file ->
InputStream is = Files.newInputStream(file));
XQDocPayload payload = controller.process(is, "");
String relativePath = new File(sourceDir).toURI().relativize(file.toURI()).getPath();
File outputFile = new File(targetDir, relativePath)
outputFile.parentFile.mkdirs()
outputFile.write(payload.getXQDocXML())
}
}
}
add a comment |
up vote
2
down vote
accepted
Some thing like this should work (untested). You can adjust the hard-coded paths to use project properties, but should be enough to demonstrate how to iterate over each file in the fileset and execute
task generateXQDoc {
description = 'Generate XQDocs'
doLast {
def sourceDir = 'src/main/ml-modules'
File targetDir = new File('xqDoc')
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
def xqueryFiles = fileTree(dir: sourceDir, include: '**/*.xq*')
xqueryFiles.each { file ->
InputStream is = Files.newInputStream(file));
XQDocPayload payload = controller.process(is, "");
String relativePath = new File(sourceDir).toURI().relativize(file.toURI()).getPath();
File outputFile = new File(targetDir, relativePath)
outputFile.parentFile.mkdirs()
outputFile.write(payload.getXQDocXML())
}
}
}
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Some thing like this should work (untested). You can adjust the hard-coded paths to use project properties, but should be enough to demonstrate how to iterate over each file in the fileset and execute
task generateXQDoc {
description = 'Generate XQDocs'
doLast {
def sourceDir = 'src/main/ml-modules'
File targetDir = new File('xqDoc')
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
def xqueryFiles = fileTree(dir: sourceDir, include: '**/*.xq*')
xqueryFiles.each { file ->
InputStream is = Files.newInputStream(file));
XQDocPayload payload = controller.process(is, "");
String relativePath = new File(sourceDir).toURI().relativize(file.toURI()).getPath();
File outputFile = new File(targetDir, relativePath)
outputFile.parentFile.mkdirs()
outputFile.write(payload.getXQDocXML())
}
}
}
Some thing like this should work (untested). You can adjust the hard-coded paths to use project properties, but should be enough to demonstrate how to iterate over each file in the fileset and execute
task generateXQDoc {
description = 'Generate XQDocs'
doLast {
def sourceDir = 'src/main/ml-modules'
File targetDir = new File('xqDoc')
HashMap uriMap = new HashMap();
uriMap.put(XPathDriver.XPATH_PREFIX, XPathDriver.XPATH_URI);
controller = new XQDocController(XQDocController.JUL2017);
controller.setPredefinedFunctionNamespaces(uriMap);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
def xqueryFiles = fileTree(dir: sourceDir, include: '**/*.xq*')
xqueryFiles.each { file ->
InputStream is = Files.newInputStream(file));
XQDocPayload payload = controller.process(is, "");
String relativePath = new File(sourceDir).toURI().relativize(file.toURI()).getPath();
File outputFile = new File(targetDir, relativePath)
outputFile.parentFile.mkdirs()
outputFile.write(payload.getXQDocXML())
}
}
}
answered Nov 11 at 19:07
Mads Hansen
43.6k1093119
43.6k1093119
add a comment |
add a comment |
up vote
0
down vote
This is what I ended up developing using the filtered copy task.
import org.apache.tools.ant.filters.BaseFilterReader
buildscript {
repositories {
jcenter()
}
dependencies {
classpath files('lib/xqdoc-1.9-jar-with-dependencies.jar')
}
}
plugins {
id "net.saliman.properties" version "1.4.6"
id "com.marklogic.ml-gradle" version "3.6.0"
}
repositories {
jcenter()
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}
configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}
dependencies {
mlcp "com.marklogic:mlcp:9.0.6"
mlcp files("marklogic/lib")
}
class XQDocFilter extends BaseFilterReader {
XQDocFilter(Reader input) {
super(new StringReader(new org.exquery.xqdoc.MarkLogicProcessor().process(input.text)))
}
}
/**
* Generate the xqDoc files from the XQuery source code
*/
task generateXQDocs(type: Copy) {
into 'xqDoc'
from 'src/main/ml-modules/root'
include '**/*.xqy'
rename { it - '.xqy' + '.xml' }
includeEmptyDirs = false
filter XQDocFilter
}
/**
* Deploy the xqDoc files to the content repository
*/
task importXQDoc(type: com.marklogic.gradle.task.MlcpTask) {
classpath = configurations.mlcp
command = "IMPORT"
database = "emh-accelerator-content"
input_file_path = "xqDoc"
output_collections = "xqdoc"
output_uri_replace = ".*xqDoc,'/xqDoc'"
document_type = "mixed"
}
And here is the Java class being called.
public class MarkLogicProcessor {
public String process(String txt) throws XQDocException, ParserConfigurationException, IOException, SAXException {
HashMap uriMap = new HashMap();
uriMap.put("fn", "http://www.w3.org/2003/05/xpath-functions");
uriMap.put("cts", "http://marklogic.com/cts"); // MarkLogic Server search functions (Core Text Services)
uriMap.put("dav", "DAV:"); // Used with WebDAV
uriMap.put("dbg", "http://marklogic.com/xdmp/debug"); // Debug Built-In functions
uriMap.put("dir", "http://marklogic.com/xdmp/directory"); // MarkLogic Server directory XML
uriMap.put("err", "http://www.w3.org/2005/xqt-errors"); // namespace for XQuery and XPath errors
uriMap.put("error", "http://marklogic.com/xdmp/error"); // MarkLogic Server error namespace
uriMap.put("local", "http://www.w3.org/2005/xquery-local-functions"); // local namespace for functions defined in main modules
uriMap.put("lock", "http://marklogic.com/xdmp/lock"); // MarkLogic Server locks
uriMap.put("map", "http://marklogic.com/xdmp/map"); // MarkLogic Server maps
uriMap.put("math", "http://marklogic.com/xdmp/math"); // math Built-In functions
uriMap.put("prof", "http://marklogic.com/xdmp/profile"); // profile Built-In functions
uriMap.put("prop", "http://marklogic.com/xdmp/property"); // MarkLogic Server properties
uriMap.put("sec", "http://marklogic.com/xdmp/security"); // security Built-In functions
uriMap.put("sem", "http://marklogic.com/semantics"); // semantic Built-In functions
uriMap.put("spell", "http://marklogic.com/xdmp/spell"); // spelling correction functions
uriMap.put("xdmp", "http://marklogic.com/xdmp"); // MarkLogic Server Built-In functions
uriMap.put("xml", "http://www.w3.org/XML/1998/namespace"); // XML namespace
uriMap.put("xmlns", "http://www.w3.org/2000/xmlns/"); // xmlns namespace
uriMap.put("xqe", "http://marklogic.com/xqe"); // deprecated MarkLogic Server xqe namespace
uriMap.put("xqterr", "http://www.w3.org/2005/xqt-errors"); // XQuery test suite errors (same as err)
uriMap.put("xs", "http://www.w3.org/2001/XMLSchema"); // XML Schema namespace
ANTLRInputStream inputStream = new ANTLRInputStream(txt);
XQueryLexer markupLexer = new XQueryLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(markupLexer);
XQueryParser markupParser = new XQueryParser(commonTokenStream);
XQueryParser.ModuleContext fileContext = markupParser.module();
StringBuffer buffer = new StringBuffer();
XQueryVisitor visitor = new XQueryVisitor(buffer, uriMap);
visitor.visit(fileContext);
return DocumentUtility.getStringFromDoc(DocumentUtility.getDocumentFromBuffer(buffer));
}
}
The xqDoc codebase is here https://github.com/lcahlander/xqdoc
The code to display the xqDoc documents is here https://github.com/lcahlander/marklogic-xqdoc-display
add a comment |
up vote
0
down vote
This is what I ended up developing using the filtered copy task.
import org.apache.tools.ant.filters.BaseFilterReader
buildscript {
repositories {
jcenter()
}
dependencies {
classpath files('lib/xqdoc-1.9-jar-with-dependencies.jar')
}
}
plugins {
id "net.saliman.properties" version "1.4.6"
id "com.marklogic.ml-gradle" version "3.6.0"
}
repositories {
jcenter()
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}
configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}
dependencies {
mlcp "com.marklogic:mlcp:9.0.6"
mlcp files("marklogic/lib")
}
class XQDocFilter extends BaseFilterReader {
XQDocFilter(Reader input) {
super(new StringReader(new org.exquery.xqdoc.MarkLogicProcessor().process(input.text)))
}
}
/**
* Generate the xqDoc files from the XQuery source code
*/
task generateXQDocs(type: Copy) {
into 'xqDoc'
from 'src/main/ml-modules/root'
include '**/*.xqy'
rename { it - '.xqy' + '.xml' }
includeEmptyDirs = false
filter XQDocFilter
}
/**
* Deploy the xqDoc files to the content repository
*/
task importXQDoc(type: com.marklogic.gradle.task.MlcpTask) {
classpath = configurations.mlcp
command = "IMPORT"
database = "emh-accelerator-content"
input_file_path = "xqDoc"
output_collections = "xqdoc"
output_uri_replace = ".*xqDoc,'/xqDoc'"
document_type = "mixed"
}
And here is the Java class being called.
public class MarkLogicProcessor {
public String process(String txt) throws XQDocException, ParserConfigurationException, IOException, SAXException {
HashMap uriMap = new HashMap();
uriMap.put("fn", "http://www.w3.org/2003/05/xpath-functions");
uriMap.put("cts", "http://marklogic.com/cts"); // MarkLogic Server search functions (Core Text Services)
uriMap.put("dav", "DAV:"); // Used with WebDAV
uriMap.put("dbg", "http://marklogic.com/xdmp/debug"); // Debug Built-In functions
uriMap.put("dir", "http://marklogic.com/xdmp/directory"); // MarkLogic Server directory XML
uriMap.put("err", "http://www.w3.org/2005/xqt-errors"); // namespace for XQuery and XPath errors
uriMap.put("error", "http://marklogic.com/xdmp/error"); // MarkLogic Server error namespace
uriMap.put("local", "http://www.w3.org/2005/xquery-local-functions"); // local namespace for functions defined in main modules
uriMap.put("lock", "http://marklogic.com/xdmp/lock"); // MarkLogic Server locks
uriMap.put("map", "http://marklogic.com/xdmp/map"); // MarkLogic Server maps
uriMap.put("math", "http://marklogic.com/xdmp/math"); // math Built-In functions
uriMap.put("prof", "http://marklogic.com/xdmp/profile"); // profile Built-In functions
uriMap.put("prop", "http://marklogic.com/xdmp/property"); // MarkLogic Server properties
uriMap.put("sec", "http://marklogic.com/xdmp/security"); // security Built-In functions
uriMap.put("sem", "http://marklogic.com/semantics"); // semantic Built-In functions
uriMap.put("spell", "http://marklogic.com/xdmp/spell"); // spelling correction functions
uriMap.put("xdmp", "http://marklogic.com/xdmp"); // MarkLogic Server Built-In functions
uriMap.put("xml", "http://www.w3.org/XML/1998/namespace"); // XML namespace
uriMap.put("xmlns", "http://www.w3.org/2000/xmlns/"); // xmlns namespace
uriMap.put("xqe", "http://marklogic.com/xqe"); // deprecated MarkLogic Server xqe namespace
uriMap.put("xqterr", "http://www.w3.org/2005/xqt-errors"); // XQuery test suite errors (same as err)
uriMap.put("xs", "http://www.w3.org/2001/XMLSchema"); // XML Schema namespace
ANTLRInputStream inputStream = new ANTLRInputStream(txt);
XQueryLexer markupLexer = new XQueryLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(markupLexer);
XQueryParser markupParser = new XQueryParser(commonTokenStream);
XQueryParser.ModuleContext fileContext = markupParser.module();
StringBuffer buffer = new StringBuffer();
XQueryVisitor visitor = new XQueryVisitor(buffer, uriMap);
visitor.visit(fileContext);
return DocumentUtility.getStringFromDoc(DocumentUtility.getDocumentFromBuffer(buffer));
}
}
The xqDoc codebase is here https://github.com/lcahlander/xqdoc
The code to display the xqDoc documents is here https://github.com/lcahlander/marklogic-xqdoc-display
add a comment |
up vote
0
down vote
up vote
0
down vote
This is what I ended up developing using the filtered copy task.
import org.apache.tools.ant.filters.BaseFilterReader
buildscript {
repositories {
jcenter()
}
dependencies {
classpath files('lib/xqdoc-1.9-jar-with-dependencies.jar')
}
}
plugins {
id "net.saliman.properties" version "1.4.6"
id "com.marklogic.ml-gradle" version "3.6.0"
}
repositories {
jcenter()
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}
configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}
dependencies {
mlcp "com.marklogic:mlcp:9.0.6"
mlcp files("marklogic/lib")
}
class XQDocFilter extends BaseFilterReader {
XQDocFilter(Reader input) {
super(new StringReader(new org.exquery.xqdoc.MarkLogicProcessor().process(input.text)))
}
}
/**
* Generate the xqDoc files from the XQuery source code
*/
task generateXQDocs(type: Copy) {
into 'xqDoc'
from 'src/main/ml-modules/root'
include '**/*.xqy'
rename { it - '.xqy' + '.xml' }
includeEmptyDirs = false
filter XQDocFilter
}
/**
* Deploy the xqDoc files to the content repository
*/
task importXQDoc(type: com.marklogic.gradle.task.MlcpTask) {
classpath = configurations.mlcp
command = "IMPORT"
database = "emh-accelerator-content"
input_file_path = "xqDoc"
output_collections = "xqdoc"
output_uri_replace = ".*xqDoc,'/xqDoc'"
document_type = "mixed"
}
And here is the Java class being called.
public class MarkLogicProcessor {
public String process(String txt) throws XQDocException, ParserConfigurationException, IOException, SAXException {
HashMap uriMap = new HashMap();
uriMap.put("fn", "http://www.w3.org/2003/05/xpath-functions");
uriMap.put("cts", "http://marklogic.com/cts"); // MarkLogic Server search functions (Core Text Services)
uriMap.put("dav", "DAV:"); // Used with WebDAV
uriMap.put("dbg", "http://marklogic.com/xdmp/debug"); // Debug Built-In functions
uriMap.put("dir", "http://marklogic.com/xdmp/directory"); // MarkLogic Server directory XML
uriMap.put("err", "http://www.w3.org/2005/xqt-errors"); // namespace for XQuery and XPath errors
uriMap.put("error", "http://marklogic.com/xdmp/error"); // MarkLogic Server error namespace
uriMap.put("local", "http://www.w3.org/2005/xquery-local-functions"); // local namespace for functions defined in main modules
uriMap.put("lock", "http://marklogic.com/xdmp/lock"); // MarkLogic Server locks
uriMap.put("map", "http://marklogic.com/xdmp/map"); // MarkLogic Server maps
uriMap.put("math", "http://marklogic.com/xdmp/math"); // math Built-In functions
uriMap.put("prof", "http://marklogic.com/xdmp/profile"); // profile Built-In functions
uriMap.put("prop", "http://marklogic.com/xdmp/property"); // MarkLogic Server properties
uriMap.put("sec", "http://marklogic.com/xdmp/security"); // security Built-In functions
uriMap.put("sem", "http://marklogic.com/semantics"); // semantic Built-In functions
uriMap.put("spell", "http://marklogic.com/xdmp/spell"); // spelling correction functions
uriMap.put("xdmp", "http://marklogic.com/xdmp"); // MarkLogic Server Built-In functions
uriMap.put("xml", "http://www.w3.org/XML/1998/namespace"); // XML namespace
uriMap.put("xmlns", "http://www.w3.org/2000/xmlns/"); // xmlns namespace
uriMap.put("xqe", "http://marklogic.com/xqe"); // deprecated MarkLogic Server xqe namespace
uriMap.put("xqterr", "http://www.w3.org/2005/xqt-errors"); // XQuery test suite errors (same as err)
uriMap.put("xs", "http://www.w3.org/2001/XMLSchema"); // XML Schema namespace
ANTLRInputStream inputStream = new ANTLRInputStream(txt);
XQueryLexer markupLexer = new XQueryLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(markupLexer);
XQueryParser markupParser = new XQueryParser(commonTokenStream);
XQueryParser.ModuleContext fileContext = markupParser.module();
StringBuffer buffer = new StringBuffer();
XQueryVisitor visitor = new XQueryVisitor(buffer, uriMap);
visitor.visit(fileContext);
return DocumentUtility.getStringFromDoc(DocumentUtility.getDocumentFromBuffer(buffer));
}
}
The xqDoc codebase is here https://github.com/lcahlander/xqdoc
The code to display the xqDoc documents is here https://github.com/lcahlander/marklogic-xqdoc-display
This is what I ended up developing using the filtered copy task.
import org.apache.tools.ant.filters.BaseFilterReader
buildscript {
repositories {
jcenter()
}
dependencies {
classpath files('lib/xqdoc-1.9-jar-with-dependencies.jar')
}
}
plugins {
id "net.saliman.properties" version "1.4.6"
id "com.marklogic.ml-gradle" version "3.6.0"
}
repositories {
jcenter()
maven { url "http://developer.marklogic.com/maven2/" }
maven { url "http://repository.cloudera.com/artifactory/cloudera-repos/" }
}
configurations {
mlcp {
resolutionStrategy {
force "xml-apis:xml-apis:1.4.01"
}
}
}
dependencies {
mlcp "com.marklogic:mlcp:9.0.6"
mlcp files("marklogic/lib")
}
class XQDocFilter extends BaseFilterReader {
XQDocFilter(Reader input) {
super(new StringReader(new org.exquery.xqdoc.MarkLogicProcessor().process(input.text)))
}
}
/**
* Generate the xqDoc files from the XQuery source code
*/
task generateXQDocs(type: Copy) {
into 'xqDoc'
from 'src/main/ml-modules/root'
include '**/*.xqy'
rename { it - '.xqy' + '.xml' }
includeEmptyDirs = false
filter XQDocFilter
}
/**
* Deploy the xqDoc files to the content repository
*/
task importXQDoc(type: com.marklogic.gradle.task.MlcpTask) {
classpath = configurations.mlcp
command = "IMPORT"
database = "emh-accelerator-content"
input_file_path = "xqDoc"
output_collections = "xqdoc"
output_uri_replace = ".*xqDoc,'/xqDoc'"
document_type = "mixed"
}
And here is the Java class being called.
public class MarkLogicProcessor {
public String process(String txt) throws XQDocException, ParserConfigurationException, IOException, SAXException {
HashMap uriMap = new HashMap();
uriMap.put("fn", "http://www.w3.org/2003/05/xpath-functions");
uriMap.put("cts", "http://marklogic.com/cts"); // MarkLogic Server search functions (Core Text Services)
uriMap.put("dav", "DAV:"); // Used with WebDAV
uriMap.put("dbg", "http://marklogic.com/xdmp/debug"); // Debug Built-In functions
uriMap.put("dir", "http://marklogic.com/xdmp/directory"); // MarkLogic Server directory XML
uriMap.put("err", "http://www.w3.org/2005/xqt-errors"); // namespace for XQuery and XPath errors
uriMap.put("error", "http://marklogic.com/xdmp/error"); // MarkLogic Server error namespace
uriMap.put("local", "http://www.w3.org/2005/xquery-local-functions"); // local namespace for functions defined in main modules
uriMap.put("lock", "http://marklogic.com/xdmp/lock"); // MarkLogic Server locks
uriMap.put("map", "http://marklogic.com/xdmp/map"); // MarkLogic Server maps
uriMap.put("math", "http://marklogic.com/xdmp/math"); // math Built-In functions
uriMap.put("prof", "http://marklogic.com/xdmp/profile"); // profile Built-In functions
uriMap.put("prop", "http://marklogic.com/xdmp/property"); // MarkLogic Server properties
uriMap.put("sec", "http://marklogic.com/xdmp/security"); // security Built-In functions
uriMap.put("sem", "http://marklogic.com/semantics"); // semantic Built-In functions
uriMap.put("spell", "http://marklogic.com/xdmp/spell"); // spelling correction functions
uriMap.put("xdmp", "http://marklogic.com/xdmp"); // MarkLogic Server Built-In functions
uriMap.put("xml", "http://www.w3.org/XML/1998/namespace"); // XML namespace
uriMap.put("xmlns", "http://www.w3.org/2000/xmlns/"); // xmlns namespace
uriMap.put("xqe", "http://marklogic.com/xqe"); // deprecated MarkLogic Server xqe namespace
uriMap.put("xqterr", "http://www.w3.org/2005/xqt-errors"); // XQuery test suite errors (same as err)
uriMap.put("xs", "http://www.w3.org/2001/XMLSchema"); // XML Schema namespace
ANTLRInputStream inputStream = new ANTLRInputStream(txt);
XQueryLexer markupLexer = new XQueryLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(markupLexer);
XQueryParser markupParser = new XQueryParser(commonTokenStream);
XQueryParser.ModuleContext fileContext = markupParser.module();
StringBuffer buffer = new StringBuffer();
XQueryVisitor visitor = new XQueryVisitor(buffer, uriMap);
visitor.visit(fileContext);
return DocumentUtility.getStringFromDoc(DocumentUtility.getDocumentFromBuffer(buffer));
}
}
The xqDoc codebase is here https://github.com/lcahlander/xqdoc
The code to display the xqDoc documents is here https://github.com/lcahlander/marklogic-xqdoc-display
answered Nov 25 at 11:55
Loren Cahlander
534314
534314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239147%2fhow-do-i-run-a-java-method-against-all-files-of-a-type-within-a-gradle-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
– JB Nizet
Nov 10 at 12:56
And what is your exact problem? Did you try anything?
– vanje
Nov 10 at 13:11
I have been using gradle, but have not developed tasks. I need to be able to pull down the maven project from github and then be able to run the java command against all XQuery files. I am looking for example tasks of doing something similar.
– Loren Cahlander
Nov 10 at 13:16
Asking for tutorials is off-topic here. You should use Google to find tutorials and example code.
– vanje
Nov 10 at 14:47