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.IOException; |
23 | |
import java.io.InputStream; |
24 | |
import java.util.Properties; |
25 | |
import java.util.jar.JarFile; |
26 | |
import java.util.zip.ZipEntry; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public abstract class AbstractEclipseOsgiPlugin |
35 | |
implements EclipseOsgiPlugin |
36 | |
{ |
37 | |
|
38 | |
private File file; |
39 | |
|
40 | |
private Properties pluginProperties; |
41 | |
|
42 | |
public AbstractEclipseOsgiPlugin( File file ) |
43 | 0 | { |
44 | 0 | this.setFile( file ); |
45 | 0 | } |
46 | |
|
47 | |
public void setFile( File file ) |
48 | |
{ |
49 | 0 | this.file = file; |
50 | 0 | } |
51 | |
|
52 | |
public File getFile() |
53 | |
{ |
54 | 0 | return file; |
55 | |
} |
56 | |
|
57 | |
public String toString() |
58 | |
{ |
59 | 0 | return getFile().getAbsolutePath(); |
60 | |
} |
61 | |
|
62 | |
public Properties getPluginProperties() |
63 | |
throws IOException |
64 | |
{ |
65 | 0 | if ( pluginProperties == null ) |
66 | |
{ |
67 | 0 | JarFile file = getJar(); |
68 | 0 | InputStream pluginPropertiesStream = null; |
69 | |
try |
70 | |
{ |
71 | 0 | pluginProperties = new Properties(); |
72 | 0 | ZipEntry jarEntry = file.getEntry( "plugin.properties" ); |
73 | 0 | if ( jarEntry != null ) |
74 | |
{ |
75 | 0 | pluginPropertiesStream = file.getInputStream( jarEntry ); |
76 | 0 | pluginProperties.load( pluginPropertiesStream ); |
77 | |
} |
78 | 0 | } |
79 | |
finally |
80 | |
{ |
81 | 0 | if ( pluginPropertiesStream != null ) |
82 | |
{ |
83 | |
try |
84 | |
{ |
85 | 0 | pluginPropertiesStream.close(); |
86 | |
} |
87 | 0 | catch ( IOException e ) |
88 | |
{ |
89 | |
|
90 | 0 | } |
91 | |
} |
92 | 0 | } |
93 | |
} |
94 | 0 | return pluginProperties; |
95 | |
} |
96 | |
|
97 | |
public Properties getPomProperties() |
98 | |
{ |
99 | 0 | return new Properties(); |
100 | |
} |
101 | |
|
102 | |
public String getManifestAttribute( String key ) |
103 | |
throws IOException |
104 | |
{ |
105 | 0 | String value = getManifest().getMainAttributes().getValue( key ); |
106 | |
|
107 | 0 | if ( value == null ) |
108 | |
{ |
109 | 0 | return null; |
110 | |
} |
111 | |
|
112 | |
|
113 | 0 | if ( value.startsWith( "%" ) ) |
114 | |
{ |
115 | 0 | String valueFromProperties = getPluginProperties().getProperty( value.substring( 1 ) ); |
116 | 0 | if ( valueFromProperties != null ) |
117 | |
{ |
118 | 0 | value = valueFromProperties; |
119 | |
} |
120 | |
} |
121 | |
|
122 | 0 | return value; |
123 | |
} |
124 | |
} |