1 | package npanday.plugin.aspx; |
2 | |
3 | /* |
4 | * Licensed to the Apache Software Foundation (ASF) under one |
5 | * or more contributor license agreements. See the NOTICE file |
6 | * distributed with this work for additional information |
7 | * regarding copyright ownership. The ASF licenses this file |
8 | * to you under the Apache License, Version 2.0 (the |
9 | * "License"); you may not use this file except in compliance |
10 | * with the License. You may obtain a copy of the License at |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, |
15 | * software distributed under the License is distributed on an |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
17 | * KIND, either express or implied. See the License for the |
18 | * specific language governing permissions and limitations |
19 | * under the License. |
20 | */ |
21 | |
22 | import java.io.File; |
23 | import java.io.IOException; |
24 | |
25 | import org.apache.maven.plugin.AbstractMojo; |
26 | import org.apache.maven.plugin.MojoExecutionException; |
27 | import org.apache.maven.project.MavenProject; |
28 | import org.codehaus.plexus.archiver.ArchiverException; |
29 | import org.codehaus.plexus.archiver.zip.ZipArchiver; |
30 | |
31 | /** |
32 | * Maven Mojo for packaging .Net Web applications |
33 | * |
34 | * @goal package |
35 | * @phase package |
36 | * @description Maven Mojo for packaging .Net Web applications |
37 | */ |
38 | public class AspxPackageMojo |
39 | extends AbstractMojo |
40 | { |
41 | /** |
42 | * The maven project. |
43 | * |
44 | * @parameter expression="${project}" |
45 | * @required |
46 | */ |
47 | private MavenProject project; |
48 | |
49 | /** |
50 | * The directory for the compilated web application |
51 | * |
52 | * @parameter expression = "${outputDirectory}" default-value = "${project.build.directory}" |
53 | * @required |
54 | */ |
55 | private File outputDirectory; |
56 | |
57 | /** |
58 | * The Zip archiver. |
59 | * |
60 | * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#zip}" |
61 | * @required |
62 | */ |
63 | private ZipArchiver archiver; |
64 | |
65 | public void execute() |
66 | throws MojoExecutionException |
67 | { |
68 | |
69 | long startTime = System.currentTimeMillis(); |
70 | |
71 | File webappDir = new File( outputDirectory, project.getArtifactId() ); |
72 | |
73 | if ( !webappDir.exists() ) |
74 | { |
75 | return; |
76 | } |
77 | |
78 | performPackaging( webappDir ); |
79 | |
80 | long endTime = System.currentTimeMillis(); |
81 | getLog().info( "Mojo Execution Time = " + ( endTime - startTime ) ); |
82 | } |
83 | |
84 | private void performPackaging( File webappDir ) |
85 | throws MojoExecutionException |
86 | { |
87 | File destinationFile = new File( outputDirectory, project.getArtifactId() + ".zip" ); |
88 | archiver.setDestFile( destinationFile ); |
89 | |
90 | getLog().info( "Generating package " + destinationFile.getAbsolutePath() ); |
91 | |
92 | try |
93 | { |
94 | archiver.addDirectory( webappDir ); |
95 | } |
96 | catch ( ArchiverException e ) |
97 | { |
98 | throw new MojoExecutionException( "Unable to package web application from " + webappDir.getAbsolutePath(), |
99 | e ); |
100 | } |
101 | |
102 | // create archive |
103 | try |
104 | { |
105 | archiver.createArchive(); |
106 | } |
107 | catch ( ArchiverException e ) |
108 | { |
109 | throw new MojoExecutionException( "Unable to package web application in " + |
110 | destinationFile.getAbsolutePath(), e ); |
111 | } |
112 | catch ( IOException e ) |
113 | { |
114 | throw new MojoExecutionException( "Unable to package web application in " + |
115 | destinationFile.getAbsolutePath(), e ); |
116 | } |
117 | |
118 | project.getArtifact().setFile( destinationFile ); |
119 | } |
120 | } |