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
39
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
50
51
52
53
54 @Requirement( role = Pack200Tool.class )
55 private Pack200Tool pack200Tool;
56
57
58
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
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 }