From 818b9dc5d172b5cb3c27dac03fda25e54c341264 Mon Sep 17 00:00:00 2001 From: "Adam J. Weigold" Date: Wed, 17 Jan 2018 13:50:13 -0600 Subject: [PATCH] #52 Switching build props to property file as there is likelihood of other manifest.mf files being grabbed. --- build.gradle | 19 +++++++------ .../kenticocloud/delivery/DeliveryClient.java | 18 ++++++------- .../kenticocloud/delivery/build.properties | 27 +++++++++++++++++++ 3 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/com/kenticocloud/delivery/build.properties diff --git a/build.gradle b/build.gradle index 7c6a2797..ec56786d 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { group 'com.kenticocloud' version '1.0.6-SNAPSHOT' ext.isContinuousIntegrationBuild = System.getenv('CONTINUOUS_INTEGRATION') != null -ext.repositoryHost = ext.isContinuousIntegrationBuild ? "maven.org" : "localBuild" +ext.repositoryHost = isContinuousIntegrationBuild ? "maven.org" : "localBuild" apply plugin: 'java' apply plugin: 'jacoco' @@ -43,13 +43,16 @@ dependencies { } -jar { - manifest { - attributes( - "Implementation-Version": project.version, - "Repository-Host": repositoryHost, - "Package-Id": "$project.group:$project.name" - ) +processResources { + if (isContinuousIntegrationBuild) { + filesMatching('build.properties') { + filter { String line -> + line.replace "0.0.0", project.version + } + filter { String line -> + line.replace "localBuild", "$project.group:$project.name" + } + } } } diff --git a/src/main/java/com/kenticocloud/delivery/DeliveryClient.java b/src/main/java/com/kenticocloud/delivery/DeliveryClient.java index c0436160..c9d735c4 100644 --- a/src/main/java/com/kenticocloud/delivery/DeliveryClient.java +++ b/src/main/java/com/kenticocloud/delivery/DeliveryClient.java @@ -45,9 +45,8 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Properties; import java.util.UUID; -import java.util.jar.Attributes; -import java.util.jar.Manifest; /** * Executes requests against the Kentico Cloud Delivery API. @@ -60,14 +59,13 @@ public class DeliveryClient { static { try { - Manifest mf = new Manifest(); - mf.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/MANIFEST.MF")); - Attributes attributes = mf.getMainAttributes(); - String repositoryHost = attributes.getValue("Repository-Host"); - String version = attributes.getValue("Implementation-Version"); - String packageId = attributes.getValue("Package-Id"); + Properties buildProps = new Properties(); + buildProps.load(DeliveryClient.class.getResourceAsStream("build.properties")); + String repositoryHost = buildProps.getProperty("Repository-Host"); + String version = buildProps.getProperty("Implementation-Version"); + String packageId = buildProps.getProperty("Package-Id"); repositoryHost = repositoryHost == null ? "localBuild" : repositoryHost; - version = version == null ? "localBuild" : version; + version = version == null ? "0.0.0" : version; packageId = packageId == null ? "com.kenticocloud:delivery-sdk-java" : packageId; SDK_ID = String.format( "%s;%s;%s", @@ -77,7 +75,7 @@ public class DeliveryClient { logger.info("SDK ID: {}", SDK_ID); } catch (IOException e) { logger.info("Jar manifest read error, setting developer build SDK ID"); - SDK_ID = "localBuild;com.kenticocloud:delivery-sdk-java;localBuild"; + SDK_ID = "localBuild;com.kenticocloud:delivery-sdk-java;0.0.0"; } } diff --git a/src/main/resources/com/kenticocloud/delivery/build.properties b/src/main/resources/com/kenticocloud/delivery/build.properties new file mode 100644 index 00000000..73929a9d --- /dev/null +++ b/src/main/resources/com/kenticocloud/delivery/build.properties @@ -0,0 +1,27 @@ +# +# MIT License +# +# Copyright (c) 2018 +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +Repository-Host: localBuild +Implementation-Version: 0.0.0 +Package-Id: com.kenticocloud:delivery-sdk-java