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.maven.plugin.MojoExecutionException;
21  
22  import java.io.IOException;
23  
24  /**
25   * Launch the Play application
26   *
27   * @goal run
28   * @requiresProject false
29   * @requiresDependencyResolution provided
30   *
31   */
32  public class Play2RunMojo
33          extends AbstractPlay2Mojo {
34  
35      public void execute()
36              throws MojoExecutionException {
37  
38          String line = getPlay2().getAbsolutePath();
39  
40          CommandLine cmdLine = CommandLine.parse(line);
41          cmdLine.addArguments(getPlay2SystemPropertiesArguments(), false);
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  }