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 pack200 a dependency.
32   * <p/>
33   * Created on 1/4/14.
34   *
35   * @author Tony Chemit <chemit@codelutin.com>
36   * @since 1.0-beta-5
37   */
38  @Component( role = JnlpDependencyTask.class, hint = Pack200Task.ROLE_HINT, instantiationStrategy = "per-lookup" )
39  public class Pack200Task
40      extends AbstractJnlpTask
41  {
42  
43      public static final String ROLE_HINT = "Pack200Task";
44  
45      @Requirement( role = Pack200Tool.class )
46      private Pack200Tool pack200Tool;
47  
48      /**
49       * {@inheritDoc}
50       */
51      public void check( JnlpDependencyConfig config )
52      {
53          if ( config == null )
54          {
55              throw new NullPointerException( "config can't be null" );
56          }
57          if ( config.getArtifact() == null )
58          {
59              throw new NullPointerException( "config.artifact can't be null" );
60          }
61          if ( config.getArtifact().getFile() == null )
62          {
63              throw new NullPointerException( "config.artifact.file can't be null" );
64          }
65          if ( !config.isPack200() )
66          {
67              throw new IllegalStateException( "Can't unpack200 if config.isPack200 is false" );
68          }
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      public File execute( JnlpDependencyConfig config, File file )
75          throws JnlpDependencyTaskException
76      {
77  
78          verboseLog( config, "Pack200 file: " + file );
79          try
80          {
81              File result = pack200Tool.packJar( file, config.isGzip(), config.getPack200PassFiles() );
82              getLogger().debug( "packed200 file: " + result );
83              return result;
84          }
85          catch ( IOException e )
86          {
87              throw new JnlpDependencyTaskException( "Could not pack200 jars: ", e );
88          }
89      }
90  
91  }