View | Details | Raw Unified | Return to bug 240737 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/product/ProductModelFactory.java (-13 / +8 lines)
Lines 10-28 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.product;
11
package org.eclipse.pde.internal.core.product;
12
12
13
import org.eclipse.pde.internal.core.iproduct.IAboutInfo;
13
import org.eclipse.pde.internal.core.iproduct.*;
14
import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo;
15
import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo;
16
import org.eclipse.pde.internal.core.iproduct.IIntroInfo;
17
import org.eclipse.pde.internal.core.iproduct.IJREInfo;
18
import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
19
import org.eclipse.pde.internal.core.iproduct.IProduct;
20
import org.eclipse.pde.internal.core.iproduct.IProductFeature;
21
import org.eclipse.pde.internal.core.iproduct.IProductModel;
22
import org.eclipse.pde.internal.core.iproduct.IProductModelFactory;
23
import org.eclipse.pde.internal.core.iproduct.IProductPlugin;
24
import org.eclipse.pde.internal.core.iproduct.ISplashInfo;
25
import org.eclipse.pde.internal.core.iproduct.IWindowImages;
26
14
27
public class ProductModelFactory implements IProductModelFactory {
15
public class ProductModelFactory implements IProductModelFactory {
28
16
Lines 54-59 Link Here
54
	}
42
	}
55
43
56
	/* (non-Javadoc)
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createPluginConfiguration()
46
	 */
47
	public IProductPluginConfiguration createPluginConfiguration() {
48
		return new ProductPluginConfiguration(fModel);
49
	}
50
51
	/* (non-Javadoc)
57
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createConfigFileInfo()
52
	 * @see org.eclipse.pde.internal.core.iproduct.IProductModelFactory#createConfigFileInfo()
58
	 */
53
	 */
59
	public IConfigurationFileInfo createConfigFileInfo() {
54
	public IConfigurationFileInfo createConfigFileInfo() {
(-)src/org/eclipse/pde/internal/core/product/Product.java (-3 / +82 lines)
Lines 26-31 Link Here
26
	private IAboutInfo fAboutInfo;
26
	private IAboutInfo fAboutInfo;
27
27
28
	private TreeMap fPlugins = new TreeMap();
28
	private TreeMap fPlugins = new TreeMap();
29
	private TreeMap fPluginConfigurations = new TreeMap();
29
	private List fFeatures = new ArrayList();
30
	private List fFeatures = new ArrayList();
30
	private IConfigurationFileInfo fConfigIniInfo;
31
	private IConfigurationFileInfo fConfigIniInfo;
31
	private IJREInfo fJVMInfo;
32
	private IJREInfo fJVMInfo;
Lines 201-206 Link Here
201
			writer.println(indent + "   </features>"); //$NON-NLS-1$
202
			writer.println(indent + "   </features>"); //$NON-NLS-1$
202
		}
203
		}
203
204
205
		writer.println(indent + "   <configurations>"); //$NON-NLS-1$  
206
		iter = fPluginConfigurations.values().iterator();
207
		while (iter.hasNext()) {
208
			IProductPlugin plugin = (IProductPlugin) iter.next();
209
			plugin.write(indent + "      ", writer); //$NON-NLS-1$
210
		}
211
		writer.println(indent + "   </configurations>"); //$NON-NLS-1$
212
204
		writer.println();
213
		writer.println();
205
		writer.println("</product>"); //$NON-NLS-1$
214
		writer.println("</product>"); //$NON-NLS-1$
206
	}
215
	}
Lines 222-227 Link Here
222
		fUseFeatures = false;
231
		fUseFeatures = false;
223
		fAboutInfo = null;
232
		fAboutInfo = null;
224
		fPlugins.clear();
233
		fPlugins.clear();
234
		fPluginConfigurations.clear();
225
		fFeatures.clear();
235
		fFeatures.clear();
226
		fConfigIniInfo = null;
236
		fConfigIniInfo = null;
227
		fWindowImages = null;
237
		fWindowImages = null;
Lines 256-261 Link Here
256
						parsePlugins(child.getChildNodes());
266
						parsePlugins(child.getChildNodes());
257
					} else if (name.equals("features")) { //$NON-NLS-1$
267
					} else if (name.equals("features")) { //$NON-NLS-1$
258
						parseFeatures(child.getChildNodes());
268
						parseFeatures(child.getChildNodes());
269
					} else if (name.equals("configurations")) { //$NON-NLS-1$
270
						parsePluginConfigurations(children);
259
					} else if (name.equals("configIni")) { //$NON-NLS-1$
271
					} else if (name.equals("configIni")) { //$NON-NLS-1$
260
						fConfigIniInfo = factory.createConfigFileInfo();
272
						fConfigIniInfo = factory.createConfigFileInfo();
261
						fConfigIniInfo.parse(child);
273
						fConfigIniInfo.parse(child);
Lines 296-301 Link Here
296
		}
308
		}
297
	}
309
	}
298
310
311
	private void parsePluginConfigurations(NodeList children) {
312
		for (int i = 0; i < children.getLength(); i++) {
313
			Node child = children.item(i);
314
			if (child.getNodeType() == Node.ELEMENT_NODE) {
315
				if (child.getNodeName().equals("pluginConfiguration")) { //$NON-NLS-1$
316
					IProductPluginConfiguration configuration = getModel().getFactory().createPluginConfiguration();
317
					configuration.parse(child);
318
					fPluginConfigurations.put(configuration.getId(), configuration);
319
				}
320
			}
321
		}
322
	}
323
299
	private void parseFeatures(NodeList children) {
324
	private void parseFeatures(NodeList children) {
300
		for (int i = 0; i < children.getLength(); i++) {
325
		for (int i = 0; i < children.getLength(); i++) {
301
			Node child = children.item(i);
326
			Node child = children.item(i);
Lines 332-347 Link Here
332
	}
357
	}
333
358
334
	/* (non-Javadoc)
359
	/* (non-Javadoc)
360
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#addPluginConfigurations(org.eclipse.pde.internal.core.iproduct.IPluginConfiguration[])
361
	 */
362
	public void addPluginConfigurations(IProductPluginConfiguration[] configuration) {
363
		boolean modified = false;
364
		for (int i = 0; i < configuration.length; i++) {
365
			if (configuration[i] == null)
366
				continue;
367
			String id = configuration[i].getId();
368
			if (id == null || fPluginConfigurations.containsKey(id)) {
369
				configuration[i] = null;
370
				continue;
371
			}
372
373
			configuration[i].setModel(getModel());
374
			fPluginConfigurations.put(id, configuration[i]);
375
			modified = true;
376
		}
377
		if (modified && isEditable())
378
			fireStructureChanged(configuration, IModelChangedEvent.INSERT);
379
	}
380
381
	/* (non-Javadoc)
335
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePlugins(org.eclipse.pde.internal.core.iproduct.IProductPlugin[])
382
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePlugins(org.eclipse.pde.internal.core.iproduct.IProductPlugin[])
336
	 */
383
	 */
337
	public void removePlugins(IProductPlugin[] plugins) {
384
	public void removePlugins(IProductPlugin[] plugins) {
338
		boolean modified = false;
385
		boolean modified = false;
386
		LinkedList removedConfigurations = new LinkedList();
339
		for (int i = 0; i < plugins.length; i++) {
387
		for (int i = 0; i < plugins.length; i++) {
340
			if (fPlugins.remove(plugins[i].getId()) != null)
388
			final String id = plugins[i].getId();
389
			if (fPlugins.remove(id) != null) {
341
				modified = true;
390
				modified = true;
391
				Object configuration = fPluginConfigurations.remove(id);
392
				if (configuration != null)
393
					removedConfigurations.add(configuration);
394
			}
342
		}
395
		}
343
		if (modified && isEditable())
396
		if (isEditable()) {
344
			fireStructureChanged(plugins, IModelChangedEvent.REMOVE);
397
			if (modified)
398
				fireStructureChanged(plugins, IModelChangedEvent.REMOVE);
399
			if (!removedConfigurations.isEmpty()) {
400
				fireStructureChanged((IProductObject[]) removedConfigurations.toArray(new IProductObject[removedConfigurations.size()]), IModelChangedEvent.REMOVE);
401
			}
402
		}
403
	}
404
405
	/* (non-Javadoc)
406
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#removePluginConfigurations(org.eclipse.pde.internal.core.iproduct.IProductPluginConfiguration[])
407
	 */
408
	public void removePluginConfigurations(IProductPluginConfiguration[] configurations) {
409
		boolean modified = false;
410
		for (int i = 0; i < configurations.length; i++) {
411
			if (fPluginConfigurations.remove(configurations[i].getId()) != null) {
412
				modified = true;
413
			}
414
		}
415
		if (isEditable() && modified)
416
			fireStructureChanged(configurations, IModelChangedEvent.REMOVE);
345
	}
417
	}
346
418
347
	/* (non-Javadoc)
419
	/* (non-Javadoc)
Lines 352-357 Link Here
352
	}
424
	}
353
425
354
	/* (non-Javadoc)
426
	/* (non-Javadoc)
427
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getPluginConfigurations()
428
	 */
429
	public IProductPluginConfiguration[] getPluginConfigurations() {
430
		return (IProductPluginConfiguration[]) fPluginConfigurations.values().toArray(new IProductPluginConfiguration[fPluginConfigurations.size()]);
431
	}
432
433
	/* (non-Javadoc)
355
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getConfigurationFileInfo()
434
	 * @see org.eclipse.pde.internal.core.iproduct.IProduct#getConfigurationFileInfo()
356
	 */
435
	 */
357
	public IConfigurationFileInfo getConfigurationFileInfo() {
436
	public IConfigurationFileInfo getConfigurationFileInfo() {
(-)src/org/eclipse/pde/internal/core/iproduct/IProductModelFactory.java (+2 lines)
Lines 18-23 Link Here
18
18
19
	IProductPlugin createPlugin();
19
	IProductPlugin createPlugin();
20
20
21
	IProductPluginConfiguration createPluginConfiguration();
22
21
	IProductFeature createFeature();
23
	IProductFeature createFeature();
22
24
23
	IConfigurationFileInfo createConfigFileInfo();
25
	IConfigurationFileInfo createConfigFileInfo();
(-)src/org/eclipse/pde/internal/core/iproduct/IProduct.java (+6 lines)
Lines 52-65 Link Here
52
52
53
	void addFeatures(IProductFeature[] feature);
53
	void addFeatures(IProductFeature[] feature);
54
54
55
	void addPluginConfigurations(IProductPluginConfiguration[] configurations);
56
55
	void removePlugins(IProductPlugin[] plugins);
57
	void removePlugins(IProductPlugin[] plugins);
56
58
57
	void removeFeatures(IProductFeature[] feature);
59
	void removeFeatures(IProductFeature[] feature);
58
60
61
	void removePluginConfigurations(IProductPluginConfiguration[] configurations);
62
59
	IProductPlugin[] getPlugins();
63
	IProductPlugin[] getPlugins();
60
64
61
	IProductFeature[] getFeatures();
65
	IProductFeature[] getFeatures();
62
66
67
	IProductPluginConfiguration[] getPluginConfigurations();
68
63
	void setId(String id);
69
	void setId(String id);
64
70
65
	void setVersion(String version);
71
	void setVersion(String version);
(-)src/org/eclipse/pde/internal/core/iproduct/IProductPluginConfiguration.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Bartosz Michalik and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Bartosz Michalik (bartosz.michalik@gmail.com)
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.core.iproduct;
13
14
/**
15
 * PluginConfiguration description defines  plug-in start level, and other properties that can be used
16
 * during product launching/building    
17
 * @author Bartosz Michalik
18
 */
19
public interface IProductPluginConfiguration extends IProductObject {
20
	public static final String P_AUTO_START = "autostart"; //$NON-NLS-1$
21
	public static final String P_START_LEVEL = "startLevel"; //$NON-NLS-1$
22
23
	String getId();
24
25
	void setAutoStart(boolean autostart);
26
27
	boolean isAutoStart();
28
29
	void setStartLevel(int startLevel);
30
31
	int getStartLevel();
32
33
	/**
34
	 * Adds property, if property exists is overridden 
35
	 * @param key
36
	 * @param value
37
	 * @throws IllegalArgumentException when key or value is empty
38
	 */
39
	void addProperty(String key, String value) throws IllegalArgumentException;
40
41
	/**
42
	 * @param key
43
	 */
44
	void removeProperty(String key);
45
46
	/** 
47
	 * get property from key
48
	 * @param key
49
	 * @return property or <code>null</code>
50
	 */
51
	String getProperty(String key);
52
}
(-)src/org/eclipse/pde/internal/core/product/ProductPluginConfiguration.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Bartosz Michalik (bartosz.michalik@gmail.com)
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.core.product;
13
14
import java.io.PrintWriter;
15
import java.util.*;
16
import org.eclipse.pde.internal.core.iproduct.IProductModel;
17
import org.eclipse.pde.internal.core.iproduct.IProductPluginConfiguration;
18
import org.w3c.dom.*;
19
20
public class ProductPluginConfiguration extends ProductObject implements IProductPluginConfiguration {
21
22
	private static final long serialVersionUID = -3549668957352554876L;
23
	private boolean fAutoStart;
24
	private int fStartLevel;
25
	private String fId;
26
	private Map fPropertiesMap;
27
28
	/**
29
	 * Only for parsing usage
30
	 * @param model
31
	 */
32
	ProductPluginConfiguration(IProductModel model) {
33
		super(model);
34
	}
35
36
	/**
37
	 * @param model
38
	 */
39
	public ProductPluginConfiguration(IProductModel model, String id) {
40
		super(model);
41
		fId = id;
42
		fPropertiesMap = new HashMap();
43
	}
44
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.pde.internal.core.iproduct.IProductObject#parse(org.w3c.dom.Node)
47
	 */
48
	public void parse(Node node) {
49
		if (node.getNodeType() == Node.ELEMENT_NODE) {
50
			Element element = (Element) node;
51
			fId = element.getAttribute("id");
52
			fAutoStart = Boolean.parseBoolean(element.getAttribute(P_AUTO_START));
53
			fStartLevel = Integer.parseInt(element.getAttribute(P_START_LEVEL));
54
			NodeList children = node.getChildNodes();
55
			int length = children.getLength();
56
			for (int i = 0; i < length; ++i) {
57
				Node item = children.item(i);
58
				if (item.getNodeType() == Node.ELEMENT_NODE) {
59
					element = (Element) item;
60
					String key = element.getAttribute("key");
61
					String value = element.getAttribute("value");
62
					fPropertiesMap.put(key, value);
63
				}
64
			}
65
		}
66
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see org.eclipse.pde.core.IWritable#write(java.lang.String, java.io.PrintWriter)
71
	 */
72
	public void write(String indent, PrintWriter writer) {
73
		writer.print("<pluginConfiguration id=\"" + fId + "\""); //$NON-NLS-1$ //$NON-NLS-2$
74
		writer.print(" autoStart=\"" + fAutoStart + "\""); //$NON-NLS-1$//$NON-NLS-2$
75
		writer.print(" startLevel=\"" + fStartLevel + "\""); //$NON-NLS-1$ //$NON-NLS-2$
76
		if (fPropertiesMap.isEmpty())
77
			writer.println(" />"); //$NON-NLS-1$
78
		else {
79
			writer.println(" >"); //$NON-NLS-1$
80
			Iterator i = fPropertiesMap.keySet().iterator();
81
			while (i.hasNext()) {
82
				String key = (String) i.next();
83
				writer.println(indent + "<property key=\"" + key + " value=\"" + fPropertiesMap.get(key) + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
84
			}
85
			writer.println("</pluginConfiguration>"); //$NON-NLS-1$
86
		}
87
88
	}
89
90
	/* (non-Javadoc)
91
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#addProperty(java.lang.String, java.lang.String)
92
	 */
93
	public void addProperty(String key, String value) throws IllegalArgumentException {
94
		if (key == null || key.equals("")) //$NON-NLS-1$
95
			throw new IllegalArgumentException("key cannot empty"); //$NON-NLS-1$
96
		if (value == null || value.equals("")) //$NON-NLS-1$
97
			throw new IllegalArgumentException("value cannot empty"); //$NON-NLS-1$
98
		String oldValue = (String) fPropertiesMap.get(key);
99
		fPropertiesMap.put(key, value);
100
		if (isEditable() && !value.equals(oldValue))
101
			firePropertyChanged(key, oldValue, value);
102
103
	}
104
105
	/* (non-Javadoc)
106
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getId()
107
	 */
108
	public String getId() {
109
		return fId;
110
	}
111
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getProperty(java.lang.String)
114
	 */
115
	public String getProperty(String key) {
116
		return (String) fPropertiesMap.get(key);
117
	}
118
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#getStartLevel()
121
	 */
122
	public int getStartLevel() {
123
		return fStartLevel;
124
	}
125
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#isAutoStart()
128
	 */
129
	public boolean isAutoStart() {
130
		return fAutoStart;
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#removeProperty(java.lang.String)
135
	 */
136
	public void removeProperty(String key) {
137
		String oldValue = (String) fPropertiesMap.get(key);
138
		fPropertiesMap.remove(key);
139
		if (isEditable() && oldValue != null)
140
			firePropertyChanged(key, oldValue, null);
141
142
	}
143
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#setAutoStart(boolean)
146
	 */
147
	public void setAutoStart(boolean autostart) {
148
		boolean oldValue = fAutoStart;
149
		fAutoStart = autostart;
150
		if (isEditable() && oldValue != fAutoStart)
151
			firePropertyChanged(P_AUTO_START, new Boolean(oldValue), new Boolean(fAutoStart));
152
153
	}
154
155
	/* (non-Javadoc)
156
	 * @see org.eclipse.pde.internal.core.iproduct.IPluginConfiguration#setStartLevel(java.lang.String)
157
	 */
158
	public void setStartLevel(int startLevel) {
159
		int oldValue = fStartLevel;
160
		fStartLevel = startLevel;
161
		if (isEditable() && oldValue != fStartLevel)
162
			firePropertyChanged(P_START_LEVEL, new Integer(oldValue), new Integer(fStartLevel));
163
	}
164
165
}

Return to bug 240737