View Javadoc

1   /*
2    *  Copyright 2008 Johan Andrén.
3    * 
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    * 
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *  under the License.
16   */
17  package org.codehaus.mojo.nbm;
18  
19  import java.io.File;
20  import org.apache.maven.plugin.AbstractMojo;
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.plugin.MojoFailureException;
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.project.MavenProject;
26  import org.codehaus.plexus.archiver.util.DefaultFileSet;
27  import org.codehaus.plexus.archiver.zip.ZipArchiver;
28  
29  /**
30   * Create a standalone application out of the composed clusters of nbm-application
31   *
32   * @author <a href="mailto:johan.andren@databyran.se">Johan Andrén</a>
33   * @author Milos Kleint
34   */
35  @Mojo(name="standalone-zip", requiresProject=true, threadSafe = true)
36  public class CreateStandaloneMojo
37          extends AbstractMojo
38  {
39  
40      /**
41       * The branding token for the application based on NetBeans platform.
42       */
43      @Parameter(property="netbeans.branding.token", required=true)
44      protected String brandingToken;
45      /**
46       * output directory where the the NetBeans application will be created.
47       */
48      @Parameter(required=true, defaultValue="${project.build.directory}")
49      private File outputDirectory;
50      /**
51       * Name of the zip artifact produced by the goal (without .zip extension)
52       */
53      @Parameter(defaultValue="${project.build.finalName}")
54      private String finalName;
55      /**
56       * The Maven project.
57       */
58      @Parameter(required=true, readonly=true, property="project")
59      private MavenProject project;
60  
61      /**
62       * 
63       * @throws org.apache.maven.plugin.MojoExecutionException 
64       * @throws org.apache.maven.plugin.MojoFailureException 
65       */
66      public void execute()
67          throws MojoExecutionException, MojoFailureException
68      {
69  
70          try
71          {
72              File nbmBuildDirFile = new File( outputDirectory, brandingToken );
73  
74              ZipArchiver archiver = new ZipArchiver();
75              DefaultFileSet fs = new DefaultFileSet();
76              fs.setDirectory( outputDirectory );
77              fs.setIncludes( new String[] {
78                  brandingToken + "/**",
79              } );
80              fs.setExcludes( new String[] {
81                  brandingToken + "/bin/*",
82              } );
83              archiver.addFileSet( fs );
84              File bins = new File( nbmBuildDirFile, "bin" );
85              for ( File bin : bins.listFiles() )
86              {
87                  archiver.addFile( bin, brandingToken + "/bin/" + bin.getName(), 0755 );
88              }
89              File zipFile = new File( outputDirectory, finalName + ".zip" );
90              //TODO - somehow check for last modified content to see if we shall be
91              //recreating the zip file.
92              archiver.setDestFile( zipFile );
93              archiver.setForced( false );
94              archiver.createArchive();
95              project.getArtifact().setFile( zipFile );
96  
97          }
98          catch ( Exception ex )
99          {
100             throw new MojoExecutionException( "", ex );
101         }
102 
103     }
104 }