/**
   * Swtiches to or from groovy version 1.6.x depending on the boolean passed in A restart is
   * required immediately after or else many exceptions will be thrown.
   *
   * @param toVersion16
   * @return {@link Status.OK_STATUS} if successful or error status that contains the exception
   *     thrown otherwise
   */
  public static IStatus switchVersions(SpecifiedVersion fromVersion, SpecifiedVersion toVersion) {
    try {
      State state = ((StateManager) Platform.getPlatformAdmin()).getSystemState();
      BundleDescription toBundle = getBundleDescription(toVersion);
      BundleDescription[] allBundles = getAllGroovyBundleDescriptions();
      if (toBundle == null) {
        throw new Exception("Could not find any " + toVersion + " groovy version to enable");
      }

      // go through all bundles and ensure disabled
      for (BundleDescription bundle : allBundles) {
        DisabledInfo info = createDisabledInfo(state, bundle.getBundleId());
        if (bundle.equals(toBundle)) {
          // ensure enabled
          Platform.getPlatformAdmin().removeDisabledInfo(info);
        } else {
          // don't actually stop
          // switch (bundle.getState()) {
          // case Bundle.ACTIVE:
          // case Bundle.INSTALLED:
          // case Bundle.STARTING:
          // case Bundle.RESOLVED:
          // bundle.stop();
          // }
          // ensure disabled
          Platform.getPlatformAdmin().addDisabledInfo(info);
        }
      }
      CompilerLevelUtils.writeConfigurationVersion(
          toVersion,
          // need to get the system bundle
          GroovyCoreActivator.getDefault()
              .getBundle()
              .getBundleContext()
              .getBundle(0)
              .getBundleContext());
      return Status.OK_STATUS;
    } catch (Exception e) {
      GroovyCore.logException(e.getMessage(), e);
      return new Status(
          IStatus.ERROR,
          GroovyCoreActivator.PLUGIN_ID,
          e.getMessage() + "\n\nSee the error log for more information.",
          e);
    }
  }
 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;
 }
Ejemplo n.º 3
0
 private void addSWTJars(List rtes) {
   if (fgSWTEntries == null) {
     fgSWTEntries = new ArrayList();
     Bundle bundle = Platform.getBundle("org.eclipse.swt"); // $NON-NLS-1$
     BundleDescription description =
         Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId());
     BundleDescription[] fragments = description.getFragments();
     for (int i = 0; i < fragments.length; i++) {
       Bundle fragmentBundle = Platform.getBundle(fragments[i].getName());
       URL bundleURL;
       try {
         bundleURL = FileLocator.resolve(fragmentBundle.getEntry("/")); // $NON-NLS-1$
       } catch (IOException e) {
         AntLaunching.log(e);
         continue;
       }
       String urlFileName = bundleURL.getFile();
       if (urlFileName.startsWith("file:")) { // $NON-NLS-1$
         try {
           urlFileName = new URL(urlFileName).getFile();
           if (urlFileName.endsWith("!/")) { // $NON-NLS-1$
             urlFileName = urlFileName.substring(0, urlFileName.length() - 2);
           }
         } catch (MalformedURLException e) {
           AntLaunching.log(e);
           continue;
         }
       }
       IPath fragmentPath = new Path(urlFileName);
       if (fragmentPath.getFileExtension() != null) { // JAR file
         fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath));
       } else { // folder
         File bundleFolder = fragmentPath.toFile();
         if (!bundleFolder.isDirectory()) {
           continue;
         }
         String[] names =
             bundleFolder.list(
                 new FilenameFilter() {
                   public boolean accept(File dir, String name) {
                     return name.endsWith(".jar"); // $NON-NLS-1$
                   }
                 });
         for (int j = 0; j < names.length; j++) {
           String jarName = names[j];
           fgSWTEntries.add(
               JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath.append(jarName)));
         }
       }
     }
   }
   rtes.addAll(fgSWTEntries);
 }
 private static BundleDescription[] getAllGroovyBundleDescriptions() {
   BundleDescription[] bundles =
       Platform.getPlatformAdmin().getState(false).getBundles("org.codehaus.groovy");
   // sort by version
   Arrays.sort(
       bundles,
       new Comparator<BundleDescription>() {
         public int compare(BundleDescription l, BundleDescription r) {
           // reverse order so highest version is first
           return r.getVersion().compareTo(l.getVersion());
         }
       });
   return bundles;
 }
  /**
   * Build the table of plug-in dependencies. Iterate over all the plug-ins in the plug-in registry
   * and the cycle through the list of pre-requisites and create the parent/child relationships in
   * the nodes.
   */
  private Map getDependencyGraph() {
    if (dependencyGraph != null) return dependencyGraph;
    // Build up the dependency graph (see PluginDependencyGraphNode) so
    // we have the information readily available for any plug-in.
    State state = Platform.getPlatformAdmin().getState(false);
    BundleDescription[] plugins = state.getBundles();
    dependencyGraph = new HashMap();
    for (int i = 0; i < plugins.length; i++) {
      BundleDescription descriptor = plugins[i];
      PluginDependencyGraphNode node =
          (PluginDependencyGraphNode) dependencyGraph.get(new Long(descriptor.getBundleId()));
      if (node == null) {
        node = new PluginDependencyGraphNode(descriptor);
        dependencyGraph.put(new Long(descriptor.getBundleId()), node);
      }

      // Cycle through the prerequisites
      BundleSpecification[] requires = descriptor.getRequiredBundles();
      for (int j = 0; j < requires.length; j++) {
        BundleDescription childDesc = (BundleDescription) requires[j].getSupplier();
        // if the child doesn't exist then move to the next child
        if (childDesc == null) continue;

        // if the child entry is not in the table yet then add it
        PluginDependencyGraphNode childNode =
            (PluginDependencyGraphNode) dependencyGraph.get(new Long(childDesc.getBundleId()));
        if (childNode == null) {
          childNode = new PluginDependencyGraphNode(childDesc);
          dependencyGraph.put(new Long(childDesc.getBundleId()), childNode);
        }

        // Add the child to this node's children and set this node as an ancestor
        // of the child node
        node.addChild(childNode);
        childNode.addAncestor(node);
      }
    }
    return dependencyGraph;
  }
 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;
 }