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

Decoupled adhoc static plugin method invocations on hooks management #300

Merged
merged 13 commits into from
Sep 20, 2021

Conversation

imonteroperez
Copy link
Contributor

@imonteroperez imonteroperez commented Sep 10, 2021

Highlights

  • Current code of PCT on TransformPom and MultiParentCompileHook hooks is highly coupled to some AbstractMultiParentHook instances (like StructsHook, BlueOceanHook, etc.)

  • Current proposal remove the need to explicitly mention each hook involved in as a bad smell design

  • In addition, with the current code, if we want to fork the PCT and include new hooks, every time we sync with upstream we will have to deal with including our additional hooks on these two ones (TransformPom and MultiParentCompileHook)

  • What is proposed here is to provide a public method on PluginCompatTesterHooks to dynamically retrieve the registered hooks for a given stage, and to use that method on the affected ones to be refactored

  • Also it provides a new option arg named -externalHooksJars to specify a comma-separated list of external hooks jar file locations

  • 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

@imonteroperez imonteroperez force-pushed the external-hooks-support branch 2 times, most recently from 3065594 to 52f1332 Compare September 10, 2021 09:15
@imonteroperez
Copy link
Contributor Author

The failure on buildtriggerbadge test seems happening on master branch too. See: https://ci.jenkins.io/blue/organizations/jenkins/jenkinsci-libraries%2Fplugin-compat-tester/detail/master/159/pipeline

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

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

the external hook jars looks OK (would be nice if it did not fail silently though).

Do not understand the other code we enough to spot anything obviously wrong.

@imonteroperez
Copy link
Contributor Author

Do not understand the other code we enough to spot anything obviously wrong

I tried to explain it in the PR description. Mostly this PR is providing support to decouple everything related with hooks to make it feasible to use and provide external ones from outside the PCT code by itself.

So, some code, mostly from MultiParentCompileHook and TransformPom has been adapted/refactored to avoid having things like:

boolean isStructs = StructsHook.isStructsPlugin(pomData);
boolean isBO = BlueOceanHook.isBOPlugin(pomData);
boolean isDeclarativePipeline = DeclarativePipelineHook.isDPPlugin(pomData);
boolean isCasC = ConfigurationAsCodeHook.isCascPlugin(pomData);
boolean isPipelineStageViewPlugin = PipelineStageViewHook.isPipelineStageViewPlugin(pomData);
boolean isSwarm = SwarmHook.isSwarmPlugin(pomData);
boolean isDeclarativePipelineMigration = DeclarativePipelineMigrationHook.isPlugin(pomData);
boolean isWarningsMG = WarningsNGCheckoutHook.isWarningsNG(pomData);
[...]
if (isDeclarativePipeline || 
    isBO || 
    isCB || 
    isStructs ||
    isCasC ||
    isPipelineStageViewPlugin ||
    isSwarm ||
    isDeclarativePipelineMigration ||
[...]

Which seems like a bad smell and makes it hard to use these hooks if you want to apply it for external ones too. So proposed to get all this dynamically as shown in the PR content, mostly using a new method to retrieve all the hooks before a specific stage. It would get internal ones (from the PCT by itself) and external ones provided by --externalHooksJars and --hookPrefixes.

Happy to clarify more doubts here if needed @jtnord
Hope it helps!

@imonteroperez
Copy link
Contributor Author

imonteroperez commented Sep 20, 2021

Checks have the same results as master branch. Safe to be merged.

@imonteroperez imonteroperez merged commit 33ed49d into jenkinsci:master Sep 20, 2021
// Find all steps for a given stage. Long due to casting
switch(stage) {
case "compilation" :
Set<Class<? extends PluginCompatTesterHookBeforeCompile>> compSteps = reflections.getSubTypesOf(PluginCompatTesterHookBeforeCompile.class);
Copy link
Member

Choose a reason for hiding this comment

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

Just found this PR. Is it too late to request that this be improved to use either ServiceLoader (with metainf-services-annotation) or https://github.com/jglick/sezpoz? Scanning bytecode for classes that happen to implement some interface is pretty fragile (as well as more work than the clean solutions).

Copy link

@MRamonLeon MRamonLeon Oct 1, 2021

Choose a reason for hiding this comment

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

I suggested the former, so 👍🏽

Copy link
Member

Choose a reason for hiding this comment

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

I understand that PCT was already using bytecode scanning, but this PR switches it from an unfortunate implementation detail to a public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants