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.artifact.factory.ArtifactFactory;
22  import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
23  import org.apache.maven.artifact.repository.ArtifactRepository;
24  import org.apache.maven.artifact.resolver.ArtifactCollector;
25  import org.apache.maven.artifact.resolver.ArtifactResolver;
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.dependency.CopyDependenciesMojo;
28  
29  import java.io.File;
30  import java.io.IOException;
31  import java.util.List;
32  
33  /**
34   * Compile the Play application
35   *
36   * @goal compile
37   * @phase compile
38   */
39  public class Play2CompilationMojo
40          extends AbstractPlay2Mojo {
41  
42  
43      public void execute()
44              throws MojoExecutionException {
45  
46          String line = getPlay2().getAbsolutePath();
47  
48          CommandLine cmdLine = CommandLine.parse(line);
49          cmdLine.addArgument("compile");
50          DefaultExecutor executor = new DefaultExecutor();
51  
52          if (timeout > 0) {
53              ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
54              executor.setWatchdog(watchdog);
55          }
56  
57          executor.setExitValue(0);
58          executor.setWorkingDirectory(project.getBasedir());
59          try {
60              executor.execute(cmdLine, getEnvironment());
61          } catch (IOException e) {
62              throw new MojoExecutionException("Error during compilation", e);
63          }
64      }
65  }