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.AbstractMojo;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.project.MavenProject;
30 import org.codehaus.mojo.javascript.archive.JavascriptArtifactManager;
31 import org.codehaus.plexus.archiver.ArchiverException;
32
33 /**
34 * Goal that copies javascript dependencies to the web application script
35 * folder, inside the webapp source directory. This allows to prepare the webapp
36 * for running on a lightweight servlet container that does not requires
37 * packaging (when using the jetty:run goal).
38 *
39 * @goal inplace
40 * @requiresDependencyResolution runtime
41 * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
42 */
43 public class InPlaceMojo
44 extends AbstractMojo
45 {
46
47 /**
48 * The maven project.
49 *
50 * @parameter expression="${project}"
51 * @required
52 * @readonly
53 */
54 private MavenProject project;
55
56 /**
57 * Single directory for extra files to include in the WAR.
58 *
59 * @parameter expression="${basedir}/src/main/webapp"
60 * @required
61 */
62 private File warSourceDirectory;
63
64 /**
65 * The folder in webapp for javascripts
66 *
67 * @parameter expression="${scripts}" default-value="scripts/libs"
68 */
69 private String scriptsDirectory;
70
71 /**
72 * The folder for javascripts dependencies
73 *
74 * @parameter expression="${scripts}" default-value="lib"
75 */
76 private String libsDirectory;
77
78 /**
79 * Use the artifactId as folder
80 *
81 * @parameter
82 */
83 private boolean useArtifactId;
84
85 /**
86 * @component
87 */
88 private JavascriptArtifactManager javascriptArtifactManager;
89
90 /**
91 * {@inheritDoc}
92 *
93 * @see org.apache.maven.plugin.Mojo#execute()
94 */
95 public void execute()
96 throws MojoExecutionException, MojoFailureException
97 {
98 try
99 {
100 javascriptArtifactManager.unpack( project, DefaultArtifact.SCOPE_RUNTIME, new File(
101 warSourceDirectory, scriptsDirectory + File.separator + libsDirectory ), useArtifactId );
102 }
103 catch ( ArchiverException e )
104 {
105 throw new MojoExecutionException( "Failed to unpack javascript dependencies", e );
106 }
107
108 }
109 }