From e11d1ca257cc074b9b3d1d10e1caa66d092b8441 Mon Sep 17 00:00:00 2001 From: strangelookingnerd <49242855+strangelookingnerd@users.noreply.github.com> Date: Sat, 11 May 2024 13:27:00 +0200 Subject: [PATCH] Remove readme generator --- pom.xml | 67 ------ .../badge/annotations/OptionalParam.java | 46 ----- .../plugins/badge/annotations/Param.java | 51 ----- .../badge/dsl/AbstractAddBadgeStep.java | 21 +- .../plugins/badge/dsl/AbstractStep.java | 5 +- .../plugins/badge/dsl/AddBadgeStep.java | 15 +- .../plugins/badge/dsl/AddErrorBadgeStep.java | 6 +- .../plugins/badge/dsl/AddHtmlBadgeStep.java | 7 +- .../plugins/badge/dsl/AddInfoBadgeStep.java | 6 +- .../plugins/badge/dsl/AddShortTextStep.java | 27 ++- .../badge/dsl/AddWarningBadgeStep.java | 6 +- .../plugins/badge/dsl/CreateSummaryStep.java | 11 +- .../plugins/badge/readme/DescribeStepTag.java | 190 ------------------ .../plugins/badge/readme/ListImagesTag.java | 45 ----- .../plugins/badge/readme/ReadmeGenerator.java | 29 --- src/test/resources/readme/README.tmpl | 172 ---------------- 16 files changed, 64 insertions(+), 640 deletions(-) delete mode 100644 src/main/java/com/jenkinsci/plugins/badge/annotations/OptionalParam.java delete mode 100644 src/main/java/com/jenkinsci/plugins/badge/annotations/Param.java delete mode 100644 src/test/java/com/jenkinsci/plugins/badge/readme/DescribeStepTag.java delete mode 100644 src/test/java/com/jenkinsci/plugins/badge/readme/ListImagesTag.java delete mode 100644 src/test/java/com/jenkinsci/plugins/badge/readme/ReadmeGenerator.java delete mode 100644 src/test/resources/readme/README.tmpl diff --git a/pom.xml b/pom.xml index d1243e5..b1e8de2 100644 --- a/pom.xml +++ b/pom.xml @@ -56,36 +56,6 @@ ${scmTag} - - - - org.apache.maven.plugins - maven-compiler-plugin - - -Xlint:all - - - - org.codehaus.mojo - exec-maven-plugin - 3.2.0 - - - - java - - prepare-package - - true - test - com.jenkinsci.plugins.badge.readme.ReadmeGenerator - - - - - - - repo.jenkins-ci.org @@ -115,7 +85,6 @@ org.jenkins-ci.plugins.workflow workflow-step-api - org.jenkins-ci.plugins structs @@ -124,7 +93,6 @@ org.jenkins-ci.plugins script-security - org.jenkins-ci.plugins antisamy-markup-formatter @@ -133,16 +101,6 @@ io.jenkins.plugins ionicons-api - - org.jenkins-ci.plugins - jackson2-api - test - - - io.jenkins.plugins - commons-lang3-api - test - org.jenkins-ci.plugins.workflow workflow-cps @@ -164,30 +122,5 @@ workflow-job test - - - com.hubspot.jinjava - jinjava - 2.7.2 - test - - - commons-net - commons-net - - - org.apache.commons - commons-lang3 - - - com.fasterxml.jackson.core - * - - - com.fasterxml.jackson.dataformat - * - - - diff --git a/src/main/java/com/jenkinsci/plugins/badge/annotations/OptionalParam.java b/src/main/java/com/jenkinsci/plugins/badge/annotations/OptionalParam.java deleted file mode 100644 index 23abf61..0000000 --- a/src/main/java/com/jenkinsci/plugins/badge/annotations/OptionalParam.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2004-2010, Sun Microsystems, Inc., Serban Iordache - * - * 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 com.jenkinsci.plugins.badge.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * An optional badge param - */ - -@Documented -@Retention(RUNTIME) -@Target({ElementType.METHOD, ElementType.PARAMETER}) -public @interface OptionalParam { - - /** - * @return description for this param - */ - String description(); -} diff --git a/src/main/java/com/jenkinsci/plugins/badge/annotations/Param.java b/src/main/java/com/jenkinsci/plugins/badge/annotations/Param.java deleted file mode 100644 index 90af7aa..0000000 --- a/src/main/java/com/jenkinsci/plugins/badge/annotations/Param.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2004-2010, Sun Microsystems, Inc., Serban Iordache - * - * 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 com.jenkinsci.plugins.badge.annotations; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * A required badge param - */ - -@Documented -@Retention(RUNTIME) -@Target({ElementType.FIELD, ElementType.PARAMETER}) -public @interface Param { - - /** - * @return the name of this param - */ - String name(); - - /** - * @return description for this param - */ - String description(); -} diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractAddBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractAddBadgeStep.java index 1b8542a..4626960 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractAddBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractAddBadgeStep.java @@ -23,21 +23,15 @@ */ package com.jenkinsci.plugins.badge.dsl; -import java.io.Serializable; - import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; -import com.jenkinsci.plugins.badge.annotations.Param; -import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import hudson.Extension; import hudson.model.Run; import org.jenkinsci.plugins.workflow.steps.StepContext; -import org.jenkinsci.plugins.workflow.steps.StepExecution; import org.jenkinsci.plugins.workflow.steps.SynchronousStepExecution; -import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; +import java.io.Serializable; + /** * Abstract class to add badges. */ @@ -45,8 +39,11 @@ public abstract class AbstractAddBadgeStep extends AbstractStep { private final Badge badge; - public AbstractAddBadgeStep(@Param(name = "icon", description = "The icon for this badge") String icon, - @Param(name = "text", description = "The text for this badge") String text) { + /** + * @param icon The icon for this badge + * @param text The text for this badge + */ + public AbstractAddBadgeStep(String icon, String text) { this.badge = new Badge(icon, text); } @@ -62,8 +59,10 @@ public String getLink() { return badge.getLink(); } + /** + * @param link The link to be added to this badge + */ @DataBoundSetter - @OptionalParam(description = "The link to be added to this badge") public void setLink(String link) { badge.setLink(link); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractStep.java index c414689..fced38b 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AbstractStep.java @@ -23,7 +23,6 @@ */ package com.jenkinsci.plugins.badge.dsl; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; import org.jenkinsci.plugins.workflow.steps.Step; import org.kohsuke.stapler.DataBoundSetter; @@ -33,8 +32,10 @@ abstract class AbstractStep extends Step { private String id; + /** + * @param id Badge identifier. Selectively delete badges by id. + */ @DataBoundSetter - @OptionalParam(description = "Badge identifier. Selectively delete badges by id.") public void setId(String id) { this.id = id; } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddBadgeStep.java index 6674641..6b928c2 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddBadgeStep.java @@ -24,14 +24,10 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; -import hudson.model.Run; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.StepExecution; -import org.jenkinsci.plugins.workflow.steps.SynchronousStepExecution; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -40,9 +36,12 @@ */ public class AddBadgeStep extends AbstractAddBadgeStep { + /** + * @param icon The icon for this badge + * @param text The text for this badge + */ @DataBoundConstructor - public AddBadgeStep(@Param(name = "icon", description = "The icon for this badge") String icon, - @Param(name = "text", description = "The text for this badge") String text) { + public AddBadgeStep(String icon, String text) { super(icon, text); } @@ -50,8 +49,10 @@ public String getColor() { return getBadge().getColor(); } + /** + * @param color The Jenkins palette/semantic color name of the badge icon symbol + */ @DataBoundSetter - @OptionalParam(description = "The Jenkins palette/semantic color name of the badge icon symbol") public void setColor(String color) { getBadge().setColor(color); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep.java index cf9bc54..a87ecf4 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddErrorBadgeStep.java @@ -24,7 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -36,8 +35,11 @@ */ public class AddErrorBadgeStep extends AbstractAddBadgeStep { + /** + * @param text The text for this error badge + */ @DataBoundConstructor - public AddErrorBadgeStep(@Param(name = "text", description = "The text for this error badge") String text) { + public AddErrorBadgeStep(String text) { super(null, text); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStep.java index d561a33..d9d89a0 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddHtmlBadgeStep.java @@ -24,7 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.HtmlBadgeAction; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; @@ -41,8 +40,12 @@ public class AddHtmlBadgeStep extends AbstractStep { private final String html; + /** + * + * @param html The html content to be used for this badge + */ @DataBoundConstructor - public AddHtmlBadgeStep(@Param(name = "html", description = "The html content to be used for this badge") String html) { + public AddHtmlBadgeStep(String html) { this.html = html; } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep.java index 2b6425c..15224e9 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddInfoBadgeStep.java @@ -24,7 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -36,8 +35,11 @@ */ public class AddInfoBadgeStep extends AbstractAddBadgeStep { + /** + * @param text The info text for this badge + */ @DataBoundConstructor - public AddInfoBadgeStep(@Param(name = "text", description = "The info text for this badge") String text) { + public AddInfoBadgeStep(String text) { super(null, text); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddShortTextStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddShortTextStep.java index 50ccef0..6da8b99 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddShortTextStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddShortTextStep.java @@ -24,8 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; @@ -46,8 +44,11 @@ public class AddShortTextStep extends Step { private final ShortText shortText; + /** + * @param text The text to add fot this badge + */ @DataBoundConstructor - public AddShortTextStep(@Param(name = "text", description = "The text to add fot this badge") String text) { + public AddShortTextStep(String text) { this.shortText = new ShortText(text); } @@ -59,8 +60,10 @@ public String getColor() { return shortText.getColor(); } + /** + * @param color The color for this short text + */ @DataBoundSetter - @OptionalParam(description = "The color for this short text") public void setColor(String color) { this.shortText.setColor(color); } @@ -69,8 +72,10 @@ public String getBackground() { return shortText.getBackground(); } + /** + * @param background The background-color for this short text + */ @DataBoundSetter - @OptionalParam(description = "The background-color for this short text") public void setBackground(String background) { this.shortText.setBackground(background); } @@ -79,8 +84,10 @@ public Integer getBorder() { return shortText.getBorder(); } + /** + * @param border The border width for this short text + */ @DataBoundSetter - @OptionalParam(description = "The border width for this short text") public void setBorder(Integer border) { this.shortText.setBorder(border); } @@ -89,14 +96,18 @@ public String getBorderColor() { return shortText.getBorderColor(); } + /** + * @param borderColor The order color for this short text + */ @DataBoundSetter - @OptionalParam(description = "The order color for this short text") public void setBorderColor(String borderColor) { this.shortText.setBorderColor(borderColor); } + /** + * @param link The link for this short text + */ @DataBoundSetter - @OptionalParam(description = "The link for this short text") public void setLink(String link) { this.shortText.setLink(link); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep.java index 5662f36..b116604 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/AddWarningBadgeStep.java @@ -24,7 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeAction; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -36,8 +35,11 @@ */ public class AddWarningBadgeStep extends AbstractAddBadgeStep { + /** + * @param text The text for this warning badge + */ @DataBoundConstructor - public AddWarningBadgeStep(@Param(name = "text", description = "The text for this warning badge") String text) { + public AddWarningBadgeStep(String text) { super(null, text); } diff --git a/src/main/java/com/jenkinsci/plugins/badge/dsl/CreateSummaryStep.java b/src/main/java/com/jenkinsci/plugins/badge/dsl/CreateSummaryStep.java index f0b705f..c108022 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/dsl/CreateSummaryStep.java +++ b/src/main/java/com/jenkinsci/plugins/badge/dsl/CreateSummaryStep.java @@ -24,8 +24,6 @@ package com.jenkinsci.plugins.badge.dsl; import com.jenkinsci.plugins.badge.action.BadgeSummaryAction; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; -import com.jenkinsci.plugins.badge.annotations.Param; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; @@ -45,8 +43,11 @@ public class CreateSummaryStep extends AbstractStep { private final String icon; private String text; + /** + * @param icon "The icon for this summary" + */ @DataBoundConstructor - public CreateSummaryStep(@Param(name = "icon", description = "The icon for this summary") String icon) { + public CreateSummaryStep(String icon) { this.icon = icon; } @@ -58,8 +59,10 @@ public String getText() { return text; } + /** + * @param text "The title text for this summary" + */ @DataBoundSetter - @OptionalParam(description = "The title text for this summary") public void setText(String text) { this.text = text; } diff --git a/src/test/java/com/jenkinsci/plugins/badge/readme/DescribeStepTag.java b/src/test/java/com/jenkinsci/plugins/badge/readme/DescribeStepTag.java deleted file mode 100644 index 945f0f9..0000000 --- a/src/test/java/com/jenkinsci/plugins/badge/readme/DescribeStepTag.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.jenkinsci.plugins.badge.readme; - -import com.hubspot.jinjava.interpret.JinjavaInterpreter; -import com.hubspot.jinjava.lib.tag.Tag; -import com.hubspot.jinjava.tree.TagNode; -import com.hubspot.jinjava.util.HelperStringTokenizer; -import com.jenkinsci.plugins.badge.annotations.OptionalParam; -import com.jenkinsci.plugins.badge.annotations.Param; -import hudson.Extension; -import org.apache.commons.lang3.builder.CompareToBuilder; -import org.jenkinsci.plugins.workflow.steps.StepDescriptor; -import org.kohsuke.stapler.DataBoundConstructor; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.Optional; - -import static java.util.Arrays.sort; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Stream.concat; - -public class DescribeStepTag implements Tag { - - - @Override - public String getName() { - return "describe_step"; - } - - @Override - public String interpret(TagNode tagNode, JinjavaInterpreter jinjavaInterpreter) { - HelperStringTokenizer helper = new HelperStringTokenizer(tagNode.getHelpers()); - - - if (!helper.hasNext()) { - return null; - } - - StringBuilder sb = new StringBuilder(); - - String className = helper.next(); - - try { - Class clazz = Class.forName(className); - Constructor[] constructors = clazz.getConstructors(); - - Class[] declaredClasses = clazz.getDeclaredClasses(); - - - String functionName = getFunctionName(declaredClasses); - - Optional constructorParameterNames = getConstructorParameterNames(constructors); - - if (!constructorParameterNames.isPresent()) { - throw new IllegalStateException("No constructor parameters found"); - } - - MethodParameter[] constructorParams = constructorParameterNames.get(); - - MethodParameter[] optionalParameterNames = getOptionalParams(clazz); - - sb.append("// ").append(functionName).append("\n"); - sb.append("// ------------------------------------------\n\n"); - - sb.append("/**\n"); - if (optionalParameterNames.length != 0) { - sb.append(" * minimal params"); - } else { - sb.append(" * params"); - } - sb.append("\n *\n"); - - stream(constructorParams).forEach(sb::append); - sb.append(" */\n"); - - sb.append(functionName).append("(") - .append(stream(constructorParams).map(p -> p.getName() + ": <" + p.getName() + ">") - .collect(joining(", "))).append(")\n\n"); - - - if (optionalParameterNames.length != 0) { - sb.append("/**\n * all params\n *\n"); - concat(stream(constructorParams), stream(optionalParameterNames)).forEach(sb::append); - - sb.append(" */\n"); - - sb.append(functionName).append("(").append(concat(stream(constructorParams), stream(optionalParameterNames)) - .map(p -> p.getName() + ": <" + p.getName() + ">").collect(joining(", "))).append(")\n"); - } - - } catch (Exception e) { - throw new RuntimeException(e); - } - - return sb.toString(); - } - - private MethodParameter[] getOptionalParams(Class clazz) { - return stream(clazz.getMethods()).filter(m -> m.getAnnotation(OptionalParam.class) != null) - .map(m -> new MethodParameter(m.getAnnotation(OptionalParam.class), m)).sorted().toArray(MethodParameter[]::new); - } - - /** - * The constructor parameters need to have @Param in order to get the name of the parameter - * - * @param constructors - * @return - */ - private Optional getConstructorParameterNames(Constructor[] constructors) { - return stream(constructors).filter(c -> c.getAnnotation(DataBoundConstructor.class) != null).map(c -> { - - MethodParameter[] names = new MethodParameter[c.getParameterCount()]; - - for (int i = 0; i < c.getParameterCount(); i++) { - - Parameter parameter = c.getParameters()[i]; - - Param param = parameter.getAnnotation(Param.class); - - if (param == null) { - throw new IllegalStateException("Constructor argument " + i + " of class " + c.getDeclaringClass().getName() + " needs to have @" + Param.class.getName() + " annotation."); - } - - names[i] = new MethodParameter(param); - - } - - sort(names); - - return names; - }).findFirst(); - } - - private String getFunctionName(Class[] declaredClasses) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { - for (Class innerClass : declaredClasses) { - Extension extension = innerClass.getAnnotation(Extension.class); - if (extension != null && StepDescriptor.class.isAssignableFrom(innerClass)) { - return ((StepDescriptor) innerClass.getDeclaredConstructor().newInstance()).getFunctionName(); - } - } - return null; - } - - @Override - public String getEndTagName() { - return null; - } - - private static class MethodParameter implements Comparable { - final String name; - final String description; - final boolean optional; - - MethodParameter(Param param) { - this.name = param.name(); - this.description = param.description(); - this.optional = false; - } - - MethodParameter(OptionalParam param, Method method) { - - String methodName = method.getName().substring(3); - this.name = methodName.substring(0, 1).toLowerCase() + methodName.substring(1); - this.description = param.description(); - this.optional = true; - } - - private String getName() { - return name; - } - - private boolean isOptional() { - return optional; - } - - @Override - public String toString() { - return " * " + name + ": " + (optional ? "(optional) " : "") + description + "\n"; - } - - @Override - public int compareTo(MethodParameter o) { - return new CompareToBuilder().append(this.optional, o.isOptional()).append(this.name, o.getName()).toComparison(); - } - } - -} diff --git a/src/test/java/com/jenkinsci/plugins/badge/readme/ListImagesTag.java b/src/test/java/com/jenkinsci/plugins/badge/readme/ListImagesTag.java deleted file mode 100644 index c13ff3b..0000000 --- a/src/test/java/com/jenkinsci/plugins/badge/readme/ListImagesTag.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.jenkinsci.plugins.badge.readme; - -import com.hubspot.jinjava.interpret.JinjavaInterpreter; -import com.hubspot.jinjava.lib.tag.Tag; -import com.hubspot.jinjava.tree.TagNode; -import com.hubspot.jinjava.util.HelperStringTokenizer; - -import java.io.File; - -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; - -public class ListImagesTag implements Tag { - - - @Override - public String getName() { - return "list_images"; - } - - @Override - public String interpret(TagNode tagNode, JinjavaInterpreter jinjavaInterpreter) { - HelperStringTokenizer helper = new HelperStringTokenizer(tagNode.getHelpers()); - - - if (!helper.hasNext()) { - return null; - } - - String path = helper.next(); - - - File[] files = new File(path).listFiles(); - if (files == null) { - return null; - } - return stream(files).map(File::getName).sorted().map(name -> "- ![alt text](" + path + "/" + name + " \"" + name + "\") " + name).collect(joining("\n")); - } - - @Override - public String getEndTagName() { - return null; - } - -} diff --git a/src/test/java/com/jenkinsci/plugins/badge/readme/ReadmeGenerator.java b/src/test/java/com/jenkinsci/plugins/badge/readme/ReadmeGenerator.java deleted file mode 100644 index 6b10117..0000000 --- a/src/test/java/com/jenkinsci/plugins/badge/readme/ReadmeGenerator.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.jenkinsci.plugins.badge.readme; - -import com.google.common.io.Resources; -import com.hubspot.jinjava.Jinjava; - -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -public class ReadmeGenerator { - public static void main(String... args) throws IOException { - Jinjava jinjava = new Jinjava(); - jinjava.getGlobalContext().registerTag(new ListImagesTag()); - jinjava.getGlobalContext().registerTag(new DescribeStepTag()); - - Map context = new HashMap<>(); - - String template = Resources.toString(Resources.getResource("readme/README.tmpl"), StandardCharsets.UTF_8); - - String renderedTemplate = jinjava.render(template, context); - - try (PrintWriter out = new PrintWriter("README.md")) { - out.println(renderedTemplate); - } - - } -} diff --git a/src/test/resources/readme/README.tmpl b/src/test/resources/readme/README.tmpl deleted file mode 100644 index 2cf8d23..0000000 --- a/src/test/resources/readme/README.tmpl +++ /dev/null @@ -1,172 +0,0 @@ -# Badge plugin - -[![Build Status](https://ci.jenkins.io/job/Plugins/job/badge-plugin/job/master/badge/icon)](https://ci.jenkins.io/job/Plugins/job/badge-plugin/job/master/) -[![Codecov Coverage](https://codecov.io/gh/jenkinsci/badge-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/jenkinsci/badge-plugin) -[![Jenkins Security Scan](https://github.com/jenkinsci/badge-plugin/actions/workflows/jenkins-security-scan.yml/badge.svg)](https://github.com/jenkinsci/badge-plugin/actions/workflows/jenkins-security-scan.yml) - -[![Installations](https://img.shields.io/jenkins/plugin/i/badge.svg?color=blue&label=installations)](https://stats.jenkins.io/pluginversions/badge.html) -[![Contributors](https://img.shields.io/github/contributors/jenkinsci/badge-plugin.svg?color=blue)](https://github.com/jenkinsci/badge-plugin/graphs/contributors) -[![Changelog](https://img.shields.io/github/release/jenkinsci/badge-plugin.svg?label=changelog)](https://github.com/jenkinsci/badge-plugin/releases/latest) - -Jenkins plugin to add badges and build summary entries from a pipeline. - -This plugin was forked from the [Groovy Postbuild Plugin](https://plugins.jenkins.io/groovy-postbuild) which will in future use the API from this plugin. - -## addBadge - -This method allows to add build badge icons. - -![alt text](src/doc/badge.png "Badge") - -```groovy - -// puts a badge with the given icon and text. - -{% describe_step com.jenkinsci.plugins.badge.dsl.AddBadgeStep %} - -{% describe_step com.jenkinsci.plugins.badge.dsl.AddInfoBadgeStep %} - -{% describe_step com.jenkinsci.plugins.badge.dsl.AddWarningBadgeStep %} - -{% describe_step com.jenkinsci.plugins.badge.dsl.AddErrorBadgeStep %} -``` - -## removeBadges - -Removes badges - -```groovy - -// removes badges. If no id is provided all are removed. -// If an id is provided, remove badges with the matching id. - -{% describe_step com.jenkinsci.plugins.badge.dsl.RemoveBadgesStep %} -``` - -## addHtmlBadge - -Puts a badge with custom html - -```groovy - -// puts a badge with a custom html content. -{% describe_step com.jenkinsci.plugins.badge.dsl.AddHtmlBadgeStep %} -``` -## removeHtmlBadges - -Removes html badges - -```groovy - -// removes html badges. If no id is provided all are removed. -// If an id is provided, remove badges with the matching id. - -{% describe_step com.jenkinsci.plugins.badge.dsl.RemoveHtmlBadgesStep -%} ``` - -## addShortText - -Puts a badge with a short text - -```groovy - -// puts a badge with a short text, using the default format. -// For Colors supported, Google "html color names". - -{% describe_step com.jenkinsci.plugins.badge.dsl.AddShortTextStep %} -``` - -## createSummary - -Puts a badge with a short text - -![alt text](src/doc/summary.png "Summary") - -```groovy - -// creates an entry in the build summary page and returns a summary -// object corresponding to this entry. The icon must be one of the 48x48 -// icons offered. - -{% describe_step com.jenkinsci.plugins.badge.dsl.CreateSummaryStep %} - -def summary = createSummary(icon) -summary.appendText(text, escapeHtml) -summary.appendText(text, escapeHtml, bold, italic, color) -``` - -## removeSummaries - -Removes summaries - -```groovy - -// removes summaries. If no id is provided all are removed. -// If an id is provided, remove badges with the matching id. - -{% describe_step com.jenkinsci.plugins.badge.dsl.RemoveSummariesStep %} -``` - -## Icons - -Icons can reference [Jenkins Symbols](https://weekly.ci.jenkins.io/design-library/Symbols/), including all the symbols provided by the [ionicons-api-plugin](https://plugins.jenkins.io/ionicons-api). - -More symbols can be referenced by installing additional plugins, such as [font-awesome-api-plugin](https://plugins.jenkins.io/font-awesome-api) or [custom-folder-icon-plugin](https://plugins.jenkins.io/custom-folder-icon). - -```groovy -addBadge(icon: 'symbol-cube', text: 'a cubed build') -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'a starred build') -addBadge(icon: 'symbol-symbolName plugin-yourArtifactId', text: 'another icon build') -``` - -In addition to the default [16x16](https://github.com/jenkinsci/jenkins/tree/master/war/src/main/webapp/images/16x16) icons offered by Jenkins, badge plugin provides the following icons: - -{% list_images src/main/webapp/images %} - -### Other plugin icons - -Other plugin icons can be used by setting the path of the icon within the jenkins context. Don't forget the leading '/'. - -```groovy -addBadge(icon: "/static/8361d0d6/images/16x16/help.png", text: "help") -``` - -## Colors - -Colors may reference [Jenkins palette colors or variables](https://weekly.ci.jenkins.io/design-library/Colors/). - -`symbol` badges **must** reference a named color from the Jenkins palette. -```groovy -// jenkins palette colors -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'yellow') -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'dark-yellow') -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-color-yellow') - -// jenkins semantic colors -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'warning') -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'success') -addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-warning-color') -``` - -Short text badges may use additional css color styles. -```groovy -// jenkins palette colors -addShortText(text: 'ok', color: 'green') -addShortText(text: 'ok', color: 'jenkins-!-color-green') - -// jenkins semantic colors -addShortText(text: 'ok', color: 'success') -addShortText(text: 'ok', color: 'jenkins-!-success-color') - -// css colors -addShortText(text: 'ok', color: '#42f557') -addShortText(text: 'ok', color: 'rgb(66, 245, 87)') -addShortText(text: 'ok', color: 'var(--green)') // jenkins css vars -``` - -## Allow HTML in Badge and Summary - -The badge plugin uses by default the OWASP Markup Formatter to sanitize the HTML Badge and Summary. This feature can be disabled in the Jenkins configuration: -Manage Jenkins -> Configure System -> Badge Plugin - -![alt text](src/doc/config.png "Config")