Parsing 从限制性项目(绑定到框架/IDE)解析Groovy脚本 问题

Parsing 从限制性项目(绑定到框架/IDE)解析Groovy脚本 问题,parsing,groovy,classpath,katalon-studio,Parsing,Groovy,Classpath,Katalon Studio,我正在将一个项目从Katalon Studio项目(封闭系统)移植到一个更标准的Groovy项目。目前,我正在尝试构建一个自动工具,该工具将解析我的脚本和类,以提供对我的结构和语法的更改。目前,我在解析groovy脚本时遇到了很多困难,因为这些文件不能从Katalon Studio外部构建(如果我将项目导入IntelliJ之类的东西,我就无法构建) 客观的 我们的目标是能够以某种方式解析脚本,而不需要自定义解析器(Groovy会让这变得非常困难,因为它的语法松散) 卡塔隆工作室项目摘要 它的设置

我正在将一个项目从Katalon Studio项目(封闭系统)移植到一个更标准的Groovy项目。目前,我正在尝试构建一个自动工具,该工具将解析我的脚本和类,以提供对我的结构和语法的更改。目前,我在解析groovy脚本时遇到了很多困难,因为这些文件不能从Katalon Studio外部构建(如果我将项目导入IntelliJ之类的东西,我就无法构建)

客观的 我们的目标是能够以某种方式解析脚本,而不需要自定义解析器(Groovy会让这变得非常困难,因为它的语法松散)

卡塔隆工作室项目摘要 它的设置就像一个Eclipse项目。我已经在下面粘贴了类路径。
.class
文件位于
bin/keyword


(失败的)尝试 我曾尝试使用GroovyDocTool、GroovyCassLoader和GroovyShell来测试源代码,但无可否认,我不知道自己在做什么,而且几乎没有文档可供参考。我最后尝试的是这个网站上其他答案的汇编,可能不正确

我尝试的(可能是错误的):

注-在Katalon软件结构中,类被称为“关键字”

输出(全部为空):

下面是对GroovyClassLoader和GroovyShell的尝试。它们运行,但无法通过导入语句

File classDir = new File(baseDir + '/git/myProj/.classPath')
String classPath = classDir.toString()
println "classpath: ${classPath}"

File binDir = new File(baseDir + '/git/myProj/bin')
String binPath = binDir.toString()
println "binDir: ${binPath}"

File keywordDir = new File(baseDir + '/git/myProj/bin/keyword')
String keywordPath = keywordDir.toString()
println "keywordDir: ${keywordPath}"

GroovyClassLoader classLoader = new GroovyClassLoader()
classLoader.addClasspath(classPath)
classLoader.addClasspath(binPath)
println "Added classpath:\n${classLoader.getClassPath()}"
println "Loaded classes:\n${classLoader.getLoadedClasses()*.getName()}"
GroovyShell shell = new GroovyShell(classLoader)
Script script = shell.parse(fileText)

例外情况:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class com.myClass
 @ line 2, column 1.
   import com.myClass
   ^

EclipseIDE可以为您提供类似的体验。您的.classpath文件示例应该可以在vanilla eclipse plus GDT和JDT中的Java/Groovy项目中直接使用。我建议从一个小项目开始,先验证Groovy脚本,然后添加源代码和库。@emilles遗憾的是,由于某些原因,它无法工作。但我不知道确切的原因。我认为这是Katalon的创作者有意锁定的,目的是将项目与他们的产品联系起来。“我的心告诉我,必须有某种方法来解耦它,但看起来我无法找到确切的方法。”daggett我也检查了那篇文章,虽然它对运行一次性脚本很有用,但它仍然需要访问原始Katalon项目才能构建,并且不适合我的用例。谢谢你!我现在决定把我所有的鸡蛋都放进regex的篮子里。祝我好运D
File classDir = new File(baseDir + '/git/myProj/.classPath')
String classPath = classDir.toString()
println "classpath: ${classPath}"

File binDir = new File(baseDir + '/git/myProj/bin')
String binPath = binDir.toString()
println "binDir: ${binPath}"

File keywordDir = new File(baseDir + '/git/myProj/bin/keyword')
String keywordPath = keywordDir.toString()
println "keywordDir: ${keywordPath}"

GroovyClassLoader classLoader = new GroovyClassLoader()
classLoader.addClasspath(classPath)
classLoader.addClasspath(binPath)
println "Added classpath:\n${classLoader.getClassPath()}"
println "Loaded classes:\n${classLoader.getLoadedClasses()*.getName()}"
GroovyShell shell = new GroovyShell(classLoader)
Script script = shell.parse(fileText)

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class com.myClass
 @ line 2, column 1.
   import com.myClass
   ^