Skip to content

Commit

Permalink
Add new set of OpenSource icon using oss-symbols-api-plugin (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy authored Aug 30, 2024
1 parent 9ffaa37 commit ce5c13c
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,31 @@ folder('ionicon-icon') {
}
----

==== OpenSource Folder Icon

Use icons provided by https://github.com/jenkinsci/oss-symbols-api-plugin[oss-symbols-api-plugin] as icon.

image:images/oss-folder-icon.png[]

Select the _OpenSource Folder Icon_ option and select any of the available icons.

image:images/oss-folder-icon-configuration.png[]

===== Job DSL

Configuration via https://github.com/jenkinsci/job-dsl-plugin[job-dsl-plugin]:

[source,groovy]
----
folder('opensource-icon') {
icon {
openSourceFolderIcon {
ossicon('cdf-icon-color')
}
}
}
----

=== Global Configuration

Check for unused custom folder icon files and delete them.
Expand Down
Binary file added images/oss-folder-icon-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/oss-folder-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<groupId>io.jenkins.plugins</groupId>
<artifactId>ionicons-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>oss-symbols-api</artifactId>
<version>17.v25a_23d15993c</version>
<!-- Until in bom -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
Expand Down
95 changes: 95 additions & 0 deletions src/main/java/jenkins/plugins/foldericon/OpenSourceFolderIcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* The MIT License
*
* Copyright (c) 2024
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.plugins.foldericon;

import com.cloudbees.hudson.plugins.folder.AbstractFolder;
import com.cloudbees.hudson.plugins.folder.FolderIcon;
import com.cloudbees.hudson.plugins.folder.FolderIconDescriptor;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import io.jenkins.plugins.oss.symbols.OpenSourceSymbols;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* An Open Source Folder Icon.
*/
public class OpenSourceFolderIcon extends FolderIcon {

private static final String DEFAULT_ICON = "cdf-icon-color";

private final String ossicon;

private AbstractFolder<?> owner;

@DataBoundConstructor
public OpenSourceFolderIcon(String ossicon) {
this.ossicon = StringUtils.isEmpty(ossicon) ? DEFAULT_ICON : ossicon;
}

@Override
protected void setOwner(AbstractFolder<?> folder) {
this.owner = folder;
}

public String getOssicon() {
return ossicon;
}

@Override
public String getImageOf(String size) {
return null;
}

@Override
public String getIconClassName() {
return OpenSourceSymbols.getIconClassName(getOssicon());
}

@Override
public String getDescription() {
if (owner != null) {
return owner.getPronoun();
} else {
return Messages.Folder_description();
}
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) Jenkins.get().getDescriptorOrDie(getClass());
}

@Extension
public static class DescriptorImpl extends FolderIconDescriptor {

@Override
@NonNull
public String getDisplayName() {
return Messages.OpenSourceFolderIcon_description();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ BuildStatusFolderIcon.description=Build Status Folder Icon
EmojiFolderIcon.description=Emoji Folder Icon
FontAwesomeFolderIcon.description=FontAwesome Folder Icon
IoniconFolderIcon.description=Ionicon Folder Icon
OpenSourceFolderIcon.description=OpenSource Folder Icon
Upload.exceedsFileSize=The request was rejected because its size ({0,number} kb) exceeds the allowed maximum ({1,number} kb)!
Upload.invalidFile=The request was rejected because its file is invalid - please select a valid file!
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
The MIT License
Copyright (c) 2024
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:f="/lib/form">
<link rel="stylesheet" href="${rootURL}/plugin/custom-folder-icon/css/oss.css" type="text/css" />
<script src="${rootURL}/plugin/custom-folder-icon/js/oss-config.js" type="text/javascript" />
<j:invokeStatic var="openSourceIcons" method="getAvailableIcons" className="io.jenkins.plugins.oss.symbols.OpenSourceSymbols" />
<f:entry title="${%IconPreview}" help="${descriptor.getHelpFile('preview')}">
<l:icon id="oss-preview" src="${openSourceIcons.get(instance.ossicon ?: 'cdf-icon-color')}" title="${icon.key}"
class="icon-xlg" />
</f:entry>
<f:advanced title="${%AvailableIcons}${not empty openSourceIcons ? ' (' + openSourceIcons.size() + ')' : ''}">
<j:forEach var="icon" items="${openSourceIcons}">
<a id="select-oss-${icon.key}" class="oss-icon-selection" onclick="setOpenSourceIcon('${icon.key}')">
<l:icon id="oss-icon-${icon.key}" src="${icon.value}" title="${icon.key}" tooltip="${icon.key}"
class="icon-md" />
</a>
</j:forEach>
</f:advanced>
<f:entry field="ossicon">
<f:textbox id="oss-icon-name" value="${instance.ossicon}" clazz="oss-icon-name" />
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# The MIT License
#
# Copyright (c) 2024
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

IconPreview=Icon preview
AvailableIcons=Show all available icons
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
The MIT License
Copyright (c) 2024
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<div>
Use OpenSource tools icons provided by <a href="https://github.com/jenkinsci/oss-symbols-api-plugin" target="_blank">OSS Symbols API Plugin</a> as icon.
</div>
33 changes: 33 additions & 0 deletions src/main/webapp/css/oss.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* The MIT License
*
* Copyright (c) 2024
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

.oss-icon-name {
display: none;
}

.oss-icon-selection {
color: unset;
cursor: pointer;
text-decoration: none !important;
}
42 changes: 42 additions & 0 deletions src/main/webapp/js/oss-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* The MIT License
*
* Copyright (c) 2024
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

function setOpenSourceIcon(icon) {
if (icon == null || icon === "") {
return;
}

let iconName = document.getElementById("oss-icon-name");
iconName.setAttribute("value", icon);
iconName.dispatchEvent(new Event("input"));

let oldPreview = document.getElementById("oss-preview");
let selectedIcon = document.getElementById("oss-icon-" + icon);

let newPreview = selectedIcon.cloneNode(true);
newPreview.id = "oss-preview";
newPreview.classList.replace("icon-md", "icon-xlg");

oldPreview.parentElement.replaceChild(newPreview, oldPreview);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ void testIoniconFolderIcon(JenkinsRule r) throws Exception {
assertEquals("jenkins", customIcon.getIonicon());
}

/**
* Test behavior for oss-icon.groovy.
*
* @throws Exception in case anything goes wrong
*/
@Test
void testOpenSourceFolderIcon(JenkinsRule r) throws Exception {
OpenSourceFolderIcon customIcon = createFolder(r, "opensource-icon.groovy", OpenSourceFolderIcon.class);
assertEquals("cdf-icon-color", customIcon.getOssicon());
}

@SuppressWarnings("unchecked")
private static <T extends FolderIcon> T createFolder(JenkinsRule r, String scriptName, Class<T> clazz)
throws Exception {
Expand Down
Loading

0 comments on commit ce5c13c

Please sign in to comment.