Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 185477 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/plugin/AbstractPluginModelBase.java (+12 lines)
Lines 27-32 Link Here
27
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
27
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
28
import org.eclipse.pde.core.plugin.IPluginImport;
28
import org.eclipse.pde.core.plugin.IPluginImport;
29
import org.eclipse.pde.core.plugin.IPluginLibrary;
29
import org.eclipse.pde.core.plugin.IPluginLibrary;
30
import org.eclipse.pde.core.plugin.IPluginManifestInfo;
30
import org.eclipse.pde.core.plugin.IPluginModelBase;
31
import org.eclipse.pde.core.plugin.IPluginModelBase;
31
import org.eclipse.pde.core.plugin.IPluginModelFactory;
32
import org.eclipse.pde.core.plugin.IPluginModelFactory;
32
import org.eclipse.pde.core.plugin.IPluginObject;
33
import org.eclipse.pde.core.plugin.IPluginObject;
Lines 47-52 Link Here
47
		super();
48
		super();
48
	}
49
	}
49
	
50
	
51
	/**
52
	 * Returns information about the plugin manifest.
53
	 * 
54
	 * @return null - not supported
55
	 */
56
	public IPluginManifestInfo getPluginManifestInfo() {
57
58
		// TODO See if we can get hold of this information via the id?
59
		return null;
60
	}
61
	
50
	public abstract String getInstallLocation();
62
	public abstract String getInstallLocation();
51
	
63
	
52
	public abstract IPluginBase createPluginBase();
64
	public abstract IPluginBase createPluginBase();
(-)text/org/eclipse/pde/internal/core/text/plugin/PluginModelBase.java (+12 lines)
Lines 21-26 Link Here
21
import org.eclipse.pde.core.plugin.IExtensions;
21
import org.eclipse.pde.core.plugin.IExtensions;
22
import org.eclipse.pde.core.plugin.IExtensionsModelFactory;
22
import org.eclipse.pde.core.plugin.IExtensionsModelFactory;
23
import org.eclipse.pde.core.plugin.IPluginBase;
23
import org.eclipse.pde.core.plugin.IPluginBase;
24
import org.eclipse.pde.core.plugin.IPluginManifestInfo;
24
import org.eclipse.pde.core.plugin.IPluginModelBase;
25
import org.eclipse.pde.core.plugin.IPluginModelBase;
25
import org.eclipse.pde.core.plugin.IPluginModelFactory;
26
import org.eclipse.pde.core.plugin.IPluginModelFactory;
26
import org.eclipse.pde.internal.core.NLResourceHelper;
27
import org.eclipse.pde.internal.core.NLResourceHelper;
Lines 57-62 Link Here
57
		return fPluginBase;
58
		return fPluginBase;
58
	}
59
	}
59
60
61
	/**
62
	 * Returns information about the plugin manifest.
63
	 * 
64
	 * @return null - not supported
65
	 */
66
	public IPluginManifestInfo getPluginManifestInfo() {
67
68
		// TODO See if we can get hold of this information via the id?
69
		return null;
70
	}
71
	
60
	protected IWritable getRoot() {
72
	protected IWritable getRoot() {
61
		return getPluginBase();
73
		return getPluginBase();
62
	}
74
	}
(-)src/org/eclipse/pde/internal/core/bundle/WorkspaceBundlePluginModelBase.java (+18 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.pde.core.IEditableModel;
17
import org.eclipse.pde.core.IEditableModel;
18
import org.eclipse.pde.core.plugin.IPluginBase;
18
import org.eclipse.pde.core.plugin.IPluginBase;
19
import org.eclipse.pde.core.plugin.IPluginManifestInfo;
19
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
20
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
20
import org.eclipse.pde.internal.core.ibundle.IBundle;
21
import org.eclipse.pde.internal.core.ibundle.IBundle;
21
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
22
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
Lines 37-42 Link Here
37
38
38
	abstract public IPluginBase createPluginBase();
39
	abstract public IPluginBase createPluginBase();
39
40
41
	/**
42
	 * Returns information about the plugin manifest.
43
	 * 
44
	 * @return Plugin manifest information.
45
	 */
46
	public IPluginManifestInfo getPluginManifestInfo() {
47
48
		IBundle bundle = null;
49
		bundle = getBundleModel().getBundle();
50
		
51
		IPluginManifestInfo manifestInfo = null;
52
		if( bundle != null ) {
53
			manifestInfo = new BundleManifestInfo(bundle, this);
54
		}
55
		return manifestInfo;
56
	}
57
	
40
	public void load(InputStream stream, boolean outOfSync)	throws CoreException {
58
	public void load(InputStream stream, boolean outOfSync)	throws CoreException {
41
		if (fPluginBase == null) 
59
		if (fPluginBase == null) 
42
			fPluginBase = createPluginBase();
60
			fPluginBase = createPluginBase();
(-)src/org/eclipse/pde/internal/core/bundle/BundlePluginModelBase.java (+19 lines)
Lines 30-35 Link Here
30
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
30
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
31
import org.eclipse.pde.core.plugin.IPluginImport;
31
import org.eclipse.pde.core.plugin.IPluginImport;
32
import org.eclipse.pde.core.plugin.IPluginLibrary;
32
import org.eclipse.pde.core.plugin.IPluginLibrary;
33
import org.eclipse.pde.core.plugin.IPluginManifestInfo;
33
import org.eclipse.pde.core.plugin.IPluginModelFactory;
34
import org.eclipse.pde.core.plugin.IPluginModelFactory;
34
import org.eclipse.pde.core.plugin.IPluginObject;
35
import org.eclipse.pde.core.plugin.IPluginObject;
35
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
36
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
Lines 67-72 Link Here
67
	public IResource getUnderlyingResource() {
68
	public IResource getUnderlyingResource() {
68
		return fBundleModel.getUnderlyingResource();
69
		return fBundleModel.getUnderlyingResource();
69
	}
70
	}
71
	
72
	/**
73
	 * Returns information about the plugin manifest.
74
	 * 
75
	 * @return manifest information, or null if not an OSGi based bundle.
76
	 */
77
	public IPluginManifestInfo getPluginManifestInfo() {
78
79
		IBundle bundle = null;
80
		bundle = getBundleModel().getBundle();
81
		
82
		IPluginManifestInfo manifestInfo = null;
83
		if( bundle != null ) {
84
			manifestInfo = new BundleManifestInfo(bundle, this);
85
		}
86
		return manifestInfo;
87
	}
88
	
70
	/*
89
	/*
71
	 * (non-Javadoc)
90
	 * (non-Javadoc)
72
	 * 
91
	 * 
(-)src/org/eclipse/pde/core/plugin/IPluginModelBase.java (+8 lines)
Lines 67-72 Link Here
67
	 * @return a top-level model object
67
	 * @return a top-level model object
68
	 */
68
	 */
69
	IPluginBase getPluginBase(boolean createIfMissing);
69
	IPluginBase getPluginBase(boolean createIfMissing);
70
	
71
	/**
72
	 * Returns information about the plugin manifest.
73
	 * 
74
	 * @return manifest information, or null if not an OSGi based bundle.
75
	 */
76
	IPluginManifestInfo getPluginManifestInfo();
77
	
70
	/**
78
	/**
71
	 * Returns </samp>true</samp> if this model is currently enabled.
79
	 * Returns </samp>true</samp> if this model is currently enabled.
72
	 *
80
	 *
(-)src/org/eclipse/pde/core/plugin/IPluginManifestInfo.java (+26 lines)
Added Link Here
1
package org.eclipse.pde.core.plugin;
2
3
/**
4
 * Model representing information held within the manifest.
5
 * 
6
 * @author Les Jones
7
 */
8
public interface IPluginManifestInfo {
9
10
    /**
11
     * Get the value of a generic manifest header.
12
     * @param name The name of the header
13
     * @return The value of the header
14
     * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String)
15
     */
16
	String getHeader(String name);
17
18
    /**
19
     * Set the value of a generic manifest header.
20
     * @param name The name of the header
21
     * @param value The value of the header
22
     * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String)
23
     */
24
	void setHeader(String name, String value);
25
	
26
}
(-)src/org/eclipse/pde/internal/core/bundle/BundleManifestInfo.java (+153 lines)
Added Link Here
1
package org.eclipse.pde.internal.core.bundle;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
import org.eclipse.pde.core.plugin.IFragment;
7
import org.eclipse.pde.core.plugin.IPlugin;
8
import org.eclipse.pde.core.plugin.IPluginBase;
9
import org.eclipse.pde.core.plugin.IPluginManifestInfo;
10
import org.eclipse.pde.core.plugin.IPluginObject;
11
import org.eclipse.pde.internal.core.ibundle.IBundle;
12
import org.eclipse.pde.core.IIdentifiable;
13
import org.eclipse.pde.core.IModelChangeProvider;
14
import org.osgi.framework.Constants;
15
16
/**
17
 * Implementation of Manifest information for the plug-in model.
18
 * 
19
 * TODO: Consider refactoring existing models to utilise this class as the point
20
 * that changes the manifest.
21
 * 
22
 * @author Les Jones
23
 */
24
public class BundleManifestInfo implements IPluginManifestInfo {
25
26
	/** Underlying bundle representation */
27
	private IBundle fBundle = null;
28
29
	/** Object interested in change events */
30
	private IModelChangeProvider fModelChangeProvider = null;
31
32
	/**
33
	 * The header event type map links a header with the event that needs to be
34
	 * fired to indicate that the value has been updated.
35
	 */
36
	private Map headerEventTypeMap = null;
37
	
38
	/**
39
	 * Create a new manifest info instance using the specified bundle.
40
	 * 
41
	 * @param bundle
42
	 *            Bundle to refer to.
43
	 */
44
	public BundleManifestInfo(IBundle bundle) {
45
46
		this(bundle, null);
47
	}
48
49
	
50
	/**
51
	 * Create a new manifest info instance using the specified bundle, providing model
52
	 * update information to the specified model change provider.
53
	 * 
54
	 * @param bundle
55
	 *            Bundle to refer to.
56
	 * @param modelChangeProvider
57
	 *            object where model changes should be fired
58
	 */
59
	public BundleManifestInfo(IBundle bundle,
60
			IModelChangeProvider modelChangeProvider) {
61
		
62
		fBundle = bundle;
63
		
64
		initializeManagedHeaders();
65
	}
66
67
	/**
68
	 * Initialize the bundle headers that are known to be managed. 
69
	 * i.e. those that require a model update. 
70
	 */
71
	private void initializeManagedHeaders() {
72
73
		headerEventTypeMap = new HashMap();
74
		
75
		headerEventTypeMap.put(Constants.BUNDLE_ACTIVATOR, IPlugin.P_CLASS_NAME);
76
		headerEventTypeMap.put(Constants.BUNDLE_VERSION, IPluginBase.P_VERSION);
77
		headerEventTypeMap.put(Constants.BUNDLE_NAME, IPluginObject.P_NAME);
78
		headerEventTypeMap.put(Constants.BUNDLE_VENDOR, IPluginBase.P_PROVIDER);
79
		headerEventTypeMap.put(Constants.FRAGMENT_HOST, IFragment.P_PLUGIN_ID);
80
		headerEventTypeMap.put(Constants.BUNDLE_SYMBOLICNAME, IIdentifiable.P_ID);
81
	}
82
83
    /**
84
     * Get the value of a generic manifest header.
85
     * @param name The name of the header
86
     * @return The value of the header
87
     * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String)
88
     */
89
	public String getHeader(String name) {
90
91
		if (fBundle == null) {
92
			return null;
93
		}
94
95
		return fBundle.getHeader(name);
96
	}
97
98
    /**
99
     * Set the value of a generic manifest header.
100
     * @param name The name of the header
101
     * @param value The value of the header
102
     * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(String)
103
     */
104
	public void setHeader(String name, String value) {
105
106
		if (fBundle == null) {
107
			return;
108
		}
109
110
		String oldValue = fBundle.getHeader(name);
111
112
		fBundle.setHeader(name, value);
113
114
		fireHeaderUpdated(name, oldValue, value);
115
	}
116
117
	/**
118
	 * Fire an event to indicate to a model that a header has been updated. Two
119
	 * types of event can be fired, one where the property name is the name of
120
	 * the header, and another where the name is mapped from the header, e.g.
121
	 * mapping Bundle-Name (Constants.BUNDLE_NAME) to name
122
	 * (IPluginObject.P_NAME)
123
	 * 
124
	 * If no model change provider is associated with this manifest model, this
125
	 * method does nothing.
126
	 * 
127
	 * TODO: Check whether this is actually required - the Bundle
128
	 * implementations appear to fire their own events.
129
	 * 
130
	 * @param header The name of the header to be updated
131
	 * @param oldValue The old value of the header
132
	 * @param newValue The new value of the header
133
	 */
134
	private void fireHeaderUpdated(String header, String oldValue, String newValue) {
135
136
		if (fModelChangeProvider == null) {
137
			// early exit if no change provider
138
			return;
139
		}
140
141
		// Fire an event mapped from the header name
142
		if (headerEventTypeMap.containsKey(header)) {
143
			String eventType = (String) headerEventTypeMap.get(header);
144
145
			fModelChangeProvider.fireModelObjectChanged(this, eventType,
146
					oldValue, newValue);
147
		}
148
149
		// Fire the actual event for the header
150
		fModelChangeProvider.fireModelObjectChanged(this, header, oldValue,
151
				newValue);
152
	}
153
}

Return to bug 185477