org.eclipse.pde.core_3.7.1.v20120103_r372

ion) {}
    return false;
  }
  
  static synchronized P2TargetUtils getSynchronizer(ITargetDefinition target)
  {
    try
    {
      String memento = target.getHandle().getMemento();
      P2TargetUtils result = (P2TargetUtils)synchronizers.get(memento);
      if (result != null) {
        return result;
      }
      result = new P2TargetUtils(target);
      synchronizers.put(memento, result);
      return result;
    }
    catch (CoreException e)
    {
      throw new IllegalStateException(e.toString());
    }
  }
  
  public static IQueryResult getIUs(ITargetDefinition target, IProgressMonitor monitor)
    throws CoreException
  {
    P2TargetUtils synchronizer = getSynchronizer(target);
    if (synchronizer == null) {
      return null;
    }
    synchronizer.synchronize(target, monitor);
    return synchronizer.getProfile().query(QueryUtil.createIUAnyQuery(), null);
  }
  
  public synchronized void synchronize(ITargetDefinition target, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    if (fProfile == null) {
      fProfile = getProfileRegistry().getProfile(getProfileId(target));
    }
    if ((fProfile != null) && (checkProfile(target)))
    {
      notify(target, progress.newChild(25));
      return;
    }
    deleteProfile(target.getHandle());
    createProfile(target);
    if (progress.isCanceled()) {
      return;
    }
    progress.setWorkRemaining(75);
    if (getIncludeAllRequired()) {
      resolveWithPlanner(target, progress.newChild(60));
    } else {
      resolveWithSlicer(target, progress.newChild(60));
    }
    notify(target, progress.newChild(15));
    fDirty = false;
  }
  
  private void createProfile(ITargetDefinition target)
    throws CoreException, ProvisionException
  {
    IProfileRegistry registry = getProfileRegistry();
    if (registry == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.AbstractTargetHandle_0));
    }
    Map properties = new HashMap();
    properties.put("org.eclipse.equinox.p2.installFolder", INSTALL_FOLDERS.append(Long.toString(LocalTargetHandle.nextTimeStamp())).toOSString());
    properties.put("org.eclipse.equinox.p2.cache", BUNDLE_POOL.toOSString());
    properties.put("org.eclipse.update.install.features", Boolean.TRUE.toString());
    properties.put("org.eclipse.equinox.p2.environments", generateEnvironmentProperties(target));
    properties.put("org.eclipse.equinox.p2.nl", generateNLProperty(target));
    properties.put("org.eclipse.pde.core.sequence", Integer.toString(((TargetDefinition)target).getSequenceNumber()));
    properties.put("org.eclipse.pde.core.provision_mode", getProvisionMode(target));
    properties.put("org.eclipse.pde.core.all_environments", Boolean.toString(getIncludeAllEnvironments()));
    properties.put("org.eclipse.pde.core.autoIncludeSource", Boolean.toString(getIncludeSource()));
    fProfile = registry.addProfile(getProfileId(target), properties);
  }
  
  private void notify(ITargetDefinition target, IProgressMonitor monitor)
    throws CoreException
  {
    ((TargetDefinition)target).flushCaches(BUNDLE_POOL.toOSString());
    
    IBundleContainer[] containers = target.getBundleContainers();
    if (containers != null) {
      for (int i = 0; i < containers.length; i++)
      {
        IBundleContainer container = containers[i];
        if ((container instanceof IUBundleContainer)) {
          ((IUBundleContainer)container).synchronizerChanged(target);
        }
      }
    }
  }
  
  private static String getProfileId(ITargetHandle handle)
    throws CoreException
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("TARGET_DEFINITION:");
    buffer.append(handle.getMemento());
    return buffer.toString();
  }
  
  public static String getProfileId(ITargetDefinition definition)
  {
    try
    {
      return getProfileId(definition.getHandle());
    }
    catch (CoreException localCoreException) {}
    return null;
  }
  
  public static IProfileRegistry getProfileRegistry()
    throws CoreException
  {
    IProfileRegistry result = (IProfileRegistry)getAgent().getService(IProfileRegistry.SERVICE_NAME);
    if (result == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_8));
    }
    return result;
  }
  
  private String getProvisionMode(ITargetDefinition target)
  {
    return getIncludeAllRequired() ? "planner" : "slicer";
  }
  
  public static IMetadataRepositoryManager getRepoManager()
    throws CoreException
  {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager)getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", Messages.IUBundleContainer_2));
    }
    return manager;
  }
  
  static IQueryable getQueryableMetadata(URI[] repos, IProgressMonitor monitor)
    throws CoreException
  {
    IMetadataRepositoryManager manager = getRepoManager();
    if (repos == null) {
      repos = manager.getKnownRepositories(0);
    }
    IProgressMonitor loadMonitor = new SubProgressMonitor(monitor, 10);
    int repoCount = repos.length;
    loadMonitor.beginTask(null, repoCount * 10);
    List result = new ArrayList(repoCount);
    MultiStatus repoStatus = new MultiStatus("org.eclipse.pde.core", 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null);
    for (int i = 0; i < repoCount; i++) {
      try
      {
        result.add(manager.loadRepository(repos[i], new SubProgressMonitor(loadMonitor, 10)));
      }
      catch (ProvisionException e)
      {
        repoStatus.add(e.getStatus());
      }
    }
    loadMonitor.done();
    if (result.size() != repos.length) {
      throw new CoreException(repoStatus);
    }
    if (result.size() == 1) {
      return (IQueryable)result.get(0);
    }
    return QueryUtil.compoundQueryable(result);
  }
  
  private void resolveWithPlanner(ITargetDefinition target, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, 200);
    
    IInstallableUnit[] units = getRootIUs(target);
    if (subMonitor.isCanceled()) {
      return;
    }
    IPlanner planner = getPlanner();
    IProfileChangeRequest request = planner.createChangeRequest(fProfile);
    
    computeRemovals(fProfile, request, getIncludeSource());
    request.addAll(Arrays.asList(units));
    for (int i = 0; i < units.length; i++)
    {
      IInstallableUnit unit = units[i];
      request.setInstallableUnitProfileProperty(unit, "org.eclipse.pde.core.installed_iu", Boolean.toString(true));
    }
    ProvisioningContext context = new ProvisioningContext(getAgent());
    context.setMetadataRepositories(getMetadataRepositories(target));
    context.setArtifactRepositories(getArtifactRepositories(target));
    if (subMonitor.isCanceled()) {
      return;
    }
    IProvisioningPlan plan = planner.getProvisioningPlan(request, context, subMonitor.newChild(20));
    IStatus status = plan.getStatus();
    if (!status.isOK()) {
      throw new CoreException(status);
    }
    setPlanProperties(plan, target, "planner");
    IProvisioningPlan installerPlan = plan.getInstallerPlan();
    if (installerPlan != null) {
      PDECore.log(new Status(1, "org.eclipse.pde.core", Messages.IUBundleContainer_6));
    }
    subMonitor.worked(10);
    if (subMonitor.isCanceled()) {
      return;
    }
    IPhaseSet phases = createPhaseSet();
    IEngine engine = getEngine();
    IStatus result = engine.perform(plan, phases, subMonitor.newChild(100));
    if (subMonitor.isCanceled()) {
      return;
    }
    if (!result.isOK()) {
      throw new CoreException(result);
    }
    try
    {
      planInSourceBundles(fProfile, context, subMonitor.newChild(60));
    }
    catch (CoreException e)
    {
      getProfileRegistry().removeProfile(fProfile.getProfileId(), fProfile.getTimestamp());
      throw e;
    }
  }
  
  private void setPlanProperties(IProvisioningPlan plan, ITargetDefinition definition, String mode)
  {
    plan.setProfileProperty("org.eclipse.pde.core.provision_mode", mode);
    plan.setProfileProperty("org.eclipse.pde.core.all_environments", Boolean.toString(getIncludeAllEnvironments()));
    plan.setProfileProperty("org.eclipse.pde.core.autoIncludeSource", Boolean.toString(getIncludeSource()));
    plan.setProfileProperty("org.eclipse.pde.core.sequence", Integer.toString(((TargetDefinition)definition).getSequenceNumber()));
  }
  
  private IPhaseSet createPhaseSet()
  {
    ArrayList phases = new ArrayList(4);
    phases.add(new Collect(100));
    phases.add(new Property(1));
    phases.add(new Uninstall(50, true));
    phases.add(new Install(50));
    phases.add(new CollectNativesPhase(100));
    return new PhaseSet((Phase[])phases.toArray(new Phase[phases.size()]));
  }
  
  private void computeRemovals(IProfile profile, IProfileChangeRequest request, boolean includeSource)
  {
    if (!includeSource)
    {
      IInstallableUnit sourceIU = getCurrentSourceIU(profile);
      if (sourceIU != null) {
        request.remove(sourceIU);
      }
    }
    IQuery query = new IUProfilePropertyQuery("org.eclipse.pde.core.installed_iu", Boolean.toString(true));
    IQueryResult installedIUs = profile.query(query, null);
    request.removeAll(installedIUs.toSet());
  }
  
  private void planInSourceBundles(IProfile fProfile, ProvisioningContext context, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.P2TargetUtils_ProvisioningSourceTask, 100);
    
    IInstallableUnit currentSourceIU = getCurrentSourceIU(fProfile);
    
    Version sourceVersion = Version.createOSGi(1, 0, 0);
    if (currentSourceIU != null)
    {
      Integer major = (Integer)currentSourceIU.getVersion().getSegment(0);
      sourceVersion = Version.createOSGi(major.intValue() + 1, 0, 0);
    }
    IInstallableUnit sourceIU = createSourceIU(fProfile, sourceVersion);
    
    IPlanner planner = getPlanner();
    IProfileChangeRequest request = planner.createChangeRequest(fProfile);
    if (currentSourceIU != null) {
      request.remove(currentSourceIU);
    }
    request.add(sourceIU);
    IProvisioningPlan plan = planner.getProvisioningPlan(request, context, subMonitor.newChild(25));
    IStatus status = plan.getStatus();
    if (!status.isOK()) {
      throw new CoreException(status);
    }
    if (subMonitor.isCanceled()) {
      return;
    }
    long oldTimestamp = fProfile.getTimestamp();
    IPhaseSet phases = PhaseSetFactory.createDefaultPhaseSetExcluding(new String[] { PhaseSetFactory.PHASE_CHECK_TRUST, PhaseSetFactory.PHASE_CONFIGURE, PhaseSetFactory.PHASE_UNCONFIGURE, PhaseSetFactory.PHASE_UNINSTALL });
    IEngine engine = getEngine();
    plan.setProfileProperty("org.eclipse.pde.core.provision_mode", "planner");
    plan.setProfileProperty("org.eclipse.pde.core.all_environments", Boolean.toString(false));
    IStatus result = engine.perform(plan, phases, subMonitor.newChild(75));
    if (subMonitor.isCanceled()) {
      return;
    }
    if (!result.isOK()) {
      throw new CoreException(result);
    }
    getProfileRegistry().removeProfile(fProfile.getProfileId(), oldTimestamp);
  }
  
  private IInstallableUnit createSourceIU(IQueryable queryable, Version iuVersion)
  {
    IRequirement bundleRequirement = MetadataFactory.createRequirement("org.eclipse.equinox.p2.eclipse.type", "bundle", null, null, false, false, false);
    IQueryResult profileIUs = queryable.query(QueryUtil.createIUAnyQuery(), null);
    ArrayList requirements = new ArrayList();
    for (Iterator i = profileIUs.iterator(); i.hasNext();)
    {
      IInstallableUnit profileIU = (IInstallableUnit)i.next();
      if (profileIU.satisfies(bundleRequirement))
      {
        String id = profileIU.getId() + ".source";
        Version version = profileIU.getVersion();
        VersionRange range = new VersionRange(version, true, version, true);
        IRequirement sourceRequirement = MetadataFactory.createRequirement("osgi.bundle", id, range, null, true, false, true);
        requirements.add(sourceRequirement);
      }
    }
    MetadataFactory.InstallableUnitDescription sourceDescription = new MetadataFactory.InstallableUnitDescription();
    sourceDescription.setSingleton(true);
    sourceDescription.setId("org.eclipse.pde.core.target.source.bundles");
    sourceDescription.setVersion(iuVersion);
    sourceDescription.addRequirements(requirements);
    IProvidedCapability capability = MetadataFactory.createProvidedCapability("org.eclipse.equinox.p2.iu", "org.eclipse.pde.core.target.source.bundles", iuVersion);
    sourceDescription.setCapabilities(new IProvidedCapability[] { capability });
    return MetadataFactory.createInstallableUnit(sourceDescription);
  }
  
  private IInstallableUnit getCurrentSourceIU(IQueryable queryable)
  {
    IQuery query = QueryUtil.createIUQuery("org.eclipse.pde.core.target.source.bundles");
    IQueryResult list = queryable.query(query, null);
    IInstallableUnit currentSourceIU = null;
    if (!list.isEmpty()) {
      currentSourceIU = (IInstallableUnit)list.iterator().next();
    }
    return currentSourceIU;
  }
  
  private void resolveWithSlicer(ITargetDefinition target, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_0, 100);
    
    IInstallableUnit[] units = getRootIUs(target);
    if (subMonitor.isCanceled()) {
      return;
    }
    URI[] repositories = getMetadataRepositories(target);
    int repoCount = repositories.length;
    if (repoCount == 0) {
      return;
    }
    IQueryable allMetadata = getQueryableMetadata(repositories, subMonitor.newChild(10));
    
    IQueryResult queryResult = slice(units, allMetadata, target, subMonitor.newChild(10));
    if ((subMonitor.isCanceled()) || (queryResult == null) || (queryResult.isEmpty())) {
      return;
    }
    if (getIncludeSource())
    {
      IInstallableUnit sourceIU = createSourceIU(queryResult, Version.createOSGi(1, 0, 0));
      IInstallableUnit[] units2 = new IInstallableUnit[units.length + 1];
      System.arraycopy(units, 0, units2, 0, units.length);
      units2[units.length] = sourceIU;
      
      queryResult = slice(units2, allMetadata, target, subMonitor.newChild(10));
      if ((subMonitor.isCanceled()) || (queryResult == null) || (queryResult.isEmpty())) {
        return;
      }
    }
    IEngine engine = getEngine();
    ProvisioningContext context = new ProvisioningContext(getAgent());
    context.setMetadataRepositories(repositories);
    context.setArtifactRepositories(getArtifactRepositories(target));
    IProvisioningPlan plan = engine.createPlan(fProfile, context);
    setPlanProperties(plan, target, "slicer");
    
    Set newSet = queryResult.toSet();
    Iterator itor = newSet.iterator();
    while (itor.hasNext()) {
      plan.addInstallableUnit((IInstallableUnit)itor.next());
    }
    for (int i = 0; i < units.length; i++)
    {
      IInstallableUnit unit = units[i];
      plan.setInstallableUnitProfileProperty(unit, "org.eclipse.pde.core.installed_iu", Boolean.toString(true));
    }
    Set toRemove = fProfile.query(QueryUtil.ALL_UNITS, null).toSet();
    toRemove.removeAll(newSet);
    for (Iterator i = toRemove.iterator(); i.hasNext();) {
      plan.removeInstallableUnit((IInstallableUnit)i.next());
    }
    if (subMonitor.isCanceled()) {
      return;
    }
    subMonitor.worked(10);
    
    IPhaseSet phases = createPhaseSet();
    IStatus result = engine.perform(plan, phases, subMonitor.newChild(60));
    if (!result.isOK()) {
      throw new CoreException(result);
    }
  }
  
  private IQueryResult slice(IInstallableUnit[] units, IQueryable allMetadata, ITargetDefinition definition, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    
    PermissiveSlicer slicer = null;
    if (getIncludeAllEnvironments())
    {
      slicer = new PermissiveSlicer(allMetadata, new HashMap(), true, false, true, true, false);
    }
    else
    {
      Map props = new HashMap();
      props.put("osgi.os", definition.getOS() != null ? definition.getOS() : Platform.getOS());
      props.put("osgi.ws", definition.getWS() != null ? definition.getWS() : Platform.getWS());
      props.put("osgi.arch", definition.getArch() != null ? definition.getArch() : Platform.getOSArch());
      props.put("osgi.nl", definition.getNL() != null ? definition.getNL() : Platform.getNL());
      props.put("org.eclipse.update.install.features", Boolean.TRUE.toString());
      slicer = new PermissiveSlicer(allMetadata, props, true, false, false, true, false);
    }
    IQueryable slice = slicer.slice(units, subMonitor.newChild(50));
    IStatus sliceStatus = slicer.getStatus();
    if (sliceStatus.getSeverity() == 4) {
      throw new CoreException(sliceStatus);
    }
    IQueryResult queryResult = null;
    if (slice != null) {
      queryResult = slice.query(QueryUtil.createIUAnyQuery(), subMonitor.newChild(50));
    }
    if ((!sliceStatus.isOK()) && 
      (!queryResult.iterator().hasNext())) {
      throw new CoreException(sliceStatus);
    }
    return queryResult;
  }
  
  private URI[] getArtifactRepositories(ITargetDefinition target)
    throws CoreException
  {
    Set result = new HashSet();
    IBundleContainer[] containers = target.getBundleContainers();
    IArtifactRepositoryManager manager = getArtifactRepositoryManager();
    for (int i = 0; i < containers.length; i++)
    {
      IBundleContainer container = containers[i];
      if ((container instanceof IUBundleContainer))
      {
        URI[] repos = ((IUBundleContainer)container).getRepositories();
        if (repos == null) {
          repos = manager.getKnownRepositories(0);
        }
        result.addAll(Arrays.asList(repos));
      }
    }
    if (useAdditionalLocalArtifacts())
    {
      result.addAll(Arrays.asList(manager.getKnownRepositories(0)));
      
      findProfileRepos(result);
      findWorkspaceRepos(result);
    }
    return (URI[])result.toArray(new URI[result.size()]);
  }
  
  private boolean useAdditionalLocalArtifacts()
  {
    return true;
  }
  
  private void findWorkspaceRepos(Set additionalRepos)
  {
    IPreferencesService prefs = getPreferences();
    if (prefs == null) {
      return;
    }
    String recent = prefs.getString("org.eclipse.ui.ide", "RECENT_WORKSPACES", null, null);
    if (recent == null) {
      return;
    }
    String[] recents = recent.split("\n");
    for (int i = 0; i < recents.length; i++)
    {
      String bundlePool = recents[i] + "/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool";
      if (new File(bundlePool).exists()) {
        try
        {
          URI uri = new URI("file", bundlePool, null);
          additionalRepos.add(uri);
        }
        catch (URISyntaxException localURISyntaxException) {}
      }
    }
  }
  
  private void findProfileRepos(Set additionalRepos)
  {
    try
    {
      IProfileRegistry profileRegistry = (IProfileRegistry)getGlobalAgent().getService(IProfileRegistry.SERVICE_NAME);
      if (profileRegistry == null) {
        return;
      }
      IProfile self = profileRegistry.getProfile("_SELF_");
      if (self == null) {
        return;
      }
      IAgentLocation location = (IAgentLocation)getGlobalAgent().getService(IAgentLocation.SERVICE_NAME);
      URI dataArea = location.getDataArea("org.eclipse.equinox.p2.engine");
      dataArea = URIUtil.append(dataArea, "profileRegistry/" + self.getProfileId() + ".profile");
      ProfileMetadataRepository profileRepo = new ProfileMetadataRepository(getGlobalAgent(), dataArea, null);
      Collection repos = profileRepo.getReferences();
      for (Iterator i = repos.iterator(); i.hasNext();)
      {
        Object element = i.next();
        if ((element instanceof IRepositoryReference))
        {
          IRepositoryReference reference = (IRepositoryReference)element;
          if ((reference.getType() == 1) && (reference.getLocation() != null)) {
            additionalRepos.add(reference.getLocation());
          }
        }
      }
    }
    catch (CoreException localCoreException) {}
  }
  
  private IInstallableUnit[] getRootIUs(ITargetDefinition definition)
    throws CoreException
  {
    HashSet result = new HashSet();
    IBundleContainer[] containers = definition.getBundleContainers();
    for (int i = 0; i < containers.length; i++)
    {
      IBundleContainer container = containers[i];
      if ((container instanceof IUBundleContainer))
      {
        IUBundleContainer iuContainer = (IUBundleContainer)container;
        IQueryable repos = getQueryableMetadata(iuContainer.getRepositories(), new NullProgressMonitor());
        String[] ids = iuContainer.getIds();
        Version[] versions = iuContainer.getVersions();
        for (int j = 0; j < ids.length; j++)
        {
          IQuery query = QueryUtil.createIUQuery(ids[j], versions[j]);
          IQueryResult queryResult = repos.query(query, null);
          if (queryResult.isEmpty()) {
            throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.IUBundleContainer_1, ids[j])));
          }
          result.add(queryResult.iterator().next());
        }
      }
    }
    return (IInstallableUnit[])result.toArray(new IInstallableUnit[result.size()]);
  }
  
  private URI[] getMetadataRepositories(ITargetDefinition target)
    throws CoreException
  {
    Set result = new HashSet();
    IBundleContainer[] containers = target.getBundleContainers();
    IMetadataRepositoryManager manager = getRepoManager();
    for (int i = 0; i < containers.length; i++)
    {
      IBundleContainer container = containers[i];
      if ((container instanceof IUBundleContainer))
      {
        URI[] repos = ((IUBundleContainer)container).getRepositories();
        if (repos == null) {
          repos = manager.getKnownRepositories(0);
        }
        result.addAll(Arrays.asList(repos));
      }
    }
    return (URI[])result.toArray(new URI[result.size()]);
  }
  
  protected static class 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;
    }
  }
  
  protected static class CollectNativesPhase
    extends InstallableUnitPhase
  {
    public CollectNativesPhase(int weight)
    {
      super(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);
    }
  }
  
  IProfile getProfile()
  {
    return fProfile;
  }
  
  void markDirty()
  {
    fDirty = true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.target.P2TargetUtils
 * 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.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.build.site.PluginPathFinder;
import org.eclipse.pde.internal.core.P2Utils;
import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
import org.eclipse.pde.internal.core.target.provisional.IResolvedBundle;
import org.eclipse.pde.internal.core.target.provisional.ITargetDefinition;

public class ProfileBundleContainer
  extends AbstractBundleContainer
{
  private static final String CONFIG_INI = "config.ini";
  private static final String PROP_AGENT_DATA_AREA = "eclipse.p2.data.area";
  private static final String PROP_PROFILE = "eclipse.p2.profile";
  private static final String PROP_CONFIG_DIR = "osgi.configuration.area";
  private static final String PROP_USER_DIR = "user.dir";
  private static final String PROP_USER_HOME = "user.home";
  private static final String VAR_CONFIG_DIR = "@config.dir";
  private static final String VAR_USER_DIR = "@user.dir";
  private static final String VAR_USER_HOME = "@user.home";
  public static final String TYPE = "Profile";
  private String fHome;
  private String fConfiguration;
  
  public ProfileBundleContainer(String home, String configurationLocation)
  {
    fHome = home;
    fConfiguration = configurationLocation;
  }
  
  public String getLocation(boolean resolve)
    throws CoreException
  {
    if (resolve) {
      return resolveHomeLocation().toOSString();
    }
    return fHome;
  }
  
  public String getType()
  {
    return "Profile";
  }
  
  public String getConfigurationLocation()
  {
    return fConfiguration;
  }
  
  protected IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor)
    throws CoreException
  {
    String home = resolveHomeLocation().toOSString();
    if (!new File(home).isDirectory()) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.ProfileBundleContainer_0, home)));
    }
    URL configUrl = getConfigurationArea();
    if ((configUrl != null) && 
      (!new File(configUrl.getFile()).isDirectory())) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.ProfileBundleContainer_2, home)));
    }
    BundleInfo[] infos = P2Utils.readBundles(home, configUrl);
    if (infos == null)
    {
      IResolvedBundle[] platformXML = resolvePlatformXML(definition, home, monitor);
      if (platformXML != null) {
        return platformXML;
      }
      infos = new BundleInfo[0];
    }
    if (monitor.isCanceled()) {
      return new IResolvedBundle[0];
    }
    BundleInfo[] source = P2Utils.readSourceBundles(home, configUrl);
    if (source == null) {
      source = new BundleInfo[0];
    }
    IResolvedBundle[] all = new IResolvedBundle[infos.length + source.length];
    SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, all.length);
    for (int i = 0; i < infos.length; i++)
    {
      if (monitor.isCanceled()) {
        return new IResolvedBundle[0];
      }
      BundleInfo info = infos[i];
      all[i] = resolveBundle(info, false);
      localMonitor.worked(1);
    }
    int index = 0;
    for (int i = infos.length; i < all.length; i++)
    {
      if (monitor.isCanceled()) {
        return new IResolvedBundle[0];
      }
      BundleInfo info = source[index];
      all[i] = resolveBundle(info, true);
      index++;
      localMonitor.worked(1);
    }
    localMonitor.done();
    return all;
  }
  
  protected IFeatureModel[] resolveFeatures(ITargetDefinition definition, IProgressMonitor monitor)
    throws CoreException
  {
    if ((definition instanceof TargetDefinition)) {
      return ((TargetDefinition)definition).getFeatureModels(getLocation(false), monitor);
    }
    return new IFeatureModel[0];
  }
  
  protected IResolvedBundle[] resolvePlatformXML(ITargetDefinition definition, String home, IProgressMonitor monitor)
    throws CoreException
  {
    File[] files = PluginPathFinder.getPaths(home, false, false);
    if (files.length > 0)
    {
      List all = new ArrayList(files.length);
      SubMonitor localMonitor = SubMonitor.convert(monitor, Messages.DirectoryBundleContainer_0, files.length);
      for (int i = 0; i < files.length; i++)
      {
        if (localMonitor.isCanceled()) {
          throw new OperationCanceledException();
        }
        try
        {
          IResolvedBundle rb = generateBundle(files[i]);
          if (rb != null) {
            all.add(rb);
          }
        }
        catch (CoreException localCoreException) {}
        localMonitor.worked(1);
      }
      localMonitor.done();
      if (!all.isEmpty()) {
        return (IResolvedBundle[])all.toArray(new IResolvedBundle[all.size()]);
      }
    }
    return null;
  }
  
  private IPath resolveHomeLocation()
    throws CoreException
  {
    return new Path(resolveVariables(fHome));
  }
  
  private URL getConfigurationArea()
    throws CoreException
  {
    IPath home = resolveHomeLocation();
    IPath configuration = null;
    if (fConfiguration == null) {
      configuration = home.append("configuration");
    } else {
      configuration = new Path(resolveVariables(fConfiguration));
    }
    File file = configuration.toFile();
    if (file.exists()) {
      try
      {
        return file.toURL();
      }
      catch (MalformedURLException e)
      {
        throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.ProfileBundleContainer_1, home.toOSString()), e));
      }
    }
    if (fConfiguration != null) {
      throw new CoreException(new Status(4, "org.eclipse.pde.core", NLS.bind(Messages.ProfileBundleContainer_2, configuration.toOSString())));
    }
    return null;
  }
  
  public boolean isContentEqual(AbstractBundleContainer container)
  {
    if ((container instanceof ProfileBundleContainer))
    {
      ProfileBundleContainer pbc = (ProfileBundleContainer)container;
      return (fHome.equals(fHome)) && (isNullOrEqual(fConfiguration, fConfiguration));
    }
    return false;
  }
  
  /* Error */
  public File getProfileFileLocation()
    throws CoreException
  {
    // Byte code:
    //   0: aload_0
    //   1: invokespecial 369	org/eclipse/pde/internal/core/target/ProfileBundleContainer:resolveHomeLocation	()Lorg/eclipse/core/runtime/IPath;
    //   4: invokeinterface 382 1 0
    //   9: astore_1
    //   10: new 179	java/io/File
    //   13: dup
    //   14: aload_1
    //   15: invokespecial 330	java/io/File:<init>	(Ljava/lang/String;)V
    //   18: invokevirtual 327	java/io/File:isDirectory	()Z
    //   21: ifne +28 -> 49
    //   24: new 190	org/eclipse/core/runtime/CoreException
    //   27: dup
    //   28: new 195	org/eclipse/core/runtime/Status
    //   31: dup
    //   32: iconst_4
    //   33: ldc 9
    //   35: getstatic 321	org/eclipse/pde/internal/core/target/Messages:ProfileBundleContainer_0	Ljava/lang/String;
    //   38: aload_1
    //   39: invokestatic 361	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   42: invokespecial 355	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;)V
    //   45: invokespecial 351	org/eclipse/core/runtime/CoreException:<init>	(Lorg/eclipse/core/runtime/IStatus;)V
    //   48: athrow
    //   49: aconst_null
    //   50: astore_2
    //   51: aload_0
    //   52: invokespecial 368	org/eclipse/pde/internal/core/target/ProfileBundleContainer:getConfigurationArea	()Ljava/net/URL;
    //   55: astore_3
    //   56: aload_3
    //   57: ifnull +18 -> 75
    //   60: new 179	java/io/File
    //   63: dup
    //   64: aload_3
    //   65: invokevirtual 346	java/net/URL:getFile	()Ljava/lang/String;
    //   68: invokespecial 330	java/io/File:<init>	(Ljava/lang/String;)V
    //   71: astore_2
    //   72: goto +12 -> 84
    //   75: new 179	java/io/File
    //   78: dup
    //   79: aload_1
    //   80: invokespecial 330	java/io/File:<init>	(Ljava/lang/String;)V
    //   83: astore_2
    //   84: aload_2
    //   85: invokevirtual 327	java/io/File:isDirectory	()Z
    //   88: ifne +28 -> 116
    //   91: new 190	org/eclipse/core/runtime/CoreException
    //   94: dup
    //   95: new 195	org/eclipse/core/runtime/Status
    //   98: dup
    //   99: iconst_4
    //   100: ldc 9
    //   102: getstatic 323	org/eclipse/pde/internal/core/target/Messages:ProfileBundleContainer_2	Ljava/lang/String;
    //   105: aload_2
    //   106: invokestatic 361	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   109: invokespecial 355	org/eclipse/core/runtime/Status:<init>	(ILjava/lang/String;Ljava/lang/String;)V
    //   112: invokespecial 351	org/eclipse/core/runtime/CoreException:<init>	(Lorg/eclipse/core/runtime/IStatus;)V
    //   115: athrow
    //   116: aconst_null
    //   117: astore 4
    //   119: aconst_null
    //   120: astore 5
    //   122: new 179	java/io/File
    //   125: dup
    //   126: aload_2
    //   127: ldc 5
    //   129: invokespecial 332	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   132: astore 6
    //   134: aload 6
    //   136: invokevirtual 328	java/io/File:isFile	()Z
    //   139: ifeq +264 -> 403
    //   142: new 189	java/util/Properties
    //   145: dup
    //   146: invokespecial 348	java/util/Properties:<init>	()V
    //   149: astore 7
    //   151: aconst_null
    //   152: astore 8
    //   154: new 180	java/io/FileInputStream
    //   157: dup
    //   158: aload 6
    //   160: invokespecial 334	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   163: astore 8
    //   165: aload 7
    //   167: aload 8
    //   169: invokevirtual 349	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   172: aload 8
    //   174: invokevirtual 333	java/io/FileInputStream:close	()V
    //   177: goto +46 -> 223
    //   180: astore 9
    //   182: aload 9
    //   184: invokestatic 365	org/eclipse/pde/internal/core/PDECore:log	(Ljava/lang/Throwable;)V
    //   187: aload 8
    //   189: ifnull +48 -> 237
    //   192: aload 8
    //   194: invokevirtual 333	java/io/FileInputStream:close	()V
    //   197: goto +40 -> 237
    //   200: pop
    //   201: goto +36 -> 237
    //   204: astore 10
    //   206: aload 8
    //   208: ifnull +12 -> 220
    //   211: aload 8
    //   213: invokevirtual 333	java/io/FileInputStream:close	()V
    //   216: goto +4 -> 220
    //   219: pop
    //   220: aload 10
    //   222: athrow
    //   223: aload 8
    //   225: ifnull +12 -> 237
    //   228: aload 8
    //   230: invokevirtual 333	java/io/FileInputStream:close	()V
    //   233: goto +4 -> 237
    //   236: pop
    //   237: aload 7
    //   239: ldc 7
    //   241: invokevirtual 350	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   244: astore 9
    //   246: aload 9
    //   248: ifnull +146 -> 394
    //   251: aload 9
    //   253: ldc 3
    //   255: invokevirtual 339	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   258: ifeq +38 -> 296
    //   261: aload_0
    //   262: aload 7
    //   264: aload 9
    //   266: ldc 3
    //   268: ldc 12
    //   270: aload_2
    //   271: invokespecial 375	org/eclipse/pde/internal/core/target/ProfileBundleContainer:substituteVar	(Ljava/util/Properties;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/lang/String;
    //   274: astore 10
    //   276: new 194	org/eclipse/core/runtime/Path
    //   279: dup
    //   280: aload 10
    //   282: invokespecial 354	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;)V
    //   285: invokevirtual 353	org/eclipse/core/runtime/Path:toFile	()Ljava/io/File;
    //   288: invokevirtual 329	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   291: astore 9
    //   293: goto +90 -> 383
    //   296: aload 9
    //   298: ldc 2
    //   300: invokevirtual 339	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   303: ifeq +38 -> 341
    //   306: aload_0
    //   307: aload 7
    //   309: aload 9
    //   311: ldc 2
    //   313: ldc 11
    //   315: aload_2
    //   316: invokespecial 375	org/eclipse/pde/internal/core/target/ProfileBundleContainer:substituteVar	(Ljava/util/Properties;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/lang/String;
    //   319: astore 10
    //   321: new 194	org/eclipse/core/runtime/Path
    //   324: dup
    //   325: aload 10
    //   327: invokespecial 354	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;)V
    //   330: invokevirtual 353	org/eclipse/core/runtime/Path:toFile	()Ljava/io/File;
    //   333: invokevirtual 329	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   336: astore 9
    //   338: goto +45 -> 383
    //   341: aload 9
    //   343: ldc 1
    //   345: invokevirtual 339	java/lang/String:startsWith	(Ljava/lang/String;)Z
    //   348: ifeq +35 -> 383
    //   351: aload_0
    //   352: aload 7
    //   354: aload 9
    //   356: ldc 1
    //   358: ldc 10
    //   360: aload_2
    //   361: invokespecial 375	org/eclipse/pde/internal/core/target/ProfileBundleContainer:substituteVar	(Ljava/util/Properties;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/lang/String;
    //   364: astore 10
    //   366: new 194	org/eclipse/core/runtime/Path
    //   369: dup
    //   370: aload 10
    //   372: invokespecial 354	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;)V
    //   375: invokevirtual 353	org/eclipse/core/runtime/Path:toFile	()Ljava/io/File;
    //   378: invokevirtual 329	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   381: astore 9
    //   383: new 179	java/io/File
    //   386: dup
    //   387: aload 9
    //   389: invokespecial 330	java/io/File:<init>	(Ljava/lang/String;)V
    //   392: astore 4
    //   394: aload 7
    //   396: ldc 8
    //   398: invokevirtual 350	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   401: astore 5
    //   403: aload 4
    //   405: ifnull +11 -> 416
    //   408: aload 4
    //   410: invokevirtual 327	java/io/File:isDirectory	()Z
    //   413: ifne +16 -> 429
    //   416: new 179	java/io/File
    //   419: dup
    //   420: aload_2
    //   421: ldc_w 176
    //   424: invokespecial 332	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   
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