View Javadoc

1   package org.codehaus.mojo.javascript;
2   
3   /*
4    * Derivative Work
5    * Copyright 2010 SOFTEC sa. All rights reserved.
6    *
7    * Original Work
8    * Copyright 2001-2005 The Apache Software Foundation.
9    *
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   */
22  
23  import java.io.File;
24  
25  import org.apache.maven.artifact.DefaultArtifact;
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.codehaus.plexus.archiver.ArchiverException;
29  
30  /**
31   * Goal that prepares scripts for packaging as a web application.
32   * 
33   * @goal war-package
34   * @requiresDependencyResolution runtime
35   * @phase compile
36   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
37   */
38  public class WarPackageMojo
39      extends CompileMojo
40  {
41  
42      /**
43       * The directory where the webapp is built.
44       * 
45       * @parameter expression="${project.build.directory}/${project.build.finalName}"
46       * @required
47       */
48      private File webappDirectory;
49  
50      /**
51       * The folder in webapp for javascripts
52       * 
53       * @parameter expression="${scripts}" default-value="scripts"
54       */
55      private String scriptsDirectory;
56  
57      /**
58       * The folder for javascripts dependencies
59       * 
60       * @parameter expression="${scripts}" default-value="lib"
61       */
62      private String libsDirectory;
63  
64      /**
65       * Use the artifactId as folder
66       * 
67       * @parameter
68       */
69      private boolean useArtifactId;
70  
71      /**
72       * {@inheritDoc}
73       * 
74       * @see org.apache.maven.plugin.Mojo#execute()
75       */
76      public void execute()
77          throws MojoExecutionException, MojoFailureException
78      {
79          super.outputDirectory = new File( webappDirectory, scriptsDirectory );
80          super.execute();
81  
82          try
83          {
84              getJavascriptArtifactManager().unpack( getProject(), DefaultArtifact.SCOPE_RUNTIME,
85                  new File( webappDirectory, scriptsDirectory + File.separator + libsDirectory ), useArtifactId );
86          }
87          catch ( ArchiverException e )
88          {
89              throw new MojoExecutionException( "Failed to unpack javascript dependencies", e );
90          }
91      }
92  
93  }