View Javadoc
1   package org.codehaus.mojo.webstart.dependency.task;
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.codehaus.mojo.webstart.pack200.Pack200Tool;
23  import org.codehaus.mojo.webstart.dependency.JnlpDependencyConfig;
24  import org.codehaus.plexus.component.annotations.Component;
25  import org.codehaus.plexus.component.annotations.Requirement;
26  
27  import java.io.File;
28  import java.io.IOException;
29  
30  /**
31   * To unpack200 a dependency.
32   * <p/>
33   * http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html
34   * we need to pack then unpack the files before signing them
35   * <p/>
36   * Created on 1/4/14.
37   *
38   * @author Tony Chemit <chemit@codelutin.com>
39   * @since 1.0-beta-5
40   */
41  @Component( role = JnlpDependencyTask.class, hint = UnPack200Task.ROLE_HINT, instantiationStrategy = "per-lookup" )
42  public class UnPack200Task
43      extends AbstractJnlpTask
44  {
45  
46      public static final String ROLE_HINT = "UnPack200Task";
47  
48      /**
49       * All available pack200 tools.
50       * <p/>
51       * We use a plexus list injection instead of a direct component injection since for a jre 1.4, we will at the
52       * moment have no implementation of this tool.
53       */
54      @Requirement( role = Pack200Tool.class )
55      private Pack200Tool pack200Tool;
56  
57      /**
58       * {@inheritDoc}
59       */
60      public void check( JnlpDependencyConfig config )
61      {
62          if ( config == null )
63          {
64              throw new NullPointerException( "config can't be null" );
65          }
66          if ( config.getArtifact() == null )
67          {
68              throw new NullPointerException( "config.artifact can't be null" );
69          }
70          if ( config.getArtifact().getFile() == null )
71          {
72              throw new NullPointerException( "config.artifact.file can't be null" );
73          }
74          if (!config.isPack200()) {
75              throw new IllegalStateException( "Can't pack200 if config.isPack200 is false" );
76          }
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      public File execute( JnlpDependencyConfig config, File file )
83          throws JnlpDependencyTaskException
84      {
85  
86          verboseLog( config, "Unpack 200 file: " + file );
87          try
88          {
89              File result = pack200Tool.unpackJar( file );
90              getLogger().debug( "Unpacked 200 file: " + result );
91              return result;
92          }
93          catch ( IOException e )
94          {
95              throw new JnlpDependencyTaskException( "Could not pack200 jars: ", e );
96          }
97      }
98  
99  }