Skip to content

Commit 49fffaf

Browse files
authored
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
1 parent 3f2532a commit 49fffaf

3 files changed

Lines changed: 12 additions & 20 deletions

File tree

imgui-binding/build.gradle

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.apache.tools.ant.filters.ReplaceTokens
12
import tool.generator.GenerateLibs
23

34
plugins {
@@ -35,18 +36,10 @@ jar {
3536
}
3637
}
3738

38-
tasks.register('makePropertyResource') {
39-
def directory = file "${buildDir}/resources/main/imgui/"
40-
directory.mkdirs()
41-
def propertyFile = file "${directory}/imgui-java.properties"
42-
def props = new Properties()
43-
if (propertyFile.exists()) {
44-
propertyFile.withReader { props.load(it) }
45-
}
46-
props.setProperty("version", project.version)
47-
propertyFile.withWriter { props.store(it, "imgui-java") }
48-
}
49-
5039
processResources {
51-
dependsOn makePropertyResource
40+
filesMatching('**/imgui-java.properties') {
41+
filter(ReplaceTokens, tokens: [
42+
'version': project.version
43+
])
44+
}
5245
}

imgui-binding/src/main/java/imgui/ImGui.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
2525
import java.nio.file.StandardCopyOption;
26+
import java.util.Optional;
2627
import java.util.Properties;
2728

2829
public class ImGui {
@@ -122,10 +123,7 @@ private static String tryLoadFromClasspath(final String fullLibName) {
122123
return null;
123124
}
124125

125-
String version = getVersionString();
126-
if (version == null) {
127-
version = "unknown";
128-
}
126+
final String version = getVersionString().orElse("undefined");
129127
final Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(LIB_TMP_DIR_PREFIX).resolve(version);
130128
if (!Files.exists(tmpDir)) {
131129
Files.createDirectories(tmpDir);
@@ -146,17 +144,17 @@ private static String tryLoadFromClasspath(final String fullLibName) {
146144
}
147145
}
148146

149-
private static String getVersionString() {
147+
private static Optional<String> getVersionString() {
150148
final Properties properties = new Properties();
151149
try (InputStream is = ImGui.class.getResourceAsStream("/imgui/imgui-java.properties")) {
152150
if (is != null) {
153151
properties.load(is);
154-
return properties.get("version").toString();
152+
return Optional.of(properties.get("imgui.java.version").toString());
155153
}
156154
} catch (IOException e) {
157155
throw new UncheckedIOException(e);
158156
}
159-
return null;
157+
return Optional.empty();
160158
}
161159

162160
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
imgui.java.version=@version@

0 commit comments

Comments
 (0)