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 super( folder );
47 }
48
49 private File getManifestFile()
50 {
51 return new File( getFile(), "META-INF/MANIFEST.MF" );
52 }
53
54 public Manifest getManifest()
55 throws IOException
56 {
57 if ( !getManifestFile().exists() )
58 {
59 return null;
60 }
61
62 FileInputStream is = new FileInputStream( getManifestFile() );
63 try
64 {
65 return new Manifest( is );
66 }
67 finally
68 {
69 is.close();
70 }
71 }
72
73 public boolean hasManifest()
74 {
75 return getManifestFile().exists();
76 }
77
78 public File getJarFile()
79 throws IOException
80 {
81 if ( tempJarFile == null )
82 {
83 try
84 {
85 tempJarFile = File.createTempFile( "mvn-eclipse", null );
86 tempJarFile.deleteOnExit();
87
88 JarArchiver jarArchiver = new JarArchiver();
89
90 jarArchiver.setDestFile( tempJarFile );
91 jarArchiver.addDirectory( getFile() );
92 jarArchiver.setManifest( getManifestFile() );
93 jarArchiver.createArchive();
94
95 return tempJarFile;
96 }
97 catch ( ArchiverException e )
98 {
99
100 throw new IOException( e.getMessage() );
101 }
102 }
103 return tempJarFile;
104 }
105
106 public JarFile getJar()
107 throws IOException
108 {
109 return new JarFile( getJarFile(), false );
110 }
111
112
113
114
115 public Properties getPomProperties()
116 {
117 Properties properties = new Properties();
118 properties.setProperty( InstallPluginsMojo.PROP_UNPACK_PLUGIN, Boolean.TRUE.toString() );
119 return properties;
120 }
121
122 }