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

Handle SNAPSHOT versions in with overrideWar #478

Merged
merged 2 commits into from
May 11, 2023

Conversation

jtnord
Copy link
Member

@jtnord jtnord commented May 3, 2023

if the war scanning encounters a SNAPSHOT build of a plugin then then manifest file will contain a Plugin-Version entry like 1.2.3-4-SNAPSHOT (private abcd1234-username).

This causes a failure when updating the dependencies (resolve-test-dependencies) as the plugin will try and use that directly without stripping off the extra parts.

This strips off any extra parts should they be present so that the version number matches a valid maven version number and also emits a warning to the log about non repeatable builds if any snapshots are encountered.

Testing done

manually tested with a war containing a snapshot using the command

mvn.cmd -B -V -e -DoverrideWar=C:\workarea\myWarWithSnapshot.war -Djenkins.version=2.387.3-cb-2 -DuseUpperBounds=true org.jenkins-ci.tools:maven-hpi-plugin:3.44-20230503.112206-2:resolve-test-dependencies

mojo no longer fails and the log is present in the output

...
[INFO] --- hpi:3.44-SNAPSHOT:resolve-test-dependencies (default-cli) @ operations-center-server ---
[WARNING] War contains a SNAPSHOT of com.cloudbees.operations-center.common:operations-center-context build will not be fully repeatable
[INFO] Scanned contents of C:\workarea\myWarWithSnapshot.wa with 155 bundled plugins
[INFO] Updating direct dependency io.jenkins.plugins:okhttp-api from 4.9.3-108.v0feda04578cf to 4.10.0-132.v7a_7b_91cef39c
...
[INFO] Updating direct dependency com.cloudbees.operations-center.common:operations-center-context from 2.387.0.3-JTN-SNAPSHOT to 2.387.0.3-JTN-SNAPSHOT
...

IT in #480

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

if the war scanning encounters a SNAPSHOT build of a plugin then then
manifest file will contain a `Plugin-Version` entry like
`1.2.3-4-SNAPSHOT (private abcd1234-username)`.

This causes a failure when updating the dependencies as the plugin will
try and use that directly without stripping off the extra parts.

THis strips off any extra parts should they be present so that the
version number matches a valid maven version number and also emits a
warning to the log about non repeatable builds if any snapshots are
encountered.
@jtnord jtnord changed the title handle SNAPSHOT builds correctly Handle SNAPSHOT versions in with overrideWar May 3, 2023
@jtnord jtnord added the bug label May 3, 2023
@@ -517,8 +517,7 @@ private static void appendEntries(String property, Collection<String> additions,
* @param war The WAR to scan.
* @return The bundled plugins in the WAR.
*/
private static Map<String, String> scanWar(File war, MavenSession session, MavenProject project)
throws MojoExecutionException {
private Map<String, String> scanWar(File war) throws MojoExecutionException {
Copy link
Member Author

Choose a reason for hiding this comment

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

getLog() is set for the mojo object, so this needs to be non-static. the MavenSession and MavenProject are already set in the Mojo - so these are used directly.

@@ -550,6 +549,12 @@ private static Map<String, String> scanWar(File war, MavenSession session, Maven
if (version == null) {
throw new IllegalArgumentException("Failed to determine version for " + name);
}
// handle any extra info in snapshots e.g. " (private-abcd1234-username)"
Copy link
Member Author

Choose a reason for hiding this comment

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

Whilst we could use Implementation-Version and then fall back - some plugins (gradle) do not provide this due to tooling or being too old (this was added approx. 2 years ago). Given the need to fallback, it is easier just to handle the legacy case here.

@jtnord jtnord requested a review from basil May 5, 2023 17:28
@jtnord jtnord marked this pull request as ready for review May 5, 2023 17:29
…jo.java

Co-authored-by: Basil Crow <me@basilcrow.com>
@jtnord jtnord merged commit a6c6ae7 into jenkinsci:master May 11, 2023
@jtnord jtnord deleted the snapshots-in-war branch May 11, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants