1 package org.codehaus.mojo.webstart.dependency.task;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33
34
35
36
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
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
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 }