org.eclipse.pde.core_3.7.1.v20120103_r372

))) {
      return false;
    }
    IResource resource = model.getUnderlyingResource();
    PDEClasspathContainer.Rule[] rules = useInclusions ? getInclusions(map, model) : null;
    if (resource != null) {
      addProjectEntry(resource.getProject(), rules, entries);
    } else {
      addExternalPlugin(model, rules, entries);
    }
    return true;
  }
  
  private PDEClasspathContainer.Rule[] getInclusions(Map map, IPluginModelBase model)
  {
    BundleDescription desc = model.getBundleDescription();
    if ((desc == null) || ("false".equals(System.getProperty("pde.restriction"))) || 
      (!(fModel instanceof IBundlePluginModelBase)) || (TargetPlatformHelper.getTargetVersion() < 3.1D)) {
      return null;
    }
    PDEClasspathContainer.Rule[] rules;
    PDEClasspathContainer.Rule[] rules;
    if (desc.getHost() != null) {
      rules = getInclusions(map, (BundleDescription)desc.getHost().getSupplier());
    } else {
      rules = getInclusions(map, desc);
    }
    return (rules.length == 0) && (!ClasspathUtilCore.hasBundleStructure(model)) ? null : rules;
  }
  
  private PDEClasspathContainer.Rule[] getInclusions(Map map, BundleDescription desc)
  {
    ArrayList list = (ArrayList)map.get(desc);
    return list != null ? (PDEClasspathContainer.Rule[])list.toArray(new PDEClasspathContainer.Rule[list.size()]) : new PDEClasspathContainer.Rule[0];
  }
  
  private void addHostPlugin(HostSpecification hostSpec, HashSet added, Map map, ArrayList entries)
    throws CoreException
  {
    BaseDescription desc = hostSpec.getSupplier();
    if ((desc instanceof BundleDescription))
    {
      BundleDescription host = (BundleDescription)desc;
      if ((added.add(host)) && (addPlugin(host, false, map, entries)))
      {
        BundleSpecification[] required = host.getRequiredBundles();
        for (int i = 0; i < required.length; i++) {
          addDependency((BundleDescription)required[i].getSupplier(), added, map, entries);
        }
        ImportPackageSpecification[] imports = host.getImportPackages();
        for (int i = 0; i < imports.length; i++)
        {
          BaseDescription supplier = imports[i].getSupplier();
          if ((supplier instanceof ExportPackageDescription)) {
            addDependencyViaImportPackage(((ExportPackageDescription)supplier).getExporter(), added, map, entries);
          }
        }
      }
    }
  }
  
  private boolean hasExtensibleAPI(BundleDescription desc)
  {
    IPluginModelBase model = PluginRegistry.findModel(desc);
    return model != null ? ClasspathUtilCore.hasExtensibleAPI(model) : false;
  }
  
  protected void addExtraClasspathEntries(HashSet added, ArrayList entries)
  {
    IBuildEntry[] buildEntries = fBuild.getBuildEntries();
    for (int i = 0; i < buildEntries.length; i++)
    {
      String name = buildEntries[i].getName();
      if ((name.equals("jars.extra.classpath")) || (name.startsWith("extra."))) {
        addExtraClasspathEntries(added, entries, buildEntries[i].getTokens());
      }
    }
  }
  
  protected void addExtraClasspathEntries(HashSet added, ArrayList entries, String[] tokens)
  {
    for (int i = 0; i < tokens.length; i++)
    {
      IPath path = Path.fromPortableString(tokens[i]);
      if (!path.isAbsolute())
      {
        File file = new File(fModel.getInstallLocation(), path.toString());
        if (file.exists())
        {
          IFile resource = PDECore.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
          if ((resource != null) && (resource.getProject().equals(fModel.getUnderlyingResource().getProject())))
          {
            addExtraLibrary(resource.getFullPath(), null, entries);
            continue;
          }
        }
        if ((path.segmentCount() >= 3) && ("..".equals(path.segment(0))))
        {
          path = path.removeFirstSegments(1);
          path = Path.fromPortableString("platform:/plugin/").append(path);
        }
      }
      else if (!path.toPortableString().startsWith("platform:"))
      {
        addExtraLibrary(path, null, entries);
      }
      else
      {
        int count = path.getDevice() == null ? 4 : 3;
        if (path.segmentCount() >= count)
        {
          String pluginID = path.segment(count - 2);
          if (!added.contains(pluginID))
          {
            IPluginModelBase model = PluginRegistry.findModel(pluginID);
            if ((model != null) && (model.isEnabled()))
            {
              path = path.setDevice(null);
              path = path.removeFirstSegments(count - 1);
              if (model.getUnderlyingResource() == null)
              {
                File file = new File(model.getInstallLocation(), path.toOSString());
                if (file.exists()) {
                  addExtraLibrary(new Path(file.getAbsolutePath()), model, entries);
                }
              }
              else
              {
                IProject project = model.getUnderlyingResource().getProject();
                IFile file = project.getFile(path);
                if (file.exists()) {
                  addExtraLibrary(file.getFullPath(), model, entries);
                }
              }
            }
          }
        }
      }
    }
  }
  
  private void addSecondaryDependencies(BundleDescription desc, HashSet added, ArrayList entries)
  {
    try
    {
      IBuildEntry entry = fBuild.getEntry("additional.bundles");
      if (entry != null)
      {
        String[] tokens = entry.getTokens();
        for (int i = 0; i < tokens.length; i++)
        {
          String pluginId = tokens[i];
          
          IPluginModelBase model = PluginRegistry.findModel(pluginId);
          if (model != null)
          {
            BundleDescription bundleDesc = model.getBundleDescription();
            if (!added.contains(bundleDesc))
            {
              Map rules = new HashMap();
              findExportedPackages(bundleDesc, desc, rules);
              if (model != null) {
                addDependency(bundleDesc, added, rules, entries, true);
              }
            }
          }
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  protected final void findExportedPackages(BundleDescription desc, BundleDescription projectDesc, Map map)
  {
    if (desc != null)
    {
      Stack stack = new Stack();
      stack.add(desc);
      BundleSpecification[] requiredBundles;
      int i;
      for (; !stack.isEmpty(); i < requiredBundles.length)
      {
        BundleDescription bdesc = (BundleDescription)stack.pop();
        ExportPackageDescription[] expkgs = bdesc.getExportPackages();
        ArrayList rules = new ArrayList();
        for (int i = 0; i < expkgs.length; i++)
        {
          PDEClasspathContainer.Rule rule = new PDEClasspathContainer.Rule(this);
          discouraged = restrictPackage(projectDesc, expkgs[i]);
          path = new Path(expkgs[i].getName().replaceAll("\\.", "/") + "/*");
          rules.add(rule);
        }
        map.put(bdesc, rules);
        
        requiredBundles = bdesc.getRequiredBundles();
        i = 0; continue;
        if (requiredBundles[i].isExported())
        {
          BaseDescription bd = requiredBundles[i].getSupplier();
          if ((bd != null) && ((bd instanceof BundleDescription))) {
            stack.add(bd);
          }
        }
        i++;
      }
    }
  }
  
  private boolean restrictPackage(BundleDescription desc, ExportPackageDescription pkg)
  {
    String[] friends = (String[])pkg.getDirective("x-friends");
    if (friends != null)
    {
      String symbolicName = desc.getSymbolicName();
      for (int i = 0; i < friends.length; i++) {
        if (symbolicName.equals(friends[i])) {
          return false;
        }
      }
      return true;
    }
    return ((Boolean)pkg.getDirective("x-internal")).booleanValue();
  }
  
  private void addExtraLibrary(IPath path, IPluginModelBase model, ArrayList entries)
  {
    if (path.segmentCount() > 1)
    {
      IPath srcPath = null;
      if (model != null)
      {
        IPath shortPath = path.removeFirstSegments(path.matchingFirstSegments(new Path(model.getInstallLocation())));
        srcPath = ClasspathUtilCore.getSourceAnnotation(model, shortPath.toString());
      }
      else
      {
        String filename = ClasspathUtilCore.getSourceZipName(path.lastSegment());
        IPath candidate = path.removeLastSegments(1).append(filename);
        if (PDECore.getWorkspace().getRoot().getFile(candidate).exists()) {
          srcPath = candidate;
        }
      }
      IClasspathEntry clsEntry = JavaCore.newLibraryEntry(path, srcPath, null);
      if (!entries.contains(clsEntry)) {
        entries.add(clsEntry);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;

public class RequiredPluginsInitializer
  extends ClasspathContainerInitializer
{
  public void initialize(IPath containerPath, IJavaProject javaProject)
    throws CoreException
  {
    IProject project = javaProject.getProject();
    IPluginModelBase model = PluginRegistry.findModel(project);
    JavaCore.setClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, new IJavaProject[] { javaProject }, new IClasspathContainer[] { new RequiredPluginsClasspathContainer(model) }, null);
  }
  
  public Object getComparisonID(IPath containerPath, IJavaProject project)
  {
    if ((containerPath == null) || (project == null)) {
      return null;
    }
    return containerPath.segment(0) + "/" + project.getPath().segment(0);
  }
  
  public String getDescription(IPath containerPath, IJavaProject project)
  {
    return PDECoreMessages.RequiredPluginsClasspathContainer_description;
  }
  
  public IStatus getSourceAttachmentStatus(IPath containerPath, IJavaProject project)
  {
    return Status.OK_STATUS;
  }
  
  public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project)
  {
    return true;
  }
  
  public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion)
    throws CoreException
  {
    JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { containerSuggestion }, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.RequiredPluginsInitializer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import java.util.Set;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;

class SearchablePluginsManager$Listener
  implements IElementChangedListener
{
  final SearchablePluginsManager this$0;
  
  SearchablePluginsManager$Listener(SearchablePluginsManager paramSearchablePluginsManager)
  {
    this$0 = paramSearchablePluginsManager;
  }
  
  public void elementChanged(ElementChangedEvent e)
  {
    if (e.getType() == 1) {
      handleDelta(e.getDelta());
    }
  }
  
  private boolean handleDelta(IJavaElementDelta delta)
  {
    Object element = delta.getElement();
    if ((element instanceof IJavaModel))
    {
      IJavaElementDelta[] projectDeltas = delta.getAffectedChildren();
      for (int i = 0; i < projectDeltas.length; i++) {
        if (handleDelta(projectDeltas[i])) {
          break;
        }
      }
      return true;
    }
    if ((delta.getElement() instanceof IJavaProject))
    {
      IJavaProject project = (IJavaProject)delta.getElement();
      if (project.getElementName().equals("External Plug-in Libraries")) {
        if (delta.getKind() == 2) {
          SearchablePluginsManager.access$0(this$0).clear();
        } else if (delta.getKind() == 1) {
          if ((SearchablePluginsManager.access$0(this$0) == null) || (SearchablePluginsManager.access$0(this$0).size() == 0)) {
            SearchablePluginsManager.access$1(this$0);
          }
        }
      }
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.SearchablePluginsManager.Listener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.ModelEntry;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.util.CoreUtility;

public class SearchablePluginsManager
  implements IFileAdapterFactory, IPluginModelListener, ISaveParticipant
{
  private static final String PROXY_FILE_NAME = ".searchable";
  public static final String PROXY_PROJECT_NAME = "External Plug-in Libraries";
  private static final String KEY = "searchablePlugins";
  private Listener fElementListener;
  private Set fPluginIdSet;
  private ArrayList fListeners;
  
  class Listener
    implements IElementChangedListener
  {
    Listener() {}
    
    public void elementChanged(ElementChangedEvent e)
    {
      if (e.getType() == 1) {
        handleDelta(e.getDelta());
      }
    }
    
    private boolean handleDelta(IJavaElementDelta delta)
    {
      Object element = delta.getElement();
      if ((element instanceof IJavaModel))
      {
        IJavaElementDelta[] projectDeltas = delta.getAffectedChildren();
        for (int i = 0; i < projectDeltas.length; i++) {
          if (handleDelta(projectDeltas[i])) {
            break;
          }
        }
        return true;
      }
      if ((delta.getElement() instanceof IJavaProject))
      {
        IJavaProject project = (IJavaProject)delta.getElement();
        if (project.getElementName().equals("External Plug-in Libraries")) {
          if (delta.getKind() == 2) {
            fPluginIdSet.clear();
          } else if (delta.getKind() == 1) {
            if ((fPluginIdSet == null) || (fPluginIdSet.size() == 0)) {
              SearchablePluginsManager.this.initializeStates();
            }
          }
        }
        return true;
      }
      return false;
    }
  }
  
  public SearchablePluginsManager()
  {
    initializeStates();
    fElementListener = new Listener();
    JavaCore.addElementChangedListener(fElementListener);
    PDECore.getDefault().getModelManager().addPluginModelListener(this);
  }
  
  private void initializeStates()
  {
    fPluginIdSet = new TreeSet();
    IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
    IProject project = root.getProject("External Plug-in Libraries");
    try
    {
      if ((project.exists()) && (project.isOpen()))
      {
        IFile proxyFile = project.getFile(".searchable");
        if (proxyFile.exists())
        {
          Properties properties = new Properties();
          InputStream stream = proxyFile.getContents(true);
          properties.load(stream);
          stream.close();
          String value = properties.getProperty("searchablePlugins");
          if (value != null)
          {
            StringTokenizer stok = new StringTokenizer(value, ",");
            while (stok.hasMoreTokens()) {
              fPluginIdSet.add(stok.nextToken());
            }
          }
        }
      }
    }
    catch (IOException localIOException) {}catch (CoreException localCoreException) {}
  }
  
  public IJavaProject getProxyProject()
  {
    IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
    IProject project = root.getProject("External Plug-in Libraries");
    try
    {
      if ((project.exists()) && (project.isOpen()) && (project.hasNature("org.eclipse.jdt.core.javanature"))) {
        return JavaCore.create(project);
      }
    }
    catch (CoreException localCoreException) {}
    return null;
  }
  
  public void shutdown()
  {
    JavaCore.removeElementChangedListener(fElementListener);
    PDECore.getDefault().getModelManager().removePluginModelListener(this);
    if (fListeners != null) {
      fListeners.clear();
    }
  }
  
  public IClasspathEntry[] computeContainerClasspathEntries()
    throws CoreException
  {
    ArrayList result = new ArrayList();
    
    IPluginModelBase[] wModels = PluginRegistry.getWorkspaceModels();
    for (int i = 0; i < wModels.length; i++)
    {
      IProject project = wModels[i].getUnderlyingResource().getProject();
      if (project.hasNature("org.eclipse.jdt.core.javanature")) {
        result.add(JavaCore.newProjectEntry(project.getFullPath()));
      }
    }
    Iterator iter = fPluginIdSet.iterator();
    while (iter.hasNext())
    {
      ModelEntry entry = PluginRegistry.findEntry(iter.next().toString());
      if (entry != null)
      {
        boolean addModel = true;
        wModels = entry.getWorkspaceModels();
        for (int i = 0; i < wModels.length; i++)
        {
          IProject project = wModels[i].getUnderlyingResource().getProject();
          if (project.hasNature("org.eclipse.jdt.core.javanature")) {
            addModel = false;
          }
        }
        if (addModel)
        {
          IPluginModelBase[] models = entry.getExternalModels();
          for (int i = 0; i < models.length; i++) {
            if (models[i].isEnabled()) {
              ClasspathUtilCore.addLibraries(models[i], result);
            }
          }
        }
      }
    }
    if (result.size() > 1)
    {
      Map map = new TreeMap();
      for (int i = 0; i < result.size(); i++)
      {
        IClasspathEntry entry = (IClasspathEntry)result.get(i);
        String key = entry.getPath().lastSegment().toString();
        if (map.containsKey(key)) {
          key = key + System.currentTimeMillis();
        }
        map.put(key, entry);
      }
      return (IClasspathEntry[])map.values().toArray(new IClasspathEntry[map.size()]);
    }
    return (IClasspathEntry[])result.toArray(new IClasspathEntry[result.size()]);
  }
  
  public Object createAdapterChild(FileAdapter parent, File file)
  {
    if ((!file.isDirectory()) && 
      (file.isFile()))
    {
      IPackageFragmentRoot root = findPackageFragmentRoot(new Path(file.getAbsolutePath()));
      if (root != null) {
        return root;
      }
    }
    return new FileAdapter(parent, file, this);
  }
  
  private IPackageFragmentRoot findPackageFragmentRoot(IPath jarPath)
  {
    IJavaProject jProject = getProxyProject();
    if (jProject != null) {
      try
      {
        IPackageFragmentRoot[] roots = jProject.getAllPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++)
        {
          IPackageFragmentRoot root = roots[i];
          IPath path = root.getPath();
          if (path.equals(jarPath)) {
            return root;
          }
        }
      }
      catch (JavaModelException localJavaModelException1) {}
    }
    IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels();
    for (int i = 0; i < pluginModels.length; i++)
    {
      IProject project = pluginModels[i].getUnderlyingResource().getProject();
      IJavaProject javaProject = JavaCore.create(project);
      try
      {
        IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
        for (int j = 0; j < roots.length; j++)
        {
          IPackageFragmentRoot root = roots[j];
          IPath path = root.getPath();
          if (path.equals(jarPath)) {
            return root;
          }
        }
      }
      catch (JavaModelException localJavaModelException2) {}
    }
    return null;
  }
  
  private void checkForProxyProject()
  {
    IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
    try
    {
      IProject project = root.getProject("External Plug-in Libraries");
      if (!project.exists()) {
        createProxyProject(new NullProgressMonitor());
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  public void addToJavaSearch(IPluginModelBase[] models)
  {
    checkForProxyProject();
    PluginModelDelta delta = new PluginModelDelta();
    int size = fPluginIdSet.size();
    for (int i = 0; i < models.length; i++)
    {
      String id = models[i].getPluginBase().getId();
      if (fPluginIdSet.add(id))
      {
        ModelEntry entry = PluginRegistry.findEntry(id);
        if (entry != null) {
          delta.addEntry(entry, 4);
        }
      }
    }
    if (fPluginIdSet.size() > size)
    {
      resetContainer();
      fireDelta(delta);
    }
  }
  
  public void removeFromJavaSearch(IPluginModelBase[] models)
  {
    PluginModelDelta delta = new PluginModelDelta();
    int size = fPluginIdSet.size();
    for (int i = 0; i < models.length; i++)
    {
      String id = models[i].getPluginBase().getId();
      if (fPluginIdSet.remove(id))
      {
        ModelEntry entry = PluginRegistry.findEntry(id);
        if (entry != null) {
          delta.addEntry(entry, 4);
        }
      }
    }
    if (fPluginIdSet.size() < size)
    {
      resetContainer();
      fireDelta(delta);
    }
  }
  
  public void removeAllFromJavaSearch()
  {
    if (fPluginIdSet.size() > 0)
    {
      PluginModelDelta delta = new PluginModelDelta();
      for (Iterator iterator = fPluginIdSet.iterator(); iterator.hasNext();)
      {
        String id = (String)iterator.next();
        ModelEntry entry = PluginRegistry.findEntry(id);
        if (entry != null) {
          delta.addEntry(entry, 4);
        }
      }
      fPluginIdSet.clear();
      resetContainer();
      fireDelta(delta);
    }
  }
  
  public boolean isInJavaSearch(String symbolicName)
  {
    return fPluginIdSet.contains(symbolicName);
  }
  
  private void resetContainer()
  {
    IJavaProject jProject = getProxyProject();
    try
    {
      if (jProject != null) {
        JavaCore.setClasspathContainer(PDECore.JAVA_SEARCH_CONTAINER_PATH, new IJavaProject[] { jProject }, new IClasspathContainer[] { new ExternalJavaSearchClasspathContainer() }, null);
      }
    }
    catch (JavaModelException localJavaModelException) {}
  }
  
  public void modelsChanged(PluginModelDelta delta)
  {
    ModelEntry[] entries = delta.getRemovedEntries();
    for (int i = 0; i < entries.length; i++) {
      if (fPluginIdSet.contains(entries[i].getId())) {
        fPluginIdSet.remove(entries[i].getId());
      }
    }
    resetContainer();
  }
  
  private void fireDelta(PluginModelDelta delta)
  {
    if (fListeners != null) {
      for (int i = 0; i < fListeners.size(); i++) {
        ((IPluginModelListener)fListeners.get(i)).modelsChanged(delta);
      }
    }
  }
  
  public void addPluginModelListener(IPluginModelListener listener)
  {
    if (fListeners == null) {
      fListeners = new ArrayList();
    }
    if (!fListeners.contains(listener)) {
      fListeners.add(listener);
    }
  }
  
  public void removePluginModelListener(IPluginModelListener listener)
  {
    if (fListeners != null) {
      fListeners.remove(listener);
    }
  }
  
  public void doneSaving(ISaveContext context) {}
  
  public void prepareToSave(ISaveContext context) {}
  
  public void rollback(ISaveContext context) {}
  
  public void saving(ISaveContext context)
    throws CoreException
  {
    if (context.getKind() != 1) {
      return;
    }
    IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
    IProject project = root.getProject("External Plug-in Libraries");
    if ((project.exists()) && (project.isOpen()))
    {
      IFile file = project.getFile(".searchable");
      Properties properties = new Properties();
      StringBuffer buffer = new StringBuffer();
      Iterator iter = fPluginIdSet.iterator();
      while (iter.hasNext())
      {
        if (buffer.length() > 0) {
          buffer.append(",");
        }
        buffer.append(iter.next().toString());
      }
      properties.setProperty("searchablePlugins", buffer.toString());
      try
      {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        properties.store(outStream, "");
        outStream.flush();
        outStream.close();
        ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
        if (file.exists()) {
          file.setContents(inStream, true, false, new NullProgressMonitor());
        } else {
          file.create(inStream, true, new NullProgressMonitor());
        }
        inStream.close();
      }
      catch (IOException e)
      {
        PDECore.log(e);
      }
    }
  }
  
  public IProject createProxyProject(IProgressMonitor monitor)
    throws CoreException
  {
    IWorkspaceRoot root = PDECore.getWorkspace().getRoot();
    IProject project = root.getProject("External Plug-in Libraries");
    if (project.exists())
    {
      if (!project.isOpen()) {
        project.open(monitor);
      }
      return project;
    }
    monitor.beginTask(NLS.bind(PDECoreMessages.SearchablePluginsManager_createProjectTaskName, "External Plug-in Libraries"), 5);
    project.create(new SubProgressMonitor(monitor, 1));
    project.open(new SubProgressMonitor(monitor, 1));
    CoreUtility.addNatureToProject(project, "org.eclipse.jdt.core.javanature", new SubProgressMonitor(monitor, 1));
    IJavaProject jProject = JavaCore.create(project);
    jProject.setOutputLocation(project.getFullPath(), new SubProgressMonitor(monitor, 1));
    computeClasspath(jProject, new SubProgressMonitor(monitor, 1));
    return project;
  }
  
  private void computeClasspath(IJavaProject project, IProgressMonitor monitor)
  {
    IClasspathEntry[] classpath = new IClasspathEntry[2];
    classpath[0] = JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath());
    classpath[1] = JavaCore.newContainerEntry(PDECore.JAVA_SEARCH_CONTAINER_PATH);
    try
    {
      project.setRawClasspath(classpath, monitor);
    }
    catch (JavaModelException localJavaModelException) {}
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.SearchablePluginsManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import org.eclipse.core.runtime.IPath;

public class SourceLocation
{
  private IPath path;
  private boolean userDefined = true;
  
  public SourceLocation(IPath path)
  {
    this.path = path;
  }
  
  public IPath getPath()
  {
    return path;
  }
  
  public void setPath(IPath path)
  {
    this.path = path;
  }
  
  public boolean isUserDefined()
  {
    return userDefined;
  }
  
  public void setUserDefined(boolean userDefined)
  {
    this.userDefined = userDefined;
  }
  
  public String toString()
  {
    return path.toOSString();
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof SourceLocation))
    {
      SourceLocation object = (SourceLocation)obj;
      return object.getPath().equals(path);
    }
    return false;
  }
  
  public int hashCode()
  {
    return path.hashCode();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.SourceLocation
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import org.osgi.framework.Version;

public class SourceLocationKey
{
  private String fBundleName;
  private Version fVersion;
  
  public SourceLocationKey(String bundleName, Version version)
  {
    fBundleName = bundleName;
    fVersion = version;
  }
  
  public SourceLocationKey(String bundleName)
  {
    this(bundleName, null);
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof SourceLocationKey))
    {
      SourceLocationKey key = (SourceLocationKey)obj;
      if ((fVersion != null) && (fVersion != null)) {
        return (fBundleName.equals(fBundleName)) && (fVersion.equals(fVersion));
      }
      if ((fVersion == null) && (fVersion == null)) {
        return fBundleName.equals(fBundleName);
      }
    }
    return false;
  }
  
  public int hashCode()
  {
    if (fVersion == null) {
      return fBundleName.hashCode();
    }
    int result = 1;
    result = 31 * result + fBundleName.hashCode();
    result = 31 * result + fVersion.hashCode();
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.SourceLocationKey
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.ModelEntry;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.osgi.framework.Version;

public class SourceLocationManager
  implements ICoreConstants
{
  private List fExtensionLocations = null;
  private BundleManifestSourceLocationManager fBundleManifestLocator = null;
  
  public IPath findSourcePath(IPluginBase pluginBase, IPath sourceLibraryPath)
  {
    if ((pluginBase.getId() == null) || (pluginBase.getVersion() == null)) {
      return null;
    }
    IPath relativePath = getRelativePath(pluginBase, sourceLibraryPath);
    IPath result = searchUserSpecifiedLocations(relativePath);
    if (result == null)
    {
      result = searchBundleManifestLocations(pluginBase);
      if (result == null) {
        result = searchExtensionLocations(relativePath);
      }
    }
    return result;
  }
  
  public URL findSourceFile(IPluginBase pluginBase, IPath filePath)
  {
    if ((pluginBase.getId() == null) || (pluginBase.getVersion() == null)) {
      return null;
    }
    IPath relativePath = getRelativePath(pluginBase, filePath);
    IPath result = searchUserSpecifiedLocations(relativePath);
    if (result == null)
    {
      result = searchBundleManifestLocations(pluginBase);
      if (result != null) {
        try
        {
          return new URL("jar:" + result.toFile().toURI().toURL() + "!/" + filePath.toString());
        }
        catch (MalformedURLException e)
        {
          PDECore.log(e);
        }
      }
      result = searchExtensionLocations(relativePath);
    }
    if (result != null) {
      try
      {
        return result.toFile().toURL();
      }
      catch (MalformedURLException e)
      {
        PDECore.log(e);
      }
    }
    return null;
  }
  
  public File findSourcePlugin(IPluginBase pluginBase)
  {
    if ((pluginBase.getId() == null) || (pluginBase.getVersion() == null)) {
      return null;
    }
    IPath path = findSourcePath(pluginBase, null);
    return path == null ? null : path.toFile();
  }
  
  public boolean hasBundleManifestLocation(IPluginBase plugin)
  {
    if ((plugin.getId() == null) || (plugin.getVersion() == null)) {
      return false;
    }
    return getBundleManifestLocator().hasValidSourceLocation(plugin.getId(), new Version(plugin.getVersion()));
  }
  
  public Set findAllSourceRootsInSourceLocation(IPluginBase plugin)
  {
    if ((plugin.getId() == null) || (plugin.getVersion() == null)) {
      return Collections.EMPTY_SET;
    }
    return getBundleManifestLocator().getAllSourceRoots(plugin.getId(), new Version(plugin.getVersion()));
  }
  
  public Set findSourceRoots(IPluginBase plugin)
  {
    if ((plugin.getId() == null) || (plugin.getVersion() == null)) {
      return Collections.EMPTY_SET;
    }
    return getBundleManifestLocator().getSourceRoots(plugin.getId(), new Version(plugin.getVersion()));
  }
  
  public void reset()
  {
    fExtensionLocations = null;
    fBundleManifestLocator = null;
  }
  
  public List getUserLocations()
  {
    List userLocations = new ArrayList();
    String pref = PDECore.getDefault().getPreferencesManager().getString("source_locations");
    if (pref.length() > 0) {
      parseSavedSourceLocations(pref, userLocations);
    }
    return userLocations;
  }
  
  public List getExtensionLocations()
  {
    if (fExtensionLocations == null) {
      fExtensionLocations = processExtensions();
    }
    return fExtensionLocations;
  }
  
  public Collection getBundleManifestLocations()
  {
    return getBundleManifestLocator().getSourceLocations();
  }
  
  private SourceLocation getBundleManifestLocation(String pluginID, Version version)
  {
    return getBundleManifestLocator().getSourceLocation(pluginID, version);
  }
  
  private BundleManifestSourceLocationManager getBundleManifestLocator()
  {
    if (fBundleManifestLocator == null) {
      fBundleManifestLocator = initializeBundleManifestLocations();
    }
    return fBundleManifestLocator;
  }
  
  private IPath getRelativePath(IPluginBase pluginBase, IPath sourceFilePath)
  {
    try
    {
      String pluginDir = pluginBase.getId();
      if (pluginDir == null) {
        return null;
      }
      String version = pluginBase.getVersion();
      if (version != null)
      {
        Version vid = new Version(version);
        pluginDir = pluginDir + "_" + vid.toString();
      }
      IPath path = new Path(pluginDir);
      return sourceFilePath == null ? path : path.append(sourceFilePath);
    }
    catch (IllegalArgumentException localIllegalArgumentException) {}
    return null;
  }
  
  private IPath searchUserSpecifiedLocations(IPath relativePath)
  {
    List userLocations = getUserLocations();
    for (Iterator iterator = userLocations.iterator(); iterator.hasNext();)
    {
      SourceLocation currentLocation = (SourceLocation)iterator.next();
      IPath fullPath = currentLocation.getPath().append(relativePath);
      File file = fullPath.toFile();
      if (file.exists()) {
        return fullPath;
      }
    }
    return null;
  }
  
  private IPath searchExtensionLocations(IPath relativePath)
  {
    List extensionLocations = getExtensionLocations();
    for (Iterator iterator = extensionLocations.iterator(); iterator.hasNext();)
    {
      SourceLocation currentLocation = (SourceLocation)iterator.next();
      IPath fullPath = currentLocation.getPath().append(relativePath);
      File file = fullPath.toFile();
      if (file.exists()) {
        return fullPath;
      }
    }
    return null;
  }
  
  private IPath searchBundleManifestLocations(IPluginBase pluginBase)
  {
    SourceLocation location = getBundleManifestLocation(pluginBase.getId(), new Version(pluginBase.getVersion()));
    if ((location != null) && (location.getPath().toFile().exists())) {
      return location.getPath();
    }
    return null;
  }
  
  private void parseSavedSourceLocations(String text, List entries)
  {
    text = text.replace(File.pathSeparatorChar, ';');
    StringTokenizer stok = new StringTokenizer(text, ";");
    while (stok.hasMoreTokens())
    {
      String token = stok.nextToken();
      SourceLocation location = parseSourceLocation(token);
      if (location != null) {
        entries.add(location);
      }
    }
  }
  
  private SourceLocation parseSourceLocation(String text)
  {
    try
    {
      text = text.trim();
      int commaIndex = text.lastIndexOf(',');
      if (commaIndex == -1) {
        return new SourceLocation(new Path(text));
      }
      int atLoc = text.indexOf('@');
      path = atLoc == -1 ? text.substring(0, commaIndex) : text.substring(atLoc + 1, commaIndex);
    }
    catch (RuntimeException localRuntimeException)
    {
      String path;
      return null;
    }
    String path;
    return new SourceLocation(new Path(path));
  }
  
  private static List processExtensions()
  {
    ArrayList result = new ArrayList();
    IExtension[] extensions = PDECore.getDefault().getExtensionsRegistry().findExtensions("org.eclipse.pde.core.source", false);
    for (int i = 0; i < extensions.length; i++)
    {
      IConfigurationElement[] children = extensions[i].getConfigurationElements();
      RegistryContributor contributor = (RegistryContributor)extensions[i].getContributor();
      long bundleId = Long.parseLong(contributor.getActualId());
      BundleDescription desc = PDECore.getDefault().getModelManager().getState().getState().getBundle(Long.parseLong(contributor.getActualId()));
      IPluginModelBase base = null;
      if (desc != null)
      {
        base = PluginRegistry.findModel(desc);
      }
      else
      {
        ModelEntry entry = PluginRegistry.findEntry(contributor.getActualName());
        IPluginModelBase[] externalModels = entry.getExternalModels();
        for (int j = 0; j < externalModels.length; j++)
        {
          BundleDescription extDesc = externalModels[j].getBundleDescription();
          if ((extDesc != null) && (extDesc.getBundleId() == bundleId)) {
            base = externalModels[j];
          }
        }
      }
      if (base != null) {
        for (int j = 0; j < children.length; j++) {
          if (children[j].getName().equals("location"))
          {
            String pathValue = children[j].getAttribute("path");
            IPath path = new Path(base.getInstallLocation()).append(pathValue);
            if (path.toFile().exists())
            {
              SourceLocation location = new SourceLocation(path);
              location.setUserDefined(false);
              if (!result.contains(location)) {
                result.add(location);
              }
            }
          }
        }
      }
    }
    return result;
  }
  
  protected BundleManifestSourceLocationManager initializeBundleManifestLocations()
  {
    BundleManifestSourceLocationManager manager = new BundleManifestSourceLocationManager();
    manager.setPlugins(PDECore.getDefault().getModelMa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd