View Javadoc
1   package org.codehaus.mojo.webstart;
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 org.apache.maven.plugin.AbstractMojo;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.Component;
25  import org.apache.maven.plugins.annotations.LifecyclePhase;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.shared.jarsigner.JarSignerUtil;
29  import org.codehaus.mojo.webstart.sign.SignTool;
30  
31  import java.io.File;
32  
33  /**
34   * Unsigns a JAR, removing signatures.
35   * <p/>
36   * This code will hopefully be moved into the jar plugin when stable enough.
37   *
38   * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
39   * @author <a href="mailto:andrius@pivotcapital.com">Andrius Ĺ abanas</a>
40   * @version $Id$
41   */
42  @Mojo( name = "unsign", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = false )
43  public class JarUnsignMojo
44      extends AbstractMojo
45  {
46      // ----------------------------------------------------------------------
47      // Mojo Parameters
48      // ----------------------------------------------------------------------
49  
50      /**
51       * Set this to <code>true</code> to disable signing.
52       * Useful to speed up build process in development environment.
53       */
54      @Parameter( property = "maven.jar.unsign.skip", defaultValue = "false" )
55      private boolean skip;
56  
57      /**
58       * The directory location used for temporary storage of files used by this mojo.
59       *
60       * @deprecated since 1.0-beta-4, no more used to unsign jars.
61       */
62      @Parameter( property = "tempdir", defaultValue = "${basedir}", required = true )
63      private File tempDirectory;
64  
65      /**
66       * Path of the jar to unsign. Will unsign all archives in case folder was specified here.
67       * When specified, the finalName is ignored.
68       */
69      @Parameter( alias = "jarpath", property = "maven.jar.unsign.jarpath",
70                  defaultValue = "${project.build.directory}/${project.build.finalName}.${project.packaging}" )
71      private File jarPath;
72  
73      /**
74       * Enable verbose mode.
75       */
76      @Parameter( property = "verbose", defaultValue = "false" )
77      private boolean verbose;
78  
79      // ----------------------------------------------------------------------
80      // Components
81      // ----------------------------------------------------------------------
82  
83      /**
84       * Sign tool.
85       */
86      @Component
87      private SignTool signTool;
88  
89      // ----------------------------------------------------------------------
90      // Mojo Implementation
91      // ----------------------------------------------------------------------
92  
93      /**
94       * {@inheritDoc}
95       */
96      public void execute()
97          throws MojoExecutionException
98      {
99          if ( skip )
100         {
101             getLog().info( "Skipping JAR unsigning for file: " + jarPath.getAbsolutePath() );
102             return;
103         }
104         if ( jarPath.isDirectory() )
105         {
106             for ( File jar : jarPath.listFiles() ) {
107                 if ( JarSignerUtil.isZipFile( jar ) ) {
108                     signTool.unsign( jar, verbose );
109                 }
110                 else
111                 {
112                     getLog().info( "Skipping JAR unsigning for file: " + jar.getAbsolutePath() );
113                 }
114             }
115         }
116         else
117         {
118             signTool.unsign( this.jarPath, verbose );
119         }
120     }
121 
122     // ----------------------------------------------------------------------
123     // Public Methods
124     // ----------------------------------------------------------------------
125 
126     public void setJarPath( File jarPath )
127     {
128         this.jarPath = jarPath;
129     }
130 
131     public void setVerbose( boolean verbose )
132     {
133         this.verbose = verbose;
134     }
135 
136     public void setSignTool( SignTool signTool )
137     {
138         this.signTool = signTool;
139     }
140 
141 }