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 support for libraries to have classes #182

Merged
merged 4 commits into from
Mar 11, 2021
Merged

add support for libraries to have classes #182

merged 4 commits into from
Mar 11, 2021

Conversation

steven-terrana
Copy link

@steven-terrana steven-terrana commented Mar 10, 2021

PR Details

This Pull Request adds support for JTE libraries to contribute classes via a src directory. These classes can be imported from pipeline templates, steps from the same library, or steps from another library.

For example, a library with a src/example/Utility.groovy file of:

package example

class Utility implements Serializable{
  void doThing(steps){ steps.echo "doing a thing" }
}

could be imported and used via:

import example.Utility

Utility u = new Utility()
u.doThing(steps)

Description

The src directory contents of all loaded libraries are synced to a common src directory within the build root directory's jte directory. This happens prior to loading the steps so that the classes are available to the classloader during compilation.

How Has This Been Tested

Manual testing + relevant unit tests.

Types of Changes

  • Added Unit Testing
  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have added the appropriate label for this PR
  • If necessary, I have updated the documentation accordingly.
  • All new and existing tests passed.

@steven-terrana steven-terrana marked this pull request as ready for review March 10, 2021 22:03
@steven-terrana steven-terrana added the enhancement New feature or request label Mar 10, 2021
@nrayapati
Copy link
Member

nrayapati commented Mar 10, 2021

This is really cool @steven-terrana thank you for adding this feature
Hope we are adding support to load classes from the base directory as well so that we can maintain common classes among libraries

@steven-terrana
Copy link
Author

Hey @nrayapati - The pattern I would recommend for that would to be to create a utility library that has helper steps and common classes consumed by other libraries.

Would this work for your use case?

@nrayapati
Copy link
Member

These classes can be imported from pipeline templates, steps from the same library, or steps from another library.

It sounds like you already mentioned about it in the description that these classes can be used across other libraries as well, so I don't think of a need where we need to maintain classes in the root directory anymore. :) Thank you for quick response.

@nrayapati
Copy link
Member

Hey @nrayapati - The pattern I would recommend for that would to be to create a utility library that has helper steps and common classes consumed by other libraries.

Would this work for your use case?

Sounds like a good idea too!

Thank you!

@cokieffebah cokieffebah merged commit 1db356f into jenkinsci:main Mar 11, 2021
@steven-terrana steven-terrana deleted the src-dir branch April 27, 2021 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants