tweak(api): simplify version get from imgui-java.properties file (#204)

Instead of generating `properties` file we make it always.
To provide version value we replace specific token.

Also, small tweaks in code which gets the version
This commit is contained in:
SpaiR authored and GitHub committed 2023-09-29 10:02:21 +03:00
1 parent 3f2532a478
commit 49fffaf02d
3 files changed
+12 -20

No files matched your search

+6 -13
View File
@@ -1,3 +1,4 @@
import org.apache.tools.ant.filters.ReplaceTokens
import tool.generator.GenerateLibs import tool.generator.GenerateLibs
plugins { plugins {
@@ -35,18 +36,10 @@ jar {
} }
} }
tasks.register('makePropertyResource') {
def directory = file "${buildDir}/resources/main/imgui/"
directory.mkdirs()
def propertyFile = file "${directory}/imgui-java.properties"
def props = new Properties()
if (propertyFile.exists()) {
propertyFile.withReader { props.load(it) }
}
props.setProperty("version", project.version)
propertyFile.withWriter { props.store(it, "imgui-java") }
}
processResources { processResources {
dependsOn makePropertyResource filesMatching('**/imgui-java.properties') {
filter(ReplaceTokens, tokens: [
'version': project.version
])
}
} }
+5 -7
View File
@@ -23,6 +23,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.Optional;
import java.util.Properties; import java.util.Properties;
public class ImGui { public class ImGui {
@@ -122,10 +123,7 @@ public class ImGui {
return null; return null;
} }
String version = getVersionString(); final String version = getVersionString().orElse("undefined");
if (version == null) {
version = "unknown";
}
final Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(LIB_TMP_DIR_PREFIX).resolve(version); final Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(LIB_TMP_DIR_PREFIX).resolve(version);
if (!Files.exists(tmpDir)) { if (!Files.exists(tmpDir)) {
Files.createDirectories(tmpDir); Files.createDirectories(tmpDir);
@@ -146,17 +144,17 @@ public class ImGui {
} }
} }
private static String getVersionString() { private static Optional<String> getVersionString() {
final Properties properties = new Properties(); final Properties properties = new Properties();
try (InputStream is = ImGui.class.getResourceAsStream("/imgui/imgui-java.properties")) { try (InputStream is = ImGui.class.getResourceAsStream("/imgui/imgui-java.properties")) {
if (is != null) { if (is != null) {
properties.load(is); properties.load(is);
return properties.get("version").toString(); return Optional.of(properties.get("imgui.java.version").toString());
} }
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
return null; return Optional.empty();
} }
/** /**
@@ -0,0 +1 @@
imgui.java.version=@version@