Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version tag to show the version of the jar of RepoSense #503

Closed
fzdy1914 opened this issue Jan 23, 2019 · 19 comments · Fixed by #565
Closed

Add --version tag to show the version of the jar of RepoSense #503

fzdy1914 opened this issue Jan 23, 2019 · 19 comments · Fixed by #565

Comments

@fzdy1914
Copy link
Member

As, title. The users may not know the jar file they download is the correct version of RepoSensse or not and they cannot verify it.

Let's add a -version tag to show the version of jar file of RepoSense.

@yong24s
Copy link
Contributor

yong24s commented Jan 24, 2019

Can be done together with #449

Removing this requirement.

@eugenepeh
Copy link
Member

let's add another requirement, print the version in the report as well.

@yong24s
Copy link
Contributor

yong24s commented Feb 8, 2019

For users running RepoSense usingpublish-RepoSense with latest master, it would be helpful if we can print the commit hash rather than the release version.

@fzdy1914 fzdy1914 changed the title Add -version tag to show the version of the jar of RepoSense Add --version tag to show the version of the jar of RepoSense Feb 21, 2019
@fzdy1914
Copy link
Member Author

For users running RepoSense usingpublish-RepoSense with latest master, it would be helpful if we can print the commit hash rather than the release version.

Printing out the commit hash will be a little bit difficult to implement. For the release version, we only need to keep a variable that stores the version of RepoSense. But for commit hash, we cannot store it.

There is one way that may solve the problem, the --version tag can also take in a argument, in publish-RepoSense, when we choose the latest master, it can pass the hash to the jar file. So, the generated report can contains the hash. What's your opinion on this?

@yong24s
Copy link
Contributor

yong24s commented Feb 21, 2019

I think we could get the version information pushed into the Jar manifest. 🤔

@fzdy1914
Copy link
Member Author

@yong24s But we will need it to be included in our generated report right? It should be better to let it be a variable.

@yong24s
Copy link
Contributor

yong24s commented Feb 21, 2019

I believe you can access manifest values at runtime. 🤔

shadowJar {
    archiveName = 'RepoSense.jar'
    destinationDir = file("${buildDir}/jar/")

    manifest {
    	attributes 'Version': project.property("version")
    }
}
Building Jar

$ ./gradlew shadowJar -Pversion='1.8'

META-INF\MANIFEST.MF
Manifest-Version: 1.0
Version: '1.8'
Main-Class: reposense.RepoSense

@yong24s
Copy link
Contributor

yong24s commented Feb 21, 2019

Printing out the commit hash will be a little bit difficult to implement. For the release version, we only need to keep a variable that stores the version of RepoSense. But for commit hash, we cannot store it.

Where would you proposed to keep the version variable?

If its inside the source code then we have to make a new commit to update the version value every time we release. I would like to minimize trivial commits to the repository. This approach also makes it hard to track the commit hash.

There is one way that may solve the problem, the --version tag can also take in a argument, in publish-RepoSense, when we choose the latest master, it can pass the hash to the jar file. So, the generated report can contains the hash. What's your opinion on this?

Yes, something like this workflow.

My suggested workflow would be:

  • For releaser to run ./gradlew shadowJar -Pversion='1.8' to generate Jar
  • For CI to run ./gradlew shadowJar -Pversion=$(git rev-parse --short HEAD)

At this point of time, I don't think our code needs to know anything about versions.

@fzdy1914
Copy link
Member Author

  • For releaser to run ./gradlew shadowJar -Pversion='1.8' to generate Jar
  • For CI to run ./gradlew shadowJar -Pversion=$(git rev-parse --short HEAD)

At this point of time, I don't think our code needs to know anything about versions.

OK, I will investigate how to access manifest values at runtime.

@yong24s
Copy link
Contributor

yong24s commented Feb 21, 2019

Also at frontend we can just take the version and plug it in https://github.com/reposense/RepoSense/commits/<VERSION>

https://github.com/reposense/RepoSense/commits/v1.7
https://github.com/reposense/RepoSense/commit/6dd74a0

@fzdy1914
Copy link
Member Author

  • For releaser to run ./gradlew shadowJar -Pversion='1.8' to generate Jar
  • For CI to run ./gradlew shadowJar -Pversion=$(git rev-parse --short HEAD)

A little nit, then, we are unable to have a default version for our project.

@fzdy1914
Copy link
Member Author

fzdy1914 commented Feb 21, 2019

I have investigated how to access MANIFEST file and gradle.property during runtime, it seems that there is no elegant way to do so. Can you suggest a good way to do so?

@fzdy1914
Copy link
Member Author

fzdy1914 commented Feb 21, 2019

~The last one looks promising but we need to add two more dependencies which we may not want.

@yong24s Please give a review. Also, you may see my implementation until now #565.~

@fzdy1914
Copy link
Member Author

I found a way to get the version of our project correctly using s.getClass().getPackage().getImplementationVersion()

@yong24s
Copy link
Contributor

yong24s commented Feb 21, 2019

I found a way to get the version of our project correctly using s.getClass().getPackage().getImplementationVersion()

Hmm, it worked for you? I only got the installed Java version in my system 1.8.0_172. 😂

I'm okay with jcabi-manifests if it helps to prevent dangerous coding. You may want to check with other mentors.

When needed, a well documented/maintained library can be used, if it simplifies development. Just don't pick a library that is clearly an overkill.

@fzdy1914
Copy link
Member Author

@yong24s I have implemented the solution.
See my pr to test out.
Try:
./gradlew shadowJar -Pversion='6dd74a0'
and for the generated jar
Try:
java -jar RepoSense.jar --version
and try use it to generate a report.

@fzdy1914
Copy link
Member Author

However, I still leave a default version number in my implementation, which is not so necessary.

@eugenepeh
Copy link
Member

eugenepeh commented Feb 23, 2019

perhaps try out using git tag for this purpose?
https://github.com/palantir/gradle-git-version

yamidark pushed a commit that referenced this issue Apr 16, 2019
Users may want to figure out whether the jar file they download is
the correct version of RepoSense they want to use.

The users cannot verify it because we do not have a 'version' tag,
and the generated report do not contain such information.

Let's add a -version tag to show the version of jar file of RepoSense,
and include it in the generated report.

The version can be passed in to RepoSense using -Pversion for both run
and shadowJar. Otherwise, latest git tag will be used instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants