diff --git a/sdk/storage/azure-storage-queue/pom.xml b/sdk/storage/azure-storage-queue/pom.xml index 886d42a15b28..2fe6a2793121 100644 --- a/sdk/storage/azure-storage-queue/pom.xml +++ b/sdk/storage/azure-storage-queue/pom.xml @@ -81,9 +81,14 @@ src/main/java src/test/java + + + src/main/resources + true + + - org.apache.maven.plugins maven-compiler-plugin diff --git a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/BaseQueueClientBuilder.java b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/BaseQueueClientBuilder.java index 1d13bd4c7c89..d427deadd7d2 100644 --- a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/BaseQueueClientBuilder.java +++ b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/BaseQueueClientBuilder.java @@ -16,7 +16,8 @@ abstract class BaseQueueClientBuilder> extends Ba @Override protected final UserAgentPolicy getUserAgentPolicy() { - return new UserAgentPolicy(QueueConfiguration.NAME, QueueConfiguration.VERSION, super.getConfiguration()); + QueueConfiguration queueConfiguration = new QueueConfiguration(); + return new UserAgentPolicy(queueConfiguration.getName(), queueConfiguration.getVersion(), super.getConfiguration()); } @Override diff --git a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueConfiguration.java b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueConfiguration.java index 2f7e97180b8b..074997e137ab 100644 --- a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueConfiguration.java +++ b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueConfiguration.java @@ -2,11 +2,46 @@ // Licensed under the MIT License. package com.azure.storage.queue; +import com.azure.core.util.logging.ClientLogger; +import java.io.IOException; +import java.util.Properties; + /* * Gets the SDK information for this library component. */ class QueueConfiguration { //TODO: Eventually remove these hardcoded strings with https://github.com/Azure/azure-sdk-for-java/issues/3141 - static final String NAME = "azure-storage-queue"; - static final String VERSION = "12.0.0-preview.3"; + private final ClientLogger logger = new ClientLogger(QueueClient.class); + private final Properties properties = new Properties(); + + public QueueConfiguration() { + loadProperties(); + } + + private void loadProperties() { + try { + properties.load(this.getClass().getClassLoader().getResourceAsStream("client.properties")); + } catch (IOException e) { + throw logger.logExceptionAsError(new RuntimeException("Please check the client properties for queue module. " + + "Error Details: " + e.getMessage())); + } + } + + public String getName() { + String name = properties.getProperty("artifactId"); + if (name == null || name.contains("${")) { + throw logger.logExceptionAsError(new RuntimeException("Please check the client properties for queue module name. " + + "Module Name: " + name)); + } + return name; + } + + public String getVersion() { + String version = properties.getProperty("version"); + if (version == null || version.contains("${")) { + throw logger.logExceptionAsError(new RuntimeException("Please check the client properties for queue module version. " + + "Module Version: " + version)); + } + return version; + } } diff --git a/sdk/storage/azure-storage-queue/src/main/resources/client.properties b/sdk/storage/azure-storage-queue/src/main/resources/client.properties new file mode 100644 index 000000000000..22cd83fddaee --- /dev/null +++ b/sdk/storage/azure-storage-queue/src/main/resources/client.properties @@ -0,0 +1,2 @@ +version=${project.version} +artifactId=${project.artifactId}