Skip to content

Commit

Permalink
tweak(api): simplify version get
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SpaiR committed Sep 29, 2023
1 parent a704140 commit f9acb72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
19 changes: 6 additions & 13 deletions imgui-binding/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.apache.tools.ant.filters.ReplaceTokens
import tool.generator.GenerateLibs

plugins {
Expand Down Expand Up @@ -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 {
dependsOn makePropertyResource
filesMatching('**/imgui-java.properties') {
filter(ReplaceTokens, tokens: [
'version': project.version
])
}
}
12 changes: 5 additions & 7 deletions imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Optional;
import java.util.Properties;

public class ImGui {
Expand Down Expand Up @@ -122,10 +123,7 @@ private static String tryLoadFromClasspath(final String fullLibName) {
return null;
}

String version = getVersionString();
if (version == null) {
version = "unknown";
}
final String version = getVersionString().orElse("undefined");
final Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(LIB_TMP_DIR_PREFIX).resolve(version);
if (!Files.exists(tmpDir)) {
Files.createDirectories(tmpDir);
Expand All @@ -146,17 +144,17 @@ private static String tryLoadFromClasspath(final String fullLibName) {
}
}

private static String getVersionString() {
private static Optional<String> getVersionString() {
final Properties properties = new Properties();
try (InputStream is = ImGui.class.getResourceAsStream("/imgui/imgui-java.properties")) {
if (is != null) {
properties.load(is);
return properties.get("version").toString();
return Optional.of(properties.get("imgui.java.version").toString());
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return null;
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imgui.java.version=@version@

0 comments on commit f9acb72

Please sign in to comment.