timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-28408] Jenkins can't load extension ContextExtensionPoint if dependency is optional #7211

Closed timja closed 9 years ago

timja commented 9 years ago

As in tutorial:
https://github.com/jenkinsci/job-dsl-plugin/wiki/Extending-the-DSL

extend:

@Extension(optional = true)
public class AquaPluginJobDslExtension extends ContextExtensionPoint {

    @DslExtensionMethod(context = StepContext.class)
    public Object aqua(Runnable closure) {
AquaContext context = new AquaContext();
executeInContext(closure, context);

return new AquaPluginBuilder(
context.getPacks(),
context.getRunType(),
context.getLogLevel().getName(),
context.getTimeout(),
context.getUnits().name(),
context.getDelayPollSec()
);
    }
}

with dependency:


    org.jenkins-ci.plugins
    job-dsl
    1.34
    true

Then with job-dsl 34 installed do in jenkins script console:

import javaposse.jobdsl.plugin.ContextExtensionPoint;

Jenkins.instance.refreshExtensions();
println(Jenkins.instance.getExtensionList(ContextExtensionPoint.class))

prints "[]"

With dependency false

it prints:
[com.example.dsl.AquaPluginJobDslExtension@2ee05de3]

Okay,
do the same with token macro plugin:

 
    org.jenkins-ci.plugins
    token-macro
    1.10
    true

@Extension(optional = true)
public class TokenMExt extends DataBoundTokenMacro {
    @Override
    public String evaluate(AbstractBuild abstractBuild, TaskListener taskListener, String s) throws MacroEvaluationException, IOException, InterruptedException {
return null;
    }

    @Override
    public boolean acceptsMacroName(String s) {
return false;
    }
}

in console:

import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;

println(Jenkins.getInstance().getExtensionList(DataBoundTokenMacro.class))

prints:
[..., org.jenkinsci.plugins.tokenmacro.impl.PropertyFromFileMacro@11786964, com.example.dsl.TokenMExt@13a9b76f]


Originally reported by lanwen, imported from: Jenkins can't load extension ContextExtensionPoint if dependency is optional
  • assignee: daspilker
  • status: Closed
  • priority: Major
  • resolution: Fixed
  • resolved: 2015-09-09T09:25:01+00:00
  • imported: 2022/01/10
timja commented 9 years ago

daspilker:

Hm, no clue. All I did was following the docs, see https://wiki.jenkins-ci.org/display/JENKINS/Dependencies+among+plugins#Dependenciesamongplugins-Optionaldependencies and https://wiki.jenkins-ci.org/display/JENKINS/Defining+a+new+extension+point.

timja commented 9 years ago

daspilker:

Does the manifest of your plugin list the job-dsl plugin as (optional) plugin dependency? Can you unzip the HPI and check META-INF/MANIFEST.MF? It should contain something like Plugin-Dependencies: job-dsl:1.34;resolution:=optional. Which version of the maven-hpi-plugin are you using?

timja commented 9 years ago

daspilker:

I think the problem is that the Job DSL plugin POM has packaging type of jpi (see http://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/job-dsl/1.34/job-dsl-1.34.pom) as generated by the gradle-jpi-plugin. And the maven-hpi-plugin only considers the hpi packaging type as plugin dependency, see https://github.com/jenkinsci/maven-hpi-plugin/blob/maven-hpi-plugin-1.113/src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java#L64.

timja commented 9 years ago

daspilker:

Fix for the gradle-jpi-plugin: https://github.com/jenkinsci/gradle-jpi-plugin/pull/53

timja commented 9 years ago

wolfs:

Shouldn't we fix the maven-hpi-plugin instead of the gradle jpi plugin?

timja commented 9 years ago

lanwen:

I use maven-hpi-plugin:1.106 (same with latest 1.113)
If i add token macro as optional dep, then in manifest i see

Plugin-Dependencies: token-macro:1.10;resolution:=optional

And if i add job-dsl-plugin as optional, no any tag

Plugin-Dependencies

in manifest

timja commented 9 years ago

lanwen:

What about JENKINS-28305 ?

timja commented 9 years ago

daspilker:

wolfs: I will open a pull request for the maven-hpi-plugin, but to get this fixed sooner, I will also fix (AKA add a workaround) to the gradle-jpi-plugin.

lanwen: No problem, the new pull request will deal with the problem.

timja commented 9 years ago

daspilker:

Fix for the maven-hpi-plugin: https://github.com/jenkinsci/maven-hpi-plugin/pull/17

timja commented 9 years ago

scm_issue_link:

Code changed in jenkins
User: Daniel Spilker
Path:
CHANGELOG.md
config/codenarc/rules-test.groovy
src/main/groovy/org/jenkinsci/gradle/plugins/jpi/Jpi.groovy
src/main/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPlugin.groovy
src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JpiPluginSpec.groovy
src/test/resources/org/jenkinsci/gradle/plugins/jpi/bitbucket-pom.xml
src/test/resources/org/jenkinsci/gradle/plugins/jpi/compile-dependencies-pom.xml
src/test/resources/org/jenkinsci/gradle/plugins/jpi/complex-pom.xml
src/test/resources/org/jenkinsci/gradle/plugins/jpi/minimal-pom.xml
src/test/resources/org/jenkinsci/gradle/plugins/jpi/optional-plugin-dependencies-pom.xml
src/test/resources/org/jenkinsci/gradle/plugins/jpi/plugin-dependencies-pom.xml
http://jenkins-ci.org/commit/gradle-jpi-plugin/9cafa9f31c9e1807532f29caaba53a7e746f198e
Log:
Merge pull request #53 from daspilker/JENKINS-28408

JENKINS-28408 allow JPI/HPI file extension and packaging type to be configured

Compare: https://github.com/jenkinsci/gradle-jpi-plugin/compare/5b72ac473142...9cafa9f31c9e

timja commented 9 years ago

daspilker:

Will be fixed in job-dsl-plugin 1.35 and is fixed in gradle-jpi-plugin 0.12.0.

timja commented 9 years ago

scm_issue_link:

Code changed in jenkins
User: Daniel Spilker
Path:
src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java
http://jenkins-ci.org/commit/maven-hpi-plugin/28e8336c762d5032140ea38c5d127c9394279937
Log:
fixed support for jpi packaging type

JENKINS-28408

timja commented 9 years ago

scm_issue_link:

Code changed in jenkins
User: Vincent Latombe
Path:
src/main/java/org/jenkinsci/maven/plugins/hpi/MavenArtifact.java
http://jenkins-ci.org/commit/maven-hpi-plugin/78247d32be9841ccfd165bc7bbb7d2566bc9f994
Log:
Merge pull request #17 from daspilker/JENKINS-28408

JENKINS-28408 fixed support for jpi packaging type

Compare: https://github.com/jenkinsci/maven-hpi-plugin/compare/b2d139e78da6...78247d32be98

timja commented 9 years ago

daspilker:

This has been fixed in maven-hpi-plugin 1.14.

timja commented 9 years ago

daspilker:

Ah, typo. It has been fixed in maven-hpi-plugin 1.114.