Skip to content

feat: resolve Jenkins shared library methods from @Library annotations and analysis scope#8173

Open
arnabnandy7 wants to merge 1 commit into
openrewrite:mainfrom
arnabnandy7:fix/jenkins-shared-lib
Open

feat: resolve Jenkins shared library methods from @Library annotations and analysis scope#8173
arnabnandy7 wants to merge 1 commit into
openrewrite:mainfrom
arnabnandy7:fix/jenkins-shared-lib

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jul 3, 2026

Copy link
Copy Markdown

What's changed?

Implemented type resolution and attribution for Jenkins shared library steps (vars/*.groovy) in the Groovy parser:

  1. Analysis Scope Scanning: Added scanning in GroovyParser.java to index all vars/*.groovy files in the input sources.
  2. Annotation Scanning: Added scanning of package, imports, and statement blocks in GroovyParserVisitor.java for @Library annotations.
  3. Type Attribution: In GroovyParserVisitor.visitMethodCallExpression, unresolved method calls on implicit this are resolved and attributed to the identified shared libraries (resolving to jenkins.sharedlibrary.<library_name>.Vars) if they match scope steps or when the @Library annotation is present.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

  • The implementation of collectAnnotations in GroovyParserVisitor.java which recursively traverses statement blocks to capture @Library annotations attached to script-level variable/field declarations (e.g. @Library('lib') _).
  • The use of ExecutionContext to pass the sharedLibrarySteps map collected during parseInputs down to the GroovyParserVisitor instances.

Anyone you would like to review specifically?

N/A

Have you considered any alternatives or workarounds?

Considered compiling all files together in a single CompilationUnit, but that would disrupt the lazy streaming design of GroovyParser.parseInputs and potentially introduce compilation order/dependency issues. The current design allows files to compile individually while sharing type metadata.

Any additional context

N/A

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

…s and analysis scope

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Jenkins parser does not resolve shared library methods from @Library

2 participants