Skip to content

Commit b6a9f79

Browse files
Merge pull request #228 from commercetools/227-fix-version-header
227 fix version header
2 parents d95b3d4 + b54b513 commit b6a9f79

7 files changed

Lines changed: 52 additions & 49 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dist: trusty
88
jdk:
99
- openjdk8
1010
install: true # skips travis' default installation step which executes gradle assemble.
11-
script: ./gradlew clean build
11+
script: ./gradlew clean setReleaseVersion build
1212
# The before_cache and the cache steps cache the gradle installation on travis.
1313
before_cache:
1414
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ apply from: "$rootDir/gradle-scripts/maven-publish.gradle"
2121
apply from: "$rootDir/gradle-scripts/bintray-publish.gradle"
2222
apply from: "$rootDir/gradle-scripts/oss-publish.gradle"
2323
apply from: "$rootDir/gradle-scripts/javadocs-publish.gradle"
24+
apply from: "$rootDir/gradle-scripts/set-release-version.gradle"
2425
apply from: "$rootDir/gradle-scripts/execution-order.gradle"

docs/RELEASE_NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/v1.0.0-M8...v1.0.0-M9) |
5151
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/v1.0.0-M9/) |
5252
[Jar](https://bintray.com/commercetools/maven/commercetools-sync-java/v1.0.0-M9)
53+
54+
55+
**Bug Fixes** (1)
56+
- **Commons** - Fixed library version in User-Agent headers of JVM SDK clients using the library. Now it is not fetched
57+
from the JAR manifest but injected by gradle-scripts/set-release-version.gradle. [#227](https://github.com/commercetools/commercetools-sync-java/issues/227)
58+
59+
5360
-->
5461

5562
### v1.0.0-M8 - Dec 29, 2017

gradle-scripts/execution-order.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ check.dependsOn jacocoTestReport
4545
// Ensure jacocoTestCoverageVerification and jacocoTestReport run after integrationTest
4646
jacocoTestCoverageVerification.mustRunAfter integrationTest
4747
jacocoTestReport.mustRunAfter integrationTest
48+
// Ensure build runs after setReleaseVersion
49+
build.mustRunAfter setReleaseVersion
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
task setReleaseVersion {
2+
description 'If the env var "TRAVIS_TAG" is set, injects the value in the ' +
3+
'src/main/java/com/commercetools/sync/commons/utils/SyncSolutionInfo.java. Otherwise, if the env var is not ' +
4+
'set it sets the version to the value "dev-version". Note: Should only be executed before compilation in ' +
5+
'the CI tool (e.g. Travis.)'
6+
doLast {
7+
def versionFile = 'src/main/java/com/commercetools/sync/commons/utils/SyncSolutionInfo.java'
8+
def versionFileContents = new File(versionFile).text
9+
def versionPlaceholder = '#{LIB_VERSION}'
10+
def libVersion = 'dev-version'
11+
def tagName = System.getenv('TRAVIS_TAG')
12+
13+
if (!versionFileContents.contains(versionPlaceholder)) {
14+
throw new InvalidUserCodeException("$versionFile does not contain the placeholder: $versionPlaceholder. " +
15+
"Please make sure the file contains the placeholder, in order for the version to be injected " +
16+
"correctly.")
17+
}
18+
19+
// if build was triggered by a git tag, set version to tag name
20+
if (tagName) {
21+
libVersion = tagName
22+
}
23+
24+
if (libVersion) {
25+
println "Injecting the version: '$libVersion' in $versionFile"
26+
ant.replace(file: versionFile, token: versionPlaceholder, value: libVersion)
27+
} else {
28+
throw new InvalidUserDataException("Unable to set library version in $versionFile. Please make sure the" +
29+
" var 'libVersion' is set correctly.")
30+
}
31+
}
32+
}

src/main/java/com/commercetools/sync/commons/utils/SyncSolutionInfo.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,24 @@
22

33
import io.sphere.sdk.client.SolutionInfo;
44

5-
import javax.annotation.Nullable;
6-
7-
import static org.apache.commons.lang3.StringUtils.isBlank;
8-
9-
public class SyncSolutionInfo extends SolutionInfo {
10-
static final String UNSPECIFIED = "unspecified";
5+
public final class SyncSolutionInfo extends SolutionInfo {
6+
private static final String LIB_NAME = "commercetools-sync-java";
7+
/**
8+
* This value is injected by the script at gradle-scripts/version-setter.gradle.
9+
*/
10+
private static final String LIB_VERSION = "#{LIB_VERSION}";
1111

1212
/**
1313
* Extends {@link SolutionInfo} class of the JVM SDK to append to the User-Agent header with information of the
1414
* commercetools-sync-java library
1515
*
1616
* <p>A User-Agent header with a solution information looks like this:
1717
* {@code commercetools-jvm-sdk/1.4.1 (AHC/2.0) Java/1.8.0_92-b14 (Mac OS X; x86_64)
18-
* {implementationTitle}/{implementationVersion}}</p>
18+
* {@value LIB_NAME}/{@value LIB_VERSION}}</p>
1919
*
2020
*/
2121
public SyncSolutionInfo() {
22-
final String implementationTitle = getClass().getPackage().getImplementationTitle();
23-
final String implementationVersion = getClass().getPackage().getImplementationVersion();
24-
final String solutionName = isAttributeUnspecified(implementationTitle)
25-
? "commercetools-sync-java" : implementationTitle;
26-
final String solutionVersion = isAttributeUnspecified(implementationVersion)
27-
? "DEBUG-VERSION" : implementationVersion;
28-
setName(solutionName);
29-
setVersion(solutionVersion);
30-
}
31-
32-
static boolean isAttributeUnspecified(@Nullable final String attributeValue) {
33-
return isBlank(attributeValue) || UNSPECIFIED.equals(attributeValue);
22+
setName(LIB_NAME);
23+
setVersion(LIB_VERSION);
3424
}
3525
}

src/test/java/com/commercetools/sync/commons/utils/SyncSolutionInfoTest.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)