private static void rebuildGoogleProjectIfPluginVersionChanged(IProject project) {
    try {
      // We're only worried about Google projects
      if (NatureUtils.hasNature(project, GWTNature.NATURE_ID)
          || NatureUtils.hasNature(project, GaeNature.NATURE_ID)) {
        // Find the last plugin version that know the project was built with
        Version lastForcedRebuildAt = GdtPreferences.getVersionForLastForcedRebuild(project);
        Version currentPluginVersion = GdtPlugin.getVersion();

        if (!lastForcedRebuildAt.equals(currentPluginVersion)) {
          GdtPreferences.setVersionForLastForcedRebuild(project, currentPluginVersion);

          BuilderUtilities.scheduleRebuild(project);
          CorePluginLog.logInfo(
              "Scheduled rebuild of project "
                  + project.getName()
                  + " because of plugin update (current version: "
                  + currentPluginVersion.toString()
                  + ")");
        }
      }
    } catch (CoreException e) {
      CorePluginLog.logError(e);
    }
  }
Esempio n. 2
0
 private static Resource getResource(Set<Resource> resources, String bsn, String versionString) {
   for (Resource resource : resources) {
     List<Capability> identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
     if (identities != null && identities.size() == 1) {
       Capability idCap = identities.get(0);
       Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
       Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
       if (bsn.equals(id)) {
         if (versionString == null) {
           return resource;
         }
         Version requested = Version.parseVersion(versionString);
         Version current;
         if (version instanceof Version) {
           current = (Version) version;
         } else {
           current = Version.parseVersion((String) version);
         }
         if (requested.equals(current)) {
           return resource;
         }
       }
     }
   }
   return null;
 }
  /** Note: Used by Grails tooling */
  public static boolean isGroovyVersionDisabledOrMissing(SpecifiedVersion version) {
    BundleDescription disabledBundle = null;
    disabledBundle = getDisabledBundleDescription(version);
    if (disabledBundle != null) {
      return true;
    }

    Bundle[] active = Platform.getBundles("org.codehaus.groovy", version.toVersionString());
    if (active == null) {
      return true;
    }

    // getBundles returns bundles with version >= specified version,
    // so must do one more check to see if there is a bundle where the
    // major.minor version matches
    for (Bundle bundle : active) {
      Version bundleVersion = bundle.getVersion();
      if (bundleVersion.getMajor() == version.majorVersion
          && bundleVersion.getMajor() == version.majorVersion) {
        return false;
      }
    }
    // no bundle with specifed version has been found
    return true;
  }
 @Override
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   IPluginModelBase plugin = (IPluginModelBase) element;
   Version hVersion = versions.get(plugin.getBundleDescription().getSymbolicName());
   if (hVersion == null) return true;
   return hVersion.equals(plugin.getBundleDescription().getVersion());
 }
 @Test
 public void testUpdateExceptionStop() throws Exception {
   Archive<?> assembly1 =
       assembleArchive(
           "update-bundle-stop-exc1",
           "/bundles/update/update-bundle-stop-exc1",
           BundleStopExActivator.class);
   Archive<?> assembly2 =
       assembleArchive("update-bundle-stop-exc2", "/bundles/update/update-bundle-stop-exc2");
   Bundle bundle1 = installBundle(assembly1);
   try {
     bundle1.start();
     assertEquals(Version.parseVersion("1"), bundle1.getVersion());
     try {
       bundle1.update(toInputStream(assembly2));
       fail("Should have thrown a bundle exception.");
     } catch (BundleException be) {
       // good
     }
     assertEquals(
         "Because bundle.stop() throws an exception the update should not have been applied",
         Version.parseVersion("1"),
         bundle1.getVersion());
   } finally {
     bundle1.uninstall();
   }
 }
Esempio n. 6
0
  /**
   * @warning does not work on Windows because the pattern does not account for .exe extension or
   *     finding a python executable with no version in its name.
   */
  private static String getExecutable(
      final String dirPath, final String execName, Version lessThanVersion) {

    final File dir = new File(dirPath);
    if (!dir.exists()) return null;
    if (!dir.isDirectory()) return null;

    final Pattern pattern = Pattern.compile(execName + "(\\d+\\.?\\d*)");

    String found = null;
    Version version = new Version("0.0.0");
    for (File file : dir.listFiles()) {
      if (!file.isFile()) continue;
      // if (!file.canExecute()) continue;

      final Matcher matcher = pattern.matcher(file.getName());
      if (matcher.matches()) {
        final Version v = new Version(matcher.group(1));
        if (v.compareTo(version) > 0
            && (lessThanVersion == null || v.compareTo(lessThanVersion) < 0)) {
          version = v;
          found = file.getAbsolutePath();
        }
      }
    }

    return found;
  }
Esempio n. 7
0
 /**
  * Returns the selected schema version for the given URI.
  *
  * @param doc document object model of the XML source file
  * @param namespaceUri namespace URI to examine
  * @return selected schema version for the given URI
  */
 public static Version getSchemaVersion(IDOMDocument doc, String namespaceUri) {
   String versLocation = getSelectedSchemaLocation(doc, namespaceUri);
   Matcher matcher = VERSION_PATTERN.matcher(versLocation);
   if (matcher.matches()) {
     return new Version(matcher.group(1));
   } else {
     List<INamespaceDefinition> defs = NamespaceUtils.getNamespaceDefinitions();
     for (INamespaceDefinition def : defs) {
       Version version = Version.emptyVersion;
       if (namespaceUri.equals(def.getNamespaceURI())) {
         Version tempVersion = Version.emptyVersion;
         for (String location : def.getSchemaLocations()) {
           matcher = VERSION_PATTERN.matcher(location);
           if (matcher.matches()) {
             tempVersion = new Version(matcher.group(1));
           }
           if (tempVersion.compareTo(version) >= 0) {
             version = tempVersion;
           }
         }
         return version;
       }
     }
     return Version.emptyVersion;
   }
 }
  /**
   * Cache the installed application location and version in the preferences.
   *
   * @param installDir - The directory the application was installed to.
   * @param versionedFileLocation - Can be the URL that we grabbed the installer from, or any other
   *     string that contains a version information in a form of x.y.z.
   * @param appName - The application name (e.g. xampp)
   */
  @SuppressWarnings("unchecked")
  public void cacheVersion(String installDir, String versionedFileLocation, String appName) {

    IPreferenceStore preferenceStore = PortalUIPlugin.getDefault().getPreferenceStore();
    String versions = preferenceStore.getString(IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME);
    Map<String, Map<String, String>> versionsMap = null;
    if (versions == null || versions.equals(StringUtil.EMPTY)) {
      versionsMap = new HashMap<String, Map<String, String>>();
    } else {
      versionsMap = (Map<String, Map<String, String>>) JSON.parse(versions);
    }
    Map<String, String> appVersionMap = new HashMap<String, String>();
    Version version = VersionUtil.parseVersion(versionedFileLocation);
    if (!VersionUtil.isEmpty(version)) {
      appVersionMap.put(IPortalPreferences.CACHED_VERSION_PROPERTY, version.toString());
      appVersionMap.put(IPortalPreferences.CACHED_LOCATION_PROPERTY, installDir);
      versionsMap.put(appName.toLowerCase(), appVersionMap);
      preferenceStore.setValue(
          IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME, JSON.toString(versionsMap));
    } else {
      IdeLog.logError(
          PortalUIPlugin.getDefault(),
          MessageFormat.format(
              "Could not cache the location and version for {0}. Install dir: {1}, versionedFileLocation: {2}", //$NON-NLS-1$
              appName, installDir, versionedFileLocation),
          new Exception());
    }
  }
 private String getBundleVersion(String symbolicName) {
   final Bundle bundle = Platform.getBundle(symbolicName);
   if (bundle == null) {
     return "NOT FOUND";
   }
   final Version version = bundle.getVersion();
   return version.toString();
 }
 private static String formatVersion(String version) {
   try {
     Version v = new Version(version);
     return v.toString();
   } catch (IllegalArgumentException e) {
   }
   return version;
 }
  /**
   * Pings the usage start server.
   *
   * @param pluginName the name of the plugin to appear in the stats
   * @param pluginVersion the {@link Version} of the plugin.
   */
  public static void pingUsageServer(String pluginName, Version pluginVersion) {
    String versionString =
        String.format(
            "%1$d.%2$d.%3$d",
            pluginVersion.getMajor(), pluginVersion.getMinor(), pluginVersion.getMicro());

    SdkStatsService.ping(pluginName, versionString);
  }
Esempio n. 12
0
  @Test
  public void testUpdateImportedPackagesRemoved() throws Exception {
    Archive<?> assemblyx =
        assembleArchive("bundlex", "/bundles/update/update-bundlex", ObjectX.class);
    Archive<?> assembly1 =
        assembleArchive("bundle1", "/bundles/update/update-bundle1", ObjectA.class);
    Archive<?> assembly2 =
        assembleArchive("bundle2", "/bundles/update/update-bundle101", ObjectB.class);

    Bundle bundleA = installBundle(assembly1);
    Bundle bundleX = installBundle(assemblyx);
    try {
      BundleContext systemContext = getFramework().getBundleContext();
      int beforeCount = systemContext.getBundles().length;

      bundleA.start();
      bundleX.start();

      Class<?> cls = bundleX.loadClass(ObjectX.class.getName());
      cls.newInstance();

      assertBundleState(Bundle.ACTIVE, bundleA.getState());
      assertBundleState(Bundle.ACTIVE, bundleX.getState());
      assertEquals(Version.parseVersion("1.0.0"), bundleA.getVersion());
      assertEquals("update-bundle1", bundleA.getSymbolicName());
      assertLoadClass(bundleA, ObjectA.class.getName());
      assertLoadClassFail(bundleA, ObjectB.class.getName());
      assertLoadClass(bundleX, ObjectA.class.getName());

      bundleA.update(toInputStream(assembly2));
      assertBundleState(Bundle.ACTIVE, bundleA.getState());
      assertBundleState(Bundle.ACTIVE, bundleX.getState());
      assertEquals(Version.parseVersion("1.0.1"), bundleA.getVersion());
      // Assembly X depends on a package in the bundle, this should still be available
      assertLoadClass(bundleX, ObjectA.class.getName());

      getSystemContext().addFrameworkListener(this);
      getPackageAdmin().refreshPackages(new Bundle[] {bundleA});
      assertFrameworkEvent(FrameworkEvent.ERROR, bundleX, BundleException.class);
      assertFrameworkEvent(
          FrameworkEvent.PACKAGES_REFRESHED, getSystemContext().getBundle(0), null);

      assertBundleState(Bundle.ACTIVE, bundleA.getState());
      // Bundle X is installed because it cannot be resolved any more
      assertBundleState(Bundle.INSTALLED, bundleX.getState());
      assertEquals(Version.parseVersion("1.0.1"), bundleA.getVersion());
      // Nobody depends on the packages, so we can update them straight away
      assertLoadClass(bundleA, ObjectB.class.getName());
      assertLoadClassFail(bundleA, ObjectA.class.getName());

      int afterCount = systemContext.getBundles().length;
      assertEquals("Bundle count", beforeCount, afterCount);
    } finally {
      getSystemContext().removeFrameworkListener(this);
      bundleX.uninstall();
      bundleA.uninstall();
    }
  }
 private static URL findNextBestProfile(String javaEdition, Version javaVersion) {
   URL result = null;
   int minor = javaVersion.getMinor();
   do {
     result =
         findInSystemBundle(
             javaEdition + javaVersion.getMajor() + "." + minor + PROFILE_EXT); // $NON-NLS-1$
     minor = minor - 1;
   } while (result == null && minor > 0);
   return result;
 }
  /**
   * Add Maven coordinates as attributes for group id, artifact id and version to the given element.
   *
   * @param el The element to add Maven coordinates to.
   * @param ba The bundle archive to defining the coordinates.
   */
  private void addMavenCoordinates(final Element el, final BundleArchive ba) {
    final int ix = ba.bsn.lastIndexOf('.');
    final String aId = -1 == ix ? ba.bsn : ba.bsn.substring(ix + 1);
    final String gId = -1 == ix ? (String) groupId : ba.bsn.substring(0, ix);
    final Version v = ba.version;

    if (null != gId) {
      el.setAttribute("groupId", gId);
    }
    el.setAttribute("artifactId", aId);
    el.setAttribute("version", v.toString());
  }
Esempio n. 15
0
  public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    launchConfigurationWorkingCopy = configuration;

    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_TOOL, LaunchConfigurationConstants.DEFAULT_TOOL);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD,
        LaunchConfigurationConstants.DEFAULT_GENERAL_TRACECHILD);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_FREERES,
        LaunchConfigurationConstants.DEFAULT_GENERAL_FREERES);

    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_DEMANGLE,
        LaunchConfigurationConstants.DEFAULT_GENERAL_DEMANGLE);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_NUMCALLERS,
        LaunchConfigurationConstants.DEFAULT_GENERAL_NUMCALLERS);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_ERRLIMIT,
        LaunchConfigurationConstants.DEFAULT_GENERAL_ERRLIMIT);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_BELOWMAIN,
        LaunchConfigurationConstants.DEFAULT_GENERAL_BELOWMAIN);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_MAXFRAME,
        LaunchConfigurationConstants.DEFAULT_GENERAL_MAXFRAME);
    configuration.setAttribute(
        LaunchConfigurationConstants.ATTR_GENERAL_SUPPFILES,
        LaunchConfigurationConstants.DEFAULT_GENERAL_SUPPFILES);

    // 3.4.0 specific
    if (valgrindVersion == null || valgrindVersion.compareTo(ValgrindLaunchPlugin.VER_3_4_0) >= 0) {
      configuration.setAttribute(
          LaunchConfigurationConstants.ATTR_GENERAL_MAINSTACK_BOOL,
          LaunchConfigurationConstants.DEFAULT_GENERAL_MAINSTACK_BOOL);
      configuration.setAttribute(
          LaunchConfigurationConstants.ATTR_GENERAL_MAINSTACK,
          LaunchConfigurationConstants.DEFAULT_GENERAL_MAINSTACK);
    }

    // 3.6.0 specific
    if (valgrindVersion == null || valgrindVersion.compareTo(ValgrindLaunchPlugin.VER_3_6_0) >= 0) {
      configuration.setAttribute(
          LaunchConfigurationConstants.ATTR_GENERAL_DSYMUTIL,
          LaunchConfigurationConstants.DEFAULT_GENERAL_DSYMUTIL);
    }

    if (dynamicTab != null) {
      dynamicTab.setDefaults(configuration);
      initDefaults = false;
    }
  }
Esempio n. 16
0
  private boolean getConverter(String convertToId) {

    String fromId = null;
    String toId = null;

    // Get the Converter Extension Point
    IExtensionPoint extensionPoint =
        Platform.getExtensionRegistry()
            .getExtensionPoint(
                "org.eclipse.cdt.managedbuilder.core", //$NON-NLS-1$
                "projectConverter"); //$NON-NLS-1$
    if (extensionPoint != null) {
      // Get the extensions
      IExtension[] extensions = extensionPoint.getExtensions();
      for (int i = 0; i < extensions.length; i++) {
        // Get the configuration elements of each extension
        IConfigurationElement[] configElements = extensions[i].getConfigurationElements();
        for (int j = 0; j < configElements.length; j++) {

          IConfigurationElement element = configElements[j];

          if (element.getName().equals("converter")) { // $NON-NLS-1$

            fromId = element.getAttribute("fromId"); // $NON-NLS-1$
            toId = element.getAttribute("toId"); // $NON-NLS-1$
            // Check whether the current converter can be used for
            // the selected project type

            if (fromId.equals(getId()) && toId.equals(convertToId)) {
              // If it matches
              String mbsVersion = element.getAttribute("mbsVersion"); // $NON-NLS-1$
              Version currentMbsVersion = ManagedBuildManager.getBuildInfoVersion();

              // set the converter element based on the MbsVersion
              if (currentMbsVersion.compareTo(new Version(mbsVersion)) > 0) {
                previousMbsVersionConversionElement = element;
              } else {
                currentMbsVersionConversionElement = element;
              }
              return true;
            }
          }
        }
      }
    }

    // If control comes here, it means 'Tool Integrator' specified
    // 'convertToId' attribute in toolchain definition file, but
    // has not provided any converter. So, make the project is invalid

    return false;
  }
Esempio n. 17
0
 private String getTestApplication(EquinoxInstallationDescription testRuntime) {
   if (useUIHarness) {
     ArtifactDescriptor systemBundle = testRuntime.getSystemBundle();
     Version osgiVersion = Version.parseVersion(systemBundle.getKey().getVersion());
     if (osgiVersion.compareTo(EquinoxInstallationDescription.EQUINOX_VERSION_3_3_0) < 0) {
       return "org.sonatype.tycho.surefire.osgibooter.uitest32";
     } else {
       return "org.sonatype.tycho.surefire.osgibooter.uitest";
     }
   } else {
     return "org.sonatype.tycho.surefire.osgibooter.headlesstest";
   }
 }
 public void setModel(IPluginModelBase[] plugins) {
   if (plugins != null && plugins.length > 0) {
     versions.clear();
   }
   for (int i = 0; i < plugins.length; ++i) {
     String name = plugins[i].getBundleDescription().getSymbolicName();
     Version version = plugins[i].getBundleDescription().getVersion();
     Version oldVersion = versions.get(name);
     if (oldVersion == null || oldVersion.compareTo(version) < 0) {
       versions.put(name, version);
     }
   }
 }
  /**
   * The output stream is left open
   *
   * @param simpleInfos
   * @param stream
   * @throws IOException
   */
  public static void writeConfiguration(BundleInfo[] simpleInfos, OutputStream stream)
      throws IOException {
    // sort by symbolic name
    Arrays.sort(
        simpleInfos,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            if (o1 instanceof BundleInfo && o2 instanceof BundleInfo) {
              BundleInfo b1 = (BundleInfo) o1;
              BundleInfo b2 = (BundleInfo) o2;
              int bsnComparison = b1.getSymbolicName().compareTo(b2.getSymbolicName());
              if (bsnComparison != 0) return bsnComparison;
              // prefer latest version, see https://bugs.eclipse.org/363590
              return new Version(b2.getVersion()).compareTo(new Version(b1.getVersion()));
            }
            return 0;
          }
        });

    BufferedWriter writer = null;
    boolean oldStyle = false;
    boolean utf8 = true;
    for (int i = 0; i < simpleInfos.length; i++) {
      if (SimpleConfiguratorManipulator.SERVICE_PROP_VALUE_CONFIGURATOR_SYMBOLICNAME.equals(
          simpleInfos[i].getSymbolicName())) {
        Version version = new Version(simpleInfos[i].getVersion());
        if (version.compareTo(OLD_STYLE_SIMPLE_CONFIGURATOR_VERSION) < 0) oldStyle = true;
        if (version.compareTo(DEFAULT_ENCODING_CONFIGURATOR_VERSION) <= 0) utf8 = false;
        break;
      }
    }

    if (utf8) {
      writer = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); // $NON-NLS-1$
      // encoding is expected to be the first line
      writer.write(SimpleConfiguratorUtils.ENCODING_UTF8);
      writer.newLine();
    } else {
      writer = new BufferedWriter(new OutputStreamWriter(stream));
    }
    writer.write(createVersionLine());
    writer.newLine();

    // bundle info lines
    for (int i = 0; i < simpleInfos.length; i++) {
      writer.write(createBundleInfoLine(simpleInfos[i], oldStyle));
      writer.newLine();
    }
    writer.flush();
  }
Esempio n. 20
0
  /**
   * Compares v1 <-> v2, if v1 is greater than v2, then result will be > 0 if v2 is greater than v1
   * the result will be < 0
   *
   * @param v1
   * @param v2
   * @return
   */
  public static int compareVersions(Version v1, Version v2) {
    if (v2 == v1) { // quicktest
      return 0;
    }

    int result = v1.getMajor() - v2.getMajor();

    if (result != 0) {
      return result;
    }

    result = v1.getMinor() - v2.getMinor();

    if (result != 0) {
      return result;
    }

    result = v1.getMicro() - v2.getMicro();

    if (result != 0) {
      return result;
    }

    return v1.getQualifier().compareTo(v2.getQualifier());
  }
Esempio n. 21
0
  @Override
  public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    configuration.setAttribute(LaunchConfigurationConstants.ATTR_TOOL, MemcheckPlugin.TOOL_ID);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_LEAKCHECK,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_LEAKCHECK);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_LEAKRES,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_LEAKRES);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_SHOWREACH,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_SHOWREACH);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_FREELIST,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_FREELIST);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_PARTIAL,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_PARTIAL);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_UNDEF,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_UNDEF);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_GCCWORK,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_GCCWORK);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_ALIGNMENT_BOOL,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_ALIGNMENT_BOOL);
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_ALIGNMENT_VAL,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_ALIGNMENT_VAL);

    // VG >= 3.4.0
    if (valgrindVersion == null || valgrindVersion.compareTo(VER_3_4_0) >= 0) {
      configuration.setAttribute(
          MemcheckLaunchConstants.ATTR_MEMCHECK_TRACKORIGINS,
          MemcheckLaunchConstants.DEFAULT_MEMCHECK_TRACKORIGINS);
    }

    // VG >= 3.6.0
    if (valgrindVersion == null || valgrindVersion.compareTo(VER_3_6_0) >= 0) {
      configuration.setAttribute(
          MemcheckLaunchConstants.ATTR_MEMCHECK_POSSIBLY_LOST_BOOL,
          MemcheckLaunchConstants.DEFAULT_MEMCHECK_POSSIBLY_LOST_BOOL);
    }

    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_IGNORE_RANGES,
        MemcheckLaunchConstants.DEFAULT_MEMCHECK_IGNORE_RANGES);
  }
Esempio n. 22
0
  /**
   * Look at the argument URL for the workspace's version information. Return that version if found
   * and null otherwise.
   */
  private static Version readWorkspaceVersion(URL workspace) {
    File versionFile = getVersionFile(workspace, false);
    if (versionFile == null || !versionFile.exists()) {
      return null;
    }

    try {
      // Although the version file is not spec'ed to be a Java properties
      // file, it happens to follow the same format currently, so using
      // Properties to read it is convenient.
      Properties props = new Properties();
      FileInputStream is = new FileInputStream(versionFile);
      try {
        props.load(is);
      } finally {
        is.close();
      }

      String versionString = props.getProperty(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME);
      if (versionString != null) {
        return Version.parseVersion(versionString);
      }
      versionString = props.getProperty(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY);
      if (versionString != null) {
        return Version.parseVersion(versionString);
      }
      return null;
    } catch (IOException e) {
      IDEWorkbenchPlugin.log(
          "Could not read version file " + versionFile,
          new Status( //$NON-NLS-1$
              IStatus.ERROR,
              IDEWorkbenchPlugin.IDE_WORKBENCH,
              IStatus.ERROR,
              e.getMessage() == null ? "" : e.getMessage(), // $NON-NLS-1$
              e));
      return null;
    } catch (IllegalArgumentException e) {
      IDEWorkbenchPlugin.log(
          "Could not parse version in " + versionFile,
          new Status( //$NON-NLS-1$
              IStatus.ERROR,
              IDEWorkbenchPlugin.IDE_WORKBENCH,
              IStatus.ERROR,
              e.getMessage() == null ? "" : e.getMessage(), // $NON-NLS-1$
              e));
      return null;
    }
  }
Esempio n. 23
0
  public static boolean isValidSDKVersion(String sdkVersion, Version lowestValidVersion) {
    Version sdkVersionValue = null;

    try {
      sdkVersionValue = new Version(sdkVersion);
    } catch (Exception ex) {
      // ignore means we don't have valid version
    }

    if (sdkVersionValue != null && sdkVersionValue.compareTo(lowestValidVersion) >= 0) {
      return true;
    }

    return false;
  }
  private static Object convertValueIfNecessary(Object value, String type) throws Exception {
    if (type == null) {
      // No conversion needed
    } else if ("String".equals(type)) {
      // No conversion needed
    } else if ("Version".equals(type)) {
      value = Version.parseVersion(((String) value).trim());
    } else if ("Long".equals(type)) {
      value = Long.parseLong(((String) value).trim());
    } else if ("Double".equals(type)) {
      value = Double.parseDouble(((String) value).trim());
    } else if (type.startsWith("List<")) {
      String scalarType = type.substring("List<".length(), type.length() - 1);
      StringTokenizer values = new StringTokenizer((String) value, ",\\", true);

      ArrayList<Object> list = new ArrayList<Object>();
      String t = null;
      String v = null;
      while (t != null || values.hasMoreTokens()) {
        if (t == null) t = values.nextToken();
        if (t.equals("\\")) {
          if (values.hasMoreTokens()) {
            t = values.nextToken();
            if (t.equals("\\")) {
              v = v == null ? "\\" : v + "\\";
              t = null;
            } else if (t.equals(",")) {
              v = v == null ? "," : v + ",";
              t = null;
            } else {
              v = v == null ? "\\" : v + "\\";
            }
          } else {
            v = v == null ? "\\" : v + "\\";
            t = null;
          }
        } else if (t.equals(",")) {
          if (v == null) {
            list.add(convertValueIfNecessary("", scalarType));
          } else if (v.endsWith("\\")) {
            v += ",";
          } else {
            list.add(convertValueIfNecessary(v.trim(), scalarType));
            v = null;
          }
          t = null;
        } else {
          v = v == null ? t : v + t;
          t = null;
        }
      }
      if (v != null) {
        list.add(convertValueIfNecessary(v.trim(), scalarType));
      }
      value = list;
    } else {
      throw new Exception("Unknown or unsupported type: " + type);
    }
    return value;
  }
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append(fName);
   if (fVersion != null) {
     buf.append(";version="); // $NON-NLS-1$
     buf.append(fVersion.toString());
   }
   if (fFriends != null) {
     buf.append(";x-friends="); // $NON-NLS-1$
     buf.append('"');
     for (int i = 0; i < fFriends.length; i++) {
       if (i > 0) {
         buf.append(',');
       }
       buf.append(fFriends[i]);
     }
     buf.append('"');
   } else {
     if (!fApi) {
       buf.append(";x-internal=true"); // $NON-NLS-1$
     }
   }
   return buf.toString();
 }
  private String getConfigInfoFromManifest(String configType, IPath portalDir) {
    File implJar = portalDir.append("/WEB-INF/lib/portal-impl.jar").toFile();

    String version = null;
    String serverInfo = null;

    if (implJar.exists()) {
      try (JarFile jar = new JarFile(implJar)) {
        Manifest manifest = jar.getManifest();

        Attributes attributes = manifest.getMainAttributes();

        version = attributes.getValue("Liferay-Portal-Version");
        serverInfo = attributes.getValue("Liferay-Portal-Server-Info");

        if (CoreUtil.compareVersions(Version.parseVersion(version), MANIFEST_VERSION_REQUIRED)
            < 0) {
          version = null;
          serverInfo = null;
        }
      } catch (IOException e) {
        LiferayServerCore.logError(e);
      }
    }

    if (configType.equals(CONFIG_TYPE_VERSION)) {
      return version;
    }

    if (configType.equals(CONFIG_TYPE_SERVER)) {
      return serverInfo;
    }

    return null;
  }
 private static String versionToShortString(Version version) {
   String result = version.toString();
   while (result.endsWith(".0")) {
     result = result.substring(0, result.length() - 2);
   }
   return result;
 }
Esempio n. 28
0
 private String getFeatureVersionImpl() {
   String version = "?";
   try {
     final IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
     if (providers != null) {
       version = findErlideFeatureVersion(providers);
     } else {
       ErlLogger.debug("***: no bundle group providers");
     }
   } catch (final Throwable e) {
     // ignore
   }
   final Version coreVersion = getBundle().getVersion();
   version = version + " (core=" + coreVersion.toString() + ")";
   return version;
 }
  /**
   * Construct a {@link StandardDeploymentIdentity} with the given type, name, and version.
   *
   * @param type the type of the deployed artefact
   * @param symbolicName the symbolic name of the deployed artefact
   * @param version the version of the deployed artefact
   */
  public StandardDeploymentIdentity(String type, String symbolicName, String version) {
    this.type = type;
    this.symbolicName = symbolicName;

    // Normalise the version to ensure accurate comparisons.
    this.version = Version.parseVersion(version).toString();
  }
Esempio n. 30
0
  @Override
  public void performApply(ILaunchConfigurationWorkingCopy configuration) {
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_LEAKCHECK, leakCheckButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_LEAKRES, leakResCombo.getText());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_SHOWREACH, showReachableButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_FREELIST, freelistSpinner.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_PARTIAL, partialLoadsButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_UNDEF, undefValueButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_GCCWORK, gccWorkaroundButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_ALIGNMENT_BOOL, alignmentButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_ALIGNMENT_VAL, alignmentSpinner.getSelection());

    // VG >= 3.4.0
    if (valgrindVersion == null || valgrindVersion.compareTo(VER_3_4_0) >= 0) {
      configuration.setAttribute(
          MemcheckLaunchConstants.ATTR_MEMCHECK_TRACKORIGINS, trackOriginsButton.getSelection());
    }

    // VG >= 3.6.0
    if (valgrindVersion == null || valgrindVersion.compareTo(VER_3_6_0) >= 0) {
      configuration.setAttribute(
          MemcheckLaunchConstants.ATTR_MEMCHECK_POSSIBLY_LOST_BOOL,
          showPossiblyLostButton.getSelection());
    }

    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_MALLOCFILL_BOOL, mallocFillButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_MALLOCFILL_VAL, mallocFillText.getText());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_FREEFILL_BOOL, freeFillButton.getSelection());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_FREEFILL_VAL, freeFillText.getText());
    configuration.setAttribute(
        MemcheckLaunchConstants.ATTR_MEMCHECK_IGNORE_RANGES,
        Arrays.asList(ignoreRangesList.getItems()));
  }