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);
}
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;
}
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;
}
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"));
}
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);
}
}
Aggregations