예제 #1
0
  public static String resolveArtifactParam(Map<String, Object> parameters) throws CoreException {
    String artifactLocation = (String) parameters.get(EclipseTouchpoint.PARM_ARTIFACT_LOCATION);
    if (artifactLocation != null) return artifactLocation;

    IArtifactKey artifactKey = (IArtifactKey) parameters.get(EclipseTouchpoint.PARM_ARTIFACT);
    if (artifactKey == null) {
      IInstallableUnit iu = (IInstallableUnit) parameters.get(EclipseTouchpoint.PARM_IU);
      throw new CoreException(Util.createError(NLS.bind(Messages.iu_contains_no_arifacts, iu)));
    }

    throw new CoreException(
        Util.createError(NLS.bind(Messages.artifact_file_not_found, artifactKey)));
  }
예제 #2
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);
  }
  public void testExecuteUndo() throws Exception {
    Properties profileProperties = new Properties();
    File installFolder = getTempFolder();
    profileProperties.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.toString());
    profileProperties.setProperty(IProfile.PROP_CACHE, installFolder.toString());
    IProfile profile = createProfile("test", profileProperties);

    IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(getAgent(), profile);
    File osgiSource =
        getTestData(
            "1.0",
            "/testData/eclipseTouchpoint/bundles/org.eclipse.osgi.source_3.4.2.R34x_v20080826-1230.jar");
    File targetPlugins = new File(installFolder, "plugins");
    assertTrue(targetPlugins.mkdir());
    File osgiTarget =
        new File(targetPlugins, "org.eclipse.osgi.source_3.4.2.R34x_v20080826-1230.jar");
    copy("2.0", osgiSource, osgiTarget);

    BundleDescription bundleDescription = BundlesAction.createBundleDescription(osgiTarget);
    IArtifactKey key =
        BundlesAction.createBundleArtifactKey(
            bundleDescription.getSymbolicName(), bundleDescription.getVersion().toString());
    IArtifactDescriptor descriptor = PublisherHelper.createArtifactDescriptor(key, osgiTarget);
    IInstallableUnit iu = createBundleIU(bundleDescription, osgiTarget.isDirectory(), key);
    bundlePool.addDescriptor(descriptor);

    Map parameters = new HashMap();
    parameters.put(ActionConstants.PARM_AGENT, getAgent());
    parameters.put(ActionConstants.PARM_PROFILE, profile);
    EclipseTouchpoint touchpoint = new EclipseTouchpoint();
    touchpoint.initializePhase(null, profile, "test", parameters);
    InstallableUnitOperand operand = new InstallableUnitOperand(null, iu);
    parameters.put("iu", operand.second());
    touchpoint.initializeOperand(profile, parameters);

    parameters.put(ActionConstants.PARM_BUNDLE, key.toString());
    parameters = Collections.unmodifiableMap(parameters);

    SourceManipulator manipulator =
        (SourceManipulator) parameters.get(EclipseTouchpoint.PARM_SOURCE_BUNDLES);
    assertNotNull(manipulator);

    assertFalse(inBundles(manipulator, osgiTarget));
    AddSourceBundleAction action = new AddSourceBundleAction();
    action.execute(parameters);
    assertTrue(inBundles(manipulator, osgiTarget));
    action.undo(parameters);
    assertFalse(inBundles(manipulator, osgiTarget));
  }