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

Scan classpaths for extensions only once #109

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## Unreleased

* Scan classpaths for extensions only once
* Fixed a bug for Java 11 compatibility

## 2.1.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,35 +1104,38 @@ public abstract class JenkinsPipelineSpecification extends Specification {
}
}

APipelineExtensionDetector classpath_scanner = new WholeClasspathPipelineExtensionDetector()

PIPELINE_STEPS = classpath_scanner.getPipelineSteps(Optional.<String>empty())

Set<String> symbols = classpath_scanner.getSymbols(Optional.<String>empty())
Set<String> global_variables = classpath_scanner.getGlobalVariables(Optional.<String>empty())
Set<String> shared_library_variables = getSharedLibraryVariables()

PIPELINE_SYMBOLS.addAll( symbols )
PIPELINE_SYMBOLS.addAll( global_variables )
PIPELINE_SYMBOLS.addAll( shared_library_variables )

Set<Class<?>> classes = new LocalProjectPipelineExtensionDetector()
.getClassesOfTypeInPackage(
Object.class,
Optional.<String>empty())

// This class will behave differently and _not_ forward pipeline step invocations directly to the appropriately-named mock.
classes.remove(PipelineVariableImpersonator.class)

// instrument CpsScript, which we know we'll be using.
classes.add( CpsScript.class )

// exclude all interfaces - nobody will be able to call them, so they don't need to be instrumented.
// any implementation will be a real, detected class.
classes = classes.findAll { ! it.isInterface() }

// and publish that list of classes
DEFAULT_TEST_CLASSES.addAll( classes )
// Scan classpaths for extensions only once
if(PIPELINE_STEPS.isEmpty()) {
APipelineExtensionDetector classpath_scanner = new WholeClasspathPipelineExtensionDetector()

PIPELINE_STEPS = classpath_scanner.getPipelineSteps(Optional.<String> empty())

Set<String> symbols = classpath_scanner.getSymbols(Optional.<String> empty())
Set<String> global_variables = classpath_scanner.getGlobalVariables(Optional.<String> empty())
Set<String> shared_library_variables = getSharedLibraryVariables()

PIPELINE_SYMBOLS.addAll(symbols)
PIPELINE_SYMBOLS.addAll(global_variables)
PIPELINE_SYMBOLS.addAll(shared_library_variables)

Set<Class<?>> classes = new LocalProjectPipelineExtensionDetector()
.getClassesOfTypeInPackage(
Object.class,
Optional.<String> empty())

// This class will behave differently and _not_ forward pipeline step invocations directly to the appropriately-named mock.
classes.remove(PipelineVariableImpersonator.class)

// instrument CpsScript, which we know we'll be using.
classes.add(CpsScript.class)

// exclude all interfaces - nobody will be able to call them, so they don't need to be instrumented.
// any implementation will be a real, detected class.
classes = classes.findAll { !it.isInterface() }

// and publish that list of classes
DEFAULT_TEST_CLASSES.addAll(classes)
}
}

/**
Expand Down