在gradle中执行bash脚本 [英] Executing bash script in gradle

查看:955
本文介绍了在gradle中执行bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用geb进行功能测试。

我的应用程序使用virgo进行部署,并使用HSQLDB存储数据。我想在这个应用程序的工作版本上执行测试,但是我希望从空数据库开始,每次运行webtests。



我写了一个简单的bash脚本

 #!/ bin / sh 
rm -rf $ VIRGO_HOME / aresdb *
$ VIRGO_HOME / bin /shutdown.sh&
sleep 10
$ VIRGO_HOME / bin / startup.sh&

删除数据库并重新启动virgo。



 任务cleanDB(类型:Exec)

然而,当我将它添加到我的build.gradle任务执行命令中时, {
commandLine'./clean.sh'
}

为什么这条路?当我在控制台中运行这个脚本时,它会很快返回(但处女座仍然会写入控制台)。

我试图在单独的线程中运行它,但遇到以下错误:



pre $ 任务cleanDBThread()<< {
def cleanDBThread1 = Thread.start {
cleanDB .execute()
}
sleep 10000
println唤醒!
}

线程Thread-32中的异常java.lang.IllegalStateException:
无法启动长时间运行操作,因为任务工件状态缓存
(/ home /tomasz/ares/.gradle/1.0-milestone-9/taskArtifacts)尚未锁定。

我也尝试在休眠配置中设置'create-drop',但它也需要重新启动处女座。即使重新部署应用程序也无济于事。



我应该如何运行具有空数据库的webtest?

解决方案

这很奇怪



我创建了一个任务

 任务调用CL(类型:Exec){
commandLine'./cl.sh'
}

调用cl.sh文件

 #!/ bin / sh 
echo开始
./acl.sh&
睡眠10
./acl.sh&

调用acl.sh



<$ p $

,它的工作!但是有一件事,当你添加./acl.sh和符号 & 时,你是从另一个启动gradle的线程调用任务的,并且看起来像是挂。我会删除&从您的电话到关机并开始像这样

 #!/ bin / sh 
rm -rf $ VIRGO_HOME / aresdb *
$ VIRGO_HOME / bin / shutdown.sh
$ VIRGO_HOME / bin / startup.sh

无论如何,你想在关机的同一个线程中等待开始,而且不需要调用睡眠!


I am doing functional testing with geb.

My application is deployed using virgo and uses HSQLDB to store data. I would like to perform tests on this working version of application, but I would like to start with empty database, every time I run webtests.

I wrote a simple bash script

#!/bin/sh
rm -rf $VIRGO_HOME/aresdb*
$VIRGO_HOME/bin/shutdown.sh &
sleep 10
$VIRGO_HOME/bin/startup.sh &

which removes the database and restarts virgo.

However, when I add it to my build.gradle task executing command never ends.

task cleanDB(type: Exec) {
    commandLine './clean.sh' 
}

Why is it this way? When I run this script in console it returns quickly (but virgo still writes to the console).

I have tried to run it in separate thread, but I encountered following error:

task cleanDBThread()<<{
    def cleanDBThread1 = Thread.start {
         cleanDB.execute()
    }
    sleep 10000
    println "wake up!"
}

Exception in thread "Thread-32" java.lang.IllegalStateException:
Cannot start long running operation, as the task artifact state cache
(/home/tomasz/ares/.gradle/1.0-milestone-9/taskArtifacts) has not been locked.

I also tried setting 'create-drop' in hibernate configuration, but it also requires restarting virgo. Even redeploying the application does not help.

What should I do to run webtests with empty database?

解决方案

That's weird

I created a task

task callCL(type: Exec) {
    commandLine './cl.sh'
}

that calls cl.sh file

#!/bin/sh
echo "starting "
./acl.sh &
sleep 10
./acl.sh &

that call acl.sh

#!/bin/sh
echo "I am not doing anything"

and it worked! but one thing though, when you add ./acl.sh ampersand character & you're calling the task from a different thread that started gradle, and kinda looks like it's hanging. I would remove the & from your calls to shutdown and start like this

#!/bin/sh
rm -rf $VIRGO_HOME/aresdb*
$VIRGO_HOME/bin/shutdown.sh
$VIRGO_HOME/bin/startup.sh

anyways you want to wait in the same thread from shutdown to start, and no need to call sleep too!

这篇关于在gradle中执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆