*** empty log message ***
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathContainerResolver.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathContainerResolver.java new file mode 100644 index 0000000..c1f6cb9 --- /dev/null +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathContainerResolver.java
@@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.osgi.service.resolver.BaseDescription; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.osgi.service.resolver.BundleSpecification; +import org.eclipse.osgi.service.resolver.HostSpecification; +import org.eclipse.pde.core.plugin.IPluginModelBase; + +public class ClasspathContainerResolver { + + public static IClasspathEntry[] resolve(IPluginModelBase model) { + ArrayList result = new ArrayList(); + resolve(model, result, null); + return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); + } + + private static void resolve( + IPluginModelBase model, + ArrayList result, + IProgressMonitor monitor) { + + BundleDescription desc = model.getBundleDescription(); + if (desc == null) + return; + + HashSet added = new HashSet(); + + HostSpecification hostSpec = desc.getHost(); + BundleDescription host = (hostSpec != null) ? addHost(hostSpec, result, added) : null; + + BundleSpecification[] required = desc.getRequiredBundles(); + for (int i = 0; i < required.length; i++) { + addRequiredBundle(required[i], required[i].isExported(), result, added); + } + + if (host != null) + addHostDependencies(host, result, added); + + addImportedPackages(desc, host, result, added); + + addImplicitDependencies(); + + addExtraClasspathEntries(); + } + + private static BundleDescription addHost(HostSpecification hostSpec, ArrayList result, Set added) { + BundleDescription[] hosts = hostSpec.getHosts(); + if (hosts.length == 0) + return null; + + BundleDescription host = hosts[0]; + if (added.add(host.getSymbolicName())) + addClasspathEntries(host, result); + return host; + } + + private static void addHostDependencies(BundleDescription host, ArrayList result, Set added) { + boolean inWorkspace = inWorkspace(host); + BundleSpecification[] required = host.getRequiredBundles(); + for (int i = 0; i < required.length; i++) { + if (!inWorkspace || !required[i].isExported()) { + addRequiredBundle(required[i], false, result, added); + } + } + } + + private static void addRequiredBundle(BundleSpecification spec, boolean exported, ArrayList result, Set added) { + if (!added.add(spec.getName())) + return; + + BaseDescription supplier = spec.getSupplier(); + if (supplier instanceof BundleDescription) { + BundleDescription desc = (BundleDescription)supplier; + addClasspathEntries(desc, result); + BundleSpecification[] required = desc.getRequiredBundles(); + for (int i = 0; i < required.length; i++) { + if (required[i].isExported()) + addRequiredBundle(required[i], exported, result, added); + } + } + } + + private static void addImportedPackages(BundleDescription desc, BundleDescription host, ArrayList result, HashSet added) { + + } + + private static void addExtraClasspathEntries() { + } + + private static void addImplicitDependencies() { + } + + private static void addClasspathEntries(BundleDescription desc, ArrayList result) { + } + + private static boolean inWorkspace(BundleDescription desc) { + IPath path = new Path(desc.getLocation()); + return PDECore.getWorkspace().getRoot().findMember(path) != null; + } + + +}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathUtilCore2.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathUtilCore2.java new file mode 100644 index 0000000..572a147 --- /dev/null +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathUtilCore2.java
@@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core; + +import java.util.Vector; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaModelStatus; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaConventions; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.pde.core.plugin.IPluginModelBase; + +public class ClasspathUtilCore2 { + + public static void setClasspath( + IPluginModelBase model, + IProgressMonitor monitor) + throws CoreException { + + Vector result = new Vector(); + monitor.beginTask("", 3); //$NON-NLS-1$ + + // add own libraries/source + //addSourceAndLibraries(model, result); + monitor.worked(1); + + result.add(createContainerEntry()); + monitor.worked(1); + + // add JRE + result.add(createJREEntry()); + monitor.worked(1); + + IClasspathEntry[] entries = + (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); + + IJavaProject javaProject = + JavaCore.create(model.getUnderlyingResource().getProject()); + IJavaModelStatus validation = + JavaConventions.validateClasspath( + javaProject, + entries, + javaProject.getOutputLocation()); + if (!validation.isOK()) { + throw new CoreException(validation); + } + javaProject.setRawClasspath(entries, monitor); + monitor.done(); + } + + public static IClasspathEntry createContainerEntry() { + return JavaCore.newContainerEntry(new Path(PDECore.CLASSPATH_CONTAINER_ID)); + } + + public static IClasspathEntry createJREEntry() { + return JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); //$NON-NLS-1$ + } + +}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginManager.java new file mode 100644 index 0000000..597a3f1 --- /dev/null +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PluginManager.java
@@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.osgi.service.resolver.State; +import org.eclipse.pde.core.IModelProviderEvent; +import org.eclipse.pde.core.IModelProviderListener; +import org.eclipse.pde.core.plugin.IPluginModelBase; +import org.osgi.framework.Version; + +public class PluginManager implements IAdaptable { + + private static final String OSGI_RUNTIME ="org.eclipse.osgi"; //$NON-NLS-1$ + + private IModelProviderListener fProviderListener; + private ArrayList fListeners; + + private ExternalModelManager fExternalManager; + private WorkspaceModelManager fWorkspaceManager; + //private SearchablePluginsManager fSearchablePluginsManager; + + private State fCurrentState; + private Map fEntries; + + public PluginManager() { + fProviderListener = new IModelProviderListener() { + public void modelsChanged(IModelProviderEvent e) { + handleModelsChanged(e); + } + }; + fListeners = new ArrayList(); + //fSearchablePluginsManager = new SearchablePluginsManager(this); + } + + public String getTargetVersion() { + BundleDescription desc = fCurrentState.getBundle(OSGI_RUNTIME, null); + if (desc == null) + return ICoreConstants.TARGET21; + + Version version = desc.getVersion(); + if (version != null && version.getMajor() == 3 && version.getMinor() == 0) + return ICoreConstants.TARGET30; + + return ICoreConstants.TARGET31; + } + + public void addPluginModelListener(IPluginModelListener listener) { + if (!fListeners.contains(listener)) + fListeners.add(listener); + } + + public void removePluginModelListener(IPluginModelListener listener) { + if (fListeners.contains(listener)) + fListeners.remove(listener); + } + + private void handleModelsChanged(IModelProviderEvent e) { + PluginModelDelta delta = new PluginModelDelta(); + ArrayList changedPlugins = new ArrayList(); + //boolean javaSearchAffected=false; + + if ((e.getEventTypes() & IModelProviderEvent.MODELS_REMOVED) != 0) { + } + if ((e.getEventTypes() & IModelProviderEvent.MODELS_ADDED) != 0) { + } + if ((e.getEventTypes() & IModelProviderEvent.MODELS_CHANGED) != 0) { + } + + if (changedPlugins.size() > 0) + fExternalManager.getState().resolveState(true); + //if (javaSearchAffected) + //fSearchablePluginsManager.updateClasspathContainer(); + fireDelta(delta); + } + + /* + * Allow access to the table only through this getter. + * It always calls initialize to make sure the table is initialized. + * If more than one thread tries to read the table at the same time, + * and the table is not initialized yet, thread2 would wait. + * This way there are no partial reads. + */ + protected Map getEntryTable() { + initializeTable(); + return fEntries; + } + + /* + * This method must be synchronized so that only one thread + * initializes the table, and the rest would block until + * the table is initialized. + * + */ + private synchronized void initializeTable() { + if (fEntries != null) return; + fEntries = Collections.synchronizedMap(new TreeMap()); + //fSearchablePluginsManager.initialize(); + } + + protected void updateBundleDescription(IPluginModelBase model) { + BundleDescription description = model.getBundleDescription(); + if (description == null) + return; + PDEState state = fExternalManager.getState(); + state.removeBundleDescription(description); + + BundleDescription newDesc = state.addBundle(model); + model.setBundleDescription(newDesc); + } + + private void fireDelta(PluginModelDelta delta) { + Object [] entries = fListeners.toArray(); + for (int i=0; i<entries.length; i++) { + ((IPluginModelListener)entries[i]).modelsChanged(delta); + } + } + + public void connect(WorkspaceModelManager wm, ExternalModelManager em) { + fExternalManager = em; + fWorkspaceManager = wm; + fExternalManager.addModelProviderListener(fProviderListener); + fWorkspaceManager.addModelProviderListener(fProviderListener); + } + + public void shutdown() { + if (fWorkspaceManager != null) + fWorkspaceManager.removeModelProviderListener(fProviderListener); + if (fExternalManager != null) + fExternalManager.removeModelProviderListener(fProviderListener); + //fSearchablePluginsManager.shutdown(); + } + + public void setInJavaSearch(ModelEntry [] entries, boolean value, IProgressMonitor monitor) throws CoreException { + PluginModelDelta delta = new PluginModelDelta(); + for (int i=0; i<entries.length; i++) { + ModelEntry entry = entries[i]; + if (entry.isInJavaSearch()!=value) { + entry.setInJavaSearch(value); + delta.addEntry(entry, PluginModelDelta.CHANGED); + } + } + if (delta.getKind()!=0) { + //fSearchablePluginsManager.persistStates( monitor); + fireDelta(delta); + } + } + + public Object getAdapter(Class adapter) { + return null; + } + +}