public static BundleDescription getBundleDescription(SpecifiedVersion version) {
   BundleDescription[] active = getAllGroovyBundleDescriptions();
   // return highest bundle version that matches the major.minor specified
   // version
   for (BundleDescription bundle : active) {
     if (bundle.getVersion().getMajor() == version.majorVersion
         && bundle.getVersion().getMinor() == version.minorVersion) {
       return bundle;
     }
   }
   return null;
 }
 private static BundleDescription getDisabledBundleDescription(SpecifiedVersion version) {
   BundleDescription[] bundles = Platform.getPlatformAdmin().getState(false).getDisabledBundles();
   for (BundleDescription bundle : bundles) {
     if (bundle.getSymbolicName().equals("org.codehaus.groovy")
         && bundle.getVersion().getMajor() == version.majorVersion
         && bundle.getVersion().getMinor() == version.minorVersion) {
       return bundle;
     }
   }
   return null;
 }
 public static Bundle getActiveGroovyBundle() {
   BundleDescription bundleDesc = getActiveGroovyBundleDescription();
   if (bundleDesc == null) {
     return null;
   }
   Bundle[] allBundles =
       Platform.getBundles("org.codehaus.groovy", bundleDesc.getVersion().toString());
   if (allBundles == null || allBundles.length == 0) {
     return null;
   }
   return allBundles[0];
 }
 private static BundleDescription getActiveGroovyBundleDescription() {
   BundleDescription[] active = getAllGroovyBundleDescriptions();
   if (active == null || active.length == 0) {
     return null;
   }
   // go through each bundle in versioned order and see if it is disabled
   // The highest bundle that is not disabled is the active bundle
   BundleDescription[] disabled = Platform.getPlatformAdmin().getState(false).getDisabledBundles();
   for (BundleDescription bundle : active) {
     boolean isAvailable = true;
     for (BundleDescription d : disabled) {
       if (d.getVersion().equals(bundle.getVersion())
           && d.getSymbolicName().equals(bundle.getSymbolicName())) {
         isAvailable = false;
         break;
       }
     }
     if (isAvailable) {
       return bundle;
     }
   }
   return null;
 }
  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));
  }
Пример #6
0
 /**
  * Returns an IU corresponding to the given artifact key and bundle, or <code>null</code> if an IU
  * could not be created.
  */
 public static IInstallableUnit createBundleIU(IArtifactKey artifactKey, File bundleFile) {
   BundleDescription bundleDescription = BundlesAction.createBundleDescription(bundleFile);
   if (bundleDescription == null) return null;
   PublisherInfo info = new PublisherInfo();
   Version version = Version.create(bundleDescription.getVersion().toString());
   AdviceFileAdvice advice =
       new AdviceFileAdvice(
           bundleDescription.getSymbolicName(),
           version,
           new Path(bundleFile.getAbsolutePath()),
           AdviceFileAdvice.BUNDLE_ADVICE_FILE);
   if (advice.containsAdvice()) info.addAdvice(advice);
   String shape = bundleFile.isDirectory() ? IBundleShapeAdvice.DIR : IBundleShapeAdvice.JAR;
   info.addAdvice(new BundleShapeAdvice(bundleDescription.getSymbolicName(), version, shape));
   return BundlesAction.createBundleIU(bundleDescription, artifactKey, info);
 }
  /**
   * Provides UI for switching compiler between versions
   *
   * @param toVersion
   */
  private static void switchVersion(
      final SpecifiedVersion toVersion, final Composite compilerPage) {
    final BundleDescription toBundle = CompilerUtils.getBundleDescription(toVersion);
    if (toBundle == null) {
      // this version is not installed
      return;
    }

    Button switchTo = new Button(compilerPage, SWT.PUSH);
    switchTo.setText("Switch to " + toBundle.getVersion());
    switchTo.addSelectionListener(
        new SelectionListener() {

          public void widgetSelected(SelectionEvent e) {
            Shell shell = compilerPage.getShell();
            boolean result =
                MessageDialog.openQuestion(
                    shell,
                    "Change compiler and restart?",
                    "Do you want to change the compiler?\n\nIf you select \"Yes\","
                        + " the compiler will be changed and Eclipse will be restarted.\n\n"
                        + "Make sure all your work is saved before clicking \"Yes\".");

            if (result) {
              // change compiler
              SpecifiedVersion activeGroovyVersion = CompilerUtils.getActiveGroovyVersion();
              IStatus status = CompilerUtils.switchVersions(activeGroovyVersion, toVersion);
              if (status == Status.OK_STATUS) {
                restart(shell);
              } else {
                ErrorDialog error =
                    new ErrorDialog(
                        shell,
                        "Error occurred",
                        "Error occurred when trying to enable Groovy " + toBundle.getVersion(),
                        status,
                        IStatus.ERROR);
                error.open();
              }
            }
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });
  }
 public static SpecifiedVersion getActiveGroovyVersion() {
   BundleDescription groovyBundle = getActiveGroovyBundleDescription();
   return SpecifiedVersion.findVersion(groovyBundle.getVersion());
 }
 /** Note: Used by Grails tooling */
 public static String getGroovyVersion() {
   BundleDescription groovyBundle = getActiveGroovyBundleDescription();
   return groovyBundle != null ? groovyBundle.getVersion().toString() : "NONE";
 }
 public String deriveMavenVersion(@NotNull BundleDescription bundle) {
   final Version version = Version.parse(bundle.getVersion().toString());
   return deriveMavenVersion(bundle, version);
 }