org.eclipse.pde.api.tools_1.0.301.v20111129-2053

()
  {
    IElementDescriptor parent = getParent();
    if ((parent instanceof IReferenceTypeDescriptor)) {
      return (IReferenceTypeDescriptor)parent;
    }
    return null;
  }
  
  public IPackageDescriptor getPackage()
  {
    IElementDescriptor parent = getParent();
    while (!(parent instanceof IPackageDescriptor)) {
      parent = ((MemberDescriptorImpl)parent).getParent();
    }
    return (IPackageDescriptor)parent;
  }
  
  public IElementDescriptor getParent()
  {
    return fParent;
  }
}

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

import org.eclipse.jdt.core.Signature;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;

public class MethodDescriptorImpl
  extends MemberDescriptorImpl
  implements IMethodDescriptor
{
  private String fSignature;
  
  MethodDescriptorImpl(String name, IReferenceTypeDescriptor enclosingType, String signature)
  {
    super(name, enclosingType);
    fSignature = signature;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(getEnclosingType().getQualifiedName());
    buffer.append("#");
    buffer.append(Signature.toString(getSignature(), getName(), null, true, true));
    return buffer.toString();
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof IMethodDescriptor))
    {
      IMethodDescriptor method = (IMethodDescriptor)obj;
      
      return (getName().equals(method.getName())) && (getEnclosingType().equals(method.getEnclosingType())) && (getSignature().equals(method.getSignature()));
    }
    return false;
  }
  
  public int hashCode()
  {
    return getName().hashCode() + getEnclosingType().hashCode();
  }
  
  public int getElementType()
  {
    return 6;
  }
  
  public String getSignature()
  {
    return fSignature;
  }
  
  public boolean isConstructor()
  {
    return "<init>".equals(getName());
  }
}

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

public abstract class NamedElementDescriptorImpl
  extends ElementDescriptorImpl
{
  private String fName;
  
  NamedElementDescriptorImpl(String name)
  {
    fName = name;
  }
  
  public String getName()
  {
    return fName;
  }
  
  protected Comparable getComparable()
  {
    return getName();
  }
}

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

import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;

public class PackageDescriptorImpl
  extends NamedElementDescriptorImpl
  implements IPackageDescriptor
{
  public PackageDescriptorImpl(String name)
  {
    super(name);
  }
  
  public String toString()
  {
    String name = getName();
    return name.equals("") ? "<default package>" : name;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof IPackageDescriptor))
    {
      IPackageDescriptor pkg = (IPackageDescriptor)obj;
      return getName().equals(pkg.getName());
    }
    return false;
  }
  
  public int hashCode()
  {
    return getName().hashCode();
  }
  
  public int getElementType()
  {
    return 1;
  }
  
  public IReferenceTypeDescriptor getType(String typeQualifiedName, String signature)
  {
    String[] names = typeQualifiedName.split("\\$");
    IReferenceTypeDescriptor typeDescriptor = new ReferenceTypeDescriptorImpl(names[0], this, signature);
    for (int i = 1; i < names.length; i++) {
      typeDescriptor = typeDescriptor.getType(names[i]);
    }
    return typeDescriptor;
  }
  
  public IReferenceTypeDescriptor getType(String typeQualifiedName)
  {
    String[] names = typeQualifiedName.split("\\$");
    IReferenceTypeDescriptor typeDescriptor = new ReferenceTypeDescriptorImpl(names[0], this);
    for (int i = 1; i < names.length; i++) {
      typeDescriptor = typeDescriptor.getType(names[i]);
    }
    return typeDescriptor;
  }
}

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IFieldDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor;

public class ReferenceTypeDescriptorImpl
  extends MemberDescriptorImpl
  implements IReferenceTypeDescriptor
{
  private String fFullName = null;
  private String fSignature = null;
  private String fGenericSignature = null;
  
  ReferenceTypeDescriptorImpl(String name, IElementDescriptor parent)
  {
    super(name, parent);
  }
  
  ReferenceTypeDescriptorImpl(String name, IElementDescriptor parent, String genericSignature)
  {
    this(name, parent);
    fGenericSignature = genericSignature;
  }
  
  public IFieldDescriptor getField(String name)
  {
    return new FieldDescriptorImpl(name, this);
  }
  
  public IMethodDescriptor getMethod(String name, String signature)
  {
    return new MethodDescriptorImpl(name, this, signature);
  }
  
  public IReferenceTypeDescriptor getType(String simpleName)
  {
    return new ReferenceTypeDescriptorImpl(simpleName, this);
  }
  
  public String toString()
  {
    return getQualifiedName();
  }
  
  public synchronized String getQualifiedName()
  {
    if (fFullName == null)
    {
      StringBuffer buffer = new StringBuffer();
      buffer.append(getPackage().getName());
      if (buffer.length() > 0) {
        buffer.append('.');
      }
      List all = null;
      IReferenceTypeDescriptor enclosingType = getEnclosingType();
      while (enclosingType != null)
      {
        if (all == null) {
          all = new ArrayList();
        }
        all.add(0, enclosingType);
        enclosingType = enclosingType.getEnclosingType();
      }
      if (all != null)
      {
        Iterator iterator = all.iterator();
        while (iterator.hasNext())
        {
          buffer.append(((IReferenceTypeDescriptor)iterator.next()).getName());
          buffer.append('$');
        }
      }
      buffer.append(getName());
      fFullName = buffer.toString();
    }
    return fFullName;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof IReferenceTypeDescriptor))
    {
      IReferenceTypeDescriptor refType = (IReferenceTypeDescriptor)obj;
      return getQualifiedName().equals(refType.getQualifiedName());
    }
    return false;
  }
  
  public int hashCode()
  {
    return getQualifiedName().hashCode();
  }
  
  protected Comparable getComparable()
  {
    return getQualifiedName();
  }
  
  public int getElementType()
  {
    return 2;
  }
  
  public String getSignature()
  {
    if (fSignature == null)
    {
      StringBuffer buf = new StringBuffer();
      buf.append('L');
      buf.append(getQualifiedName());
      buf.append(';');
      fSignature = buf.toString();
    }
    return fSignature;
  }
  
  public String getGenericSignature()
  {
    return fGenericSignature;
  }
  
  public boolean isAnonymous()
  {
    if (getEnclosingType() != null) {
      try
      {
        Integer.parseInt(getName());
        return true;
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.descriptors.ReferenceTypeDescriptorImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;

public abstract class AbstractApiTypeContainer
  extends ApiElement
  implements IApiTypeContainer
{
  private List fApiTypeContainers = null;
  
  protected AbstractApiTypeContainer(IApiElement parent, int type, String name)
  {
    super(parent, type, name);
  }
  
  public void accept(ApiTypeContainerVisitor visitor)
    throws CoreException
  {
    IApiTypeContainer[] containers = getApiTypeContainers();
    for (int i = 0; i < containers.length; i++) {
      containers[i].accept(visitor);
    }
  }
  
  public synchronized void close()
    throws CoreException
  {
    if (fApiTypeContainers == null) {
      return;
    }
    ApiModelCache.getCache().removeElementInfo(this);
    
    MultiStatus multi = null;
    IStatus single = null;
    IApiTypeContainer[] containers = getApiTypeContainers();
    for (int i = 0; i < containers.length; i++) {
      try
      {
        containers[i].close();
      }
      catch (CoreException e)
      {
        if (single == null)
        {
          single = e.getStatus();
        }
        else
        {
          if (multi == null) {
            multi = new MultiStatus("org.eclipse.pde.api.tools", single.getCode(), single.getMessage(), single.getException());
          }
          multi.add(e.getStatus());
        }
      }
    }
    if (multi != null) {
      throw new CoreException(multi);
    }
    if (single != null) {
      throw new CoreException(single);
    }
  }
  
  public IApiTypeRoot findTypeRoot(String qualifiedName)
    throws CoreException
  {
    IApiTypeContainer[] containers = getApiTypeContainers();
    for (int i = 0; i < containers.length; i++)
    {
      IApiTypeRoot file = containers[i].findTypeRoot(qualifiedName);
      if (file != null) {
        return file;
      }
    }
    return null;
  }
  
  public IApiTypeRoot findTypeRoot(String qualifiedName, String id)
    throws CoreException
  {
    IApiTypeContainer[] containers = getApiTypeContainers();
    String origin = null;
    IApiComponent comp = null;
    for (int i = 0; i < containers.length; i++)
    {
      comp = (IApiComponent)containers[i].getAncestor(1);
      if (comp != null) {
        origin = comp.getSymbolicName();
      }
      if (origin == null)
      {
        IApiTypeRoot file = containers[i].findTypeRoot(qualifiedName);
        if (file != null) {
          return file;
        }
      }
      else if (origin.equals(id))
      {
        IApiTypeRoot file = containers[i].findTypeRoot(qualifiedName, id);
        if (file != null) {
          return file;
        }
      }
    }
    return null;
  }
  
  public String[] getPackageNames()
    throws CoreException
  {
    List names = new ArrayList();
    IApiTypeContainer[] containers = getApiTypeContainers();
    int i = 0;
    for (int max = containers.length; i < max; i++)
    {
      String[] packageNames = containers[i].getPackageNames();
      int j = 0;
      for (int max2 = packageNames.length; j < max2; j++) {
        names.add(packageNames[j]);
      }
    }
    String[] result = new String[names.size()];
    names.toArray(result);
    Arrays.sort(result);
    return result;
  }
  
  protected synchronized IApiTypeContainer[] getApiTypeContainers()
    throws CoreException
  {
    if (fApiTypeContainers == null) {
      fApiTypeContainers = createApiTypeContainers();
    }
    return (IApiTypeContainer[])fApiTypeContainers.toArray(new IApiTypeContainer[fApiTypeContainers.size()]);
  }
  
  protected synchronized IApiTypeContainer[] getApiTypeContainers(String id)
    throws CoreException
  {
    if (fApiTypeContainers == null) {
      fApiTypeContainers = createApiTypeContainers();
    }
    List containers = new ArrayList();
    String origin = null;
    IApiTypeContainer container = null;
    for (Iterator iterator = fApiTypeContainers.iterator(); iterator.hasNext();)
    {
      container = (IApiTypeContainer)iterator.next();
      origin = ((IApiComponent)container.getAncestor(1)).getSymbolicName();
      if ((origin != null) && (origin.equals(id))) {
        containers.add(container);
      }
    }
    return (IApiTypeContainer[])containers.toArray(new IApiTypeContainer[containers.size()]);
  }
  
  protected abstract List createApiTypeContainers()
    throws CoreException;
  
  protected synchronized void setApiTypeContainers(IApiTypeContainer[] containers)
  {
    if (fApiTypeContainers != null)
    {
      try
      {
        close();
      }
      catch (CoreException localCoreException) {}
      fApiTypeContainers.clear();
    }
    else
    {
      fApiTypeContainers = new ArrayList(containers.length);
    }
    for (int i = 0; i < containers.length; i++) {
      fApiTypeContainers.add(containers[i]);
    }
  }
  
  public int getContainerType()
  {
    return 0;
  }
}

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiType;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;

public abstract class AbstractApiTypeRoot
  extends ApiElement
  implements IApiTypeRoot
{
  protected AbstractApiTypeRoot(IApiElement parent, String name)
  {
    super(parent, 7, name);
  }
  
  public abstract byte[] getContents()
    throws CoreException;
  
  public IApiType getStructure()
    throws CoreException
  {
    ApiModelCache cache = ApiModelCache.getCache();
    IApiComponent comp = getApiComponent();
    IApiType type = null;
    if (comp != null)
    {
      IApiBaseline baseline = comp.getBaseline();
      type = (IApiType)cache.getElementInfo(baseline.getName(), comp.getSymbolicName(), getTypeName(), 2);
    }
    if (type == null)
    {
      type = TypeStructureBuilder.buildTypeStructure(getContents(), getApiComponent(), this);
      if (type == null) {
        return null;
      }
      cache.cacheElementInfo(type);
    }
    return type;
  }
  
  public IApiComponent getApiComponent()
  {
    return (IApiComponent)getAncestor(1);
  }
}

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

import com.ibm.icu.text.MessageFormat;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstall2;
import org.eclipse.jdt.launching.IVMInstallChangedListener;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.PropertyChangeEvent;
import org.eclipse.jdt.launching.VMStandin;
import org.eclipse.jdt.launching.environments.ExecutionEnvironmentDescription;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.pde.api.tools.internal.AnyValue;
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
import org.eclipse.pde.api.tools.internal.CoreMessages;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.osgi.framework.Bundle;

public class ApiBaseline
  extends ApiElement
  implements IApiBaseline, IVMInstallChangedListener
{
  private static final IApiComponent[] EMPTY_COMPONENTS = new IApiComponent[0];
  private State fState;
  private String fExecutionEnvironment;
  private IApiComponent fSystemLibraryComponent;
  private boolean fAutoResolve = false;
  private String fLocation;
  private IStatus fEEStatus = null;
  private AnyValue ANY_VALUE = new AnyValue("*");
  private HashMap fComponentsProvidingPackageCache = null;
  private HashMap fComponentsById = null;
  private HashMap fComponentsByProjectNames = null;
  private HashSet fSystemPackageNames = null;
  private IVMInstall fVMBinding = null;
  
  public ApiBaseline(String name)
  {
    super(null, 4, name);
    fAutoResolve = true;
    fEEStatus = new Status(4, "org.eclipse.pde.api.tools", CoreMessages.ApiBaseline_0);
  }
  
  public ApiBaseline(String name, File eeDescription)
    throws CoreException
  {
    this(name, eeDescription, null);
  }
  
  public ApiBaseline(String name, File eeDescription, String location)
    throws CoreException
  {
    this(name);
    if (eeDescription != null)
    {
      fAutoResolve = false;
      ExecutionEnvironmentDescription ee = new ExecutionEnvironmentDescription(eeDescription);
      String profile = ee.getProperty("-Dee.class.library.level");
      initialize(ee);
      fEEStatus = new Status(0, "org.eclipse.pde.api.tools", 
        MessageFormat.format(CoreMessages.ApiBaseline_1, new String[] { profile }));
    }
    fLocation = location;
  }
  
  private void initialize(ExecutionEnvironmentDescription ee)
    throws CoreException
  {
    Properties properties = null;
    String environmentId = ee.getProperty("-Dee.class.library.level");
    if (ApiPlugin.isRunningInFramework()) {
      properties = getJavaProfileProperties(environmentId);
    } else {
      properties = Util.getEEProfile(environmentId);
    }
    if (properties == null) {
      abort("Unknown execution environment: " + environmentId, null);
    } else {
      initialize(properties, ee);
    }
  }
  
  public static Properties getJavaProfileProperties(String ee)
    throws CoreException
  {
    Bundle osgiBundle = Platform.getBundle("org.eclipse.osgi");
    if (osgiBundle == null) {
      return null;
    }
    URL profileURL = osgiBundle.getEntry(ee.replace('/', '_') + ".profile");
    if (profileURL != null)
    {
      InputStream is = null;
      try
      {
        profileURL = FileLocator.resolve(profileURL);
        URLConnection openConnection = profileURL.openConnection();
        openConnection.setUseCaches(false);
        is = openConnection.getInputStream();
        if (is != null)
        {
          Properties profile = new Properties();
          profile.load(is);
          return profile;
        }
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
      finally
      {
        try
        {
          if (is != null) {
            is.close();
          }
        }
        catch (IOException e)
        {
          ApiPlugin.log(e);
        }
      }
      try
      {
        if (is != null) {
          is.close();
        }
      }
      catch (IOException e)
      {
        ApiPlugin.log(e);
      }
    }
    return null;
  }
  
  private void initialize(Properties profile, ExecutionEnvironmentDescription description)
    throws CoreException
  {
    String value = profile.getProperty("org.osgi.framework.system.packages");
    String[] systemPackages = (String[])null;
    if (value != null) {
      systemPackages = value.split(",");
    }
    if (!(this instanceof WorkspaceBaseline))
    {
      Dictionary dictionary = new Hashtable();
      dictionary.put("org.osgi.framework.system.packages", value);
      value = profile.getProperty("org.osgi.framework.executionenvironment");
      if (value != null) {
        dictionary.put("org.osgi.framework.executionenvironment", value);
      }
      fExecutionEnvironment = profile.getProperty("osgi.java.profile.name");
      if (fExecutionEnvironment == null) {
        abort("Profile file missing 'osgi.java.profile.name'", null);
      }
      dictionary.put("osgi.os", ANY_VALUE);
      dictionary.put("osgi.arch", ANY_VALUE);
      dictionary.put("osgi.ws", ANY_VALUE);
      dictionary.put("osgi.nl", ANY_VALUE);
      
      getState().setPlatformProperties(dictionary);
    }
    if ((fSystemLibraryComponent != null) && (fComponentsById != null)) {
      fComponentsById.remove(fSystemLibraryComponent.getSymbolicName());
    }
    if (fSystemPackageNames != null)
    {
      fSystemPackageNames.clear();
      fSystemPackageNames = null;
    }
    clearComponentsCache();
    
    fSystemLibraryComponent = new SystemLibraryApiComponent(this, description, systemPackages);
    addComponent(fSystemLibraryComponent);
  }
  
  private synchronized void clearComponentsCache()
  {
    if (fComponentsProvidingPackageCache != null)
    {
      fComponentsProvidingPackageCache.clear();
      fComponentsProvidingPackageCache = null;
    }
  }
  
  protected void addComponent(IApiComponent component)
    throws CoreException
  {
    if (component == null) {
      return;
    }
    if (fComponentsById == null) {
      fComponentsById = new HashMap();
    }
    fComponentsById.put(component.getSymbolicName(), component);
    if ((component instanceof ProjectComponent))
    {
      ProjectComponent projectApiComponent = (ProjectComponent)component;
      if (fComponentsByProjectNames == null) {
        fComponentsByProjectNames = new HashMap();
      }
      fComponentsByProjectNames.put(projectApiComponent.getJavaProject().getProject().getName(), component);
    }
  }
  
  public void addApiComponents(IApiComponent[] components)
    throws CoreException
  {
    HashSet ees = new HashSet();
    for (int i = 0; i < components.length; i++)
    {
      BundleComponent component = (BundleComponent)components[i];
      if (!component.isSourceComponent())
      {
        BundleDescription description = component.getBundleDescription();
        getState().addBundle(description);
        addComponent(component);
        ees.addAll(Arrays.asList(component.getExecutionEnvironments()));
      }
    }
    resolveSystemLibrary(ees);
    getState().resolve();
  }
  
  protected void resolveSystemLibrary(HashSet ees)
  {
    if ((ApiPlugin.isRunningInFramework()) && (fAutoResolve))
    {
      IStatus error = null;
      IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
      Iterator iterator = ees.iterator();
      Map VMsToEEs = new HashMap();
      while (iterator.hasNext())
      {
        String ee = (String)iterator.next();
        IExecutionEnvironment environment = manager.getEnvironment(ee);
        if (environment != null)
        {
          IVMInstall[] compatibleVMs = environment.getCompatibleVMs();
          for (int i = 0; i < compatibleVMs.length; i++)
          {
            IVMInstall vm = compatibleVMs[i];
            Set EEs = (Set)VMsToEEs.get(vm);
            if (EEs == null)
            {
              EEs = new HashSet();
              VMsToEEs.put(vm, EEs);
            }
            EEs.add(ee);
          }
        }
      }
      iterator = VMsToEEs.entrySet().iterator();
      IVMInstall bestFit = null;
      int bestCount = 0;
      while (iterator.hasNext())
      {
        Map.Entry entry = (Map.Entry)iterator.next();
        Set EEs = (Set)entry.getValue();
        if (EEs.size() > bestCount)
        {
          bestCount = EEs.size();
          bestFit = (IVMInstall)entry.getKey();
        }
      }
      String systemEE = null;
      if (bestFit != null)
      {
        IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
        for (int i = 0; i < environments.length; i++)
        {
          IExecutionEnvironment environment = environments[i];
          if (environment.isStrictlyCompatible(bestFit))
          {
            systemEE = environment.getId();
            break;
          }
        }
        if (systemEE == null) {
          if ((bestFit instanceof IVMInstall2))
          {
            String javaVersion = ((IVMInstall2)bestFit).getJavaVersion();
            if ((javaVersion != null) && 
              (javaVersion.startsWith("1.7"))) {
              systemEE = "JavaSE-1.6";
            }
          }
        }
        if (systemEE != null)
        {
          if ((!systemEE.equals(getExecutionEnvironment())) || (fVMBinding == null)) {
            try
            {
              File file = Util.createEEFile(bestFit, systemEE);
              JavaRuntime.addVMInstallChangedListener(this);
              fVMBinding = bestFit;
              ExecutionEnvironmentDescription ee = new ExecutionEnvironmentDescription(file);
              initialize(ee);
            }
            catch (CoreException e)
            {
              error = new Status(4, "org.eclipse.pde.api.tools", CoreMessages.ApiBaseline_2, e);
            }
            catch (IOException e)
            {
              error = new Status(4, "org.eclipse.pde.api.tools", CoreMessages.ApiBaseline_2, e);
            }
          }
        }
        else {
          error = new Status(4, "org.eclipse.pde.api.tools", CoreMessages.ApiBaseline_3);
        }
      }
      else
      {
        error = new Status(4, "org.eclipse.pde.api.tools", CoreMessages.ApiBaseline_3);
      }
      if (error == null)
      {
        Set missing = new HashSet(ees);
        Set covered = new HashSet((Set)VMsToEEs.get(bestFit));
        missing.removeAll(covered);
        if (missing.isEmpty())
        {
          fEEStatus = new Status(0, "org.eclipse.pde.api.tools", 
            MessageFormat.format(CoreMessages.ApiBaseline_1, new String[] { systemEE }));
        }
        else
        {
          iterator = missing.iterator();
          MultiStatus multi = new MultiStatus("org.eclipse.pde.api.tools", 0, CoreMessages.ApiBaseline_4, null);
          while (iterator.hasNext())
          {
            String id = (String)iterator.next();
            multi.add(new Status(2, "org.eclipse.pde.api.tools", 
              MessageFormat.format(CoreMessages.ApiBaseline_5, new String[] { id })));
          }
          fEEStatus = multi;
        }
      }
      else
      {
        fEEStatus = error;
      }
    }
  }
  
  public boolean peekInfos()
  {
    return fComponentsById != null;
  }
  
  public IApiComponent[] getApiComponents()
  {
    loadBaselineInfos();
    if (fComponentsById == null) {
      return EMPTY_COMPONENTS;
    }
    Collection values = fComponentsById.values();
    return (IApiComponent[])values.toArray(new IApiComponent[values.size()]);
  }
  
  public synchronized IApiComponent[] resolvePackage(IApiComponent sourceComponent, String packageName)
    throws CoreException
  {
    HashMap componentsForPackage = null;
    if (fComponentsProvidingPackageCache != null) {
      componentsForPackage = (HashMap)fComponentsProvidingPackageCache.get(packageName);
    } else {
      fComponentsProvidingPackageCache = new HashMap(8);
    }
    IApiComponent[] cachedComponents = (IApiComponent[])null;
    if (componentsForPackage != null)
    {
      cachedComponents = (IApiComponent[])componentsForPackage.get(sourceComponent);
      if ((cachedComponents != null) && (cachedComponents.length > 0)) {
        return cachedComponents;
      }
    }
    else
    {
      componentsForPackage = new HashMap(8);
      fComponentsProvidingPackageCache.put(packageName, componentsForPackage);
    }
    if (isSystemPackage(packageName))
    {
      if (fSystemLibraryComponent != null) {
        cachedComponents = new IApiComponent[] { fSystemLibraryComponent };
      } else {
        return EMPTY_COMPONENTS;
      }
    }
    else if (sourceComponent != null)
    {
      List componentsList = new ArrayList();
      resolvePackage0(sourceComponent, packageName, componentsList);
      if (componentsList.size() != 0)
      {
        cachedComponents = new IApiComponent[componentsList.size()];
        componentsList.toArray(cachedComponents);
      }
    }
    if (cachedComponents == null) {
      cachedComponents = EMPTY_COMPONENTS;
    }
    if (cachedComponents.length == 0) {
      return EMPTY_COMPONENTS;
    }
    componentsForPackage.put(sourceComponent, cachedComponents);
    return cachedComponents;
  }
  
  private void resolvePackage0(IApiComponent component, String packageName, List componentsList)
    throws CoreException
  {
    if ((component instanceof BundleComponent))
    {
      BundleDescription bundle = ((BundleComponent)component).getBundleDescription();
      if (bundle != null)
      {
        StateHelper helper = getState().getStateHelper();
        ExportPackageDescription[] visiblePackages = helper.getVisiblePackages(bundle);
        int i = 0;
        for (int max = visiblePackages.length; i < max; i++)
        {
          ExportPackageDescription pkg = visiblePackages[i];
          if (packageName.equals(pkg.getName()))
          {
            BundleDescription bundleDescription = pkg.getExporter();
            IApiComponent exporter = getApiComponent(bundleDescription.getSymbolicName());
            if (exporter != null) {
              componentsList.add(exporter);
            }
          }
        }
        if (component.isFragment())
        {
          HostSpecification host = bundle.getHost();
          BundleDescription[] hosts = host.getHosts();
          int i = 0;
          for (int max = hosts.length; i < max; i++)
          {
            BundleDescription currentHost = hosts[i];
            IApiComponent apiComponent = component.getBaseline().getApiComponent(currentHost.getName());
            if (apiComponent != null) {
              resolvePackage0(apiComponent, packageName, componentsList);
            }
          }
        }
        String[] packageNames = component.getPackageNames();
        int index = Arrays.binarySearch(packageNames, packageName, null);
        if (index >= 0) {
          componentsList.add(component);
        }
      }
    }
  }
  
  public IApiComponent[] getVisibleDependentComponents(IApiComponent[] components)
    throws CoreException
  {
    ArrayList bundles = getBundleDescriptions(components);
    BundleDescription[] descs = getState().getStateHelper().getDependentBundles((BundleDescription[])bundles.toArray(new BundleDescription[bundles.size()]));
    HashSet visible = new HashSet();
    ExportPackageDescription[] packages = (ExportPackageDescription[])null;
    for (int i = 0; i < descs.length; i++)
    {
      packages = getState().getStateHelper().getVisiblePackages(descs[i]);
      for (int j = 0; j < packages.length; j++) {
        if (bundles.contains(packages[j].getSupplier())) {
          visible.add(descs[i]);
        }
      }
    }
    return getApiComponents((BundleDescription[])visible.toArray(new BundleDescription[visible.size()]));
  }
  
  private boolean isSystemPackage(String packageName)
  {
    if (packageName.startsWith("java.")) {
      return true;
    }
    if (fSystemPackageNames == null)
    {
      ExportPackageDescription[] systemPackages = getState().getSystemPackages();
      fSystemPackageNames = new HashSet(systemPackages.length);
      for (int i = 0; i < systemPackages.length; i++) {
        fSystemPackageNames.add(systemPackages[i].getName());
      }
    }
    return fSystemPackageNames.contains(packageName);
  }
  
  public State getState()
  {
    if (fState == null) {
      fState = StateObjectFactory.defaultFactory.createState(true);
    }
    return fState;
  }
  
  public IApiComponent getApiComponent(String id)
  {
    loadBaselineInfos();
    if (fComponentsById == null) {
      return null;
    }
    return (IApiComponent)fComponentsById.get(id);
  }
  
  public String getExecutionEnvironment()
  {
    return fExecutionEnvironment;
  }
  
  private void loadBaselineInfos()
  {
    if (fComponentsById != null) {
      return;
    }
    try
    {
      ApiBaselineManager.getManager().loadBaselineInfos(this);
    }
    catch (CoreException ce)
    {
      ApiPlugin.log(ce);
    }
  }
  
  public ResolverError[] getErrors()
  {
    List errs = null;
    BundleDescription[] bundles = getState().getBundles();
    for (int i = 0; i < bundles.length; i++)
    {
      ResolverError[] errors = getState().getResolverErrors(bundles[i]);
      for (int j = 0; j < errors.length; j++)
      {
        if (errs == null) {
          errs = new ArrayList();
        }
        errs.add(errors[j]);
      }
    }
    if (errs != null) {
      return (ResolverError[])errs.toArray(new ResolverError[errs.size()]);
    }
    return null;
  }
  
  public void setName(String name)
  {
    super.setName(name);
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof IApiBaseline))
    {
      IApiBaseline baseline = (IApiBaseline)obj;
      return getName().equals(baseline.getName());
    }
    return super.equals(obj);
  }
  
  public int hashCode()
  {
    return getName().hashCode();
  }
  
  public void dispose()
  {
    if (fState == null) {
      return;
    }
    doDispose();
    fState = null;
  }
  
  protected void doDispose()
  {
    if (ApiPlugin.isRunningInFramework()) {
      JavaRuntime.removeVMInstallChangedListener(this);
    }
    clearCachedElements();
    IApiComponent[] components = getApiComponents();
    for (int i = 0; i < components.length; i++) {
      components[i].dispose();
    }
    clearComponentsCache();
    if (fComponentsById != null)
    {
      fComponentsById.clear();
      fComponentsById = null;
    }
    if (fComponentsByProjectNames != null)
    {
      fComponentsByProjectNames.clear();
      fComponentsByProjectNames = null;
    }
    if (fSystemPackageNames != null) {
      fSystemPackageNames.clear();
    }
    if (fSystemLibraryComponent != null)
    {
      fSystemLibraryComponent.dispose();
      fSystemLibraryComponent = null;
    }
  }
  
  public void close()
    throws CoreException
  {
    clearCachedElements();
    IApiComponent[] components = getApiComponents();
    for (int i = 0; i < components.length; i++) {
      components[i].close();
    }
  }
  
  void clearCachedElements()
  {
    ApiModelCache.getCache().removeElementInfo(this);
  }
  
  public IApiComponent[] getDependentComponents(IApiComponent[] components)
    throws CoreException
  {
    ArrayList bundles = getBundleDescriptions(components);
    BundleDescription[] bundleDescriptions = getState().getStateHelper().getDependentBundles((BundleDescription[])bundles.toArray(new BundleDescription[bundles.size()]));
    return getApiComponents(bundleDescriptions);
  }
  
  private IApiComponent[] getApiComponents(BundleDescription[] bundles)
  {
    ArrayList dependents = new ArrayList(bundles.length);
    for (int i = 0; i < bundles.length; i++)
    {
      BundleDescription bundle = bundles[i];
      IApiComponent component = getApiComponent(bundle.getSymbolicName());
      if (component != null) {
        dependents.add(component);
      }
    }
    return (IApiComponent[])dependents.toArray(new IApiComponent[dependents.size()]);
  }
  
  private ArrayList getBundleDescriptions(IApiComponent[] components)
    throws CoreException
  {
    ArrayList bundles = new ArrayList(components.length);
    for (int i = 0; i < components.length; i++)
    {
      IApiComponent component = components[i];
      if ((component instanceof BundleComponent)) {
        bundles.add(((BundleComponent)component).getBundleDescription());
      }
    }
    return bundles;
  }
  
  public IApiComponent[] getPrerequisiteComponents(IApiComponent[] components)
    throws CoreException
  {
    ArrayList bundles = getBundleDescriptions(components);
    BundleDescription[] bundlesDescriptions = getState().getStateHelper().getPrerequisites((BundleDescription[])bundles.toArray(new BundleDescription[bundles.size()]));
    return getApiComponents(bundlesDescriptions);
  }
  
  public synchronized void clearPackage(String packageName)
  {
    if (fComponentsProvidingPackageCache != null) {
      fComponentsProvidingPackageCache.remove(packageName);
    }
  }
  
  public String toString()
  {
    return getName();
  }
  
  public IStatus getExecutionEnvironmentStatus()
  {
    return fEEStatus;
  }
  
  public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {}
  
  public void vmAdded(IVMInstall vm)
  {
    if (!(vm instanceof VMStandin)) {
      try
      {
        rebindVM();
      }
      catch (CoreException e)
      {
        ApiPlugin.log(e);
      }
    }
  }
  
  public void vmChanged(PropertyChangeEvent event)
  {
    if (!(event.getSource() instanceof VMStandin))
    {
      String property = event.getProperty();
      if ((IVMInstallChangedListener.PROPERTY_INSTALL_LOCATION.equals(property)) || 
        (IVMInstallChangedListener.PROPERTY_LIBRARY_LOCATIONS.equals(property))) {
        try
        {
          rebindVM();
        }
        catch (CoreException e)
        {
          ApiPlugin.log(e);
        }
      }
    }
  }
  
  private void rebindVM()
    throws CoreException
  {
    fVMBinding = null;
    IApiComponent[] components = getApiComponents();
    HashSet ees = new HashSet();
    for (int i = 0; i < components.length; i++) {
      ees.addAll(Arrays.asList(components[i].getExecutionEnvironments()));
    }
    resolveSystemLibrary(ees);
  }
  
  public void vmRemoved(IVMInstall vm)
  {
    if (vm.equals(fVMBinding)) {
      try
      {
        rebindVM();
      }
      catch (CoreException e)
      {
        ApiPlugin.log(e);
      }
    }
  }
  
  public String getLocation()
  {
    return fLocation;
  }
  
  public void setLocation(String location)
  {
    fLocation = location;
  }
  
  public IApiComponent getApiComponent(IProject project)
  {
    loadBaselineInfos();
    if (fComponentsByProjectNames == null) {
      return null;
    }
    return (IApiComponent)fComponentsByProjectNames.get(project.getName());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.model.ApiBaseline
 * Java C
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

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