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

Support icons in folders #1258

Merged
merged 14 commits into from
Mar 22, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// use the stock icon
folder('stock')

// use https://github.com/jenkinsci/custom-folder-icon-plugin for custom icons
userContent('customFolderIcons/custom.png', streamFileFromWorkspace('custom.png'))
folder('custom') {
icon {
customFolderIcon {
foldericon('custom.png')
}
}
}

// use https://github.com/jenkinsci/custom-folder-icon-plugin for ionicons
folder('ionicon') {
Copy link
Contributor

Choose a reason for hiding this comment

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

@strangelookingnerd Should we also have a test for new emoji type icons ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

job-dsl-plugin requires Jenkins 2.361.4 whereas custom-folder-icon-plugin 2.5 (which includes the emoji icons) requires 2.387.1 - so I guess this won't be possible right now.

Copy link
Member

Choose a reason for hiding this comment

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

I can probably get a release out next week. Once that's done I would have no problem with revving the minimum Jenkins core to 2.387.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@basil That would be great! On a side-note I found that the tests in javaposse.jobdsl.dsl.doc.ExampleValidationSpec do not seem to be run during the build anymore or are at least not reporting any failing tests. Running them manually however shows that the test for my icon.groovy example still fails. Before the switch to Maven the behavior was different. Any idea why that is?

Copy link
Member

@basil basil Mar 19, 2023

Choose a reason for hiding this comment

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

I think it has something to do with the use of @Unroll with file << findAllExamples(), where the right-hand side is a function call rather than a static set of values. Seems that JUnit isn't able to invoke the function call correctly. Are you interested in opening a PR that removes the use of @Unroll in favor of a simple for loop inside of the test?

Copy link
Member

Choose a reason for hiding this comment

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

icon {
ioniconFolderIcon {
ionicon('jenkins')
}
}
}

// use https://github.com/jenkinsci/custom-folder-icon-plugin for build status icon
folder('build-status') {
icon {
buildStatusFolderIcon()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package javaposse.jobdsl.dsl

import javaposse.jobdsl.dsl.helpers.AuthorizationContext
import javaposse.jobdsl.dsl.helpers.icon.FolderIconContext
import javaposse.jobdsl.dsl.helpers.properties.FolderPropertiesContext

abstract class AbstractFolder extends Item {
Expand Down Expand Up @@ -54,4 +55,22 @@ abstract class AbstractFolder extends Item {
}
}
}

/**
* Sets the icon of the folder.
*
* @since 1.82
*/
void icon(@DslContext(FolderIconContext) Closure closure) {
FolderIconContext context = new FolderIconContext(jobManagement, this)
ContextHelper.executeInContext(closure, context)

configure { Node folder ->
Node icon = folder / icon
if (icon) {
folder.remove(icon)
}
folder << context.icon
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package javaposse.jobdsl.dsl.helpers.icon

import javaposse.jobdsl.dsl.AbstractExtensibleContext
import javaposse.jobdsl.dsl.ContextType
import javaposse.jobdsl.dsl.Item
import javaposse.jobdsl.dsl.JobManagement

@ContextType('com.cloudbees.hudson.plugins.folder.FolderIcon')
class FolderIconContext extends AbstractExtensibleContext {
Node icon

FolderIconContext(JobManagement jobManagement, Item item) {
super(jobManagement, item)
}

@Override
protected void addExtensionNode(Node node) {
icon = ContextHelper.toNamedNode('icon', node)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ class FolderSpec extends Specification {
folder.node.properties[0].children()[0].name() == 'hack'
}

def 'call icon'() {
when:
folder.icon {
icon = new Node(null,
'icon', ['class': 'jenkins.plugins.foldericon.CustomFolderIcon', 'plugin': 'custom-folder-icon'],
new Node(null,
'customFolderIcon', 'test.png'))
}

then:
folder.node.icon[0].name() == 'icon'
folder.node.icon[0].attribute('class') == 'jenkins.plugins.foldericon.CustomFolderIcon'
folder.node.icon[0].attribute('plugin') == 'custom-folder-icon'
folder.node.icon[0].children()[0].name() == 'customFolderIcon'
folder.node.icon[0].children()[0].value() == 'test.png'
}

def 'configure'() {
when:
folder.configure {
Expand Down