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

IT test for resolve-test-dependencies with snapshots #480

Merged
merged 4 commits into from
May 11, 2023

Conversation

jtnord
Copy link
Member

@jtnord jtnord commented May 5, 2023

this introduces test coverage for both resolve-test-dependencies with overrideWar containing a SNAPSHOT plugin as well as custom-war with addThisPluginToCustomWar

writing the IT was not done separately one for each PR or moved as this would have created more renamed files bloating the diff, or duplicating tests unnecessarily. The commits here are separate for each fix - but review in the respective PRs and the checks and order demonstrates each fix in turn)

Testing done

io.jenkins.tools.maven_hpi_plugin.its.override-war-with-snapshot.override-war-with-snapshot
Assertion failed: 

assert jf.getEntry('WEB-INF/plugins/override-war-with-snapshot.hpi') != null
       |  |                                                          |
       |  null                                                       false
       java.util.jar.JarFile@78a96c28
[INFO] --- hpi:3.44-SNAPSHOT:resolve-test-dependencies (default-cli) @ dependant ---
[INFO] Scanned contents of /home/jenkins/agent/workspace/Plugins_maven-hpi-plugin_PR-480/target/its/override-war-with-snapshot/war-with-plugin/target/override-war-with-snapshot.war with 1 bundled plugins
[INFO] Updating direct dependency org.jenkins-ci.tools.hpi.its:override-war-with-snapshot from 1.0.0-SNAPSHOT to 2.0.0-SNAPSHOT (private-e493f342-jenkins)
[INFO] Downloading from do-proxy-incrementals: https://repo.do.jenkins.io/incrementals/org/jenkins-ci/tools/hpi/its/override-war-with-snapshot/2.0.0-SNAPSHOT%20(private-e493f342-jenkins)/override-war-with-snapshot-2.0.0-SNAPSHOT%20(private-e493f342-jenkins).pom
[INFO] Downloading from do-proxy: https://repo.do.jenkins.io/public/org/jenkins-ci/tools/hpi/its/override-war-with-snapshot/2.0.0-SNAPSHOT%20(private-e493f342-jenkins)/override-war-with-snapshot-2.0.0-SNAPSHOT%20(private-e493f342-jenkins).pom
[WARNING] The POM for org.jenkins-ci.tools.hpi.its:override-war-with-snapshot:jar:2.0.0-SNAPSHOT (private-e493f342-jenkins) is missing, no dependency information available
[INFO] Downloading from do-proxy-incrementals: https://repo.do.jenkins.io/incrementals/org/jenkins-ci/tools/hpi/its/override-war-with-snapshot/2.0.0-SNAPSHOT%20(private-e493f342-jenkins)/override-war-with-snapshot-2.0.0-SNAPSHOT%20(private-e493f342-jenkins).jar
[INFO] Downloading from do-proxy: https://repo.do.jenkins.io/public/org/jenkins-ci/tools/hpi/its/override-war-with-snapshot/2.0.0-SNAPSHOT%20(private-e493f342-jenkins)/override-war-with-snapshot-2.0.0-SNAPSHOT%20(private-e493f342-jenkins).jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.668 s
[INFO] Finished at: 2023-05-05T16:56:56Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jenkins-ci.tools:maven-hpi-plugin:3.44-SNAPSHOT:resolve-test-dependencies (default-cli) on project dependant: Unable to resolve dependencies: Could not resolve dependencies for project org.jenkins-ci.tools.hpi.its:dependant:hpi:1.0-SNAPSHOT: The following artifacts could not be resolved: org.jenkins-ci.tools.hpi.its:override-war-with-snapshot:jar:2.0.0-SNAPSHOT (private-e493f342-jenkins) (absent): Could not find artifact org.jenkins-ci.tools.hpi.its:override-war-with-snapshot:jar:2.0.0-SNAPSHOT (private-e493f342-jenkins) in do-proxy-incrementals (https://repo.do.jenkins.io/incrementals/) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jenkins-ci.tools:maven-hpi-plugin:3.44-SNAPSHOT:resolve-test-dependencies (default-cli) on project dependant: Unable to resolve dependencies

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


@Test
public void testVersionOfDependency() throws IOException {
Assert.assertEquals("2.0.0-SNAPSHOT", Version.getVersion());
Copy link
Member Author

Choose a reason for hiding this comment

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

test will fail when run using the dependency declared in the pom, but will pass when using the version of the plugin in the war.

# First just build the plugin that we depend on
invoker.goals.1=-f war-with-plugin -ntp -Dhpi-plugin.version=${project.version} clean install -P quick-build -Drevision=1.0.0-SNAPSHOT
# Then build another version and create a war containing the newer version
invoker.goals.2=-f war-with-plugin -ntp -Dhpi-plugin.version=${project.version} clean install -P quick-build -P build-war -Drevision=2.0.0-SNAPSHOT
Copy link
Member Author

Choose a reason for hiding this comment

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

slightly abnormal syntax of profile activation as invoker will split into multiple invocations on seeing a , so we use -P twice


assert jf.getEntry('WEB-INF/plugins/override-war-with-snapshot.hpi') != null

return true;
Copy link
Member Author

Choose a reason for hiding this comment

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

we do not need to perform any checking of the last invocation of the dependant plugin as the junit test will fail if the dependency is not updated.

<goal>custom-war</goal>
</goals>
<configuration>
<addThisPluginToCustomWar>true</addThisPluginToCustomWar>
Copy link
Member Author

Choose a reason for hiding this comment

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

requires #479

Copy link
Member Author

Choose a reason for hiding this comment

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

this plugin depends on the plugin in war-with-plugin

<dependency>
<groupId>org.jenkins-ci.tools.hpi.its</groupId>
<artifactId>override-war-with-snapshot</artifactId>
<version>1.0.0-SNAPSHOT</version>
Copy link
Member Author

Choose a reason for hiding this comment

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

this version will cause the tests to fail, and will pass when it is updated to 2.0.0-SNAPSHOT


public class Version {

public static String getVersion() throws IOException {
Copy link
Member Author

Choose a reason for hiding this comment

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

will return a different version depending on the version of the plugin.

jtnord added 3 commits May 5, 2023 17:09
this introduces test coverage for both resolve-test-dependencies with
overrideWar containing a SNAPSHOT plugin as well as custom-war with addThisPluginToCustomWar
the paths for files should not be absolute but relative.

prior to this change the war contained files like

WEB-INF/lib/... (all the usual entries)
and
/WEB-INF/plugins/.. (for the bundled plugins)
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.
@@ -372,7 +372,7 @@
<localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
<pomInclude>*</pomInclude>
Copy link
Member Author

@jtnord jtnord May 5, 2023

Choose a reason for hiding this comment

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

any subdirectory (non recursive) of src/it is now a valid IT - we do not need a pom.xml in the root which allows us to have multiple projects for a single IT that do not share an aggregator

Copy link
Member Author

Choose a reason for hiding this comment

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

this file is #481

Copy link
Member Author

Choose a reason for hiding this comment

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

this file is #478

@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:28
@jtnord jtnord added the chore label May 5, 2023
<developers>
<developer>
<id>Bob</id>
<name>Bob McBobfaceNoam Chomsky</name>
Copy link
Member

Choose a reason for hiding this comment

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

Multiple names when a single name is expected

Suggested change
<name>Bob McBobfaceNoam Chomsky</name>
<name>Bob McBobface</name>

@jtnord jtnord merged commit 45dae8d into jenkinsci:master May 11, 2023
@jtnord jtnord deleted the ITs branch May 11, 2023 12:16
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