Skip to content

Commit

Permalink
kontent-ai#52 Switching build props to property file as there is like…
Browse files Browse the repository at this point in the history
…lihood of other manifest.mf files being grabbed.
  • Loading branch information
aweigold committed Jan 17, 2018
1 parent 37ef1e8 commit 818b9dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
19 changes: 11 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
}
}
}
}

Expand Down
18 changes: 8 additions & 10 deletions src/main/java/com/kenticocloud/delivery/DeliveryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
Expand All @@ -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";
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/com/kenticocloud/delivery/build.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 818b9dc

Please sign in to comment.