1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.maven.plugin.eclipse.osgiplugin; |
20 | |
|
21 | |
import java.io.File; |
22 | |
import java.io.FileInputStream; |
23 | |
import java.io.IOException; |
24 | |
import java.util.Properties; |
25 | |
import java.util.jar.JarFile; |
26 | |
import java.util.jar.Manifest; |
27 | |
|
28 | |
import org.apache.maven.plugin.eclipse.InstallPluginsMojo; |
29 | |
import org.codehaus.plexus.archiver.ArchiverException; |
30 | |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class ExplodedPlugin |
39 | |
extends AbstractEclipseOsgiPlugin |
40 | |
{ |
41 | |
|
42 | |
private File tempJarFile; |
43 | |
|
44 | |
public ExplodedPlugin( File folder ) |
45 | |
{ |
46 | 0 | super( folder ); |
47 | 0 | } |
48 | |
|
49 | |
private File getManifestFile() |
50 | |
{ |
51 | 0 | return new File( getFile(), "META-INF/MANIFEST.MF" ); |
52 | |
} |
53 | |
|
54 | |
public Manifest getManifest() |
55 | |
throws IOException |
56 | |
{ |
57 | 0 | if ( !getManifestFile().exists() ) |
58 | |
{ |
59 | 0 | return null; |
60 | |
} |
61 | |
|
62 | 0 | FileInputStream is = new FileInputStream( getManifestFile() ); |
63 | |
try |
64 | |
{ |
65 | 0 | return new Manifest( is ); |
66 | |
} |
67 | |
finally |
68 | |
{ |
69 | 0 | is.close(); |
70 | |
} |
71 | |
} |
72 | |
|
73 | |
public boolean hasManifest() |
74 | |
{ |
75 | 0 | return getManifestFile().exists(); |
76 | |
} |
77 | |
|
78 | |
public File getJarFile() |
79 | |
throws IOException |
80 | |
{ |
81 | 0 | if ( tempJarFile == null ) |
82 | |
{ |
83 | |
try |
84 | |
{ |
85 | 0 | tempJarFile = File.createTempFile( "mvn-eclipse", null ); |
86 | 0 | tempJarFile.deleteOnExit(); |
87 | |
|
88 | 0 | JarArchiver jarArchiver = new JarArchiver(); |
89 | |
|
90 | 0 | jarArchiver.setDestFile( tempJarFile ); |
91 | 0 | jarArchiver.addDirectory( getFile() ); |
92 | 0 | jarArchiver.setManifest( getManifestFile() ); |
93 | 0 | jarArchiver.createArchive(); |
94 | |
|
95 | 0 | return tempJarFile; |
96 | |
} |
97 | 0 | catch ( ArchiverException e ) |
98 | |
{ |
99 | |
|
100 | 0 | throw new IOException( e.getMessage() ); |
101 | |
} |
102 | |
} |
103 | 0 | return tempJarFile; |
104 | |
} |
105 | |
|
106 | |
public JarFile getJar() |
107 | |
throws IOException |
108 | |
{ |
109 | 0 | return new JarFile( getJarFile(), false ); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public Properties getPomProperties() |
116 | |
{ |
117 | 0 | Properties properties = new Properties(); |
118 | 0 | properties.setProperty( InstallPluginsMojo.PROP_UNPACK_PLUGIN, Boolean.TRUE.toString() ); |
119 | 0 | return properties; |
120 | |
} |
121 | |
|
122 | |
} |