Exemplo n.º 1
0
 @Override
 public boolean equals(Object obj) {
   if (!(obj instanceof IArtifactKey)) return false;
   IArtifactKey ak = (IArtifactKey) obj;
   return ak.getId().equals(id)
       && ak.getVersion().equals(getVersion())
       && ak.getClassifier().equals(classifier);
 }
  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));
  }
 private URI locationFor(IArtifactKey key) {
   try {
     return new URI(SCHEME, key.toString(), null);
   } catch (URISyntaxException e) {
     Assert.fail("Invalid URI in TestArtifactRepository: " + e.getMessage());
     return null;
   }
 }
 public void removeDescriptor(IArtifactKey key, IProgressMonitor monitor) {
   for (IArtifactDescriptor nextDescriptor : artifactDescriptors) {
     if (key.equals(nextDescriptor.getArtifactKey())) artifactDescriptors.remove(nextDescriptor);
   }
   if (keysToLocations.containsKey(key)) {
     URI theLocation = keysToLocations.get(key);
     locationsToContents.remove(theLocation);
     keysToLocations.remove(key);
   }
 }
 protected GAV getP2GAV(IArtifactDescriptor descriptor) {
   IArtifactKey key = descriptor.getArtifactKey();
   StringBuffer version = new StringBuffer();
   key.getVersion().toString(version);
   return RepositoryLayoutHelper.getP2Gav(key.getClassifier(), key.getId(), version.toString());
 }