Skip to content

Commit

Permalink
removing maven resources plugin dependency from SDK (dapr#1193)
Browse files Browse the repository at this point in the history
* removing maven resources plugin dependency from SDK

Signed-off-by: salaboy <[email protected]>

* Update pom.xml

Signed-off-by: salaboy <[email protected]>

* adding maven resources plugin as a plugin

Signed-off-by: salaboy <[email protected]>

* Self-validate presence of sdk_version.

Signed-off-by: Artur Souza <[email protected]>

---------

Signed-off-by: salaboy <[email protected]>
Signed-off-by: Artur Souza <[email protected]>
Co-authored-by: Artur Souza <[email protected]>
  • Loading branch information
salaboy and artursouza committed Jan 19, 2025
1 parent bb4b70c commit 2616c3c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
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;
}

}

0 comments on commit 2616c3c

Please sign in to comment.