Search in sources :

Example 6 with Version

use of com.intellij.openapi.util.Version in project intellij-plugins by JetBrains.

the class Reveal method getRevealVersion.

@Nullable
public static Version getRevealVersion(@NotNull File bundle) {
    Plist plist = PlistDriver.readAnyFormatSafe(new File(bundle, "Contents/Info.plist"));
    if (plist == null)
        return null;
    String version = plist.getString("CFBundleVersion");
    if (version == null)
        return null;
    List<String> parts = StringUtil.split(version, ".");
    if (parts.isEmpty())
        return null;
    return new Version(StringUtil.parseInt(parts.get(0), 0), parts.size() > 1 ? StringUtil.parseInt(parts.get(1), 0) : 0, parts.size() > 2 ? StringUtil.parseInt(parts.get(2), 0) : 0);
}
Also used : Plist(com.jetbrains.cidr.xcode.plist.Plist) Version(com.intellij.openapi.util.Version) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with Version

use of com.intellij.openapi.util.Version in project intellij-elixir by KronicDeth.

the class ElixirSdkType method homePathByVersion.

/**
   * Map of home paths to versions in descending version order so that newer versions are favored.
   *
   * @return Map
   */
private Map<Version, String> homePathByVersion() {
    Map<Version, String> homePathByVersion = new TreeMap<Version, String>(new Comparator<Version>() {

        @Override
        public int compare(Version version1, Version version2) {
            // compare version2 to version1 to produce descending instead of ascending order.
            return version2.compareTo(version1);
        }
    });
    if (SystemInfo.isMac) {
        File homebrewRoot = new File("/usr/local/Cellar/elixir");
        if (homebrewRoot.isDirectory()) {
            File[] files = homebrewRoot.listFiles();
            if (files != null) {
                for (File child : files) {
                    if (child.isDirectory()) {
                        String versionString = child.getName();
                        String[] versionParts = versionString.split("\\.", 3);
                        int major = Integer.parseInt(versionParts[0]);
                        int minor = Integer.parseInt(versionParts[1]);
                        int bugfix = Integer.parseInt(versionParts[2]);
                        Version version = new Version(major, minor, bugfix);
                        homePathByVersion.put(version, child.getAbsolutePath());
                    }
                }
            }
        }
    } else {
        Version version = new Version(0, 0, 0);
        String sdkPath = "";
        if (SystemInfo.isWindows) {
            if (SystemInfo.is32Bit) {
                sdkPath = "C:\\Program Files\\Elixir";
            } else {
                sdkPath = "C:\\Program Files (x86)\\Elixir";
            }
        } else if (SystemInfo.isLinux) {
            sdkPath = "/usr/local/lib/elixir";
        }
        homePathByVersion.put(version, sdkPath);
    }
    return homePathByVersion;
}
Also used : Version(com.intellij.openapi.util.Version) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with Version

use of com.intellij.openapi.util.Version in project intellij-elixir by KronicDeth.

the class SdkType method homePathByVersion.

/*
     * Private
     */
/**
     * Map of home paths to versions in descending version order so that newer versions are favored.
     *
     * @return
     */
private Map<Version, String> homePathByVersion() {
    Map<Version, String> homePathByVersion = new TreeMap<Version, String>(new Comparator<Version>() {

        @Override
        public int compare(Version version1, Version version2) {
            // compare version2 to version1 to produce descending instead of ascending order.
            return version2.compareTo(version1);
        }
    });
    if (SystemInfo.isMac) {
        File homebrewRoot = new File("/usr/local/Cellar/elixir");
        if (homebrewRoot.isDirectory()) {
            //noinspection ConstantConditions
            for (File child : homebrewRoot.listFiles()) {
                if (child.isDirectory()) {
                    String versionString = child.getName();
                    String[] versionParts = versionString.split("\\.", 3);
                    int major = Integer.parseInt(versionParts[0]);
                    int minor = Integer.parseInt(versionParts[1]);
                    int bugfix = Integer.parseInt(versionParts[2]);
                    Version version = new Version(major, minor, bugfix);
                    homePathByVersion.put(version, child.getAbsolutePath());
                }
            }
        }
    }
    return homePathByVersion;
}
Also used : Version(com.intellij.openapi.util.Version) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 9 with Version

use of com.intellij.openapi.util.Version in project intellij-community by JetBrains.

the class VersionTest method testParseVersion.

public void testParseVersion() throws Exception {
    assertEquals(new Version(1, 0, 0), Version.parseVersion("1"));
    assertEquals(new Version(1, 2, 0), Version.parseVersion("1.2"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3.4"));
    assertEquals(new Version(1, 0, 0), Version.parseVersion("1beta"));
    assertEquals(new Version(1, 2, 0), Version.parseVersion("1.2beta"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3beta"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3.4beta"));
    assertEquals(new Version(1, 0, 0), Version.parseVersion("1-beta"));
    assertEquals(new Version(1, 2, 0), Version.parseVersion("1.2-beta"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3-beta"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3.4-beta"));
    assertEquals(new Version(1, 0, 0), Version.parseVersion("1.beta"));
    assertEquals(new Version(1, 2, 0), Version.parseVersion("1.2.beta"));
    assertEquals(new Version(1, 2, 3), Version.parseVersion("1.2.3.beta"));
    assertEquals(null, Version.parseVersion(""));
    assertEquals(null, Version.parseVersion("beta1"));
    assertEquals(null, Version.parseVersion("beta.beta.beta"));
}
Also used : Version(com.intellij.openapi.util.Version)

Example 10 with Version

use of com.intellij.openapi.util.Version in project intellij-community by JetBrains.

the class JdkBundleList method addBundlesFromLocation.

public void addBundlesFromLocation(@NotNull String location, @Nullable Version minVer, @Nullable Version maxVer) {
    File jvmLocation = new File(location);
    if (!jvmLocation.exists()) {
        LOG.debug("Standard jvm location does not exists: " + jvmLocation);
        return;
    }
    File[] jvms = jvmLocation.listFiles();
    if (jvms == null) {
        LOG.debug("Cannot get jvm list from: " + jvmLocation);
        return;
    }
    for (File jvm : jvms) {
        JdkBundle jvmBundle = JdkBundle.createBundle(jvm, false, false);
        if (jvmBundle == null || jvmBundle.getVersionUpdate() == null)
            continue;
        Version jdkVer = jvmBundle.getVersion();
        // Skip unknown
        if (jdkVer == null)
            continue;
        if (minVer != null && jdkVer.lessThan(minVer.major, minVer.minor, minVer.bugfix)) {
            // Skip below supported
            continue;
        }
        if (maxVer != null && maxVer.lessThan(jdkVer.major, jdkVer.minor, jdkVer.bugfix)) {
            // Skip above supported
            continue;
        }
        addBundle(jvmBundle, false);
    }
}
Also used : Version(com.intellij.openapi.util.Version) File(java.io.File)

Aggregations

Version (com.intellij.openapi.util.Version)15 File (java.io.File)8 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Matcher (java.util.regex.Matcher)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.Test)2 GroupDescriptor (com.intellij.internal.statistic.beans.GroupDescriptor)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Notification (com.intellij.notification.Notification)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 RequestFailedException (com.intellij.tasks.impl.RequestFailedException)1 JdkBundle (com.intellij.util.JdkBundle)1 Plist (com.jetbrains.cidr.xcode.plist.Plist)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1