01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core;
11:
12: import java.io.File;
13: import java.net.URL;
14: import java.util.StringTokenizer;
15: import java.util.Vector;
16:
17: import org.eclipse.core.runtime.Preferences;
18: import org.eclipse.pde.core.plugin.IPluginModelBase;
19:
20: public class ExternalModelManager extends AbstractModelManager {
21:
22: private IPluginModelBase[] fModels = new IPluginModelBase[0];
23:
24: protected IPluginModelBase[] getAllModels() {
25: return fModels;
26: }
27:
28: protected void initializeModels(IPluginModelBase[] models) {
29: fModels = models;
30: Preferences pref = PDECore.getDefault().getPluginPreferences();
31: String saved = pref.getString(ICoreConstants.CHECKED_PLUGINS);
32: if (saved.equals(ICoreConstants.VALUE_SAVED_ALL)) {
33: for (int i = 0; i < fModels.length; i++)
34: fModels[i].setEnabled(true);
35: } else if (!saved.equals(ICoreConstants.VALUE_SAVED_NONE)) {
36: Vector result = new Vector();
37: StringTokenizer stok = new StringTokenizer(saved);
38: while (stok.hasMoreTokens()) {
39: result.add(stok.nextToken());
40: }
41: for (int i = 0; i < fModels.length; i++) {
42: fModels[i].setEnabled(!result.contains(fModels[i]
43: .getPluginBase().getId()));
44: }
45: }
46: }
47:
48: public void setModels(IPluginModelBase[] models) {
49: fModels = models;
50: }
51:
52: protected URL[] getPluginPaths() {
53: Preferences pref = PDECore.getDefault().getPluginPreferences();
54: URL[] base = PluginPathFinder.getPluginPaths(pref
55: .getString(ICoreConstants.PLATFORM_PATH));
56:
57: String value = pref
58: .getString(ICoreConstants.ADDITIONAL_LOCATIONS);
59: StringTokenizer tokenizer = new StringTokenizer(value, ","); //$NON-NLS-1$
60:
61: if (tokenizer.countTokens() == 0)
62: return base;
63:
64: File[] extraLocations = new File[tokenizer.countTokens()];
65: for (int i = 0; i < extraLocations.length; i++) {
66: String location = tokenizer.nextToken();
67: File dir = new File(location, "plugins"); //$NON-NLS-1$
68: if (!dir.exists() || !dir.isDirectory())
69: dir = new File(location);
70: extraLocations[i] = dir;
71: }
72: URL[] additional = PluginPathFinder
73: .scanLocations(extraLocations);
74:
75: if (additional.length == 0)
76: return base;
77:
78: URL[] result = new URL[base.length + additional.length];
79: System.arraycopy(base, 0, result, 0, base.length);
80: System.arraycopy(additional, 0, result, base.length,
81: additional.length);
82:
83: return result;
84: }
85:
86: }
|