org.eclipse.pde.core_3.7.1.v20120103_r372

Set();
    IQueryResult queryResult = fSynchronizer.getProfile().query(QueryUtil.createIUAnyQuery(), null);
    if (queryResult.isEmpty()) {
      return new IFeatureModel[0];
    }
    for (Iterator i = queryResult.iterator(); i.hasNext();)
    {
      IInstallableUnit unit = (IInstallableUnit)i.next();
      String id = unit.getId();
      if (id.endsWith(".feature.group"))
      {
        id = id.substring(0, id.length() - ".feature.group".length());
        String version = unit.getVersion().toString();
        features.add(new NameVersionDescriptor(id, version, "feature"));
      }
    }
    if (features.isEmpty()) {
      return new IFeatureModel[0];
    }
    IFeatureModel[] allFeatures = ((TargetDefinition)target).getFeatureModels(getLocation(false), new NullProgressMonitor());
    
    List result = new ArrayList();
    for (int i = 0; i < allFeatures.length; i++)
    {
      NameVersionDescriptor candidate = new NameVersionDescriptor(allFeatures[i].getFeature().getId(), allFeatures[i].getFeature().getVersion(), "feature");
      if (features.contains(candidate)) {
        result.add(allFeatures[i]);
      }
    }
    fFeatures = ((IFeatureModel[])result.toArray(new IFeatureModel[result.size()]));
    return fFeatures;
  }
  
  protected IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor)
    throws CoreException
  {
    fSynchronizer.synchronize(definition, monitor);
    return fBundles;
  }
  
  IInstallableUnit[] cacheIUs(ITargetDefinition target)
    throws CoreException
  {
    IProfile profile = fSynchronizer.getProfile();
    ArrayList result = new ArrayList();
    for (int i = 0; i < fIds.length; i++)
    {
      IQuery query = QueryUtil.createIUQuery(fIds[i], fVersions[i]);
      IQueryResult queryResult = profile.query(query, null);
      if (queryResult.isEmpty()) {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.IUBundleContainer_1, fIds[i])));
      }
      result.add(queryResult.iterator().next());
    }
    fUnits = ((IInstallableUnit[])result.toArray(new IInstallableUnit[result.size()]));
    return fUnits;
  }
  
  IResolvedBundle[] cacheBundles(ITargetDefinition target)
    throws CoreException
  {
    boolean onlyStrict = !fSynchronizer.getIncludeAllRequired();
    IProfile metadata = fSynchronizer.getProfile();
    PermissiveSlicer slicer = new PermissiveSlicer(metadata, new HashMap(), true, false, true, onlyStrict, false);
    IQueryable slice = slicer.slice(fUnits, new NullProgressMonitor());
    if (slicer.getStatus().getSeverity() == 4) {
      throw new CoreException(slicer.getStatus());
    }
    IFileArtifactRepository artifacts = null;
    try
    {
      artifacts = P2TargetUtils.getBundlePool();
    }
    catch (CoreException localCoreException)
    {
      if (DEBUG_PROFILE) {
        System.out.println("Bundle pool repository could not be loaded");
      }
      return fBundles = null;
    }
    Map bundles = generateResolvedBundles(slice, metadata, artifacts);
    if (bundles.isEmpty())
    {
      if (DEBUG_PROFILE) {
        System.out.println("Profile does not contain any bundles or artifacts were missing");
      }
      if (slicer.getStatus().getSeverity() == 2) {
        throw new CoreException(slicer.getStatus());
      }
      return fBundles = null;
    }
    fBundles = ((ResolvedBundle[])bundles.values().toArray(new ResolvedBundle[bundles.size()]));
    return fBundles;
  }
  
  void synchronizerChanged(ITargetDefinition target)
    throws CoreException
  {
    cacheIUs(target);
    cacheBundles(target);
    cacheFeatures(target);
  }
  
  public synchronized int update(Set toUpdate, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    IQueryable source = P2TargetUtils.getQueryableMetadata(fRepos, progress.newChild(30));
    int dirty = 0;
    int updated = 0;
    SubMonitor loopProgress = progress.newChild(70).setWorkRemaining(fIds.length);
    for (int i = 0; i < fIds.length; i++) {
      if ((toUpdate.isEmpty()) || (toUpdate.contains(fIds[i])))
      {
        IQuery query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery(fIds[i]));
        IQueryResult queryResult = source.query(query, loopProgress.newChild(1));
        Iterator it = queryResult.iterator();
        if (!it.hasNext()) {
          throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.IUBundleContainer_1, fIds[i])));
        }
        IInstallableUnit iu = (IInstallableUnit)it.next();
        if (!iu.getVersion().equals(fVersions[i]))
        {
          updated = 2;
          if (!fVersions[i].equals(Version.emptyVersion))
          {
            fVersions[i] = iu.getVersion();
            dirty = 4;
          }
        }
      }
    }
    if (updated == 2) {
      clearResolutionStatus();
    }
    return dirty | updated;
  }
  
  protected void clearResolutionStatus()
  {
    super.clearResolutionStatus();
    fSynchronizer.markDirty();
  }
  
  private Map generateResolvedBundles(IQueryable source, IQueryable metadata, IFileArtifactRepository artifacts)
    throws CoreException
  {
    OSGiBundleQuery query = new OSGiBundleQuery();
    IQueryResult queryResult = source.query(query, null);
    Map bundles = new LinkedHashMap();
    for (Iterator i = queryResult.iterator(); i.hasNext();)
    {
      IInstallableUnit unit = (IInstallableUnit)i.next();
      generateBundle(unit, artifacts, bundles);
      if (getIncludeSource())
      {
        IQuery sourceQuery = QueryUtil.createIUQuery(unit.getId() + ".source", unit.getVersion());
        IQueryResult result = metadata.query(sourceQuery, null);
        if (!result.isEmpty()) {
          generateBundle((IInstallableUnit)result.iterator().next(), artifacts, bundles);
        }
      }
    }
    return bundles;
  }
  
  private void generateBundle(IInstallableUnit unit, IFileArtifactRepository repo, Map bundles)
    throws CoreException
  {
    Collection artifacts = unit.getArtifacts();
    for (Iterator iterator2 = artifacts.iterator(); iterator2.hasNext();)
    {
      File file = repo.getArtifactFile((IArtifactKey)iterator2.next());
      if (file != null)
      {
        IResolvedBundle bundle = generateBundle(file);
        if (bundle != null) {
          bundles.put(bundle.getBundleInfo(), bundle);
        }
      }
    }
  }
  
  public boolean isContentEqual(AbstractBundleContainer container)
  {
    if ((container instanceof IUBundleContainer))
    {
      IUBundleContainer iuContainer = (IUBundleContainer)container;
      boolean result = true;
      result &= iuContainer.getIncludeAllRequired() == getIncludeAllRequired();
      result &= iuContainer.getIncludeAllEnvironments() == getIncludeAllEnvironments();
      result &= iuContainer.getIncludeSource() == getIncludeSource();
      return (result) && (isEqualOrNull(fIds, fIds)) && (isEqualOrNull(fVersions, fVersions)) && (isEqualOrNull(fRepos, fRepos));
    }
    return false;
  }
  
  private boolean isEqualOrNull(Object[] objects1, Object[] objects2)
  {
    if (objects1 == null) {
      return objects2 == null;
    }
    if (objects2 == null) {
      return false;
    }
    if (objects1.length == objects2.length)
    {
      for (int i = 0; i < objects1.length; i++) {
        if (!objects1[i].equals(objects2[i])) {
          return false;
        }
      }
      return true;
    }
    return false;
  }
  
  public URI[] getRepositories()
  {
    return fRepos;
  }
  
  public synchronized void removeInstallableUnit(IInstallableUnit unit)
  {
    List newIds = new ArrayList(fIds.length);
    List newVersions = new ArrayList(fIds.length);
    for (int i = 0; i < fIds.length; i++) {
      if ((!fIds[i].equals(unit.getId())) || (!fVersions[i].equals(unit.getVersion())))
      {
        newIds.add(fIds[i]);
        newVersions.add(fVersions[i]);
      }
    }
    fIds = ((String[])newIds.toArray(new String[newIds.size()]));
    fVersions = ((Version[])newVersions.toArray(new Version[newVersions.size()]));
    
    clearResolutionStatus();
  }
  
  public boolean getIncludeAllRequired()
  {
    if (fSynchronizer == null) {
      return (fFlags & 0x1) == 1;
    }
    return fSynchronizer.getIncludeAllRequired();
  }
  
  public boolean getIncludeAllEnvironments()
  {
    if (fSynchronizer == null) {
      return (fFlags & 0x2) == 2;
    }
    return fSynchronizer.getIncludeAllEnvironments();
  }
  
  public boolean getIncludeSource()
  {
    if (fSynchronizer == null) {
      return (fFlags & 0x4) == 4;
    }
    return fSynchronizer.getIncludeSource();
  }
  
  public IInstallableUnit[] getInstallableUnits()
    throws CoreException
  {
    if (fUnits == null) {
      return new IInstallableUnit[0];
    }
    return fUnits;
  }
  
  String[] getIds()
  {
    return fIds;
  }
  
  Version[] getVersions()
  {
    return fVersions;
  }
  
  P2TargetUtils getSynchronizer(ITargetDefinition definition)
  {
    if (fSynchronizer != null) {
      return fSynchronizer;
    }
    if (definition == null) {
      return null;
    }
    return fSynchronizer = P2TargetUtils.getSynchronizer(definition);
  }
  
  void setSynchronizer(P2TargetUtils value)
  {
    fSynchronizer = value;
  }
  
  protected void associateWithTarget(ITargetDefinition target)
  {
    super.associateWithTarget(target);
    fSynchronizer = getSynchronizer(target);
    
    fSynchronizer.markDirty();
    fSynchronizer.setIncludeAllRequired((fFlags & 0x1) == 1);
    fSynchronizer.setIncludeAllEnvironments((fFlags & 0x2) == 2);
    fSynchronizer.setIncludeSource((fFlags & 0x4) == 4);
  }
}

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

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetHandle;

public class LocalTargetHandle
  extends AbstractTargetHandle
{
  private long fTimeStamp;
  private static long fgLastStamp = -1L;
  static final String SCHEME = "local";
  static final IPath LOCAL_TARGET_CONTAINER_PATH = PDECore.getDefault().getStateLocation().append(".local_targets");
  
  static synchronized long nextTimeStamp()
  {
    long stamp = System.currentTimeMillis();
    if (stamp == fgLastStamp) {
      stamp += 1L;
    }
    fgLastStamp = stamp;
    return stamp;
  }
  
  static ITargetHandle restoreHandle(URI uri)
    throws CoreException
  {
    String part = uri.getSchemeSpecificPart();
    try
    {
      Path path = new Path(part);
      String name = path.lastSegment();
      if (name.endsWith("target"))
      {
        String lng = name.substring(0, name.length() - "target".length() - 1);
        long stamp = Long.parseLong(lng);
        return new LocalTargetHandle(stamp);
      }
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_0, null));
    }
    catch (NumberFormatException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_0, e));
    }
  }
  
  LocalTargetHandle()
  {
    fTimeStamp = nextTimeStamp();
  }
  
  private LocalTargetHandle(long stamp)
  {
    fTimeStamp = stamp;
  }
  
  protected InputStream getInputStream()
    throws CoreException
  {
    try
    {
      return new BufferedInputStream(new FileInputStream(getFile()));
    }
    catch (FileNotFoundException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_1, e));
    }
  }
  
  public String getMemento()
    throws CoreException
  {
    try
    {
      URI uri = new URI("local", getFile().getName(), null);
      return uri.toString();
    }
    catch (URISyntaxException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_2, e));
    }
  }
  
  public boolean exists()
  {
    return getFile().exists();
  }
  
  private File getFile()
  {
    StringBuffer name = new StringBuffer();
    name.append(Long.toString(fTimeStamp));
    name.append('.');
    name.append("target");
    return LOCAL_TARGET_CONTAINER_PATH.append(name.toString()).toFile();
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof LocalTargetHandle))
    {
      LocalTargetHandle handle = (LocalTargetHandle)obj;
      return fTimeStamp == fTimeStamp;
    }
    return false;
  }
  
  public int hashCode()
  {
    return (int)fTimeStamp;
  }
  
  void delete()
    throws CoreException
  {
    File file = getFile();
    if (file.exists())
    {
      file.delete();
      if (file.exists()) {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.LocalTargetHandle_3, file.getName())));
      }
    }
    P2TargetUtils.deleteProfile(this);
  }
  
  protected OutputStream getOutputStream()
    throws CoreException
  {
    try
    {
      File file = getFile();
      if (!file.exists())
      {
        file.getParentFile().mkdirs();
        file.createNewFile();
      }
      return new BufferedOutputStream(new FileOutputStream(file));
    }
    catch (FileNotFoundException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_1, e));
    }
    catch (IOException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.LocalTargetHandle_5, e));
    }
  }
  
  void save(ITargetDefinition definition)
    throws CoreException
  {
    OutputStream stream = getOutputStream();
    ((TargetDefinition)definition).write(stream);
    try
    {
      stream.close();
    }
    catch (IOException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.LocalTargetHandle_4, getFile().getName()), e));
    }
  }
  
  public String toString()
  {
    return getFile().getName();
  }
}

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

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.pde.internal.core.target.Messages";
  public static String AbstractBundleContainer_1;
  public static String AbstractBundleContainer_2;
  public static String AbstractBundleContainer_3;
  public static String AbstractBundleContainer_4;
  public static String AbstractTargetHandle_0;
  public static String DirectoryBundleContainer_0;
  public static String DirectoryBundleContainer_1;
  public static String DirectoryBundleContainer_2;
  public static String DirectoryBundleContainer_3;
  public static String FeatureBundleContainer_0;
  public static String FeatureBundleContainer_1;
  public static String FeatureBundleContainer_2;
  public static String FeatureBundleContainer_4;
  public static String FeatureBundleContainer_5;
  public static String IUBundleContainer_0;
  public static String IUBundleContainer_1;
  public static String IUBundleContainer_10;
  public static String IUBundleContainer_11;
  public static String IUBundleContainer_2;
  public static String IUBundleContainer_3;
  public static String IUBundleContainer_4;
  public static String IUBundleContainer_5;
  public static String IUBundleContainer_6;
  public static String IUBundleContainer_7;
  public static String IUBundleContainer_8;
  public static String IUBundleContainer_9;
  public static String IUBundleContainer_LoadingFromProfileJob;
  public static String IUBundleContainer_NoBundlePool;
  public static String IUBundleContainer_ProblemsLoadingRepositories;
  public static String IUBundleContainer_ProvisioningSourceBundles;
  public static String LoadTargetDefinitionJob_0;
  public static String LoadTargetDefinitionJob_1;
  public static String LoadTargetOperation_argsTaskName;
  public static String LoadTargetOperation_envTaskName;
  public static String LoadTargetOperation_implicitPluginsTaskName;
  public static String LoadTargetOperation_jreTaskName;
  public static String LoadTargetOperation_loadPluginsTaskName;
  public static String LoadTargetOperation_mainTaskName;
  public static String LoadTargetOperation_reloadTaskName;
  public static String LocalTargetHandle_0;
  public static String LocalTargetHandle_1;
  public static String LocalTargetHandle_2;
  public static String LocalTargetHandle_3;
  public static String LocalTargetHandle_4;
  public static String LocalTargetHandle_5;
  public static String P2TargetUtils_ProvisioningSourceTask;
  public static String ProfileBundleContainer_0;
  public static String ProfileBundleContainer_1;
  public static String ProfileBundleContainer_2;
  public static String TargetDefinition_0;
  public static String TargetDefinition_1;
  public static String TargetDefinition_2;
  public static String TargetDefinition_3;
  public static String TargetDefinition_4;
  public static String TargetDefinition_5;
  public static String TargetDefinition_RequiredFeatureCouldNotBeFound;
  public static String TargetDefinitionPersistenceHelper_0;
  public static String TargetDefinitionPersistenceHelper_1;
  public static String TargetPlatformService_0;
  public static String TargetPlatformService_1;
  public static String TargetPlatformService_2;
  public static String TargetPlatformService_3;
  public static String TargetPlatformService_4;
  public static String TargetPlatformService_5;
  public static String TargetPlatformService_7;
  public static String UpdateTargetJob_UpdateJobName;
  public static String UpdateTargetJob_UpdatingContainer;
  public static String UpdateTargetJob_UpdatingTarget;
  public static String WorkspaceFileTargetHandle_0;
  
  static
  {
    NLS.initializeMessages("org.eclipse.pde.internal.core.target.Messages", Messages.class);
  }
}

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

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public class P2TargetUtils$CollectNativesAction
  extends ProvisioningAction
{
  public IStatus execute(Map parameters)
  {
    InstallableUnitOperand operand = (InstallableUnitOperand)parameters.get("operand");
    IInstallableUnit installableUnit = operand.second();
    if (installableUnit == null) {
      return Status.OK_STATUS;
    }
    try
    {
      Collection toDownload = installableUnit.getArtifacts();
      if (toDownload == null) {
        return Status.OK_STATUS;
      }
      List artifactRequests = (List)parameters.get("nativeArtifacts");
      IArtifactRepository destinationArtifactRepository = P2TargetUtils.getBundlePool();
      IArtifactRepositoryManager manager = P2TargetUtils.getArtifactRepositoryManager();
      for (Iterator i = toDownload.iterator(); i.hasNext();)
      {
        IArtifactKey keyToDownload = (IArtifactKey)i.next();
        IArtifactRequest request = manager.createMirrorRequest(keyToDownload, destinationArtifactRepository, null, null);
        artifactRequests.add(request);
      }
    }
    catch (CoreException e)
    {
      return e.getStatus();
    }
    IArtifactRepositoryManager manager;
    return Status.OK_STATUS;
  }
  
  public IStatus undo(Map parameters)
  {
    return Status.OK_STATUS;
  }
}

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.engine.DownloadManager;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.ITouchpointType;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;

public class P2TargetUtils$CollectNativesPhase
  extends InstallableUnitPhase
{
  public P2TargetUtils$CollectNativesPhase(int weight)
  {
    super("nativeArtifacts", weight);
  }
  
  protected List getActions(InstallableUnitOperand operand)
  {
    IInstallableUnit unit = operand.second();
    if ((unit != null) && (unit.getTouchpointType().getId().equals("org.eclipse.equinox.p2.native"))) {
      return Collections.singletonList(new P2TargetUtils.CollectNativesAction());
    }
    return null;
  }
  
  protected IStatus initializePhase(IProgressMonitor monitor, IProfile profile, Map parameters)
  {
    parameters.put("nativeArtifacts", new ArrayList());
    parameters.put("profile", profile);
    return null;
  }
  
  protected IStatus completePhase(IProgressMonitor monitor, IProfile profile, Map parameters)
  {
    List artifactRequests = (List)parameters.get("nativeArtifacts");
    ProvisioningContext context = (ProvisioningContext)parameters.get("context");
    IProvisioningAgent agent = (IProvisioningAgent)parameters.get("agent");
    DownloadManager dm = new DownloadManager(context, agent);
    for (Iterator i = artifactRequests.iterator(); i.hasNext();) {
      dm.add((IArtifactRequest)i.next());
    }
    return dm.start(monitor);
  }
}

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

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.engine.DownloadManager;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitOperand;
import org.eclipse.equinox.internal.p2.engine.InstallableUnitPhase;
import org.eclipse.equinox.internal.p2.engine.Phase;
import org.eclipse.equinox.internal.p2.engine.PhaseSet;
import org.eclipse.equinox.internal.p2.engine.ProfileMetadataRepository;
import org.eclipse.equinox.internal.p2.engine.phases.Collect;
import org.eclipse.equinox.internal.p2.engine.phases.Install;
import org.eclipse.equinox.internal.p2.engine.phases.Property;
import org.eclipse.equinox.internal.p2.engine.phases.Uninstall;
import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector;
import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IPhaseSet;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
import org.eclipse.equinox.p2.engine.PhaseSetFactory;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery;
import org.eclipse.equinox.p2.engine.spi.ProvisioningAction;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IProvidedCapability;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.ITouchpointType;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRequest;
import org.eclipse.equinox.p2.repository.artifact.IFileArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.target.provisional.IBundleContainer;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;
import org.eclipse.pde.internal.core.target.provisional.ITargetHandle;
import org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService;
import org.eclipse.pde.internal.core.target.provisional.NameVersionDescriptor;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

public class P2TargetUtils
{
  private static final String SOURCE_IU_ID = "org.eclipse.pde.core.target.source.bundles";
  public static URI AGENT_LOCATION;
  
  static
  {
    try
    {
      AGENT_LOCATION = URIUtil.fromString("file:" + PDECore.getDefault().getStateLocation().append(".p2"));
    }
    catch (Exception localException) {}
  }
  
  public static final IPath BUNDLE_POOL = PDECore.getDefault().getStateLocation().append(".bundle_pool");
  static final IPath INSTALL_FOLDERS = PDECore.getDefault().getStateLocation().append(".install_folders");
  static final String PROFILE_ID_PREFIX = "TARGET_DEFINITION:";
  static final String PROP_INSTALLED_IU = "org.eclipse.pde.core.installed_iu";
  static final String PROP_PROVISION_MODE = "org.eclipse.pde.core.provision_mode";
  static final String PROP_ALL_ENVIRONMENTS = "org.eclipse.pde.core.all_environments";
  static final String PROP_SEQUENCE_NUMBER = "org.eclipse.pde.core.sequence";
  static final String PROP_AUTO_INCLUDE_SOURCE = "org.eclipse.pde.core.autoIncludeSource";
  private static Map synchronizers = new HashMap();
  private IProfile fProfile;
  private boolean fIncludeAllRequired = true;
  private boolean fIncludeMultipleEnvironments = false;
  private boolean fIncludeSource = false;
  private boolean fDirty = false;
  private static final String NATIVE_ARTIFACTS = "nativeArtifacts";
  private static final String NATIVE_TYPE = "org.eclipse.equinox.p2.native";
  private static final String PARM_OPERAND = "operand";
  
  public P2TargetUtils(ITargetDefinition target)
  {
    try
    {
      synchronizers.put(target.getHandle().getMemento(), this);
    }
    catch (CoreException localCoreException) {}
  }
  
  public static List cleanOrphanedTargetDefinitionProfiles()
    throws CoreException
  {
    List list = new ArrayList();
    IProfileRegistry registry = getProfileRegistry();
    ITargetPlatformService tps = (ITargetPlatformService)PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
    if ((registry != null) && (tps != null))
    {
      IProfile[] profiles = registry.getProfiles();
      for (int i = 0; i < profiles.length; i++)
      {
        IProfile profile = profiles[i];
        String id = profile.getProfileId();
        if (id.startsWith("TARGET_DEFINITION:"))
        {
          String memento = id.substring("TARGET_DEFINITION:".length());
          ITargetHandle handle = tps.getTarget(memento);
          if (!handle.exists())
          {
            deleteProfile(handle);
            list.add(id);
          }
        }
      }
    }
    return list;
  }
  
  private static void delete(File folder)
  {
    File[] files = folder.listFiles();
    for (int i = 0; i < files.length; i++)
    {
      File file = files[i];
      if (file.isDirectory()) {
        delete(file);
      }
      file.delete();
    }
    folder.delete();
  }
  
  public static void deleteProfile(ITargetHandle handle)
    throws CoreException
  {
    IProfileRegistry registry = getProfileRegistry();
    if (registry != null)
    {
      IProfile profile = registry.getProfile(getProfileId(handle));
      if (profile != null)
      {
        String location = profile.getProperty("org.eclipse.equinox.p2.installFolder");
        registry.removeProfile(getProfileId(handle));
        if ((location != null) && (location.length() > 0))
        {
          File folder = new File(location);
          if (folder.exists()) {
            delete(folder);
          }
        }
      }
    }
  }
  
  public static void garbageCollect()
  {
    try
    {
      IProfile[] profiles = getProfileRegistry().getProfiles();
      for (int i = 0; i < profiles.length; i++) {
        if (profiles[i].getProfileId().startsWith("TARGET_DEFINITION:")) {
          getGarbageCollector().runGC(profiles[i]);
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private String generateEnvironmentProperties(ITargetDefinition target)
  {
    StringBuffer env = new StringBuffer();
    String ws = target.getWS();
    if (ws == null) {
      ws = Platform.getWS();
    }
    env.append("osgi.ws=");
    env.append(ws);
    env.append(",");
    String os = target.getOS();
    if (os == null) {
      os = Platform.getOS();
    }
    env.append("osgi.os=");
    env.append(os);
    env.append(",");
    String arch = target.getArch();
    if (arch == null) {
      arch = Platform.getOSArch();
    }
    env.append("osgi.arch=");
    env.append(arch);
    return env.toString();
  }
  
  private String generateNLProperty(ITargetDefinition target)
  {
    String nl = target.getNL();
    if (nl == null) {
      nl = Platform.getNL();
    }
    return nl;
  }
  
  public static IProvisioningAgent getAgent()
    throws CoreException
  {
    String filter = "(locationURI=" + String.valueOf(AGENT_LOCATION) + ")";
    ServiceReference[] serviceReferences = (ServiceReference[])null;
    BundleContext context = PDECore.getDefault().getBundleContext();
    try
    {
      serviceReferences = context.getServiceReferences(IProvisioningAgent.SERVICE_NAME, filter);
      if (serviceReferences != null) {
        return (IProvisioningAgent)context.getService(serviceReferences[0]);
      }
    }
    catch (InvalidSyntaxException localInvalidSyntaxException) {}finally
    {
      if (serviceReferences != null) {
        context.ungetService(serviceReferences[0]);
      }
    }
    if (serviceReferences != null) {
      context.ungetService(serviceReferences[0]);
    }
    IProvisioningAgentProvider provider = (IProvisioningAgentProvider)PDECore.getDefault().acquireService(IProvisioningAgentProvider.SERVICE_NAME);
    try
    {
      if (provider == null) {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_7));
      }
      IProvisioningAgent agent = provider.createAgent(AGENT_LOCATION);
      if (agent == null) {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_7));
      }
      GarbageCollector garbageCollector = (GarbageCollector)agent.getService(GarbageCollector.class.getName());
      if (garbageCollector != null) {
        garbageCollector.stop();
      }
      return agent;
    }
    catch (ProvisionException e)
    {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_7, e));
    }
  }
  
  public static IProvisioningAgent getGlobalAgent()
    throws CoreException
  {
    IProvisioningAgent agent = (IProvisioningAgent)PDECore.getDefault().acquireService(IProvisioningAgent.SERVICE_NAME);
    if (agent == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_11));
    }
    return agent;
  }
  
  public static IAgentLocation getAgentLocation()
    throws CoreException
  {
    IAgentLocation result = (IAgentLocation)getAgent().getService(IAgentLocation.SERVICE_NAME);
    if (result == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_10));
    }
    return result;
  }
  
  public static IArtifactRepositoryManager getArtifactRepositoryManager()
    throws CoreException
  {
    IArtifactRepositoryManager manager = (IArtifactRepositoryManager)getAgent().getService(IArtifactRepositoryManager.class.getName());
    if (manager == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_3));
    }
    return manager;
  }
  
  public static IFileArtifactRepository getBundlePool()
    throws CoreException
  {
    URI uri = BUNDLE_POOL.toFile().toURI();
    IArtifactRepositoryManager manager = getArtifactRepositoryManager();
    try
    {
      if (manager.contains(uri)) {
        return (IFileArtifactRepository)manager.loadRepository(uri, null);
      }
    }
    catch (CoreException localCoreException)
    {
      String repoName = "PDE Target Bundle Pool";
      IArtifactRepository result = manager.createRepository(uri, repoName, "org.eclipse.equinox.p2.artifact.repository.simpleRepository", null);
      return (IFileArtifactRepository)result;
    }
  }
  
  public static IEngine getEngine()
    throws CoreException
  {
    IEngine engine = (IEngine)getAgent().getService(IEngine.class.getName());
    if (engine == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_4));
    }
    return engine;
  }
  
  public static GarbageCollector getGarbageCollector()
    throws CoreException
  {
    GarbageCollector engine = (GarbageCollector)getAgent().getService(GarbageCollector.class.getName());
    if (engine == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_9));
    }
    return engine;
  }
  
  public static IPlanner getPlanner()
    throws CoreException
  {
    IPlanner planner = (IPlanner)getAgent().getService(IPlanner.class.getName());
    if (planner == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_5));
    }
    return planner;
  }
  
  public static IPreferencesService getPreferences()
  {
    return (IPreferencesService)PDECore.getDefault().acquireService(IPreferencesService.class.getName());
  }
  
  private boolean checkProfile(ITargetDefinition target)
    throws CoreException
  {
    if (fProfile == null) {
      return false;
    }
    if (fDirty) {
      return false;
    }
    String profileNumber = fProfile.getProperty("org.eclipse.pde.core.sequence");
    if (Integer.toString(((TargetDefinition)target).getSequenceNumber()).equals(profileNumber)) {
      return true;
    }
    boolean all = false;
    String value = fProfile.getProperty("org.eclipse.pde.core.all_environments");
    if (value != null)
    {
      all = Boolean.valueOf(value).booleanValue();
      if (!Boolean.toString(getIncludeAllEnvironments()).equals(value)) {
        return false;
      }
    }
    String property = null;
    if (!all)
    {
      property = generateEnvironmentProperties(target);
      value = fProfile.getProperty("org.eclipse.equinox.p2.environments");
      if (!property.equals(value)) {
        return false;
      }
    }
    property = generateNLProperty(target);
    value = fProfile.getProperty("org.eclipse.equinox.p2.nl");
    if (!property.equals(value)) {
      return false;
    }
    if (!getProvisionMode(target).equals(fProfile.getProperty("org.eclipse.pde.core.provision_mode"))) {
      return false;
    }
    if (getIncludeSource() != Boolean.valueOf(fProfile.getProperty("org.eclipse.pde.core.autoIncludeSource")).booleanValue()) {
      return false;
    }
    IUProfilePropertyQuery propertyQuery = new IUProfilePropertyQuery("org.eclipse.pde.core.installed_iu", Boolean.toString(true));
    IQueryResult queryResult = fProfile.query(propertyQuery, null);
    Iterator iterator = queryResult.iterator();
    Set installedIUs = new HashSet();
    while (iterator.hasNext())
    {
      IInstallableUnit unit = (IInstallableUnit)iterator.next();
      installedIUs.add(new NameVersionDescriptor(unit.getId(), unit.getVersion().toString()));
    }
    IBundleContainer[] containers = target.getBundleContainers();
    if (containers == null) {
      return installedIUs.isEmpty();
    }
    for (int i = 0; i < containers.length; i++) {
      if ((containers[i] instanceof IUBundleContainer))
      {
        IUBundleContainer bc = (IUBundleContainer)containers[i];
        String[] ids = bc.getIds();
        Version[] versions = bc.getVersions();
        for (int j = 0; j < versions.length; j++) {
          if (!installedIUs.remove(new NameVersionDescriptor(ids[j], versions[j].toString()))) {
            return false;
          }
        }
      }
    }
    if (!installedIUs.isEmpty()) {
      return false;
    }
    return true;
  }
  
  public void setIncludeAllRequired(boolean value)
  {
    fIncludeAllRequired = value;
  }
  
  public boolean getIncludeAllRequired()
  {
    return fIncludeAllRequired;
  }
  
  public void setIncludeAllEnvironments(boolean value)
  {
    fIncludeMultipleEnvironments = value;
  }
  
  public boolean getIncludeAllEnvironments()
  {
    return fIncludeMultipleEnvironments;
  }
  
  public void setIncludeSource(boolean value)
  {
    fIncludeSource = value;
  }
  
  public boolean getIncludeSource()
  {
    return fIncludeSource;
  }
  
  public static boolean isResolved(ITargetDefinition target)
  {
    P2TargetUtils synchronizer = getSynchronizer(target);
    if (synchronizer == null) {
      return false;
    }
    try
    {
      return synchronizer.checkProfile(target);
    }
    catch (CoreException localCoreExcept
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