mavenmaven-antrun-plugingrunt-connect

maven ant run plugin - killing process that was spawned


Can somebody tell me if it is possible to spawn a process and then kill that process when integration tests have finished running?

I am currently using the ant run plugin to start a grunt connect server and I am using cargo to deploy my rest app to tomcat, this allows me to integration test against the running angular web app which calls rest services.

I almost have everything how I want it but.. when the build has finished the grunt server is still running because I have set keep alive to true.

Ideally when my build finishes I would like to somehow kill the process the for the server.


Solution

  • I came back to this as the final piece I needed to fix to get my multi-module project building and running integration tests against an angular front end and java back end as my build runs in maven.

    The final thing to do to kill the node server which is spawned is to use the ant run plugin to kill it (simple really!).

    Anyway hopefull this might help someone else in the future:

       <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>Run grunt integration-test task in pre-integration-test phase</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <target name="starting">
                                <echo>
    
                                </echo>
                                <exec executable="cmd" spawn="true" dir="${project.basedir}"
                                    osfamily="windows">
                                    <arg line="/c grunt int-test --no-color > grunt.status " />
                                </exec>
                                <exec executable="bash" spawn="true" dir="${project.basedir}"
                                    osfamily="unix">
                                    <arg line="grunt int-test --no-color > grunt.status" />
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>                            
                    <execution>
                        <id>Kill NodeServer in post-integration-test phase</id>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <target name="ending">
                                <echo>
    
                                </echo>
                                <exec executable="cmd" spawn="true" dir="${project.basedir}"
                                    osfamily="windows">
                                    <arg line="/c Taskkill /IM node.exe /F " />
                                </exec>
                                <exec executable="bash" spawn="true" dir="${project.basedir}"
                                    osfamily="unix">
                                    <arg line="kill -9 $(ps aux | grep '\snode\s' | awk '{print $2}')" />
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>