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