org.eclipse.pde.core_3.7.1.v20120103_r372

ject), new RequiredPluginsClasspathContainer(models[i]));
          }
        }
        catch (CoreException localCoreException1) {}
      }
    }
    else
    {
      BundleDelta[] deltas = delta.getChanges();
      for (int i = 0; i < deltas.length; i++) {
        try
        {
          IPluginModelBase model = findModel(deltas[i].getBundle());
          IResource resource = model == null ? null : model.getUnderlyingResource();
          if (resource != null)
          {
            IProject project = resource.getProject();
            if (project.hasNature("org.eclipse.jdt.core.javanature"))
            {
              IJavaProject jProject = JavaCore.create(project);
              if (!map.containsKey(jProject)) {
                map.put(jProject, new RequiredPluginsClasspathContainer(model));
              }
            }
          }
        }
        catch (CoreException localCoreException2) {}
      }
      IPluginModelBase[] models = getWorkspaceModels();
      for (int i = 0; i < models.length; i++)
      {
        IProject project = models[i].getUnderlyingResource().getProject();
        try
        {
          if (project.hasNature("org.eclipse.jdt.core.javanature"))
          {
            IJavaProject jProject = JavaCore.create(project);
            if (!map.containsKey(jProject))
            {
              IBuild build = ClasspathUtilCore.getBuild(models[i]);
              if ((build != null) && (build.getEntry("additional.bundles") != null)) {
                map.put(jProject, new RequiredPluginsClasspathContainer(models[i], build));
              }
            }
          }
        }
        catch (CoreException localCoreException3) {}
      }
    }
    if (map.size() > 0)
    {
      Iterator iterator = map.entrySet().iterator();
      IJavaProject[] projects = new IJavaProject[map.size()];
      IClasspathContainer[] containers = new IClasspathContainer[projects.length];
      int index = 0;
      while (iterator.hasNext())
      {
        Map.Entry entry = (Map.Entry)iterator.next();
        projects[index] = ((IJavaProject)entry.getKey());
        containers[index] = ((IClasspathContainer)entry.getValue());
        index++;
      }
      int types = event.getEventTypes();
      if (types == 4)
      {
        fUpdateJob.add(projects, containers);
        fUpdateJob.schedule();
      }
      else
      {
        try
        {
          JavaCore.setClasspathContainer(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH, projects, containers, null);
        }
        catch (JavaModelException localJavaModelException) {}
      }
    }
  }
  
  private void fireDelta(PluginModelDelta delta)
  {
    if (fListeners != null) {
      for (int i = 0; i < fListeners.size(); i++) {
        ((IPluginModelListener)fListeners.get(i)).modelsChanged(delta);
      }
    }
  }
  
  private void fireStateDelta(StateDelta delta)
  {
    if (fStateListeners != null)
    {
      ListIterator li = fStateListeners.listIterator();
      while (li.hasNext()) {
        ((IStateDeltaListener)li.next()).stateResolved(delta);
      }
    }
  }
  
  private void fireStateChanged(PDEState newState)
  {
    if (fStateListeners != null)
    {
      ListIterator li = fStateListeners.listIterator();
      while (li.hasNext()) {
        ((IStateDeltaListener)li.next()).stateChanged(newState.getState());
      }
    }
  }
  
  public void addPluginModelListener(IPluginModelListener listener)
  {
    if (fListeners == null) {
      fListeners = new ArrayList();
    }
    if (!fListeners.contains(listener)) {
      fListeners.add(listener);
    }
  }
  
  public void addStateDeltaListener(IStateDeltaListener listener)
  {
    if (fStateListeners == null) {
      fStateListeners = new ArrayList();
    }
    if (!fStateListeners.contains(listener)) {
      fStateListeners.add(listener);
    }
  }
  
  public void removePluginModelListener(IPluginModelListener listener)
  {
    if (fListeners != null) {
      fListeners.remove(listener);
    }
  }
  
  public void removeStateDeltaListener(IStateDeltaListener listener)
  {
    if (fStateListeners != null) {
      fStateListeners.remove(listener);
    }
  }
  
  public boolean isEmpty()
  {
    return getEntryTable().size() == 0;
  }
  
  public boolean isInitialized()
  {
    return fEntries != null;
  }
  
  private Map getEntryTable()
  {
    initializeTable();
    return fEntries;
  }
  
  private synchronized void initializeTable()
  {
    if (fEntries != null) {
      return;
    }
    Map entries = Collections.synchronizedMap(new TreeMap());
    
    fState = new PDEState(fWorkspaceManager.getPluginPaths(), fExternalManager.getPluginPaths(), true, true, new NullProgressMonitor());
    
    fExternalManager.initializeModels(fState.getTargetModels());
    
    boolean statechanged = addToTable(entries, fExternalManager.getAllModels());
    if (fState.isCombined())
    {
      IPluginModelBase[] models = fState.getWorkspaceModels();
      
      fWorkspaceManager.initializeModels(models);
      
      addToTable(entries, models);
      if (statechanged) {
        fState.resolveState(true);
      }
    }
    else
    {
      IPluginModelBase[] models = fWorkspaceManager.getPluginModels();
      
      addToTable(entries, models);
      for (int i = 0; i < models.length; i++) {
        addWorkspaceBundleToState(entries, models[i]);
      }
      if (models.length > 0) {
        fState.resolveState(true);
      }
      PDECore.getDefault().getExtensionsRegistry().targetReloaded();
    }
    fEntries = entries;
    
    initDefaultTargetPlatformDefinition();
    
    PDEPreferencesManager pref = PDECore.getDefault().getPreferencesManager();
    String pooled = pref.getString("pooled_bundles");
    if ((pooled != null) && (pooled.trim().length() > 0) && 
      (!"[savedNone]".equals(pooled.trim())))
    {
      ITargetPlatformService service = (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
      if (service != null) {
        try
        {
          ITargetHandle handle = service.getWorkspaceTargetHandle();
          LoadTargetDefinitionJob.load(handle.getTargetDefinition());
        }
        catch (CoreException e)
        {
          PDECore.log(e);
        }
      }
    }
  }
  
  private synchronized void initDefaultTargetPlatformDefinition()
  {
    ITargetPlatformService service = (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
    if (service != null)
    {
      String memento = PDECore.getDefault().getPreferencesManager().getString("workspace_target_handle");
      if (memento.equals(""))
      {
        ITargetHandle[] targets = service.getTargets(null);
        TargetPlatformService ts = (TargetPlatformService)service;
        
        TargetDefinition curr = (TargetDefinition)ts.newTarget();
        ITargetHandle wsHandle = null;
        try
        {
          ts.loadTargetDefinitionFromPreferences(curr);
          for (int i = 0; i < targets.length; i++) {
            if (curr.isContentEquivalent(targets[i].getTargetDefinition()))
            {
              wsHandle = targets[i];
              break;
            }
          }
          if (wsHandle == null)
          {
            ITargetDefinition def = ts.newDefaultTargetDefinition();
            String defVMargs = def.getVMArguments();
            if (curr.getVMArguments() == null) {
              def.setVMArguments(null);
            }
            if (curr.isContentEquivalent(def))
            {
              curr.setName(Messages.TargetPlatformService_7);
              curr.setVMArguments(defVMargs);
            }
            else
            {
              curr.setName(PDECoreMessages.PluginModelManager_0);
              
              boolean defaultExists = false;
              for (int i = 0; i < targets.length; i++) {
                if (((TargetDefinition)def).isContentEquivalent(targets[i].getTargetDefinition()))
                {
                  defaultExists = true;
                  break;
                }
              }
              if (!defaultExists) {
                ts.saveTargetDefinition(def);
              }
            }
            ts.saveTargetDefinition(curr);
            wsHandle = curr.getHandle();
          }
          PDEPreferencesManager preferences = PDECore.getDefault().getPreferencesManager();
          preferences.setValue("workspace_target_handle", wsHandle.getMemento());
        }
        catch (CoreException e)
        {
          PDECore.log(e);
        }
      }
    }
  }
  
  private boolean addToTable(Map entries, IPluginModelBase[] models)
  {
    boolean stateChanged = false;
    for (int i = 0; i < models.length; i++)
    {
      String id = models[i].getPluginBase().getId();
      if (id != null)
      {
        LocalModelEntry entry = (LocalModelEntry)entries.get(id);
        if (entry == null)
        {
          entry = new LocalModelEntry(id);
          entries.put(id, entry);
        }
        entry.addModel(models[i]);
        if ((models[i].getUnderlyingResource() == null) && (!models[i].isEnabled()))
        {
          fState.removeBundleDescription(models[i].getBundleDescription());
          stateChanged = true;
        }
      }
    }
    return stateChanged;
  }
  
  private synchronized void addWorkspaceBundleToState(IPluginModelBase model)
  {
    addWorkspaceBundleToState(fEntries, model);
  }
  
  private synchronized void addWorkspaceBundleToState(Map entries, IPluginModelBase model)
  {
    String id = model.getPluginBase().getId();
    if (id == null) {
      return;
    }
    ModelEntry entry = (ModelEntry)entries.get(id);
    if (entry != null)
    {
      IPluginModelBase[] models = entry.getExternalModels();
      for (int i = 0; i < models.length; i++) {
        fState.removeBundleDescription(models[i].getBundleDescription());
      }
    }
    fState.addBundle(model, false);
    
    BundleDescription desc = model.getBundleDescription();
    if (desc != null)
    {
      HostSpecification spec = desc.getHost();
      if ((spec != null) && (("true".equals(System.getProperty("pde.allowCycles"))) || 
        (isPatchFragment(entries, desc)) || (desc.getImportPackages().length > 0) || (desc.getRequiredBundles().length > 0)))
      {
        BundleDescription host = (BundleDescription)spec.getSupplier();
        if (host != null)
        {
          ModelEntry hostEntry = (ModelEntry)entries.get(host.getName());
          if (hostEntry != null) {
            fState.addBundle(hostEntry.getModel(host), true);
          }
        }
      }
    }
  }
  
  private boolean isPatchFragment(Map entries, BundleDescription desc)
  {
    ModelEntry entry = (ModelEntry)entries.get(desc.getSymbolicName());
    if (entry != null)
    {
      IPluginModelBase base = entry.getModel(desc);
      if (base == null) {
        return false;
      }
      return ClasspathUtilCore.isPatchFragment(base);
    }
    return false;
  }
  
  private void handleAdd(String id, IPluginModelBase model, PluginModelDelta delta)
  {
    LocalModelEntry entry = (LocalModelEntry)getEntryTable().get(id);
    if (entry == null)
    {
      entry = new LocalModelEntry(id);
      getEntryTable().put(id, entry);
      delta.addEntry(entry, 1);
    }
    else
    {
      delta.addEntry(entry, 4);
    }
    entry.addModel(model);
    if (model.getUnderlyingResource() != null)
    {
      addWorkspaceBundleToState(model);
    }
    else if ((model.isEnabled()) && (!entry.hasWorkspaceModels()))
    {
      BundleDescription desc = model.getBundleDescription();
      if (desc.getContainingState().equals(fState)) {
        fState.addBundleDescription(desc);
      }
    }
  }
  
  private void handleRemove(String id, IPluginModelBase model, PluginModelDelta delta)
  {
    LocalModelEntry entry = (LocalModelEntry)getEntryTable().get(id);
    if (entry != null)
    {
      entry.removeModel(model);
      
      fState.removeBundleDescription(model.getBundleDescription());
      if ((!entry.hasExternalModels()) && (!entry.hasWorkspaceModels()))
      {
        getEntryTable().remove(id);
        delta.addEntry(entry, 2);
        return;
      }
      if ((model.getUnderlyingResource() != null) && (!entry.hasWorkspaceModels()))
      {
        IPluginModelBase[] external = entry.getExternalModels();
        for (int i = 0; i < external.length; i++) {
          if (external[i].isEnabled()) {
            fState.addBundleDescription(external[i].getBundleDescription());
          }
        }
      }
      delta.addEntry(entry, 4);
    }
  }
  
  private void handleChange(IPluginModelBase model, PluginModelDelta delta)
  {
    BundleDescription desc = model.getBundleDescription();
    String oldID = desc == null ? null : desc.getSymbolicName();
    String newID = model.getPluginBase().getId();
    if ((oldID == null) && (newID == null)) {
      return;
    }
    if ((oldID == null) && (newID != null))
    {
      handleAdd(newID, model, delta);
    }
    else if ((oldID != null) && (newID == null))
    {
      handleRemove(oldID, model, delta);
      model.setBundleDescription(null);
    }
    else if (oldID.equals(newID))
    {
      if (model.isEnabled())
      {
        ModelEntry entry = (ModelEntry)getEntryTable().get(oldID);
        IPluginModelBase[] activeModels = entry.getActiveModels();
        boolean isActive = false;
        for (int i = 0; i < activeModels.length; i++) {
          if (activeModels[i] == model)
          {
            isActive = true;
            break;
          }
        }
        if (isActive) {
          fState.addBundle(model, true);
        }
      }
      else
      {
        fState.removeBundleDescription(model.getBundleDescription());
      }
      delta.addEntry(findEntry(oldID), 4);
    }
    else
    {
      handleRemove(oldID, model, delta);
      handleAdd(newID, model, delta);
    }
  }
  
  public ModelEntry findEntry(String id)
  {
    if ("system.bundle".equals(id)) {
      id = getSystemBundleId();
    }
    return id == null ? null : (ModelEntry)getEntryTable().get(id);
  }
  
  public IPluginModelBase findModel(String id)
  {
    ModelEntry entry = findEntry(id);
    return entry == null ? null : entry.getModel();
  }
  
  public IPluginModelBase findModel(IProject project)
  {
    initializeTable();
    return fWorkspaceManager.getPluginModel(project);
  }
  
  public IPluginModelBase findModel(BundleDescription desc)
  {
    ModelEntry entry = desc != null ? findEntry(desc.getSymbolicName()) : null;
    return entry == null ? null : entry.getModel(desc);
  }
  
  public IPluginModelBase[] getActiveModels()
  {
    return getActiveModels(true);
  }
  
  public IPluginModelBase[] getActiveModels(boolean includeFragments)
  {
    int size = getEntryTable().size();
    ArrayList result = new ArrayList(size);
    Iterator iter = getEntryTable().values().iterator();
    IPluginModelBase[] models;
    int i;
    for (; iter.hasNext(); i < models.length)
    {
      ModelEntry entry = (ModelEntry)iter.next();
      models = entry.getActiveModels();
      i = 0; continue;
      if (((models[i] instanceof IPluginModel)) || (includeFragments)) {
        result.add(models[i]);
      }
      i++;
    }
    return (IPluginModelBase[])result.toArray(new IPluginModelBase[result.size()]);
  }
  
  public IPluginModelBase[] getAllModels()
  {
    return getAllModels(true);
  }
  
  public IPluginModelBase[] getAllModels(boolean includeFragments)
  {
    int size = getEntryTable().size();
    ArrayList result = new ArrayList(size);
    Iterator iter = getEntryTable().values().iterator();
    IPluginModelBase[] models;
    int i;
    for (; iter.hasNext(); i < models.length)
    {
      ModelEntry entry = (ModelEntry)iter.next();
      models = entry.hasWorkspaceModels() ? entry.getWorkspaceModels() : entry.getExternalModels();
      i = 0; continue;
      if (((models[i] instanceof IPluginModel)) || (includeFragments)) {
        result.add(models[i]);
      }
      i++;
    }
    return (IPluginModelBase[])result.toArray(new IPluginModelBase[result.size()]);
  }
  
  public IPluginModelBase[] getExternalModels()
  {
    initializeTable();
    return fExternalManager.getAllModels();
  }
  
  public IPluginModelBase[] getWorkspaceModels()
  {
    initializeTable();
    return fWorkspaceManager.getPluginModels();
  }
  
  public ExternalModelManager getExternalModelManager()
  {
    initializeTable();
    return fExternalManager;
  }
  
  public PDEState getState()
  {
    initializeTable();
    return fState;
  }
  
  public void resetState(PDEState state)
  {
    if ((fState != null) && (fState.equals(state))) {
      return;
    }
    int type = 8;
    IModel[] removed = fState.getTargetModels();
    if (removed.length > 0) {
      type |= 0x2;
    }
    IModel[] added = state.getTargetModels();
    if (added.length > 0) {
      type |= 0x1;
    }
    modelsChanged(new ModelProviderEvent(state, type, added, removed, new IModel[0]));
    
    fireStateChanged(state);
  }
  
  public String getSystemBundleId()
  {
    return getState().getSystemBundle();
  }
  
  protected void shutdown()
  {
    fWorkspaceManager.shutdown();
    fExternalManager.shutdown();
    if (fListeners != null) {
      fListeners.clear();
    }
    if (fStateListeners != null) {
      fStateListeners.clear();
    }
  }
  
  protected void save()
  {
    if (fState != null)
    {
      fState.saveExternalState();
      fState.saveWorkspaceState();
    }
  }
  
  public void addExtensionDeltaListener(IExtensionDeltaListener listener)
  {
    fWorkspaceManager.addExtensionDeltaListener(listener);
  }
  
  public void removeExtensionDeltaListener(IExtensionDeltaListener listener)
  {
    fWorkspaceManager.removeExtensionDeltaListener(listener);
  }
  
  public void bundleRootChanged(IProject project)
  {
    fWorkspaceManager.initialize();
    fWorkspaceManager.removeModel(project);
    if (fWorkspaceManager.isInterestingProject(project))
    {
      fWorkspaceManager.createModel(project, false);
      Object model = fWorkspaceManager.getModel(project);
      fWorkspaceManager.addChange(model, 4);
    }
    fWorkspaceManager.processModelChanges();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.PluginModelManager
 * 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.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.pde.core.plugin.TargetPlatform;
import org.eclipse.update.configurator.ConfiguratorUtils;
import org.eclipse.update.configurator.IPlatformConfiguration;
import org.eclipse.update.configurator.IPlatformConfiguration.ISiteEntry;

public class PluginPathFinder
{
  private static final String URL_PROPERTY = "org.eclipse.update.resolution_url";
  private static final String EMPTY_STRING = "";
  
  private static String getSitePath(String platformHome, File linkFile, boolean features)
  {
    String prefix = new Path(platformHome).removeLastSegments(1).toString();
    Properties properties = new Properties();
    try
    {
      FileInputStream fis = new FileInputStream(linkFile);
      properties.load(fis);
      fis.close();
      String path = properties.getProperty("path");
      if (path != null)
      {
        if (!new Path(path).isAbsolute()) {
          path = prefix + '/' + path;
        }
        path = path + "/eclipse/";
        if (features) {
          path = path + "features";
        } else {
          path = path + "plugins";
        }
        if (new File(path).exists()) {
          return path;
        }
      }
    }
    catch (IOException localIOException) {}
    return null;
  }
  
  private static File[] getSites(String platformHome, boolean features)
  {
    HashSet sites = new HashSet();
    File file = new File(platformHome, features ? "features" : "plugins");
    if ((!features) && (!file.exists())) {
      file = new File(platformHome);
    }
    if (file.exists()) {
      sites.add(file);
    }
    File[] linkFiles = new File(platformHome + '/' + "links").listFiles();
    if (linkFiles != null) {
      for (int i = 0; i < linkFiles.length; i++)
      {
        String path = getSitePath(platformHome, linkFiles[i], features);
        if (path != null) {
          sites.add(new File(path));
        }
      }
    }
    return (File[])sites.toArray(new File[sites.size()]);
  }
  
  public static URL[] getPluginPaths(String platformHome)
  {
    PDEPreferencesManager store = PDECore.getDefault().getPreferencesManager();
    if (!store.getBoolean("target_platform_realization")) {
      return scanLocations(getSites(platformHome, false));
    }
    URL[] urls = (URL[])null;
    if (new Path(platformHome).equals(new Path(TargetPlatform.getDefaultLocation())))
    {
      Location configArea = Platform.getConfigurationLocation();
      if (configArea != null)
      {
        urls = P2Utils.readBundlesTxt(platformHome, configArea.getURL());
        if ((urls == null) && (configArea.getParentLocation() != null)) {
          urls = P2Utils.readBundlesTxt(platformHome, configArea.getParentLocation().getURL());
        }
      }
    }
    else
    {
      File configurationArea = new File(platformHome, "configuration");
      if (configurationArea.exists()) {
        try
        {
          urls = P2Utils.readBundlesTxt(platformHome, configurationArea.toURL());
        }
        catch (MalformedURLException e)
        {
          PDECore.log(e);
        }
      }
    }
    if (urls != null) {
      return urls;
    }
    if ((new Path(platformHome).equals(new Path(TargetPlatform.getDefaultLocation()))) && (!isDevLaunchMode())) {
      return ConfiguratorUtils.getCurrentPlatformConfiguration().getPluginPath();
    }
    File file = getPlatformFile(platformHome);
    if (file != null) {
      try
      {
        String value = new Path(platformHome).toFile().toURL().toExternalForm();
        System.setProperty("org.eclipse.update.resolution_url", value);
        try
        {
          IPlatformConfiguration config = ConfiguratorUtils.getPlatformConfiguration(file.toURL());
          return getConfiguredSitesPaths(platformHome, config, false);
        }
        finally
        {
          System.setProperty("org.eclipse.update.resolution_url", "");
        }
        return scanLocations(getSites(platformHome, false));
      }
      catch (MalformedURLException localMalformedURLException1) {}catch (IOException localIOException) {}
    }
  }
  
  private static File getPlatformFile(String platformHome)
  {
    String location = System.getProperty("org.eclipse.pde.platform_location");
    File file = null;
    if (location != null) {
      try
      {
        IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
        location = manager.performStringSubstitution(location);
        Path path = new Path(location);
        if (path.isAbsolute()) {
          file = path.toFile();
        } else {
          file = new File(platformHome, location);
        }
        if (file.exists()) {
          return file;
        }
      }
      catch (CoreException e)
      {
        PDECore.log(e);
      }
    }
    file = new File(platformHome, "configuration/org.eclipse.update/platform.xml");
    return file.exists() ? file : null;
  }
  
  public static URL[] getFeaturePaths(String platformHome)
  {
    File file = getPlatformFile(platformHome);
    if (file != null) {
      try
      {
        String value = new Path(platformHome).toFile().toURL().toExternalForm();
        System.setProperty("org.eclipse.update.resolution_url", value);
        try
        {
          IPlatformConfiguration config = ConfiguratorUtils.getPlatformConfiguration(file.toURL());
          return getConfiguredSitesPaths(platformHome, config, true);
        }
        finally
        {
          System.setProperty("org.eclipse.update.resolution_url", "");
        }
        return scanLocations(getSites(platformHome, true));
      }
      catch (MalformedURLException localMalformedURLException) {}catch (IOException localIOException) {}
    }
  }
  
  private static URL[] getConfiguredSitesPaths(String platformHome, IPlatformConfiguration configuration, boolean features)
  {
    URL[] installPlugins = scanLocations(new File[] { new File(platformHome, features ? "features" : "plugins") });
    URL[] extensionPlugins = getExtensionPluginURLs(configuration, features);
    
    URL[] all = new URL[installPlugins.length + extensionPlugins.length];
    System.arraycopy(installPlugins, 0, all, 0, installPlugins.length);
    System.arraycopy(extensionPlugins, 0, all, installPlugins.length, extensionPlugins.length);
    return all;
  }
  
  private static URL[] getExtensionPluginURLs(IPlatformConfiguration config, boolean features)
  {
    ArrayList extensionPlugins = new ArrayList();
    IPlatformConfiguration.ISiteEntry[] sites = config.getConfiguredSites();
    for (int i = 0; i < sites.length; i++)
    {
      URL url = sites[i].getURL();
      if ("file".equalsIgnoreCase(url.getProtocol()))
      {
        String[] entries;
        String[] entries;
        if (features) {
          entries = sites[i].getFeatures();
        } else {
          entries = sites[i].getPlugins();
        }
        for (int j = 0; j < entries.length; j++) {
          try
          {
            extensionPlugins.add(new File(url.getFile(), entries[j]).toURL());
          }
          catch (MalformedURLException localMalformedURLException) {}
        }
      }
    }
    return (URL[])extensionPlugins.toArray(new URL[extensionPlugins.size()]);
  }
  
  public static URL[] scanLocations(File[] sites)
  {
    HashSet result = new HashSet();
    for (int i = 0; i < sites.length; i++) {
      if (sites[i].exists())
      {
        File[] children = sites[i].listFiles();
        if (children != null) {
          for (int j = 0; j < children.length; j++) {
            try
            {
              result.add(children[j].toURL());
            }
            catch (MalformedURLException localMalformedURLException) {}
          }
        }
      }
    }
    return (URL[])result.toArray(new URL[result.size()]);
  }
  
  public static boolean isDevLaunchMode()
  {
    if (Boolean.getBoolean("eclipse.pde.launch")) {
      return true;
    }
    String[] args = Platform.getApplicationArgs();
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-pdelaunch")) {
        return true;
      }
    }
    return false;
  }
}

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

import java.util.Locale;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.pde.core.plugin.TargetPlatform;
import org.osgi.service.prefs.BackingStoreException;

public class PreferenceInitializer
  extends AbstractPreferenceInitializer
{
  public void initializeDefaultPreferences()
  {
    IEclipsePreferences defaultPreferences = new DefaultScope().getNode("org.eclipse.pde.core");
    IEclipsePreferences preferences = new InstanceScope().getNode("org.eclipse.pde.core");
    defaultPreferences.put("target_mode", "useThis");
    defaultPreferences.put("checkedPlugins", "[savedAll]");
    defaultPreferences.put("checkedVersionPlugins", "[savedNone]");
    if (preferences.get("target_mode", defaultPreferences.get("target_mode", "")).equals("useThis")) {
      preferences.put("platform_path", TargetPlatform.getDefaultLocation());
    } else {
      defaultPreferences.put("platform_path", TargetPlatform.getDefaultLocation());
    }
    defaultPreferences.put("org.eclipse.pde.ui.os", Platform.getOS());
    defaultPreferences.put("org.eclipse.pde.ui.ws", Platform.getWS());
    defaultPreferences.put("org.eclipse.pde.ui.nl", Locale.getDefault().toString());
    defaultPreferences.put("org.eclipse.pde.ui.arch", Platform.getOSArch());
    defaultPreferences.putBoolean("target_platform_realization", TargetPlatform.getDefaultLocation().equals(TargetPlatform.getLocation()));
    try
    {
      preferences.flush();
      defaultPreferences.flush();
    }
    catch (BackingStoreException bse)
    {
      PDECore.log(bse);
    }
    IEclipsePreferences prefs = new DefaultScope().getNode("org.eclipse.pde");
    prefs.putInt("compilers.p.unresolved-import", 0);
    prefs.putInt("compilers.p.unresolved-ex-points", 0);
    prefs.putInt("compilers.p.no-required-att", 0);
    prefs.putInt("compilers.p.unknown-element", 1);
    prefs.putInt("compilers.p.unknown-attribute", 1);
    prefs.putInt("compilers.p.deprecated", 1);
    prefs.putInt("compilers.p.internal", 1);
    prefs.putInt("compilers.p.unknown-class", 1);
    prefs.putInt("compilers.p.discouraged-class", 1);
    prefs.putInt("compilers.p.unknown-resource", 1);
    prefs.putInt("compilers.p.unknown-identifier", 1);
    prefs.putInt("compilers.p.not-externalized-att", 2);
    
    prefs.putInt("compilers.p.build", 1);
    prefs.putInt("compilers.p.build.missing.output", 2);
    prefs.putInt("compilers.p.build.source.library", 1);
    prefs.putInt("compilers.p.build.output.library", 1);
    prefs.putInt("compilers.p.build.src.includes", 1);
    prefs.putInt("compilers.p.build.bin.includes", 1);
    prefs.putInt("compilers.p.build.java.compliance", 1);
    prefs.putInt("compilers.p.build.java.compiler", 2);
    prefs.putInt("compilers.p.build.encodings", 2);
    
    prefs.putInt("compilers.incompatible-environment", 1);
    prefs.putInt("compilers.p.missing-packages", 2);
    
    prefs.putInt("compilers.p.missing-version-export-package", 2);
    prefs.putInt("compilers.p.missing-version-import-package", 2);
    prefs.putInt("compilers.p.missing-version-require-bundle", 2);
    
    prefs.putBoolean("compilers.s.create-docs", false);
    prefs.put("compilers.s.doc-folder", "doc");
    prefs.putInt("compilers.s.open-tags", 1);
    
    prefs.putInt("compilers.f.unresolved-plugins", 1);
    prefs.putInt("compilers.f.unresolved-features", 1);
    try
    {
      prefs.flush();
    }
    catch (BackingStoreException e)
    {
      PDECore.log(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.PreferenceInitializer
 * 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.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
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.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
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.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.PlatformAdmin;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;

public class RequiredPluginsClasspathContainer
  extends PDEClasspathContainer
  implements IClasspathContainer
{
  private IClasspathEntry[] fEntries = null;
  private static boolean DEBUG = (PDECore.getDefault().isDebugging()) && ("true".equals(Platform.getDebugOption("org.eclipse.pde.core/classpath")));
  private IBuild fBuild;
  private IPluginModelBase fModel;
  
  public RequiredPluginsClasspathContainer(IPluginModelBase model)
  {
    this(model, null);
  }
  
  public RequiredPluginsClasspathContainer(IPluginModelBase model, IBuild build)
  {
    fModel = model;
    fBuild = build;
  }
  
  public int getKind()
  {
    return 1;
  }
  
  public IPath getPath()
  {
    return PDECore.REQUIRED_PLUGINS_CONTAINER_PATH;
  }
  
  public String getDescription()
  {
    return PDECoreMessages.RequiredPluginsClasspathContainer_description;
  }
  
  public IClasspathEntry[] getClasspathEntries()
  {
    if (fModel == null)
    {
      if (DEBUG)
      {
        System.out.println("********Returned an empty container");
        System.out.println();
      }
      return new IClasspathEntry[0];
    }
    if (fEntries == null) {
      fEntries = computePluginEntries();
    }
    if (DEBUG)
    {
      System.out.println("Dependencies for plugin '" + fModel.getPluginBase().getId() + "':");
      for (int i = 0; i < fEntries.length; i++) {
        System.out.println(fEntries[i]);
      }
      System.out.println();
    }
    return fEntries;
  }
  
  private IClasspathEntry[] computePluginEntries()
  {
    ArrayList entries = new ArrayList();
    try
    {
      BundleDescription desc = fModel.getBundleDescription();
      if (desc == null) {
        return new IClasspathEntry[0];
      }
      Map map = retrieveVisiblePackagesFromState(desc);
      
      HashSet added = new HashSet();
      
      added.add(desc);
      
      HostSpecification host = desc.getHost();
      if (host != null)
      {
        addHostPlugin(host, added, map, entries);
      }
      else if ("true".equals(System.getProperty("pde.allowCycles")))
      {
        BundleDescription[] fragments = desc.getFragments();
        for (int i = 0; i < fragments.length; i++) {
          if (fragments[i].isResolved()) {
            addPlugin(fragments[i], false, map, entries);
          }
        }
      }
      BundleSpecification[] required = desc.getRequiredBundles();
      for (int i = 0; i < required.length; i++) {
        addDependency((BundleDescription)required[i].getSupplier(), added, map, entries);
      }
      if (fBuild == null) {
        fBuild = ClasspathUtilCore.getBuild(fModel);
      }
      if (fBuild != null) {
        addSecondaryDependencies(desc, added, entries);
      }
      Map sortedMap = new TreeMap();
      Iterator iter = map.keySet().iterator();
      while (iter.hasNext())
      {
        BundleDescription bundle = (BundleDescription)iter.next();
        sortedMap.put(bundle.toString(), bundle);
      }
      iter = sortedMap.values().iterator();
      while (iter.hasNext())
      {
        BundleDescription bundle = (BundleDescription)iter.next();
        IPluginModelBase model = PluginRegistry.findModel(bundle);
        if ((model != null) && (model.isEnabled())) {
          addDependencyViaImportPackage(model.getBundleDescription(), added, map, entries);
        }
      }
      if (fBuild != null) {
        addExtraClasspathEntries(added, entries);
      }
    }
    catch (CoreException localCoreException) {}
    return (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]);
  }
  
  private Map retrieveVisiblePackagesFromState(BundleDescription desc)
  {
    Map visiblePackages = new HashMap();
    StateHelper helper = Platform.getPlatformAdmin().getStateHelper();
    addVisiblePackagesFromState(helper, desc, visiblePackages);
    if (desc.getHost() != null) {
      addVisiblePackagesFromState(helper, (BundleDescription)desc.getHost().getSupplier(), visiblePackages);
    }
    return visiblePackages;
  }
  
  private void addVisiblePackagesFromState(StateHelper helper, BundleDescription desc, Map visiblePackages)
  {
    if (desc == null) {
      return;
    }
    ExportPackageDescription[] exports = helper.getVisiblePackages(desc);
    for (int i = 0; i < exports.length; i++)
    {
      BundleDescription exporter = exports[i].getExporter();
      if (exporter != null)
      {
        ArrayList list = (ArrayList)visiblePackages.get(exporter);
        if (list == null)
        {
          list = new ArrayList();
          visiblePackages.put(exporter, list);
        }
        PDEClasspathContainer.Rule rule = getRule(helper, desc, exports[i]);
        if (!list.contains(rule)) {
          list.add(rule);
        }
      }
    }
  }
  
  private PDEClasspathContainer.Rule getRule(StateHelper helper, BundleDescription desc, ExportPackageDescription export)
  {
    PDEClasspathContainer.Rule rule = new PDEClasspathContainer.Rule(this);
    discouraged = (helper.getAccessCode(desc, export) == 2);
    String name = export.getName();
    path = (name.equals(".") ? new Path("*") : new Path(name.replaceAll("\\.", "/") + "/*"));
    return rule;
  }
  
  protected void addDependencyViaImportPackage(BundleDescription desc, HashSet added, Map map, ArrayList entries)
    throws CoreException
  {
    if ((desc == null) || (!added.add(desc))) {
      return;
    }
    addPlugin(desc, true, map, entries);
    if ((hasExtensibleAPI(desc)) && (desc.getContainingState() != null))
    {
      BundleDescription[] fragments = desc.getFragments();
      for (int i = 0; i < fragments.length; i++) {
        if (fragments[i].isResolved()) {
          addDependencyViaImportPackage(fragments[i], added, map, entries);
        }
      }
    }
  }
  
  private void addDependency(BundleDescription desc, HashSet added, Map map, ArrayList entries)
    throws CoreException
  {
    addDependency(desc, added, map, entries, true);
  }
  
  private void addDependency(BundleDescription desc, HashSet added, Map map, ArrayList entries, boolean useInclusion)
    throws CoreException
  {
    if ((desc == null) || (!added.add(desc))) {
      return;
    }
    BundleDescription[] fragments = hasExtensibleAPI(desc) ? desc.getFragments() : new BundleDescription[0];
    for (int i = 0; i < fragments.length; i++) {
      if ((fragments[i].isResolved()) && (ClasspathUtilCore.isPatchFragment(fragments[i]))) {
        addDependency(fragments[i], added, map, entries, useInclusion);
      }
    }
    addPlugin(desc, useInclusion, map, entries);
    for (int i = 0; i < fragments.length; i++) {
      if ((fragments[i].isResolved()) && (!ClasspathUtilCore.isPatchFragment(fragments[i]))) {
        addDependency(fragments[i], added, map, entries, useInclusion);
      }
    }
    BundleSpecification[] required = desc.getRequiredBundles();
    for (int i = 0; i < required.length; i++) {
      if (required[i].isExported()) {
        addDependency((BundleDescription)required[i].getSupplier(), added, map, entries, useInclusion);
      }
    }
  }
  
  private boolean addPlugin(BundleDescription desc, boolean useInclusions, Map map, ArrayList entries)
    throws CoreException
  {
    IPluginModelBase model = PluginRegistry.findModel(desc);
    if ((model == null) || (!model.isEnabled(
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-2017. Infinite Loop Ltd