public void testChangeIUProperty() {
    // Add into the profile the version a1;
    ProfileChangeRequest req = new ProfileChangeRequest(profile);
    req.addInstallableUnits(new IInstallableUnit[] {a1});
    req.setInstallableUnitProfileProperty(
        a1, IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString());
    IProvisioningPlan plan = planner.getProvisioningPlan(req, null, null);
    assertEquals(IStatus.OK, plan.getStatus().getSeverity());
    engine.perform(plan, null);
    assertProfileContainsAll("A1 is missing", profile, new IInstallableUnit[] {a1});

    IProfileRegistry profileRegistry = getProfileRegistry();
    profile = profileRegistry.getProfile(profile.getProfileId());
    IQueryResult c = profile.query(new UserVisibleRootQuery(), null);
    assertEquals(queryResultSize(c), 1);

    System.gc();
    ProfileChangeRequest req2 =
        ProfileChangeRequest.createByProfileId(getAgent(), profile.getProfileId());
    req2.removeInstallableUnits(new IInstallableUnit[] {a1});
    req2.addInstallableUnits(new IInstallableUnit[] {a2});
    //		req2.setInstallableUnitProfileProperty(a2, IProfile.PROP_PROFILE_ROOT_IU,
    // Boolean.TRUE.toString());
    IProvisioningPlan plan2 = planner.getProvisioningPlan(req2, null, null);
    assertEquals(IStatus.OK, plan2.getStatus().getSeverity());
    assertInstallOperand(plan2, a2);
    engine.perform(plan2, null);
    profile = getProfile(profile.getProfileId());
    assertProfileContains("A2 is missing", profile, new IInstallableUnit[] {a2});
  }
Esempio n. 2
0
 public Collection getInstalled(String id) {
   IProfile profile = registry.getProfile(id);
   if (profile == null) return Collections.EMPTY_LIST;
   IQuery query = new IUProfilePropertyQuery(PROP_TOAST_ROOT, "true");
   IQueryResult result = profile.query(query, new NullProgressMonitor());
   return result.toUnmodifiableSet();
 }
Esempio n. 3
0
  /**
   * (inheritDoc)
   *
   * @see org.goko.featuremanager.service.IFeatureManager#getInstallableUnits()
   */
  @Override
  public List<GkInstallableUnit> getInstallableUnits(IProgressMonitor monitor) throws GkException {
    List<GkInstallableUnit> lstUnits = new ArrayList<GkInstallableUnit>();
    // get the repository managers and define our repositories
    IMetadataRepositoryManager manager =
        (IMetadataRepositoryManager)
            getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);

    try {
      manager.addRepository(new URI("http://update.goko.fr/"));
      manager.loadRepository(new URI("http://update.goko.fr/"), monitor);
    } catch (ProvisionException | OperationCanceledException | URISyntaxException e) {
      throw new GkTechnicalException(e);
    }
    // Query installed units
    IProfileRegistry registry =
        (IProfileRegistry) getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
    IProfile profile = registry.getProfile(IProfileRegistry.SELF);
    Collection<IInstallableUnit> lstInstalledUnits =
        profile.query(new UserVisibleRootQuery(), monitor).toUnmodifiableSet();

    // Query "groups"
    IQuery<IInstallableUnit> query =
        QueryUtil.createLatestQuery(
            QueryUtil.createMatchQuery(
                "properties[$0] == $1 && properties[$2] != null",
                "org.eclipse.equinox.p2.type.group",
                "true",
                "org.eclipse.equinox.p2.type.category"));
    Collection<IInstallableUnit> lstInstallableUnit =
        manager.query(query, monitor).toUnmodifiableSet();

    if (CollectionUtils.isNotEmpty(lstInstallableUnit)) {
      for (IInstallableUnit iInstallableUnit : lstInstallableUnit) {
        GkInstallableUnit gkUnit = new GkInstallableUnit(iInstallableUnit);
        // Same ID already installed ?
        for (IInstallableUnit installedUnit : lstInstalledUnits) {
          if (StringUtils.equals(gkUnit.getId(), installedUnit.getId())) {
            gkUnit.setInstalled(true);
            break;
          }
        }

        lstUnits.add(gkUnit);
      }
    }

    return lstUnits;
  }
Esempio n. 4
0
 public static URI getBundlePoolLocation(IProvisioningAgent agent, IProfile profile) {
   String path = profile.getProperty(IProfile.PROP_CACHE);
   if (path != null) return new File(path).toURI();
   IAgentLocation location = getAgentLocation(agent);
   if (location == null) return null;
   return location.getDataArea(Activator.ID);
 }
Esempio n. 5
0
 public static boolean isMacOSBundled(IProfile profile) {
   String environments = profile.getProperty(IProfile.PROP_ENVIRONMENTS);
   if (environments == null) return false;
   if (environments.indexOf(Constants.MACOSX_BUNDLED + "=true") != -1) // $NON-NLS-1$
   return true;
   return false;
 }
Esempio n. 6
0
 public static File getLauncherPath(IProfile profile) {
   String name = profile.getProperty(EclipseTouchpoint.PROFILE_PROP_LAUNCHER_NAME);
   if (name == null || name.length() == 0) name = "eclipse"; // $NON-NLS-1$
   String launcherName =
       getLauncherName(
           name,
           (isMacOSBundled(profile) ? Constants.MACOSX_BUNDLED : getOSFromProfile(profile)),
           getInstallFolder(profile));
   return launcherName == null ? null : new File(getInstallFolder(profile), launcherName);
 }
Esempio n. 7
0
  public static IFileArtifactRepository getAggregatedBundleRepository(
      IProvisioningAgent agent, IProfile profile, int repoFilter) {
    List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>();

    // we check for a shared bundle pool first as it should be preferred over the user bundle pool
    // in a shared install
    IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
    if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) {
      String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE);
      if (sharedCache != null) {
        try {
          URI repoLocation = new File(sharedCache).toURI();
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repository if it could not be read
        }
      }
    }

    if ((repoFilter & AGGREGATE_CACHE) != 0) {
      IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile);
      if (bundlePool != null) bundleRepositories.add(bundlePool);
    }

    if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) {
      List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS);
      for (String repo : repos) {
        try {
          URI repoLocation;
          try {
            repoLocation = new URI(repo);
          } catch (URISyntaxException e) {
            // in 1.0 we wrote unencoded URL strings, so try as an unencoded string
            repoLocation = URIUtil.fromString(repo);
          }
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repositories that could not be read
        } catch (URISyntaxException e) {
          // unexpected, URLs should be pre-checked
          LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e));
        }
      }
    }
    return new AggregatedBundleRepository(agent, bundleRepositories);
  }
Esempio n. 8
0
 private static List<String> getListProfileProperty(IProfile profile, String key) {
   List<String> listProperty = new ArrayList<String>();
   String dropinRepositories = profile.getProperty(key);
   if (dropinRepositories != null) {
     StringTokenizer tokenizer = new StringTokenizer(dropinRepositories, PIPE);
     while (tokenizer.hasMoreTokens()) {
       listProperty.add(tokenizer.nextToken());
     }
   }
   return listProperty;
 }
Esempio n. 9
0
  public IStatus service(Command command, IProcess context)
      throws InterruptedException, CoreException {
    UpdateFeature updateFeature = (UpdateFeature) command;
    String featureId = updateFeature.getId();

    ProvisioningSession session = PlatformPlugin.createProvisioningSession();

    IProfile profile = PlatformPlugin.getProfileRegistry().getProfile(IProfileRegistry.SELF);
    IQuery<IInstallableUnit> query =
        QueryUtil.createLatestQuery(QueryUtil.createIUQuery(featureId));
    IQueryResult<IInstallableUnit> result = profile.query(query, new NullProgressMonitor());

    if (result.isEmpty()) {
      return Status.OK_STATUS;
    }

    UpdateOperation op = new UpdateOperation(session, result.toSet());
    IStatus status = op.resolveModal(new NullProgressMonitor());

    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
      return Status.OK_STATUS;
    }
    if (status.getSeverity() == IStatus.CANCEL) {
      // should not happen,
      throw new CoreException(status);
    }

    if (status.getSeverity() == IStatus.ERROR) {
      throw new CoreException(status);
    }

    ProvisioningJob job = op.getProvisioningJob(null);
    if (job == null) {
      return Status.OK_STATUS;
    }

    status = job.runModal(new NullProgressMonitor());
    if (status.getSeverity() == IStatus.CANCEL) throw new CoreException(status);

    return Status.OK_STATUS;
  }
Esempio n. 10
0
 public static String getOSFromProfile(IProfile profile) {
   String environments = profile.getProperty(IProfile.PROP_ENVIRONMENTS);
   if (environments == null) return null;
   for (StringTokenizer tokenizer = new StringTokenizer(environments, ",");
       tokenizer.hasMoreElements(); ) { // $NON-NLS-1$
     String entry = tokenizer.nextToken();
     int i = entry.indexOf('=');
     String key = entry.substring(0, i).trim();
     if (!key.equals("osgi.os")) // $NON-NLS-1$
     continue;
     return entry.substring(i + 1).trim();
   }
   return null;
 }
Esempio n. 11
0
 public static File getLauncherConfigLocation(IProfile profile) {
   String launcherConfig = profile.getProperty(IProfile.PROP_LAUNCHER_CONFIGURATION);
   return launcherConfig == null ? null : new File(launcherConfig);
 }
Esempio n. 12
0
 /**
  * Returns the install folder for the profile, or <code>null</code> if no install folder is
  * defined.
  */
 public static File getInstallFolder(IProfile profile) {
   String folder = profile.getProperty(IProfile.PROP_INSTALL_FOLDER);
   return folder == null ? null : new File(folder);
 }
Esempio n. 13
0
 public static File getConfigurationFolder(IProfile profile) {
   String config = profile.getProperty(IProfile.PROP_CONFIGURATION_FOLDER);
   if (config != null) return new File(config);
   return new File(getInstallFolder(profile), "configuration"); // $NON-NLS-1$
 }
Esempio n. 14
0
 public static IInstallableUnit[] getAllInstalledIUs(IProfile profile, IProgressMonitor monitor) {
   return profile.query(new UserVisibleRootQuery(), monitor).toArray(IInstallableUnit.class);
 }
  public ProfileChangeRequest generateProfileChangeRequest(
      IProfile profile, MultiStatus status, IProgressMonitor monitor) {
    ProfileChangeRequest request = new ProfileChangeRequest(profile);
    String carbonHome = System.getProperty("carbon.home");
    String cacheLocation =
        carbonHome + File.separator + "repository" + File.separator + "components";
    request.setProfileProperty(IProfile.PROP_CACHE, cacheLocation);
    request.setProfileProperty(
        SimpleConfiguratorConstants.PROP_KEY_USE_REFERENCE, Boolean.TRUE.toString());
    for (IInstallableUnit iu : iusToInstall) {
      // If the user is installing a patch, we mark it optional.  This allows
      // the patched IU to be updated later by removing the patch.
      if (Boolean.toString(true)
          .equals(iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_PATCH))) {
        request.setInstallableUnitInclusionRules(
            iu, ProfileInclusionRules.createOptionalInclusionRule(iu));
      }

      // Check to see if it is already installed.  This may alter the request.
      Collection alreadyInstalled =
          profile
              .query(QueryUtil.createIUQuery(iu.getId()), new NullProgressMonitor())
              .toUnmodifiableSet();

      if (alreadyInstalled.size() > 0) {
        IInstallableUnit installedIU = (IInstallableUnit) alreadyInstalled.iterator().next();
        int compareTo = iu.getVersion().compareTo(installedIU.getVersion());
        // If the iu is a newer version of something already installed, consider this an
        // update request
        if (compareTo > 0) {
          boolean lockedForUpdate = false;
          String value =
              profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_LOCKED_IU);
          if (value != null) {
            lockedForUpdate =
                (Integer.parseInt(value) & IProfile.LOCK_UPDATE) == IProfile.LOCK_UPDATE;
          }
          if (lockedForUpdate) {
            // Add a status telling the user that this implies an update, but the
            // iu should not be updated
            status.merge(
                new Status(
                    IStatus.WARNING,
                    "temp",
                    10013,
                    installedIU.getId()
                        + "-"
                        + installedIU.getVersion()
                        + " will be ignored because it is already installed, "
                        + "and updates are not permitted.",
                    null));
          } else {
            request.addInstallableUnits(new IInstallableUnit[] {iu});
            request.removeInstallableUnits(new IInstallableUnit[] {installedIU});
            // Add a status informing the user that the update has been inferred
            status.merge(
                new Status(
                    IStatus.WARNING,
                    "temp",
                    10013,
                    installedIU.getId()
                        + "-"
                        + installedIU.getVersion()
                        + " is already installed, so an update will be performed instead.",
                    null));
            // Mark it as a root if it hasn't been already
            if (!Boolean.toString(true)
                .equals(
                    profile.getInstallableUnitProperty(
                        installedIU, IProfile.PROP_PROFILE_ROOT_IU))) {
              request.setInstallableUnitProfileProperty(
                  iu, IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true));
            }
          }
        } else if (compareTo < 0) {
          // An implied downgrade.  We will not put this in the plan, add a status informing the
          // user
          status.merge(
              new Status(
                  IStatus.WARNING,
                  "temp",
                  10004,
                  installedIU.getId()
                      + "-"
                      + installedIU.getVersion()
                      + " will be ignored because a newer version is already installed.",
                  null));
        } else {
          if (Boolean.toString(true)
              .equals(
                  profile.getInstallableUnitProperty(installedIU, IProfile.PROP_PROFILE_ROOT_IU)))
          // It is already a root, nothing to do. We tell the user it was already installed
          {
            status.merge(
                new Status(
                    IStatus.WARNING,
                    "temp",
                    10005,
                    installedIU.getId()
                        + "-"
                        + installedIU.getVersion()
                        + " will be ignored because it is already installed.",
                    null));
          } else {
            // It was already installed but not as a root.
            // Tell the user that parts of it are already installed and mark it as a root.
            status.merge(
                new Status(
                    IStatus.WARNING,
                    "temp",
                    10006,
                    installedIU.getId()
                        + "-"
                        + installedIU.getVersion()
                        + " is already present because other installed software requires it.  "
                        + "It will be added to the installed software list.",
                    null));
            request.setInstallableUnitProfileProperty(
                iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true));
          }
        }
      } else {
        // install this if only this is not category type
        if (!Boolean.toString(true)
            .equals(
                iu.getProperty(MetadataFactory.InstallableUnitDescription.PROP_TYPE_CATEGORY))) {
          // Install it and mark as a root
          request.addInstallableUnits(new IInstallableUnit[] {iu});
          request.setInstallableUnitProfileProperty(
              iu, "org.eclipse.equinox.p2.type.root", Boolean.toString(true));
        }
      }
    }
    return request;
  }