Skip to content

227 fix version header#228

Merged
heshamMassoud merged 27 commits intomasterfrom
227-fix-version-header
Jan 9, 2018
Merged

227 fix version header#228
heshamMassoud merged 27 commits intomasterfrom
227-fix-version-header

Conversation

@heshamMassoud
Copy link
Copy Markdown
Contributor

@heshamMassoud heshamMassoud commented Jan 8, 2018

Summary

Addresses mainly #227.

Instead of depending on JAR manifest for fetching library version and name. Which could be removed by the users of the library, especially in the case when packing it as a dependency in a fat jar, it's quite common that the lib's manifest is replaced with the original applications' manifest.

Therefore, the SolutionInfo version is now injected by a bash script (which potentially takes the version from the tag name, if the build was caused by a tag)

More details

The template string #{LIB_VERSION} in the SyncSolutionInfo.java is replaced in the bash script here.

This sed replace command makes a backup of the original file after replacement, in case a dev runs the script locally. But it's also ignored from committing on the repo.

Relevant Issues

#227 #193

Todo

  • Add Release Notes entry.

Update (FYI: @butenkor, @andrii-kovalenko-ct):

  1. Now it is written as a gradle script: version-setter.gradle
  2. Which is only called manually by travis before compiling (https://github.com/commercetools/commercetools-sync-java/pull/228/files#diff-354f30a63fb0907d4ad57269548329e3)

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 8, 2018

Codecov Report

Merging #228 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #228      +/-   ##
===========================================
+ Coverage     93.12%   93.2%   +0.07%     
+ Complexity      805     802       -3     
===========================================
  Files            68      68              
  Lines          2080    2075       -5     
  Branches        120     118       -2     
===========================================
- Hits           1937    1934       -3     
  Misses          122     122              
+ Partials         21      19       -2
Impacted Files Coverage Δ Complexity Δ
...ercetools/sync/commons/utils/SyncSolutionInfo.java 100% <100%> (+22.22%) 1 <0> (-3) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d95b3d4...b54b513. Read the comment docs.

Copy link
Copy Markdown
Member

@butenkor butenkor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides one typo looks good 👍

Comment thread docs/RELEASE_NOTES.md Outdated

**Bug Fixes** (1)
- **Commons** - Fixed library version in User-Agent headers of JVM SDK clients using the library. Now it's fetched
from the JAR manifest but injected from set-solutioninfo-version.sh [#227](https://github.com/commercetools/commercetools-sync-java/issues/227)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> now it is not fetched

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@andrii-kovalenko-ct andrii-kovalenko-ct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or i don't understand the real issue, of the solution is an overhead in the library....
But even if you decided to replace tokens, why do you implement custom shell scripts, instead of using default gradle plugins for replacements?
https://www.google.de/search?q=gradle+replace+plugin

https://stackoverflow.com/a/30038751/907576 (the answer from known Opal guy :) )

@heshamMassoud
Copy link
Copy Markdown
Contributor Author

@andrii-kovalenko-ct Is there another advantage to having it as a gradle script as opposed to bash script, other than for consistently having all scripts in one place/language?

If so, then we should also better change this gradle as well (https://github.com/commercetools/commercetools-sync-java/blob/master/travis-publish.sh) right?

Comment thread .travis.yml Outdated
jdk:
- openjdk8
install: true # skips travis' default installation step which executes gradle assemble.
before_script: ./gradlew injectVersion
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inject and not just setReleaseVersion?

Copy link
Copy Markdown
Contributor Author

@heshamMassoud heshamMassoud Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread build.gradle Outdated
apply from: "$rootDir/gradle-scripts/javadocs-publish.gradle"
apply from: "$rootDir/gradle-scripts/execution-order.gradle" No newline at end of file
apply from: "$rootDir/gradle-scripts/execution-order.gradle"
apply from: "$rootDir/gradle-scripts/version-setter.gradle" No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here: set-release-version.gradle

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!versionFileContents.contains(versionPlaceholder)) {
throw new InvalidUserCodeException("$versionFile does not contain the placeholder: $versionPlaceholder. " +
"Please make sure the file contains the placeholder, in order for the version to be injected " +
"correctly.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@andrii-kovalenko-ct
Copy link
Copy Markdown
Contributor

@heshamMassoud

Is there another advantage to having it as a gradle script as opposed to bash script, other than for consistently having all scripts in one place/language?

Isn't it enough as an advantage? Then also:

  • having it is in gradle makes it platform independent, when bash scripts are platform dependent
  • bash language is less readable than groovy
  • less code because standard plugins incapsulate some logic
  • common plugins are pretty known by other developers, when custom script require time to investigate/understand how they work (that was the first thing i noticed: i need to read bash script, instead of some standard configuration, like in ant replace plugin)
  • common plugins are used/tested by hundreds of other users - bugs/vulnerabilities are discovered better/faster

If so, then we should also better change this gradle as well (https://github.com/commercetools/commercetools-sync-java/blob/master/travis-publish.sh) right?

Nice point! I've been dreaming to re-factor this wasp nest since my first days in the company, but never had enough time. Also, as a best approach - we could try to create our own travis publish gradle plugin. A good topic for the next hackaton :)

Comment thread .travis.yml Outdated
- openjdk8
install: true # skips travis' default installation step which executes gradle assemble.
before_script: ./set-solutioninfo-version.sh
before_script: ./gradlew injectVersion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make it as a part of build tasks graph (e.g. using dependsOn, must/shouldRunAfter, finalizedBy and so on).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I only want the release version to be replaced only on travis, but not locally on every dev's machine when they run the build locally.

Copy link
Copy Markdown
Contributor

@andrii-kovalenko-ct andrii-kovalenko-ct Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then i'd recommend to create a custom gradle task (for example, ciBuild) and run it from travis (here instead of clean build, avoiding before_script block

This approach makes build script independent from CI tool (e.g. you don't depend on Travis's native before_script)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already a custom gradle task. I made it inline now: 62bddb4, but also applies to the after_success then, no?

Copy link
Copy Markdown
Contributor

@andrii-kovalenko-ct andrii-kovalenko-ct Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also applies to the after_success

good point!

(but don't over-engineer: estimate is it easy to re-factor now all those scripts, or maybe make a dedicated task for this)

Comment thread gradle-scripts/version-setter.gradle Outdated
"correctly.")
}

if (isPr.equals("false") && tagName) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

@heshamMassoud heshamMassoud Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

168c067, I don't think I need the PR check at all actually.


if (libVersion) {
println "Injecting the version: '$libVersion' in $versionFile"
ant.replace(file: versionFile, token: versionPlaceholder, value: libVersion)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not default gradle ReplaceTokens ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because, as I understand, it is used within the filter function when files are being copied. Whereas in this case I just want to replace in file, rather then replace while copying.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@heshamMassoud
Copy link
Copy Markdown
Contributor Author

heshamMassoud commented Jan 9, 2018

Isn't it enough as an advantage?

@andrii-kovalenko-ct It is definitely enough :) but I just wanted to know the advantages. Thanks for explicitly stating them. Also great idea with creating our own gradle script!

I created an issue about it: #229

@andrii-kovalenko-ct
Copy link
Copy Markdown
Contributor

by default tasks order in gradle build is undefined, so it might be that build is executed before setReleaseVersion , even if you specify them in command line in explicit order.

@andrii-kovalenko-ct
Copy link
Copy Markdown
Contributor

andrii-kovalenko-ct commented Jan 9, 2018

@heshamMassoud
Copy link
Copy Markdown
Contributor Author

heshamMassoud commented Jan 9, 2018

@andrii-kovalenko-ct ah, I didn't know that it also doesn't ensure order when running explicitly from CLI:

FYI, Take a look at this tho: https://discuss.gradle.org/t/ordering-tasks-on-the-command-line-versus-using-mustrunafter/12017

Command line ordering is essentially the same as shouldRunAfter

But still defining explicit ordering is better than relying on CLI input. dc27248 Thanks for pointing it out.

@andrii-kovalenko-ct
Copy link
Copy Markdown
Contributor

hm, i was sure command line order doesn't influence the order at all....

@heshamMassoud heshamMassoud merged commit b6a9f79 into master Jan 9, 2018
@heshamMassoud heshamMassoud deleted the 227-fix-version-header branch January 9, 2018 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants