Skip to content

Commit

Permalink
Scan classpaths for extensions only once
Browse files Browse the repository at this point in the history
See details in #98
  • Loading branch information
bszeman9 authored and Szemán Bence (Alerant Zrt committed Sep 18, 2021
1 parent 2cde98c commit 5b97086
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
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

0 comments on commit 5b97086

Please sign in to comment.