private Map<String, EnhancedFeature> loadWSO2FeaturesInRepo(
      IArtifactRepository artifactRepository,
      IQueryResult<IInstallableUnit> allAvailableIUs,
      IProgressMonitor monitor)
      throws ProvisionException, URISyntaxException, IOException {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    SubMonitor progress = SubMonitor.convert(monitor, Messages.UpdateManager_15, 10);

    String tmpRoot = System.getProperty(JAVA_IO_TMPDIR) + File.separator + DEVS_UPDATER_TMP;

    Collection<IInstallableUnit> wso2FeatureJars =
        filterInstallableUnits(
            WSO2_FEATURE_PREFIX, FEATURE_JAR_IU_ID_SFX, allAvailableIUs, progress.newChild(1));

    Map<String, EnhancedFeature> loadedFeatureMap = new HashMap<>();

    for (IInstallableUnit iu : wso2FeatureJars) {
      SubMonitor downloadProgress =
          SubMonitor.convert(progress, Messages.UpdateManager_16, wso2FeatureJars.size() * 2);
      Collection<IArtifactKey> artifacts = iu.getArtifacts();
      // ideally there should be only one artifact in a feature.jar iu
      for (IArtifactKey iArtifactKey : artifacts) {
        IArtifactDescriptor[] artifactDescriptors =
            artifactRepository.getArtifactDescriptors(iArtifactKey);
        File featureCacheRoot =
            new File(tmpRoot, iu.getId() + File.separator + iu.getVersion().toString());
        File cachedFeatureDir = new File(featureCacheRoot, FEATURE_JAR_EXTRCT_FOLDER);

        if (cachedFeatureDir.exists() && cachedFeatureDir.isDirectory()) {
          downloadProgress.worked(2);
        } else {
          featureCacheRoot.mkdirs();
          File jarFile = new File(featureCacheRoot, iu.getId());
          try {
            if (jarFile.exists()) {
              // something is wrong with the file
              // if it is there without the cache dir.
              jarFile.delete();
            }
            FileOutputStream fop = new FileOutputStream(jarFile);
            // jar iu only contains a single artifact. hence [0]
            artifactRepository.getArtifact(
                artifactDescriptors[0], fop, downloadProgress.newChild(1));
            cachedFeatureDir.mkdirs();
            extractJar(jarFile, cachedFeatureDir);
            downloadProgress.worked(1);
          } catch (IOException e) {
            throw new IOException(Messages.UpdateManager_17, e);
          }
        }
        EnhancedFeature feature = readEnhancedMetadata(iu, cachedFeatureDir);
        loadedFeatureMap.put(feature.getId(), feature);
      }
    }
    return loadedFeatureMap;
  }
Example #2
0
 private IArtifactDescriptor[] getArtifactKeyFor(
     IArtifactRepository repo, String classifier, String id, Version version) {
   return repo.getArtifactDescriptors(new ArtifactKey(classifier, id, version));
 }