View Javadoc

1   /*
2    * Copyright 2012 akquinet
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *   http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package de.akquinet.innovation.play.maven;
17  
18  import org.apache.commons.exec.CommandLine;
19  import org.apache.commons.exec.DefaultExecutor;
20  import org.apache.commons.exec.ExecuteWatchdog;
21  import org.apache.maven.plugin.MojoExecutionException;
22  
23  import java.io.IOException;
24  
25  /**
26   * Launch the Play application
27   *
28   * @goal run
29   * @requiresProject false
30   * @requiresDependencyResolution provided
31   *
32   */
33  public class Play2RunMojo
34          extends AbstractPlay2Mojo {
35  
36      public void execute()
37              throws MojoExecutionException {
38  
39          String line = getPlay2().getAbsolutePath();
40  
41          CommandLine cmdLine = CommandLine.parse(line);
42          cmdLine.addArgument("run");
43          DefaultExecutor executor = new DefaultExecutor();
44  
45          // As where not linked to a project, we can't set the working directory.
46          // So it will use the directory where mvn was launched.
47  
48          executor.setExitValue(0);
49          try {
50              executor.execute(cmdLine, getEnvironment());
51          } catch (IOException e) {
52              // Ignore.
53          }
54      }
55  }