maven - Execute plugin only if another execution succeeds -
i have 2 executions of plugin run in 2 different phases. instance:
<executions> <execution> <id>a</id> <phase>pre-integration-test</phase> </execution> <execution> <id>b</id> <phase>post-integration-test</phase> </execution> </executions>
i want execute b if succeeds. how do that?
resolved using antrun maven plugin delete operations set run on post-integration-test, insert operations set run on pre-integration-test phase , using ant-contrib library. i've put insert operations on trycatch block. if exception caught, delete operations used , fail build.
here's code example insertoperation.xml ant script (i won't put "project" , "target" tags, "target" name "dbunit-insert"):
// classpath used maven's test scope classpath <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.test.classpath"/> // classpath used maven's test scope classpath <taskdef name="dbunit" classname="org.dbunit.ant.dbunittask" classpathref="maven.test.classpath"/> <trycatch> <try> <dbunit driver="your.driver" url="your.database.url" userid="your.database.username" password="your.database.password" schema="your.database.schema"> <operation type="insert" src="src/main/resources/insertyourdataset.flat" format="flat"/> // know has flat format default define won't // appear null on console during execution. , although // can define "transaction" parameter on "operation", // rollback "operation" in defined. means // if second file set insert , problem it, // setting "transaction" parameter "true" won't rollback // first insert made. </dbunit> </try> <catch> // xml delete operations // xml created based on inserted data // e.g.: if insert string "abc", delete // works rollback insert operations // so, if trouble on second file // grants first inserted dataset deleted. <ant antfile="src/main/resources/ant/deleteoperation.xml" inheritrefs="true"/> // command fail maven build // print message you've set , prevent running tests // rely on data tried insert <fail message="failed build due problem on insert operation"/> </catch> </trycatch>
, here's code example deleteoperation.xml ant script (i won't put "project" , "target" tags, "target" name "dbunit-delete"):
// notice don't need ant-contrib library // that's because delete operations ignored if data // doesn't exist. // won't need trycatch block, no ant-contrib here <taskdef name="dbunit" classname="org.dbunit.ant.dbunittask"/> <dbunit driver="your.driver" url="your.database.url" userid="your.database.username" password="your.database.password" schema="your.database.schema"> <operation type="delete" src="src/main/resources/deleteyourdataset.flat" format="flat"/> </dbunit>
hope this.
Comments
Post a Comment