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










share|improve this question


















  • 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















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










share|improve this question


















  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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())
}
}
}





share|improve this answer




























    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






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      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

























      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())
      }
      }
      }





      share|improve this answer

























        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())
        }
        }
        }





        share|improve this answer























          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())
          }
          }
          }





          share|improve this answer












          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())
          }
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 19:07









          Mads Hansen

          43.6k1093119




          43.6k1093119
























              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






              share|improve this answer

























                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






                share|improve this answer























                  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






                  share|improve this answer












                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 at 11:55









                  Loren Cahlander

                  534314




                  534314






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Guess what letter conforming each word

                      Port of Spain

                      Run scheduled task as local user group (not BUILTIN)