Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
<maven-deploy-plugin.version>2.7</maven-deploy-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down Expand Up @@ -156,6 +157,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down
11 changes: 5 additions & 6 deletions sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
<argLine>
--add-opens java.base/java.util=ALL-UNNAMED
</argLine>

</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-autogen</artifactId>
Expand Down Expand Up @@ -169,6 +164,10 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
26 changes: 19 additions & 7 deletions sdk/src/main/java/io/dapr/utils/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,43 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;

public final class Version {

private static String sdkVersion = null;
private static volatile AtomicReference<String> sdkVersion = new AtomicReference<>();

/**
* Retrieves sdk version from resources.
*
* @return String version of sdk.
*/
public static String getSdkVersion() {
var version = sdkVersion.get();

if (sdkVersion != null) {
return sdkVersion;
if ((version != null) && !version.isBlank()) {
return version;
}

try (InputStream input = Version.class.getResourceAsStream("/sdk_version.properties");) {
try (InputStream input = Version.class.getResourceAsStream("/sdk_version.properties")) {
Properties properties = new Properties();
properties.load(input);
sdkVersion = "dapr-sdk-java/v" + properties.getProperty("sdk_version", "unknown");
var v = properties.getProperty("sdk_version", null);
if (v == null) {
throw new IllegalStateException("Did not find sdk_version property!");
}

if (v.isBlank()) {
throw new IllegalStateException("Property sdk_version cannot be blank.");
}

version = "dapr-sdk-java/v" + v;
sdkVersion.set(version);
} catch (IOException e) {
sdkVersion = "unknown";
throw new IllegalStateException("Could not load sdk_version property!", e);
}

return sdkVersion;
return version;
}

}
Loading