001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.core.plugin;
011:
012: import org.eclipse.core.resources.IProject;
013: import org.eclipse.osgi.service.resolver.BundleDescription;
014: import org.eclipse.pde.internal.core.PDECore;
015:
016: /**
017: * The central access point for models representing plug-ins found in the workspace
018: * and in the targret platform.
019: * <p>
020: * This class provides static methods only; it is not intended to be
021: * instantiated or subclassed by clients.
022: * </p>
023: *
024: * @since 3.3
025: */
026: public class PluginRegistry {
027:
028: /**
029: * Returns a model entry containing all workspace and target plug-ins by the given ID
030: *
031: * @param id the plug-in ID
032: *
033: * @return a model entry containing all workspace and target plug-ins by the given ID
034: */
035: public static ModelEntry findEntry(String id) {
036: return PDECore.getDefault().getModelManager().findEntry(id);
037: }
038:
039: /**
040: * Returns the plug-in model for the best match plug-in with the given ID.
041: * A null value is returned if no such bundle is found in the workspace or target platform.
042: * <p>
043: * A workspace plug-in is always preferably returned over a target plug-in.
044: * A plug-in that is checked/enabled on the Target Platform preference page is always
045: * preferably returned over a target plug-in that is unchecked/disabled.
046: * </p>
047: * <p>
048: * In the case of a tie among workspace plug-ins or among target plug-ins,
049: * the plug-in with the highest version is returned.
050: * </p>
051: * <p>
052: * In the case of a tie among more than one suitable plug-in that have the same version,
053: * one of those plug-ins is randomly returned.
054: * </p>
055: *
056: * @param id the plug-in ID
057: * @return the plug-in model for the best match plug-in with the given ID
058: */
059: public static IPluginModelBase findModel(String id) {
060: return PDECore.getDefault().getModelManager().findModel(id);
061: }
062:
063: /**
064: * Returns the plug-in model corresponding to the given project, or <code>null</code>
065: * if the project does not represent a plug-in project or if it contains a manifest file
066: * that is malformed or missing vital information.
067: *
068: * @param project the project
069: * @return a plug-in model corresponding to the project or <code>null</code> if the project
070: * is not a plug-in project
071: */
072: public static IPluginModelBase findModel(IProject project) {
073: return PDECore.getDefault().getModelManager()
074: .findModel(project);
075: }
076:
077: /**
078: * Returns a plug-in model associated with the given bundle description
079: *
080: * @param desc the bundle description
081: *
082: * @return a plug-in model associated with the given bundle description or <code>null</code>
083: * if none exists
084: */
085: public static IPluginModelBase findModel(BundleDescription desc) {
086: return PDECore.getDefault().getModelManager().findModel(desc);
087: }
088:
089: /**
090: * Returns all plug-ins and fragments in the workspace as well as all plug-ins and fragments that are
091: * checked on the Target Platform preference page.
092: * <p>
093: * If a workspace plug-in/fragment has the same ID as a target plug-in/fragment, the target counterpart
094: * is skipped and not included.
095: * </p>
096: * <p>
097: * Equivalent to <code>getActiveModels(true)</code>
098: * </p>
099: *
100: * @return all plug-ins and fragments in the workspace as well as all plug-ins and fragments that are
101: * checked on the Target Platform preference page.
102: */
103: public static IPluginModelBase[] getActiveModels() {
104: return getActiveModels(true);
105: }
106:
107: /**
108: * Returns all plug-ins and (possibly) fragments in the workspace as well as all plug-ins and (possibly)
109: * fragments that are checked on the Target Platform preference page.
110: * <p>
111: * If a workspace plug-in/fragment has the same ID as a target plug-in, the target counterpart
112: * is skipped and not included.
113: * </p>
114: * <p>
115: * The returned result includes fragments only if <code>includeFragments</code>
116: * is set to true
117: * </p>
118: * @param includeFragments a boolean indicating if fragments are desired in the returned
119: * result
120: * @return all plug-ins and (possibly) fragments in the workspace as well as all plug-ins and
121: * (possibly) fragments that are checked on the Target Platform preference page.
122: */
123: public static IPluginModelBase[] getActiveModels(
124: boolean includeFragments) {
125: return PDECore.getDefault().getModelManager().getActiveModels(
126: includeFragments);
127: }
128:
129: /**
130: * Returns all plug-ins and fragments in the workspace as well as all target plug-ins and fragments, regardless
131: * whether or not they are checked or not on the Target Platform preference page.
132: * <p>
133: * If a workspace plug-in/fragment has the same ID as a target plug-in, the target counterpart
134: * is skipped and not included.
135: * </p>
136: * <p>
137: * Equivalent to <code>getAllModels(true)</code>
138: * </p>
139: *
140: * @return all plug-ins and fragments in the workspace as well as all target plug-ins and fragments, regardless
141: * whether or not they are checked on the Target Platform preference page.
142: */
143: public static IPluginModelBase[] getAllModels() {
144: return getAllModels(true);
145: }
146:
147: /**
148: * Returns all plug-ins and (possibly) fragments in the workspace as well as all plug-ins
149: * and (possibly) fragments, regardless whether or not they are
150: * checked on the Target Platform preference page.
151: * <p>
152: * If a workspace plug-in/fragment has the same ID as a target plug-in/fragment, the target counterpart
153: * is skipped and not included.
154: * </p>
155: * <p>
156: * The returned result includes fragments only if <code>includeFragments</code>
157: * is set to true
158: * </p>
159: * @param includeFragments a boolean indicating if fragments are desired in the returned
160: * result
161: * @return ll plug-ins and (possibly) fragments in the workspace as well as all plug-ins
162: * and (possibly) fragments, regardless whether or not they are
163: * checked on the Target Platform preference page.
164: */
165: public static IPluginModelBase[] getAllModels(
166: boolean includeFragments) {
167: return PDECore.getDefault().getModelManager().getAllModels(
168: includeFragments);
169: }
170:
171: /**
172: * Returns all plug-in models in the workspace
173: *
174: * @return all plug-in models in the workspace
175: */
176: public static IPluginModelBase[] getWorkspaceModels() {
177: return PDECore.getDefault().getModelManager()
178: .getWorkspaceModels();
179: }
180:
181: /**
182: * Return the model manager that keeps track of plug-ins in the target platform
183: *
184: * @return the model manager that keeps track of plug-ins in the target platform
185: */
186: public static IPluginModelBase[] getExternalModels() {
187: return PDECore.getDefault().getModelManager()
188: .getExternalModels();
189: }
190:
191: }
|