Skip to content

Commit

Permalink
Add CMake version retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
jomof committed Jan 4, 2017
1 parent bc7f494 commit 5945e66
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/jomofisher/cmake/CMake.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,28 @@ public String getVersionString() throws IOException {
}
return line.substring(CMAKE_VERSION_LINE_PREFIX.length());
}

/**
* Get the current CMake version as a structure
*/
public CMakeVersion getVersion() throws IOException {
String string = getVersionString();
String[] parts = string.split("\\.");
if (parts[2].contains("-")) {
// There is a tag, as in 3.6.0-rc2
String[] subparts = parts[2].split("-");
return new CMakeVersion(
Integer.parseInt(parts[0]),
Integer.parseInt(parts[1]),
Integer.parseInt(subparts[0]),
subparts[1]);
}

// There's no tag
return new CMakeVersion(
Integer.parseInt(parts[0]),
Integer.parseInt(parts[1]),
Integer.parseInt(parts[2]),
"");
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/jomofisher/cmake/CMakeVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.jomofisher.cmake;

/**
* A CMake release version
*/
public class CMakeVersion {
final public int major;
final public int minor;
final public int point;
final public String tag;

CMakeVersion(int major, int minor, int point, String tag) {
this.major = major;
this.minor = minor;
this.point = point;
this.tag = tag;
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/jomofisher/tests/cmake/TestCMakeServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jomofisher.cmake.CMake;
import com.jomofisher.cmake.CMakeVersion;
import com.jomofisher.cmake.database.Compilation;
import com.jomofisher.cmake.serverv1.*;
import com.jomofisher.literatehash.LiterateHash;
Expand Down Expand Up @@ -380,6 +381,18 @@ public void testAndroidStudioCMakeVersion() throws Exception {
CMake cmake = new CMake(getAndroidStudioCMakeExecutable().getParentFile());
String version = cmake.getVersionString();
assertThat(version).isEqualTo("3.6.0-rc2");
CMakeVersion cmakeVersion = cmake.getVersion();
assertThat(cmakeVersion.major).isEqualTo(3);
assertThat(cmakeVersion.minor).isEqualTo(6);
assertThat(cmakeVersion.point).isEqualTo(0);
assertThat(cmakeVersion.tag).isEqualTo("rc2");
}

@Test
public void testCMakeVersion() throws Exception {
CMake cmake = new CMake(getCMakeInstallFolder());
CMakeVersion cmakeVersion = cmake.getVersion();
assertThat(cmakeVersion.major).isEqualTo(3);
}

@Test
Expand Down

0 comments on commit 5945e66

Please sign in to comment.