I finally managed it to get this running (at least in the Jenkins instance but 
not in the test harness, see below). 
Currently I am using a mix of the ideas of Jesse and Robert: the JS libs can be 
included as a stapler adjunct and provide the new JS libs: 

<l:main-panel>

  <st:adjunct includes="io.jenkins.plugins.bootstrap4"/>
  <st:adjunct includes="io.jenkins.plugins.echarts"/>
  <st:adjunct includes="io.jenkins.plugins.font-awesome"/>
...

Rather than writing a new resource handler that extracts the resources 
dynamically (stripping of the versions, etc.) I use Maven to extract the 
WebJars and repack them to the Webapps folder automatically in the build. So 
users of the library can reuse the same concepts as before (st:adjunct, …), no 
new variable is required. 

If someone is interested, a draft PR is available for the warnings plugin: [3]

This works quite well in a Jenkins instance, however I can’t get this running 
with the Jenkins test harness. Now all my UI tests fail because the resources 
of the depending libraries are not found here, I always get a 404 (see [2]). Is 
this problem related to JENKINS-41827 [1]? Or do I need to include the JS 
dependencies in another way? Currently I’m using something like:

<dependency>
  <groupId>io.jenkins.plugins</groupId>
  <artifactId>font-awesome-api</artifactId>
  <version>${font-awesome-api.version}</version>
</dependency>
...
   
The test harness unpacks these libraries correctly in the tmp folder, however I 
can’t access these resources. The JS plugins are correctly shown as installed 
in Jenkins plugin manager.


[1] https://issues.jenkins-ci.org/browse/JENKINS-41827 
<https://issues.jenkins-ci.org/browse/JENKINS-41827>
[2] 
https://ci.jenkins.io/job/Plugins/job/warnings-ng-plugin/job/web-jars/9/testReport/junit/io.jenkins.plugins.analysis.core.scm/GitBlamerITest/Linux_Build___shouldFilterTable/
 
<https://ci.jenkins.io/job/Plugins/job/warnings-ng-plugin/job/web-jars/9/testReport/junit/io.jenkins.plugins.analysis.core.scm/GitBlamerITest/Linux_Build___shouldFilterTable/>
[3] https://github.com/jenkinsci/warnings-ng-plugin/pull/252 
<https://github.com/jenkinsci/warnings-ng-plugin/pull/252>



> Am 31.10.2019 um 15:47 schrieb Ullrich Hafner <[email protected]>:
> 
> I see. I’ll give it a try and report back if I manage it in this way...
> 
>> Am 31.10.2019 um 13:56 schrieb Jesse Glick <[email protected]>:
>> 
>> On Sat, Oct 26, 2019 at 7:03 AM Ullrich Hafner <[email protected]> 
>> wrote:
>>> I can reference my local plugin web resources with
>>> 
>>> <link rel="stylesheet" 
>>> href="${resURL}/plugin/warnings-ng/css/font-awesome/css/fontawesome.min.css"/>
>>> 
>>> But the same does not work when the fontawesome.min.css is part of the 
>>> other webjar.
>> 
>> Right, because the Jenkins resource URLs only serve files from the
>> `*.hpi` outside `WEB-INF/` and `META-INF/`, built by Maven from
>> `src/main/webapp/`. This is to match the traditional behavior of Java
>> EE WARs.
>> 
>> WebJars sounds neat, and definitely more friendly than Stapler
>> adjuncts, but to make them usable from Jenkins you would need to write
>> the infrastructure to serve their contents. I suppose this could take
>> the form of a WebJars support plugin which defines a `RootAction &
>> InvisibleAction` and then defines a page variable `webJarsUrl` so that
>> you could refer to URLs like
>> 
>> ${webJarsUrl}/warnings-ng/bootstrap/js/bootstrap.js
>> 
>> This specifies the hosting plugin for purposes of `ClassLoader`
>> lookup, the JAR `artifactId`, and the rest of path inside that JAR. (I
>> am assuming the JAR version should be omitted, since a given plugin
>> can only host one version of a given dependency without some Shade
>> contortions, and you do not want to have to change a bunch of sources
>> every time Dependabot bumps the version.) This would resolve to an
>> actual path like
>> 
>> /jenkins/webJars/4f86c88e/warnings-ng/bootstrap/js/bootstrap.js
>> 
>> The random string in there would be `Jenkins.SESSION_HASH`, so the
>> server can set a fairly long cache expiry without improper caching
>> after restarts with plugin updates. See the code used for `static` and
>> `adjunct` URLs in Jenkins.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Jenkins Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0CjSdzECgVbR_mLrJ0pHS1_NvO4h-9D7QQfxknS3-WLw%40mail.gmail.com.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/2BF266BC-EA7F-427F-812D-F40399608869%40gmail.com.

Reply via email to