/**
  * Validates that the version of the given plug-in is available in the registry. Adds a warning if
  * the plug-in could not be found.
  *
  * @param plugin xml element describing the plug-in to look for in the registry
  * @param attr set of element attributes
  */
 private void validateVersion(Element plugin, Attr attr) {
   String id = plugin.getAttribute("id"); // $NON-NLS-1$
   String version = plugin.getAttribute("version"); // $NON-NLS-1$
   if (id.trim().length() == 0
       || version.trim().length() == 0
       || version.equals("0.0.0")) // $NON-NLS-1$
   return;
   ModelEntry entry = MonitorRegistry.findEntry(id);
   if (entry != null) {
     IMonitorModelBase[] allModels = entry.getActiveModels();
     for (int i = 0; i < allModels.length; i++) {
       IMonitorModelBase availablePlugin = allModels[i];
       if (id.equals(availablePlugin.getMonitorBase().getId())) {
         if (version.equals(availablePlugin.getMonitorBase().getVersion())) {
           return;
         }
       }
     }
   }
   report(
       NLS.bind(
           MDECoreMessages.Builders_Feature_mismatchPluginVersion, new String[] {version, id}),
       getLine(plugin, attr.getName()),
       CompilerFlags.WARNING,
       MDEMarkerFactory.CAT_OTHER);
 }
 private static String[] getValue(BundleDescription bundle, MDEState state) {
   IMonitorModelBase model = MonitorRegistry.findModel(bundle);
   String[] result = null;
   if (model != null) {
     IMonitorLibrary[] libs = model.getMonitorBase().getLibraries();
     result = new String[libs.length];
     for (int i = 0; i < libs.length; i++) {
       result[i] = libs[i].getName();
     }
   } else {
     String[] libs = state.getLibraryNames(bundle.getBundleId());
     result = new String[libs.length];
     for (int i = 0; i < libs.length; i++) {
       result[i] = libs[i];
     }
   }
   if (result.length == 0) return new String[] {"."}; // $NON-NLS-1$
   return result;
 }
  public static String getTargetVersionString() {
    IMonitorModelBase model = MonitorRegistry.findModel(IPDEBuildConstants.BUNDLE_OSGI);
    if (model == null) return ICoreConstants.TARGET37;

    String version = model.getMonitorBase().getVersion();
    if (VersionUtil.validateVersion(version).getSeverity() == IStatus.OK) {
      Version vid = new Version(version);
      int major = vid.getMajor();
      int minor = vid.getMinor();
      if (major == 3 && minor == 0) return ICoreConstants.TARGET30;
      if (major == 3 && minor == 1) return ICoreConstants.TARGET31;
      if (major == 3 && minor == 2) return ICoreConstants.TARGET32;
      if (major == 3 && minor == 3) return ICoreConstants.TARGET33;
      if (major == 3 && minor == 4) return ICoreConstants.TARGET34;
      if (major == 3 && minor == 5) return ICoreConstants.TARGET35;
      if (major == 3 && minor == 6) return ICoreConstants.TARGET36;
    }
    return ICoreConstants.TARGET37;
  }
  private String getBundles(boolean defaultAuto) {
    StringBuffer buffer = new StringBuffer();
    Iterator iter = fModels.keySet().iterator();
    while (iter.hasNext()) {
      IMonitorModelBase model = (IMonitorModelBase) iter.next();
      String id = model.getMonitorBase().getId();
      if (!IPDEBuildConstants.BUNDLE_OSGI.equals(id)) {
        if (buffer.length() > 0) buffer.append(","); // $NON-NLS-1$
        buffer.append(LaunchConfigurationHelper.getBundleURL(model, true));

        // fragments must not be started or have a start level
        if (model instanceof IFragmentModel) continue;

        String data = fModels.get(model).toString();
        appendStartData(buffer, data, defaultAuto);
      }
    }
    return buffer.toString();
  }
  private void validateInternalExtensionAttribute(Element element, ISchemaElement schemaElement) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_INTERNAL);
    if (severity == CompilerFlags.IGNORE) return;

    if (schemaElement instanceof ISchemaRootElement) {
      ISchemaRootElement rootElement = (ISchemaRootElement) schemaElement;
      String epid = schemaElement.getSchema().getPluginId();
      String pid = fModel.getMonitorBase().getId();
      if (epid == null || pid == null) return;
      if (rootElement.isInternal() && !epid.equals(pid)) {
        String point = element.getAttribute("point"); // $NON-NLS-1$
        if (point == null) return; // should never come to this...
        report(
            NLS.bind(MDECoreMessages.Builders_Manifest_internal_rootElement, point),
            getLine(element, "point"),
            severity,
            MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$
      }
    }
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.pde.ui.launcher.AbstractPDELaunchConfiguration#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
   */
  protected void preLaunchCheck(
      ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    fModels = BundleLauncherHelper.getMergedBundleMap(configuration, true);
    fAllBundles = new HashMap(fModels.size());
    Iterator iter = fModels.keySet().iterator();
    while (iter.hasNext()) {
      IMonitorModelBase model = (IMonitorModelBase) iter.next();
      fAllBundles.put(model.getMonitorBase().getId(), model);
    }

    if (!fAllBundles.containsKey(IPDEBuildConstants.BUNDLE_OSGI)) {
      // implicitly add it
      IMonitorModelBase model = MonitorRegistry.findModel(IPDEBuildConstants.BUNDLE_OSGI);
      if (model != null) {
        fModels.put(model, "default:default"); // $NON-NLS-1$
        fAllBundles.put(IPDEBuildConstants.BUNDLE_OSGI, model);
      } else {
        String message = MDEMessages.EquinoxLaunchConfiguration_oldTarget;
        throw new CoreException(LauncherUtils.createErrorStatus(message));
      }
    }
    super.preLaunchCheck(configuration, launch, monitor);
  }