org.eclipse.pde.launching_3.6.0.v20110506

ine #295	-> byte code offset #16
    //   Java source line #297	-> byte code offset #18
    //   Java source line #298	-> byte code offset #31
    //   Java source line #299	-> byte code offset #38
    //   Java source line #300	-> byte code offset #47
    //   Java source line #301	-> byte code offset #54
    //   Java source line #303	-> byte code offset #61
    //   Java source line #304	-> byte code offset #62
    //   Java source line #307	-> byte code offset #66
    //   Java source line #308	-> byte code offset #70
    //   Java source line #309	-> byte code offset #77
    //   Java source line #305	-> byte code offset #81
    //   Java source line #307	-> byte code offset #82
    //   Java source line #308	-> byte code offset #86
    //   Java source line #309	-> byte code offset #93
    //   Java source line #311	-> byte code offset #94
    //   Java source line #307	-> byte code offset #96
    //   Java source line #308	-> byte code offset #100
    //   Java source line #309	-> byte code offset #107
    //   Java source line #313	-> byte code offset #108
    // Local variable table:
    //   start	length	slot	name	signature
    //   17	84	0	fis	java.io.FileInputStream
    //   30	13	1	file	File
    //   61	2	1	e	IOException
    //   81	14	2	localObject	Object
    //   77	1	4	localIOException1	IOException
    //   93	1	5	localIOException2	IOException
    //   107	1	6	localIOException3	IOException
    // Exception table:
    //   from	to	target	type
    //   18	58	61	java/io/IOException
    //   66	74	77	java/io/IOException
    //   18	66	81	finally
    //   82	90	93	java/io/IOException
    //   96	104	107	java/io/IOException
  }
  
  private static boolean shouldAdd(IProject proj, String launcherTS, String fileSystemTS)
  {
    String projTS = (String)getLastRun().get(proj.getName());
    if (projTS == null) {
      return true;
    }
    return (projTS.compareTo(launcherTS) < 0) || (projTS.compareTo(fileSystemTS) < 0);
  }
  
  public static boolean requiresUI(ILaunchConfiguration configuration)
  {
    try
    {
      String projectID = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
      if (projectID.length() > 0)
      {
        IResource project = PDELaunchingPlugin.getWorkspace().getRoot().findMember(projectID);
        if ((project instanceof IProject))
        {
          IPluginModelBase model = PluginRegistry.findModel((IProject)project);
          if (model != null)
          {
            Set plugins = DependencyManager.getSelfAndDependencies(model, null);
            return plugins.contains("org.eclipse.swt");
          }
        }
      }
    }
    catch (CoreException localCoreException) {}
    return true;
  }
  
  public static boolean clearWorkspaceLog(String workspace)
  {
    File logFile = new File(workspace, ".metadata" + File.separator + ".log");
    if ((logFile != null) && (logFile.exists())) {
      return logFile.delete();
    }
    return true;
  }
  
  public static IStatus createErrorStatus(String message)
  {
    return new Status(4, PDELaunchingPlugin.getPluginId(), 0, message, null);
  }
  
  public static void setLastLaunchMode(String launchMode)
  {
    fLastLaunchMode = launchMode;
  }
}

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

import java.util.Comparator;
import org.eclipse.core.runtime.IConfigurationElement;

class OSGiFrameworkManager$1
  implements Comparator
{
  final OSGiFrameworkManager this$0;
  
  OSGiFrameworkManager$1(OSGiFrameworkManager paramOSGiFrameworkManager)
  {
    this$0 = paramOSGiFrameworkManager;
  }
  
  public int compare(Object o1, Object o2)
  {
    String name1 = ((IConfigurationElement)o1).getAttribute("name");
    String name2 = ((IConfigurationElement)o2).getAttribute("name");
    if (name1 != null) {
      return name1.compareToIgnoreCase(name2);
    }
    return 1;
  }
}

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

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.pde.internal.core.PDEPreferencesManager;
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;
import org.eclipse.pde.launching.OSGiLaunchConfigurationInitializer;

public class OSGiFrameworkManager
  implements IRegistryChangeListener
{
  public static final String POINT_ID = "org.eclipse.pde.ui.osgiFrameworks";
  public static final String DEFAULT_FRAMEWORK = "org.eclipse.pde.ui.EquinoxFramework";
  public static final String ATT_ID = "id";
  public static final String ATT_NAME = "name";
  public static final String ATT_DELEGATE = "launcherDelegate";
  public static final String ATT_INITIALIZER = "initializer";
  public static final String ELEMENT_FRAMEWORK = "framework";
  private Map fFrameworks;
  
  public IConfigurationElement[] getFrameworks()
  {
    if (fFrameworks == null) {
      loadElements();
    }
    return (IConfigurationElement[])fFrameworks.values().toArray(new IConfigurationElement[fFrameworks.size()]);
  }
  
  public IConfigurationElement[] getSortedFrameworks()
  {
    IConfigurationElement[] elements = getFrameworks();
    return orderElements(elements);
  }
  
  private void loadElements()
  {
    fFrameworks = new HashMap();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiFrameworks");
    for (int i = 0; i < elements.length; i++)
    {
      String id = elements[i].getAttribute("id");
      if ((id != null) && (elements[i].getAttribute("name") != null) && (elements[i].getAttribute("launcherDelegate") != null)) {
        fFrameworks.put(id, elements[i]);
      }
    }
  }
  
  private IConfigurationElement[] orderElements(IConfigurationElement[] elems)
  {
    Arrays.sort(elems, new Comparator()
    {
      public int compare(Object o1, Object o2)
      {
        String name1 = ((IConfigurationElement)o1).getAttribute("name");
        String name2 = ((IConfigurationElement)o2).getAttribute("name");
        if (name1 != null) {
          return name1.compareToIgnoreCase(name2);
        }
        return 1;
      }
    });
    return elems;
  }
  
  public void registryChanged(IRegistryChangeEvent event) {}
  
  public String getDefaultFramework()
  {
    PDEPreferencesManager store = PDELaunchingPlugin.getDefault().getPreferenceManager();
    return store.getString("Preference.default.osgi.framework");
  }
  
  public OSGiLaunchConfigurationInitializer getDefaultInitializer()
  {
    return getInitializer(getDefaultFramework());
  }
  
  public OSGiLaunchConfigurationInitializer getInitializer(String frameworkID)
  {
    if (fFrameworks == null) {
      loadElements();
    }
    if (fFrameworks.containsKey(frameworkID)) {
      try
      {
        IConfigurationElement element = (IConfigurationElement)fFrameworks.get(frameworkID);
        if (element.getAttribute("initializer") != null)
        {
          Object result = element.createExecutableExtension("initializer");
          if ((result instanceof OSGiLaunchConfigurationInitializer)) {
            return (OSGiLaunchConfigurationInitializer)result;
          }
        }
      }
      catch (CoreException localCoreException) {}
    }
    return new OSGiLaunchConfigurationInitializer();
  }
  
  public LaunchConfigurationDelegate getFrameworkLauncher(String frameworkID)
  {
    if (fFrameworks == null) {
      loadElements();
    }
    if (fFrameworks.containsKey(frameworkID)) {
      try
      {
        IConfigurationElement element = (IConfigurationElement)fFrameworks.get(frameworkID);
        Object result = element.createExecutableExtension("launcherDelegate");
        if ((result instanceof LaunchConfigurationDelegate)) {
          return (LaunchConfigurationDelegate)result;
        }
      }
      catch (CoreException localCoreException) {}
    }
    return null;
  }
  
  public String getFrameworkName(String frameworkID)
  {
    if (fFrameworks == null) {
      loadElements();
    }
    if (fFrameworks.containsKey(frameworkID))
    {
      IConfigurationElement element = (IConfigurationElement)fFrameworks.get(frameworkID);
      return element.getAttribute("name");
    }
    return null;
  }
  
  public IConfigurationElement getFramework(String frameworkId)
  {
    if (fFrameworks == null) {
      loadElements();
    }
    return (IConfigurationElement)fFrameworks.get(frameworkId);
  }
}

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;

public class OSGiMigrationDelegate
  extends PDEMigrationDelegate
{
  public boolean isCandidate(ILaunchConfiguration candidate)
    throws CoreException
  {
    return (super.isCandidate(candidate)) || (!candidate.getAttribute("pde.version", "").equals("3.3"));
  }
  
  public void migrate(ILaunchConfigurationWorkingCopy wc)
    throws CoreException
  {
    if (!wc.getAttribute("pde.version", "").equals("3.3"))
    {
      wc.setAttribute("pde.version", "3.3");
      StringBuffer vmArgs = new StringBuffer(wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, ""));
      if (vmArgs.indexOf("-Declipse.ignoreApp") == -1)
      {
        if (vmArgs.length() > 0) {
          vmArgs.append(" ");
        }
        vmArgs.append("-Declipse.ignoreApp=true");
      }
      if (vmArgs.indexOf("-Dosgi.noShutdown") == -1) {
        vmArgs.append(" -Dosgi.noShutdown=true");
      }
      wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.toString());
    }
    super.migrate(wc);
  }
}

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.pde.core.plugin.IPluginModelBase;

public class OSGiValidationOperation
  extends LaunchValidationOperation
{
  public OSGiValidationOperation(ILaunchConfiguration configuration)
  {
    super(configuration);
  }
  
  protected IPluginModelBase[] getModels()
    throws CoreException
  {
    return BundleLauncherHelper.getMergedBundles(fLaunchConfiguration, true);
  }
}

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;

public class PDEMigrationDelegate
  implements ILaunchConfigurationMigrationDelegate
{
  public boolean isCandidate(ILaunchConfiguration candidate)
    throws CoreException
  {
    return (!candidate.getAttribute("append.args", false)) || (candidate.hasAttribute("vminstall"));
  }
  
  public void migrate(ILaunchConfiguration candidate)
    throws CoreException
  {
    ILaunchConfigurationWorkingCopy wc = candidate.getWorkingCopy();
    migrate(wc);
    wc.doSave();
  }
  
  public void migrate(ILaunchConfigurationWorkingCopy candidate)
    throws CoreException
  {
    if (!candidate.getAttribute("append.args", false))
    {
      candidate.setAttribute("append.args", true);
      String args = candidate.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "");
      StringBuffer buffer = new StringBuffer(LaunchArgumentsHelper.getInitialProgramArguments());
      if (args.length() > 0)
      {
        buffer.append(" ");
        buffer.append(args);
      }
      candidate.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, buffer.toString());
    }
    if (candidate.hasAttribute("vminstall"))
    {
      String name = candidate.getAttribute("vminstall", null);
      if (name != null)
      {
        IVMInstall vm = VMHelper.getVMInstall(name);
        if (vm != null)
        {
          IPath path = JavaRuntime.newJREContainerPath(vm);
          candidate.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, path.toPortableString());
        }
      }
      candidate.removeAttribute("vminstall");
    }
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.pde.core.plugin.IPluginModelBase;

public class ProductValidationOperation
  extends LaunchValidationOperation
{
  private IPluginModelBase[] fModels;
  
  public ProductValidationOperation(IPluginModelBase[] models)
  {
    super(null);
    fModels = models;
  }
  
  protected IPluginModelBase[] getModels()
    throws CoreException
  {
    return fModels;
  }
  
  protected IExecutionEnvironment[] getMatchingEnvironments()
    throws CoreException
  {
    IVMInstall install = JavaRuntime.getDefaultVMInstall();
    
    IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
    IExecutionEnvironment[] envs = manager.getExecutionEnvironments();
    List result = new ArrayList(envs.length);
    for (int i = 0; i < envs.length; i++)
    {
      IExecutionEnvironment env = envs[i];
      IVMInstall[] compatible = env.getCompatibleVMs();
      for (int j = 0; j < compatible.length; j++) {
        if (compatible[j].equals(install))
        {
          result.add(env);
          break;
        }
      }
    }
    return (IExecutionEnvironment[])result.toArray(new IExecutionEnvironment[result.size()]);
  }
}

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

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.pde.core.plugin.TargetPlatform;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PDEExtensionRegistry;

public class RequirementHelper
{
  public static String[] getApplicationRequirements(ILaunchConfiguration config)
    throws CoreException
  {
    Set requiredIds = new HashSet();
    if (config.getAttribute("useProduct", false))
    {
      String product = config.getAttribute("product", null);
      if (product != null) {
        getProductRequirements(product, requiredIds);
      }
    }
    else
    {
      String configType = config.getType().getIdentifier();
      if (configType.equals("org.eclipse.pde.ui.RuntimeWorkbench"))
      {
        String application = config.getAttribute("application", TargetPlatform.getDefaultApplication());
        if (!"org.eclipse.pde.junit.runtime.coretestapplication".equals(application)) {
          getApplicationRequirements(application, requiredIds);
        }
      }
      else
      {
        String application = config.getAttribute("testApplication", null);
        if (application == null) {
          application = config.getAttribute("application", null);
        }
        if (application == null) {
          application = TargetPlatform.getDefaultApplication();
        }
        if (!"org.eclipse.pde.junit.runtime.coretestapplication".equals(application)) {
          getApplicationRequirements(application, requiredIds);
        }
      }
    }
    return (String[])requiredIds.toArray(new String[requiredIds.size()]);
  }
  
  private static void getProductRequirements(String product, Collection requiredIds)
  {
    PDEExtensionRegistry registry = PDECore.getDefault().getExtensionsRegistry();
    IExtension[] extensions = registry.findExtensions("org.eclipse.core.runtime.products", true);
    for (int i = 0; i < extensions.length; i++) {
      if ((product.equals(extensions[i].getUniqueIdentifier())) || (product.equals(extensions[i].getSimpleIdentifier())))
      {
        requiredIds.add(extensions[i].getNamespaceIdentifier());
        
        IConfigurationElement[] elements = extensions[i].getConfigurationElements();
        for (int j = 0; j < elements.length; j++)
        {
          String application = elements[j].getAttribute("application");
          if ((application != null) && (application.length() > 0)) {
            getApplicationRequirements(application, requiredIds);
          }
        }
        break;
      }
    }
  }
  
  private static void getApplicationRequirements(String application, Collection requiredIds)
  {
    PDEExtensionRegistry registry = PDECore.getDefault().getExtensionsRegistry();
    IExtension[] extensions = registry.findExtensions("org.eclipse.core.runtime.applications", true);
    for (int i = 0; i < extensions.length; i++) {
      if ((application.equals(extensions[i].getUniqueIdentifier())) || (application.equals(extensions[i].getSimpleIdentifier())))
      {
        requiredIds.add(extensions[i].getNamespaceIdentifier());
        
        break;
      }
    }
  }
}

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

import java.io.File;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.core.util.VMUtil;
import org.eclipse.pde.internal.launching.PDEMessages;

public class VMHelper
{
  public static String getDefaultVMInstallName(ILaunchConfiguration configuration)
    throws CoreException
  {
    IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
    IVMInstall vmInstall = null;
    if (javaProject != null) {
      vmInstall = JavaRuntime.getVMInstall(javaProject);
    }
    if (vmInstall != null) {
      return vmInstall.getName();
    }
    return VMUtil.getDefaultVMInstallName();
  }
  
  public static IVMInstall getVMInstall(ILaunchConfiguration configuration)
    throws CoreException
  {
    String jre = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, null);
    IVMInstall vm = null;
    if (jre == null)
    {
      String name = configuration.getAttribute("vminstall", null);
      if (name == null) {
        name = getDefaultVMInstallName(configuration);
      }
      vm = getVMInstall(name);
      if (vm == null) {
        throw new CoreException(LauncherUtils.createErrorStatus(NLS.bind(PDEMessages.WorkbenchLauncherConfigurationDelegate_noJRE, name)));
      }
    }
    else
    {
      IPath jrePath = Path.fromPortableString(jre);
      vm = JavaRuntime.getVMInstall(jrePath);
      if (vm == null)
      {
        String id = JavaRuntime.getExecutionEnvironmentId(jrePath);
        if (id == null)
        {
          String name = JavaRuntime.getVMInstallName(jrePath);
          throw new CoreException(LauncherUtils.createErrorStatus(NLS.bind(PDEMessages.WorkbenchLauncherConfigurationDelegate_noJRE, name)));
        }
        throw new CoreException(LauncherUtils.createErrorStatus(NLS.bind(PDEMessages.VMHelper_cannotFindExecEnv, id)));
      }
    }
    return vm;
  }
  
  public static IVMInstall getVMInstall(String name)
  {
    if (name != null)
    {
      IVMInstall[] installs = VMUtil.getAllVMInstances();
      for (int i = 0; i < installs.length; i++) {
        if (installs[i].getName().equals(name)) {
          return installs[i];
        }
      }
    }
    return JavaRuntime.getDefaultVMInstall();
  }
  
  public static IVMInstall createLauncher(ILaunchConfiguration configuration)
    throws CoreException
  {
    IVMInstall launcher = getVMInstall(configuration);
    if (!launcher.getInstallLocation().exists()) {
      throw new CoreException(LauncherUtils.createErrorStatus(PDEMessages.WorkbenchLauncherConfigurationDelegate_jrePathNotFound));
    }
    return launcher;
  }
}

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

import java.io.File;
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 org.eclipse.core.filesystem.URIUtil;
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.SafeRunner;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.WorkspaceSourceContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
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.debug.core.IJavaObject;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant;
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.PDEClasspathContainer;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.internal.launching.PDELaunchingPlugin;

public class PDESourceLookupDirector
  extends AbstractSourceLookupDirector
{
  private Map fSourceContainerMap = new HashMap();
  private static Set fFilteredTypes = new HashSet(3);
  
  static
  {
    fFilteredTypes.add(ProjectSourceContainer.TYPE_ID);
    fFilteredTypes.add(WorkspaceSourceContainer.TYPE_ID);
    fFilteredTypes.add("org.eclipse.debug.ui.containerType.workingSet");
  }
  
  private double fOSGiRuntimeVersion = Double.MIN_VALUE;
  
  public void initializeParticipants()
  {
    addParticipants(new ISourceLookupParticipant[] { new JavaSourceLookupParticipant() });
  }
  
  public boolean supportsSourceContainerType(ISourceContainerType type)
  {
    return !fFilteredTypes.contains(type.getId());
  }
  
  public Object getSourceElement(Object element)
  {
    PDESourceLookupQuery query = new PDESourceLookupQuery(this, element);
    SafeRunner.run(query);
    Object result = query.getResult();
    return result != null ? result : super.getSourceElement(element);
  }
  
  public Object[] findSourceElements(Object object)
    throws CoreException
  {
    Object[] sourceElements = (Object[])null;
    if (((object instanceof IJavaStackFrame)) || ((object instanceof IJavaObject)) || ((object instanceof IJavaReferenceType))) {
      sourceElements = new Object[] { getSourceElement(object) };
    }
    if (sourceElements == null) {
      sourceElements = super.findSourceElements(object);
    }
    return sourceElements;
  }
  
  ISourceContainer[] getSourceContainers(String location, String id)
    throws CoreException
  {
    ISourceContainer[] containers = (ISourceContainer[])fSourceContainerMap.get(location);
    if (containers != null) {
      return containers;
    }
    ArrayList result = new ArrayList();
    ModelEntry entry = PluginRegistry.findEntry(id);
    
    boolean match = false;
    
    IPluginModelBase[] models = entry.getWorkspaceModels();
    for (int i = 0; i < models.length; i++) {
      if (isPerfectMatch(models[i], new Path(location)))
      {
        IResource resource = models[i].getUnderlyingResource();
        if (resource != null) {
          addProjectSourceContainers(resource.getProject(), result);
        }
        match = true;
        break;
      }
    }
    if (!match)
    {
      File file = new File(location);
      if (file.isFile())
      {
        ISourceContainer container = getArchiveSourceContainer(location);
        if (container != null)
        {
          containers = new ISourceContainer[] { container };
          fSourceContainerMap.put(location, containers);
          return containers;
        }
      }
      models = entry.getExternalModels();
      for (int i = 0; i < models.length; i++) {
        if (isPerfectMatch(models[i], new Path(location)))
        {
          IClasspathEntry[] entries = PDEClasspathContainer.getExternalEntries(models[i]);
          for (int j = 0; j < entries.length; j++)
          {
            IRuntimeClasspathEntry rte = convertClasspathEntry(entries[j]);
            if (rte != null) {
              result.add(rte);
            }
          }
          break;
        }
      }
    }
    IRuntimeClasspathEntry[] entries = (IRuntimeClasspathEntry[])result.toArray(new IRuntimeClasspathEntry[result.size()]);
    containers = JavaRuntime.getSourceContainers(entries);
    fSourceContainerMap.put(location, containers);
    return containers;
  }
  
  private boolean isPerfectMatch(IPluginModelBase model, IPath path)
  {
    return model == null ? false : path.equals(new Path(model.getInstallLocation()));
  }
  
  private IRuntimeClasspathEntry convertClasspathEntry(IClasspathEntry entry)
  {
    if (entry == null) {
      return null;
    }
    IPath srcPath = entry.getSourceAttachmentPath();
    if ((srcPath != null) && (srcPath.segmentCount() > 0))
    {
      IRuntimeClasspathEntry rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
      rte.setSourceAttachmentPath(srcPath);
      rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath());
      return rte;
    }
    return null;
  }
  
  private ISourceContainer getArchiveSourceContainer(String location)
    throws JavaModelException
  {
    IWorkspaceRoot root = PDELaunchingPlugin.getWorkspace().getRoot();
    IFile[] containers = root.findFilesForLocationURI(URIUtil.toURI(location));
    for (int i = 0; i < containers.length; i++)
    {
      IJavaElement element = JavaCore.create(containers[i]);
      if ((element instanceof IPackageFragmentRoot))
      {
        IPackageFragmentRoot archive = (IPackageFragmentRoot)element;
        IPath path = archive.getSourceAttachmentPath();
        if ((path != null) && (path.segmentCount() != 0))
        {
          IPath rootPath = archive.getSourceAttachmentRootPath();
          boolean detectRootPath = (rootPath != null) && (rootPath.segmentCount() > 0);
          
          IFile archiveFile = root.getFile(path);
          if (archiveFile.exists()) {
            return new ArchiveSourceContainer(archiveFile, detectRootPath);
          }
          File file = path.toFile();
          if (file.exists()) {
            return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath);
          }
        }
      }
    }
    return null;
  }
  
  private void addProjectSourceContainers(IProject project, ArrayList result)
    throws CoreException
  {
    if ((project == null) || (!project.hasNature("org.eclipse.jdt.core.javanature"))) {
      return;
    }
    IJavaProject jProject = JavaCore.create(project);
    result.add(JavaRuntime.newProjectRuntimeClasspathEntry(jProject));
    
    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++)
    {
      IClasspathEntry entry = entries[i];
      if (entry.getEntryKind() == 1)
      {
        IRuntimeClasspathEntry rte = convertClasspathEntry(entry);
        if (rte != null) {
          result.add(rte);
        }
      }
    }
  }
  
  public synchronized void dispose()
  {
    Iterator iterator = fSourceContainerMap.values().iterator();
    ISourceContainer[] containers;
    int i;
    for (; iterator.hasNext(); i < containers.length)
    {
      containers = (ISourceContainer[])iterator.next();
      i = 0; continue;
      containers[i].dispose();i++;
    }
    fSourceContainerMap.clear();
    super.dispose();
  }
  
  double getOSGiRuntimeVersion()
  {
    if (fOSGiRuntimeVersion == Double.MIN_VALUE) {
      fOSGiRuntimeVersion = TargetPlatformHelper.getTargetVersion();
    }
    return fOSGiRuntimeVersion;
  }
}

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

import java.io.File;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jdt.debug.core.IJavaArray;
import org.eclipse.jdt.debug.core.IJavaClassType;
import org.eclipse.jdt.debug.core.IJavaFieldVariable;
import org.eclipse.jdt.debug.core.IJavaObject;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.core.IJavaType;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PluginModelManager;
import org.eclipse.pde.internal.core.TargetPlatformHelper;

public class PDESourceLookupQuery
  implements ISafeRunnable
{
  protected static String OSGI_CLASSLOADER = "org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader";
  private static String LEGACY_ECLIPSE_CLASSLOADER = "org.eclipse.core.runtime.adaptor.EclipseClassLoader";
  private static String MAIN_CLASS = "org.eclipse.core.launcher.Main";
  private static String MAIN_PLUGIN = "org.eclipse.platform";
  private Object fElement;
  private Object fResult;
  private PDESourceLookupDirector fDirector;
  
  public PDESourceLookupQuery(PDESourceLookupDirector director, Object object)
  {
    fElement = object;
    fDirector = director;
  }
  
  public void handleException(Throwable exception) {}
  
  public void run()
    throws Exception
  {
    IJavaReferenceType declaringType = null;
    String sourcePath = null;
    if ((fElement instanceof IJavaStackFrame))
    {
      IJavaStackFrame stackFrame = (IJavaStackFrame)fElement;
      declaringType = stackFrame.getReferenceType();
      
      sourcePath = stackFrame.getSourcePath();
    }
    else if ((fElement instanceof IJavaObject))
    {
      IJavaType javaType = ((IJavaObject)fElement).getJavaType();
      if ((javaType instanceof IJavaReferenceType)) {
        declaringType = (IJavaReferenceType)javaType;
      }
    }
    else if ((fElement instanceof IJavaReferenceType))
    {
      declaringType = (IJavaReferenceType)fElement;
    }
    if (declaringType != null)
    {
      IJavaObject classLoaderObject = declaringType.getClassLoaderObject();
      String declaringTypeName = declaringType.getName();
      if (sourcePath == null)
      {
        String[] sourcePaths = declaringType.getSourcePaths(null);
        if (sourcePaths != null) {
          sourcePath = sourcePaths[0];
        }
        if (sourcePath == null) {
          sourcePath = generateSourceName(declaringTypeName);
        }
      }
      if (classLoaderObject != null)
      {
        IJavaClassType type = (IJavaClassType)classLoaderObject.getJavaType();
        if (OSGI_CLASSLOADER.equals(type.getName()))
        {
          if (fDirector.getOSGiRuntimeVersion() < 3.5D) {
            fResult = findSourceElement34(classLoaderObject, sourcePath);
          } else {
            fResult = findSourceElement(classLoaderObject, sourcePath);
          }
        }
        else if (LEGACY_ECLIPSE_CLASSLOADER.equals(type.getName()))
        {
          fResult = findSourceElement_legacy(classLoaderObject, sourcePath);
        }
        else if (MAIN_CLASS.equals(declaringTypeName))
        {
          IPluginModelBase model = PDECore.getDefault().getModelManager().findModel(MAIN_PLUGIN);
          if (model != null) {
            fResult = getSourceElement(model.getInstallLocation(), MAIN_PLUGIN, sourcePath, true);
          }
        }
      }
    }
  }
  
  protected Object getResult()
  {
    return fResult;
  }
  
  private String getValue(IJavaObject object, String variable)
    throws DebugException
  {
    IJavaFieldVariable var = object.getField(variable, false);
    return var == null ? null : var.getValue().getValueString();
  }
  
  protected Object findSourceElement34(IJavaObject object, String typeName)
    throws CoreException
  {
    IJavaObject manager = getObject(object, "manager", false);
    if (manager != null)
    {
      IJavaObject data = getObject(manager, "data", false);
      if (data != null)
      {
        String location = getValue(data, "fileName");
        String id = getValue(data, "symbolicName");
        return getSourceElement(location, id, typeName, true);
      }
    }
    return null;
  }
  
  protected Object findSourceElement(IJavaObject object, String typeName)
    throws CoreException
  {
    IJavaObject manager = getObject(object, "manager", false);
    if (manager != null)
    {
      IJavaObject data = getObject(manager, "data", false);
      if (data != null)
      {
        Object result = searchClasspathEntries(manager, typeName);
        if (result != null) {
          return result;
        }
        IJavaObject frgArray = getObject(manager, "fragments", false);
        if ((frgArray instanceof IJavaArray))
        {
          IJavaArray fragments = (IJavaArray)frgArray;
          for (int i = 0; i < fragments.getLength(); i++)
          {
            IJavaObject fragment = (IJavaObject)fragments.getValue(i);
            if (!fragment.isNull())
            {
              result = searchClasspathEntries(fragment, typeName);
              if (result != null) {
                return result;
              }
            }
          }
        }
      }
    }
    return null;
  }
  
  private Object searchClasspathEntries(IJavaObject entriesOwner, String typeName)
    throws CoreException
  {
    IJavaObject cpeArray = getObject(entriesOwner, "entries", false);
    if ((cpeArray instanceof IJavaArray))
    {
      IJavaArray entries = (IJavaArray)cpeArray;
      for (int i = 0; i < entries.getLength(); i++)
      {
        IJavaObject entry = (IJavaObject)entries.getValue(i);
        if (!entry.isNull())
        {
          IJavaObject baseData = getObject(entry, "data", false);
          if ((baseData != null) && (!baseData.isNull()))
          {
            IJavaObject fileName = getObject(baseData, "fileName", false);
            if ((fileName != null) && (!fileName.isNull()))
            {
              String location = fileName.getValueString();
              String symbolicName = getValue(baseData, "symbolicName");
              Object el = getSourceElement(location, symbolicName, typeName, false);
              if (el != null) {
                return el;
              }
            }
          }
        }
      }
    }
    return null;
  }
  
  private IJavaObject getObject(IJavaObject object, String field, boolean superfield)
    throws DebugException
  {
    IJavaFieldVariable variable = object.getField(field, superfield);
    if (variable != null)
    {
      IValue value = variable.getValue();
      if ((value instanceof IJavaObject)) {
        return (IJavaObject)value;
      }
    }
    return null;
  }
  
  private Object findSourceElement_legacy(IJavaObject object, String typeName)
    throws CoreException
  {
    IJavaObject hostdata = getObject(object, "hostdata", true);
    if (hostdata != null)
    {
      String location = getValue(hostdata, "fileName");
      String id = getValue(hostdata, "symbolicName");
      return getSourceElement(location, id, typeName, true);
    }
    return null;
  }
  
  private Object getSourceElement(String location, String id, String typeName, boolean checkFragments)
    throws CoreException
  {
    if ((location != null) && (id != null))
    {
      Object result = findSourceElement(getSourceContainers(location, id), typeName);
      if (result != null) {
        return result;
      }
      if (checkFragments)
      {
        State state = TargetPlatformHelper.getState();
        BundleDescription desc = state.getBundle(id, null);
        if (desc != null)
        {
          BundleDescription[] fragments = desc.getFragments();
          for (int i = 0; i < fragments.length; i++)
          {
            location = fragments[i].getLocation();
            id = fragments[i].getSymbolicName();
            result = findSourceElement(getSourceContainers(location, id), typeName);
            if (result != null) {
              return result;
            }
          }
        }
      }
    }
    return null;
  }
  
  private Object findSourceElement(ISourceContainer[] containers, String typeName)
    throws CoreException
  {
    for (int i = 0; i < containers.length; i++)
    {
      Object[] result = containers[i].findSourceElements(typeName);
      if (result.length > 0) {
        return result[0
1 2 3 4 5 6

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