Пример #1
0
 public static void updateRepositoryUsingElements(
     final ProvisioningUI ui, final MetadataRepositoryElement[] elements) {
   ui.signalRepositoryOperationStart();
   IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ui.getSession());
   IArtifactRepositoryManager artManager = ProvUI.getArtifactRepositoryManager(ui.getSession());
   try {
     int visibilityFlags = ui.getRepositoryTracker().getMetadataRepositoryFlags();
     URI[] currentlyEnabled = metaManager.getKnownRepositories(visibilityFlags);
     URI[] currentlyDisabled =
         metaManager.getKnownRepositories(
             IRepositoryManager.REPOSITORIES_DISABLED | visibilityFlags);
     for (int i = 0; i < elements.length; i++) {
       URI location = elements[i].getLocation();
       if (elements[i].isEnabled()) {
         if (containsURI(currentlyDisabled, location))
           // It should be enabled and is not currently
           setColocatedRepositoryEnablement(ui, location, true);
         else if (!containsURI(currentlyEnabled, location)) {
           // It is not known as enabled or disabled.  Add it.
           metaManager.addRepository(location);
           artManager.addRepository(location);
         }
       } else {
         if (containsURI(currentlyEnabled, location))
           // It should be disabled, and is currently enabled
           setColocatedRepositoryEnablement(ui, location, false);
         else if (!containsURI(currentlyDisabled, location)) {
           // It is not known as enabled or disabled.  Add it and then disable it.
           metaManager.addRepository(location);
           artManager.addRepository(location);
           setColocatedRepositoryEnablement(ui, location, false);
         }
       }
       String name = elements[i].getName();
       if (name != null && name.length() > 0) {
         metaManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name);
         artManager.setRepositoryProperty(location, IRepository.PROP_NICKNAME, name);
       }
     }
     // Are there any elements that need to be deleted?  Go over the original state
     // and remove any elements that weren't in the elements we were given
     Set<String> nowKnown = new HashSet<String>();
     for (int i = 0; i < elements.length; i++)
       nowKnown.add(URIUtil.toUnencodedString(elements[i].getLocation()));
     for (int i = 0; i < currentlyEnabled.length; i++) {
       if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyEnabled[i]))) {
         metaManager.removeRepository(currentlyEnabled[i]);
         artManager.removeRepository(currentlyEnabled[i]);
       }
     }
     for (int i = 0; i < currentlyDisabled.length; i++) {
       if (!nowKnown.contains(URIUtil.toUnencodedString(currentlyDisabled[i]))) {
         metaManager.removeRepository(currentlyDisabled[i]);
         artManager.removeRepository(currentlyDisabled[i]);
       }
     }
   } finally {
     ui.signalRepositoryOperationComplete(null, true);
   }
 }
Пример #2
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;
  }
  private Repositories loadRepositories(String id, URI specifiedUrl) throws Exception {

    IRepositoryIdManager idManager =
        (IRepositoryIdManager) subject.getService(IRepositoryIdManager.SERVICE_NAME);
    idManager.addMapping(id, specifiedUrl);

    IMetadataRepositoryManager metadataManager =
        (IMetadataRepositoryManager) subject.getService(IMetadataRepositoryManager.SERVICE_NAME);
    IMetadataRepository metadataRepo = metadataManager.loadRepository(specifiedUrl, null);

    IArtifactRepositoryManager artifactsManager =
        (IArtifactRepositoryManager) subject.getService(IArtifactRepositoryManager.SERVICE_NAME);
    IArtifactRepository artifactsRepo = artifactsManager.loadRepository(specifiedUrl, null);

    return new Repositories(metadataRepo, artifactsRepo);
  }
Пример #4
0
 private IMetadataRepository loadRepository(Repository repository) {
   try {
     return metadataManager.loadRepository(repository.getLocation(), monitor);
   } catch (ProvisionException e) {
     throw new TargetDefinitionResolutionException(
         "Failed to load p2 metadata repository from location " + repository.getLocation(), e);
   }
 }
Пример #5
0
 private IMetadataRepository[] addRepositories(String spec) {
   String[] locations = spec.split(",");
   ArrayList result = new ArrayList();
   for (int i = 0; i < locations.length; i++) {
     URI location = null;
     try {
       location = new URI(locations[i].trim());
       metadataManager.loadRepository(location, null);
       result.add(metadataManager.loadRepository(location, null));
       artifactManager.addRepository(location);
     } catch (URISyntaxException e) {
       LogUtility.logError("Invalid URI for repository " + location, e);
     } catch (ProvisionException e) {
       LogUtility.logWarning("Unable to load repository " + location, e);
     }
   }
   return (IMetadataRepository[]) result.toArray(new IMetadataRepository[result.size()]);
 }
Пример #6
0
  /**
   * Finds available WSO2 features in current profile and search for updates to them in WSO2 p2
   * repository for updates.
   *
   * @param monitor
   * @throws Exception
   */
  public void checkForAvailableUpdates(IProgressMonitor monitor) throws Exception {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_18, 6);

    // get all available IUs in update repository
    IMetadataRepository metadataRepo =
        metadataRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1));
    IQuery<IInstallableUnit> allIUQuery = QueryUtil.createIUAnyQuery();
    IQueryResult<IInstallableUnit> allIUQueryResult =
        metadataRepo.query(allIUQuery, progress.newChild(1));

    // read artifact repository for updates
    IArtifactRepository artifactRepo =
        artifactRepoManager.loadRepository(getDevStudioUpdateSite(), progress.newChild(1));

    // read meta-data of all available features
    Map<String, EnhancedFeature> allFeaturesInUpdateRepo =
        loadWSO2FeaturesInRepo(artifactRepo, allIUQueryResult, progress.newChild(1));

    // get all installed wso2 features
    Collection<IInstallableUnit> installedWSO2Features =
        getInstalledWSO2Features(progress.newChild(1));

    installedWSO2FeaturesMap = new HashMap<String, IInstallableUnit>();
    for (IInstallableUnit iInstallableUnit : installedWSO2Features) {
      installedWSO2FeaturesMap.put(iInstallableUnit.getId(), iInstallableUnit);
    }

    if (progress.isCanceled()) {
      throw new OperationCanceledException();
    }

    URI[] repos = new URI[] {getDevStudioUpdateSite()};
    updateOperation = new UpdateOperation(session, installedWSO2Features);
    updateOperation.getProvisioningContext().setArtifactRepositories(repos);
    updateOperation.getProvisioningContext().setMetadataRepositories(repos);

    // resolve update operation
    IStatus status = updateOperation.resolveModal(progress.newChild(1));
    // user cancelled the job while resolving
    if (status.getSeverity() == IStatus.CANCEL || progress.isCanceled()) {
      throw new OperationCanceledException();
    }
    // there is nothing to update
    if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
      featuresWithPossibleUpdates = new HashMap<String, EnhancedFeature>();
      log.info(Messages.UpdateManager_19);
    } else if (status.getSeverity() == IStatus.ERROR) { // resolution errors
      // something wrong with the updates
      log.info(Messages.UpdateManager_20);
    } else {
      // good to proceed installing updates
      setPossibleUpdates(updateOperation.getPossibleUpdates(), allFeaturesInUpdateRepo);
    }
  }
Пример #7
0
  /* (non-Javadoc)
   * @see org.apache.tools.ant.Task#execute()
   */
  public void execute() {
    validate();
    IMetadataRepositoryManager manager =
        (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager == null)
      throw new BuildException("Unable to aquire metadata repository manager service.");

    // load the composite repository
    CompositeMetadataRepository repo = null;
    try {
      repo = (CompositeMetadataRepository) manager.loadRepository(location, null);
    } catch (ClassCastException e) {
      throw new BuildException(
          "Repository at location: " + location + " is not a composite metadata repository.");
    } catch (ProvisionException e) {
      throw new BuildException("Error occurred while loading repository.", e);
    }

    // add the child
    repo.addChild(child);
    manager.removeRepository(location);
  }
Пример #8
0
  /**
   * Searches available features in WSO2 p2 repository for the current version of Developer Studio
   * and filters new features that can be installed.
   *
   * @param monitor
   * @throws Exception
   */
  public void checkForAvailableFeatures(IProgressMonitor monitor) throws Exception {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_21, 5);

    // get all available IUs in release repository
    IMetadataRepository metadataRepository =
        metadataRepoManager.loadRepository(getDevStudioReleaseSite(), progress.newChild(1));
    IQuery<IInstallableUnit> allIUQuery = QueryUtil.createIUAnyQuery();
    IQueryResult<IInstallableUnit> allIUQueryResult =
        metadataRepository.query(allIUQuery, progress.newChild(1));

    // load artifact repository for releases
    IArtifactRepository artifactRepository =
        artifactRepoManager.loadRepository(getDevStudioReleaseSite(), progress.newChild(1));

    // read meta-data of all available features
    Map<String, EnhancedFeature> allFeaturesInReleaseRepo =
        loadWSO2FeaturesInRepo(artifactRepository, allIUQueryResult, progress.newChild(1));

    Collection<IInstallableUnit> filteredIUs =
        filterInstallableUnits(
            WSO2_FEATURE_PREFIX, FEATURE_GROUP_IU_ID_SFX, allIUQueryResult, progress.newChild(1));
    allAvailableFeatures = new HashMap<String, IInstallableUnit>();
    availableNewFeatures = new HashMap<String, EnhancedFeature>();
    for (IInstallableUnit iInstallableUnit : filteredIUs) {
      allAvailableFeatures.put(iInstallableUnit.getId(), iInstallableUnit);
      if (!installedWSO2FeaturesMap.containsKey(iInstallableUnit.getId())) {
        availableNewFeatures.put(
            iInstallableUnit.getId(), allFeaturesInReleaseRepo.get(iInstallableUnit.getId()));
      } else {
        Version versionInstalled =
            installedWSO2FeaturesMap.get(iInstallableUnit.getId()).getVersion();
        // if the version we have is greater than the installed version view it in the available
        // feature list
        if (versionInstalled != null
            && (iInstallableUnit.getVersion().compareTo(versionInstalled) == 1)) {
          availableNewFeatures.put(
              iInstallableUnit.getId(), allFeaturesInReleaseRepo.get(iInstallableUnit.getId()));
        }
      }
    }
  }
Пример #9
0
  public List<IServerExtension> getExtensions(IProgressMonitor monitor)
      throws CoreException, ProvisionException {
    try {
      /*
       * To discovery the server adapter, there are three methods:
       * 1. Looking at the site.xml (if it exists). This is the legacy method
       * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2
       *    update site (that may not have a site.xml). The property is necessary to identify
       *    the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show
       *    up regardless of whether it is a server or not
       * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml
       *    to use category.xml)
       */
      BundleContext bd =
          org.eclipse.wst.server.discovery.internal.Activator.getDefault()
              .getBundle()
              .getBundleContext();
      IProvisioningAgent agent = ExtensionUtility.getAgent(bd);

      URI url2 = new URI(url);

      // Method 1: Looking at the site.xml
      UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory();
      mrf.setAgent(ExtensionUtility.getAgent(bd));
      // If the site.xml does not exist, the load will throw a
      // org.eclipse.equinox.p2.core.ProvisionException
      List<IServerExtension> list = new ArrayList<IServerExtension>();
      try {
        IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
        IQuery<IInstallableUnit> query =
            QueryUtil.createMatchQuery(
                "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$

        list = getInstallableUnits(repo, query, url2, monitor);
      } catch (ProvisionException pe) {
        Trace.trace(Trace.WARNING, "Error getting update site information", pe); // $NON-NLS-1$
      }

      // Call Method 2 if there are no results from Method 1 (e.g. if the site.xml exists without
      // specifying any server adapters there or no site.xml exists)
      if (list.isEmpty()) {
        IMetadataRepositoryManager manager =
            (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        manager.addRepository(url2);
        // Need to query for all IUs
        IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();

        IMetadataRepository repo = manager.loadRepository(url2, monitor);
        List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor);

        int size = list2.size();
        for (int i = 0; i < size; i++) {
          Extension e = (Extension) list2.get(i);
          IInstallableUnit[] iuArr = e.getIUs();
          if (iuArr != null && iuArr.length > 0) {
            if (iuArr[0] != null) {
              if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) {
                list.add(e);
              }
            }
          }
        }
      }

      // Call Method 3 if no results from Method 2. Creating the p2 update site using the
      // category.xml will generate
      // a provider property with org.eclipse.wst.server.core.serverAdapter
      if (list.isEmpty()) {
        IMetadataRepositoryManager manager =
            (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        manager.addRepository(url2);
        IQuery<IInstallableUnit> query =
            QueryUtil.createMatchQuery(
                "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$

        IMetadataRepository repo = manager.loadRepository(url2, monitor);
        list = getInstallableUnits(repo, query, url2, monitor);
      }

      return list;
    } catch (ProvisionException e) {
      Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$
      throw e;
    } catch (Exception e) {
      Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$

      return new ArrayList<IServerExtension>(0);
    }
  }
Пример #10
0
 /** Return a collection of features that are available to be installed. */
 public Collection getAvailableFeatures() {
   IQuery query = QueryUtil.createIUPropertyQuery(PROP_TOAST_ROOT, Boolean.TRUE.toString());
   IQueryResult result = metadataManager.query(query, new NullProgressMonitor());
   return result.toSet();
 }