Esempio n. 1
0
 public static synchronized IFileArtifactRepository getBundlePoolRepository(
     IProvisioningAgent agent, IProfile profile) {
   URI location = getBundlePoolLocation(agent, profile);
   if (location == null) return null;
   IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
   try {
     return (IFileArtifactRepository) manager.loadRepository(location, null);
   } catch (ProvisionException e) {
     // the repository doesn't exist, so fall through and create a new one
   }
   try {
     String repositoryName = Messages.BundlePool;
     Map<String, String> properties = new HashMap<String, String>(1);
     properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString());
     return (IFileArtifactRepository)
         manager.createRepository(location, repositoryName, REPOSITORY_TYPE, properties);
   } catch (ProvisionException e) {
     LogHelper.log(e);
     throw new IllegalArgumentException(NLS.bind(Messages.bundle_pool_not_writeable, location));
   }
 }
Esempio n. 2
0
 private IQuery<IInstallableUnit> getProfileQuery() {
   // We specifically avoid using the default policy's root property so that we don't load all the
   // p2 UI classes in doing so.
   return new IUProfilePropertyQuery(IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString());
 }
  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;
  }