This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-198
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-198 by this push:
     new c138d3d  Update NCCli.scala
c138d3d is described below

commit c138d3dac1c4c047f78b71f2481d14df7264bfc6
Author: Aaron Radzinski <[email protected]>
AuthorDate: Thu Dec 17 15:59:37 2020 -0800

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 977a14a..5481472 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -525,6 +525,27 @@ object NCCli extends App {
     }
 
     /**
+     * Checks whether given list of models contains class names outside of 
NLPCraft project.
+     *
+     * @param mdls Comma-separated list of fully qualified class names for 
data models.
+     * @return
+     */
+    private def hasExternalModels(mdls: String): Boolean =
+        U.splitTrimFilter(mdls, 
",").exists(!_.startsWith("org.apache.nlpcraft."))
+
+    /**
+     * Checks that every component of the given class path exists relative to 
the current user working
+     * directory of this process.
+     *
+     * @param cp Classpath to check.
+     * @return
+     */
+    private def checkClasspath(cp: String): Unit =
+        for (path <- U.splitTrimFilter(cp, ";:"))
+            if (!new File(path).exists())
+                throw new IllegalStateException(s"Classpath not found: 
${c(path)}")
+
+    /**
      * @param cmd  Command descriptor.
      * @param args Arguments, if any, for this command.
      * @param repl Whether or not running from REPL.
@@ -618,6 +639,19 @@ object NCCli extends App {
             case None ⇒ Seq("-ea", "-Xms1024m")
         }
 
+        if (mdls != null) {
+            if (hasExternalModels(mdls) && addCp == null)
+                throw new IllegalStateException(
+                    s"Additional classpath is required when deploying your own 
models. " +
+                    s"Use ${c("--cp")} parameters to provide additional 
classpath.")
+        }
+
+        if (mdls == null && addCp != null)
+            warn(s"Additional classpath (${c("--cp")}) but no models 
(${c("--models")}).")
+
+        if (addCp != null)
+            checkClasspath(addCp)
+
         checkFilePath(cfgPath)
 
         // Ensure that there isn't another local probe running.

Reply via email to