diff --git a/LICENSE b/LICENSE index 2f55958104..2657e29918 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2007-2022 Dr. Ullrich Hafner +Copyright (c) 2007-2023 Dr. Ullrich Hafner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/filter/RegexpFilter.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/filter/RegexpFilter.java index 6d019c97d5..e4b21e329f 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/filter/RegexpFilter.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/filter/RegexpFilter.java @@ -15,7 +15,7 @@ import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.verb.POST; import hudson.model.AbstractDescribableImpl; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Descriptor; import hudson.model.Item; import hudson.util.FormValidation; @@ -80,7 +80,7 @@ public RegexpFilterDescriptor() { } /** - * Performs on-the-fly validation on threshold for high warnings. + * Performs on-the-fly validation of the regexp pattern. * * @param project * the project that is configured @@ -90,7 +90,7 @@ public RegexpFilterDescriptor() { * @return the validation result */ @POST - public FormValidation doCheckPattern(@AncestorInPath final AbstractProject project, + public FormValidation doCheckPattern(@AncestorInPath final BuildableItem project, @QueryParameter final String pattern) { if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ReportScanningTool.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ReportScanningTool.java index 23eb8df259..e1ff88b725 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ReportScanningTool.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ReportScanningTool.java @@ -20,11 +20,13 @@ import org.kohsuke.stapler.verb.POST; import hudson.FilePath; import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Run; import hudson.model.TaskListener; import hudson.util.ComboBoxModel; import hudson.util.FormValidation; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.core.model.AnalysisModelParser.AnalysisModelParserDescriptor; import io.jenkins.plugins.analysis.core.util.ConsoleLogReaderFactory; @@ -257,14 +259,11 @@ protected ReportScanningToolDescriptor(final String id) { /** * Returns a model with all available charsets. * - * @param project - * the project that is configured - * * @return a model with all available charsets */ @POST - public ComboBoxModel doFillReportEncodingItems(@AncestorInPath final AbstractProject project) { - if (JENKINS.hasPermission(Item.CONFIGURE, project)) { + public ComboBoxModel doFillReportEncodingItems() { + if (JENKINS.hasPermission(Jenkins.READ)) { return VALIDATION_UTILITIES.getAllCharsets(); } return new ComboBoxModel(); @@ -281,9 +280,9 @@ public ComboBoxModel doFillReportEncodingItems(@AncestorInPath final AbstractPro * @return the validation result */ @POST - public FormValidation doCheckReportEncoding(@AncestorInPath final AbstractProject project, + public FormValidation doCheckReportEncoding(@AncestorInPath final BuildableItem project, @QueryParameter final String reportEncoding) { - if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { + if (!JENKINS.hasPermission(Jenkins.READ)) { return FormValidation.ok(); } @@ -328,7 +327,7 @@ public boolean hasDefaultPattern() { } /** - * Returns whether this parser can scan the console log. Typically, only line based parsers can scan the console + * Returns whether this parser can scan the console log. Typically, only line-based parsers can scan the console * log. XML parsers should always parse a given file only. * * @return the parser to use @@ -338,8 +337,8 @@ public boolean canScanConsoleLog() { } /** - * Returns the default filename pattern for this tool. Override if your typically works on a specific file. - * Note: if you provide a default pattern then it is not possible to scan Jenkins console log of a build. + * Returns the default filename pattern for this tool. Override if your parser typically works on a specific file. + * Note: if you provide a default pattern, then it is not possible to scan Jenkins' console log of a build. * * @return the default pattern */ diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/Tool.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/Tool.java index 8881429e3e..81164c6b2b 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/Tool.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/Tool.java @@ -17,7 +17,7 @@ import org.jenkinsci.Symbol; import hudson.FilePath; import hudson.model.AbstractDescribableImpl; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Descriptor; import hudson.model.Item; import hudson.model.Run; @@ -197,7 +197,7 @@ protected ToolDescriptor(final String defaultId) { * @return the validation result */ @POST - public FormValidation doCheckId(@AncestorInPath final AbstractProject project, + public FormValidation doCheckId(@AncestorInPath final BuildableItem project, @QueryParameter final String id) { if (!new JenkinsFacade().hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ToolSelection.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ToolSelection.java index 6f8474b129..c0b0b83d7b 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ToolSelection.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/model/ToolSelection.java @@ -16,7 +16,7 @@ import org.kohsuke.stapler.verb.POST; import hudson.Extension; import hudson.model.AbstractDescribableImpl; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Descriptor; import hudson.model.Item; import hudson.util.ComboBoxModel; @@ -113,7 +113,7 @@ static void setJenkinsFacade(final JenkinsFacade facade) { * @return a model with all static analysis tool IDs of all jobs */ @POST - public ComboBoxModel doFillIdItems(@AncestorInPath final AbstractProject project) { + public ComboBoxModel doFillIdItems(@AncestorInPath final BuildableItem project) { ComboBoxModel model = new ComboBoxModel(); if (jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { model.addAll(collectAvailableIds()); @@ -139,7 +139,7 @@ private Set collectAvailableIds() { * @return the validation result */ @POST - public FormValidation doCheckId(@AncestorInPath final AbstractProject project, + public FormValidation doCheckId(@AncestorInPath final BuildableItem project, @QueryParameter final String id) { if (!new JenkinsFacade().hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/AnalysisStepDescriptor.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/AnalysisStepDescriptor.java index b19b905402..bc8bda4f9e 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/AnalysisStepDescriptor.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/AnalysisStepDescriptor.java @@ -13,6 +13,7 @@ import hudson.util.ComboBoxModel; import hudson.util.FormValidation; import hudson.util.ListBoxModel; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.core.util.ModelValidation; import io.jenkins.plugins.util.JenkinsFacade; @@ -87,13 +88,11 @@ public FormValidation doCheckSourceCodeEncoding(@AncestorInPath final BuildableI /** * Returns a model with all available severity filters. * - * @param project - * the project that is configured * @return a model with all available severity filters */ @POST - public ListBoxModel doFillMinimumSeverityItems(@AncestorInPath final BuildableItem project) { - if (JENKINS.hasPermission(Item.READ, project)) { + public ListBoxModel doFillMinimumSeverityItems() { + if (JENKINS.hasPermission(Jenkins.READ)) { return model.getAllSeverityFilters(); } return new ListBoxModel(); @@ -162,13 +161,11 @@ public FormValidation doCheckUnhealthy(@AncestorInPath final BuildableItem proje /** * Returns a model with all aggregation trend chart positions. * - * @param project - * the project that is configured - * @return a model with all aggregation trend chart positions + * @return a model with all aggregation trend chart positions */ @POST - public ListBoxModel doFillTrendChartTypeItems(@AncestorInPath final BuildableItem project) { - if (JENKINS.hasPermission(Item.READ, project)) { + public ListBoxModel doFillTrendChartTypeItems() { + if (JENKINS.hasPermission(Jenkins.READ)) { return model.getAllTrendChartTypes(); } return new ListBoxModel(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesRecorder.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesRecorder.java index c309b22715..062975832f 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesRecorder.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/steps/IssuesRecorder.java @@ -30,6 +30,7 @@ import hudson.model.AbstractProject; import hudson.model.Action; import hudson.model.BuildListener; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Result; import hudson.model.Run; @@ -41,6 +42,7 @@ import hudson.util.ComboBoxModel; import hudson.util.FormValidation; import hudson.util.ListBoxModel; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.core.filter.RegexpFilter; import io.jenkins.plugins.analysis.core.model.AnalysisResult; @@ -907,7 +909,7 @@ public boolean isApplicable(final Class jobType) { * @return the validation result */ @POST - public FormValidation doCheckId(@AncestorInPath final AbstractProject project, + public FormValidation doCheckId(@AncestorInPath final BuildableItem project, @QueryParameter final String id) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -924,7 +926,7 @@ public FormValidation doCheckId(@AncestorInPath final AbstractProject proj * @return a model with all available charsets */ @POST - public ComboBoxModel doFillSourceCodeEncodingItems(@AncestorInPath final AbstractProject project) { + public ComboBoxModel doFillSourceCodeEncodingItems(@AncestorInPath final BuildableItem project) { if (JENKINS.hasPermission(Item.CONFIGURE, project)) { return VALIDATION_UTILITIES.getAllCharsets(); } @@ -934,13 +936,11 @@ public ComboBoxModel doFillSourceCodeEncodingItems(@AncestorInPath final Abstrac /** * Returns a model with all available severity filters. * - * @param project - * the project that is configured * @return a model with all available severity filters */ @POST - public ListBoxModel doFillMinimumSeverityItems(@AncestorInPath final AbstractProject project) { - if (JENKINS.hasPermission(Item.CONFIGURE, project)) { + public ListBoxModel doFillMinimumSeverityItems() { + if (JENKINS.hasPermission(Jenkins.READ)) { return model.getAllSeverityFilters(); } return new ListBoxModel(); @@ -957,7 +957,7 @@ public ListBoxModel doFillMinimumSeverityItems(@AncestorInPath final AbstractPro * @return the validation result */ @POST - public FormValidation doCheckReportEncoding(@AncestorInPath final AbstractProject project, + public FormValidation doCheckReportEncoding(@AncestorInPath final BuildableItem project, @QueryParameter final String reportEncoding) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -977,7 +977,7 @@ public FormValidation doCheckReportEncoding(@AncestorInPath final AbstractProjec * @return the validation result */ @POST - public FormValidation doCheckSourceCodeEncoding(@AncestorInPath final AbstractProject project, + public FormValidation doCheckSourceCodeEncoding(@AncestorInPath final BuildableItem project, @QueryParameter final String sourceCodeEncoding) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -999,7 +999,7 @@ public FormValidation doCheckSourceCodeEncoding(@AncestorInPath final AbstractPr * @return the validation result */ @POST - public FormValidation doCheckHealthy(@AncestorInPath final AbstractProject project, + public FormValidation doCheckHealthy(@AncestorInPath final BuildableItem project, @QueryParameter final int healthy, @QueryParameter final int unhealthy) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -1020,7 +1020,7 @@ public FormValidation doCheckHealthy(@AncestorInPath final AbstractProject * @return the validation result */ @POST - public FormValidation doCheckUnhealthy(@AncestorInPath final AbstractProject project, + public FormValidation doCheckUnhealthy(@AncestorInPath final BuildableItem project, @QueryParameter final int healthy, @QueryParameter final int unhealthy) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -1031,13 +1031,11 @@ public FormValidation doCheckUnhealthy(@AncestorInPath final AbstractProject project) { - if (JENKINS.hasPermission(Item.CONFIGURE, project)) { + public ListBoxModel doFillTrendChartTypeItems() { + if (JENKINS.hasPermission(Jenkins.READ)) { return model.getAllTrendChartTypes(); } return new ListBoxModel(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/QualityGate.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/QualityGate.java index b4c6ee7987..63175213d4 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/QualityGate.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/QualityGate.java @@ -12,11 +12,12 @@ import org.kohsuke.stapler.verb.POST; import hudson.Extension; import hudson.model.AbstractDescribableImpl; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Descriptor; import hudson.model.Item; import hudson.util.FormValidation; import hudson.util.ListBoxModel; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.core.util.IssuesStatistics.StatisticProperties; import io.jenkins.plugins.util.JenkinsFacade; @@ -248,15 +249,13 @@ public QualityGateDescriptor() { /** * Return the model for the select widget. * - * @param project - * the project that is configured * @return the quality gate types */ @POST - public ListBoxModel doFillTypeItems(@AncestorInPath final AbstractProject project) { + public ListBoxModel doFillTypeItems() { ListBoxModel model = new ListBoxModel(); - if (jenkins.hasPermission(Item.CONFIGURE, project)) { + if (jenkins.hasPermission(Jenkins.READ)) { for (QualityGateType qualityGateType : QualityGateType.values()) { model.add(qualityGateType.getDisplayName(), qualityGateType.name()); } @@ -275,9 +274,8 @@ public ListBoxModel doFillTypeItems(@AncestorInPath final AbstractProject * * @return the validation result */ - @SuppressWarnings("WeakerAccess") @POST - public FormValidation doCheckThreshold(@AncestorInPath final AbstractProject project, + public FormValidation doCheckThreshold(@AncestorInPath final BuildableItem project, @QueryParameter final int threshold) { if (!jenkins.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/DuplicateCodeScanner.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/DuplicateCodeScanner.java index 41055dec2d..1a4b80580b 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/DuplicateCodeScanner.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/DuplicateCodeScanner.java @@ -18,7 +18,7 @@ import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.verb.POST; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Run; import hudson.util.FormValidation; @@ -178,7 +178,7 @@ abstract static class DuplicateCodeDescriptor extends AnalysisModelParserDescrip } /** - * Performs on-the-fly validation on threshold for high warnings. + * Performs on-the-fly validation of the threshold for high warnings. * * @param project * the project that is configured @@ -190,7 +190,7 @@ abstract static class DuplicateCodeDescriptor extends AnalysisModelParserDescrip * @return the validation result */ @POST - public FormValidation doCheckHighThreshold(@AncestorInPath final AbstractProject project, + public FormValidation doCheckHighThreshold(@AncestorInPath final BuildableItem project, @QueryParameter("highThreshold") final int highThreshold, @QueryParameter("normalThreshold") final int normalThreshold) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { @@ -200,7 +200,7 @@ public FormValidation doCheckHighThreshold(@AncestorInPath final AbstractProject } /** - * Performs on-the-fly validation on threshold for normal warnings. + * Performs on-the-fly validation of the threshold for normal warnings. * * @param project * the project that is configured @@ -212,7 +212,7 @@ public FormValidation doCheckHighThreshold(@AncestorInPath final AbstractProject * @return the validation result */ @POST - public FormValidation doCheckNormalThreshold(@AncestorInPath final AbstractProject project, + public FormValidation doCheckNormalThreshold(@AncestorInPath final BuildableItem project, @QueryParameter("highThreshold") final int highThreshold, @QueryParameter("normalThreshold") final int normalThreshold) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RegisteredParser.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RegisteredParser.java index b2f7cf77b2..d93466603a 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RegisteredParser.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/RegisteredParser.java @@ -12,15 +12,13 @@ import edu.hm.hafner.util.VisibleForTesting; import edu.umd.cs.findbugs.annotations.NonNull; -import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.verb.POST; import org.jenkinsci.Symbol; import hudson.Extension; -import hudson.model.AbstractProject; -import hudson.model.Item; import hudson.util.ListBoxModel; import hudson.util.ListBoxModel.Option; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.core.model.ReportScanningTool; import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider; @@ -118,15 +116,13 @@ public Descriptor() { } /** - * Returns a model with all available severity filters. + * Returns a model with all available parsers. * - * @param project - * the project that is configured - * @return a model with all available severity filters + * @return a model with all available parsers */ @POST - public ListBoxModel doFillAnalysisModelIdItems(@AncestorInPath final AbstractProject project) { - if (jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { + public ListBoxModel doFillAnalysisModelIdItems() { + if (jenkinsFacade.hasPermission(Jenkins.READ)) { return availableParsers; } return EMPTY_MODEL; diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java index f59c0e6e3a..7c414ca859 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/axivion/AxivionSuite.java @@ -37,7 +37,7 @@ import org.jenkinsci.Symbol; import hudson.Extension; import hudson.FilePath; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Run; import hudson.model.TaskListener; @@ -291,7 +291,7 @@ public StaticAnalysisLabelProvider getLabelProvider() { * @return {@link FormValidation#ok()} is a valid url */ @POST - public FormValidation doCheckProjectUrl(@AncestorInPath final AbstractProject project, + public FormValidation doCheckProjectUrl(@AncestorInPath final BuildableItem project, @QueryParameter final String projectUrl) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); @@ -319,7 +319,7 @@ public FormValidation doCheckProjectUrl(@AncestorInPath final AbstractProject project, + public FormValidation doCheckBasedir(@AncestorInPath final BuildableItem project, @QueryParameter final String basedir) { if (!JENKINS.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParser.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParser.java index cc7b9f5235..4d38c2ed75 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParser.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParser.java @@ -21,11 +21,13 @@ import groovy.lang.Script; +import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.verb.POST; import hudson.Extension; import hudson.model.AbstractDescribableImpl; +import hudson.model.BuildableItem; import hudson.model.Descriptor; import hudson.model.Item; import hudson.util.FormValidation; @@ -95,9 +97,9 @@ private static boolean containsNewline(final String expression) { public boolean isValid() { DescriptorImpl d = new DescriptorImpl(getJenkinsFacade()); - return d.doCheckScript(script).kind == Kind.OK - && d.doCheckRegexp(regexp).kind == Kind.OK - && d.doCheckName(name).kind == Kind.OK; + return d.checkScript(script).kind == Kind.OK + && d.checkRegexp(regexp).kind == Kind.OK + && d.checkName(name).kind == Kind.OK; } public String getId() { @@ -178,22 +180,22 @@ public int hashCode() { * * @return a new parser instance * @throws IllegalArgumentException - * if this parsers configuration is not valid + * if this parser configuration is not valid */ public IssueParser createParser() { DescriptorImpl descriptor = new DescriptorImpl(getJenkinsFacade()); - FormValidation nameCheck = descriptor.doCheckName(name); + FormValidation nameCheck = descriptor.checkName(name); if (nameCheck.kind == Kind.ERROR) { throw new IllegalArgumentException("Name is not valid: " + nameCheck.getMessage()); } - FormValidation scriptCheck = descriptor.doCheckScript(script); + FormValidation scriptCheck = descriptor.checkScript(script); if (scriptCheck.kind == Kind.ERROR) { throw new IllegalArgumentException("Script is not valid: " + scriptCheck.getMessage()); } - FormValidation regexpCheck = descriptor.doCheckRegexp(regexp); + FormValidation regexpCheck = descriptor.checkRegexp(regexp); if (regexpCheck.kind == Kind.ERROR) { throw new IllegalArgumentException("RegExp is not valid: " + regexpCheck.getMessage()); } @@ -245,14 +247,17 @@ public DescriptorImpl() { /** * Performs on-the-fly validation of the parser ID. The ID needs to be unique. * + * @param project + * the project that is configured * @param id * the ID of the parser * * @return the validation result */ @POST - public FormValidation doCheckId(@QueryParameter(required = true) final String id) { - if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) { + public FormValidation doCheckId(@AncestorInPath final BuildableItem project, + @QueryParameter(required = true) final String id) { + if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); } return VALIDATION_UTILITIES.validateId(id); @@ -261,17 +266,24 @@ public FormValidation doCheckId(@QueryParameter(required = true) final String id /** * Performs on-the-fly validation on the name of the parser that needs to be unique. * + * @param project + * the project that is configured * @param name * the name of the parser * * @return the validation result */ @POST - public FormValidation doCheckName(@QueryParameter(required = true) final String name) { - if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) { + public FormValidation doCheckName(@AncestorInPath final BuildableItem project, + @QueryParameter(required = true) final String name) { + if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); } + return checkName(name); + } + + FormValidation checkName(final String name) { if (StringUtils.isBlank(name)) { return FormValidation.error(Messages.GroovyParser_Error_Name_isEmpty()); } @@ -281,17 +293,24 @@ public FormValidation doCheckName(@QueryParameter(required = true) final String /** * Performs on-the-fly validation on the regular expression. * + * @param project + * the project that is configured * @param regexp * the regular expression * * @return the validation result */ @POST - public FormValidation doCheckRegexp(@QueryParameter(required = true) final String regexp) { - if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) { + public FormValidation doCheckRegexp(@AncestorInPath final BuildableItem project, + @QueryParameter(required = true) final String regexp) { + if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); } + return checkRegexp(regexp); + } + + FormValidation checkRegexp(final String regexp) { try { if (StringUtils.isBlank(regexp)) { return FormValidation.error(Messages.GroovyParser_Error_Regexp_isEmpty()); @@ -310,19 +329,26 @@ public FormValidation doCheckRegexp(@QueryParameter(required = true) final Strin /** * Performs on-the-fly validation on the Groovy script. * + * @param project + * the project that is configured * @param script * the script * * @return the validation result */ @POST - public FormValidation doCheckScript(@QueryParameter(required = true) final String script) { - if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) { + public FormValidation doCheckScript(@AncestorInPath final BuildableItem project, + @QueryParameter(required = true) final String script) { + if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); } if (!jenkinsFacade.hasPermission(Jenkins.ADMINISTER)) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } + return checkScript(script); + } + + FormValidation checkScript(final String script) { try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.GroovyParser_Error_Script_isEmpty()); @@ -343,8 +369,10 @@ public FormValidation doCheckScript(@QueryParameter(required = true) final Strin /** * Parses the example message with the specified regular expression and script. * + * @param project + * the project that is configured * @param example - * example that should be resolve to a warning + * example that should resolve to a warning * @param regexp * the regular expression * @param script @@ -353,14 +381,19 @@ public FormValidation doCheckScript(@QueryParameter(required = true) final Strin * @return the validation result */ @POST - public FormValidation doCheckExample(@QueryParameter final String example, + public FormValidation doCheckExample(@AncestorInPath final BuildableItem project, + @QueryParameter final String example, @QueryParameter final String regexp, @QueryParameter final String script) { - if (!jenkinsFacade.hasPermission(Item.CONFIGURE)) { + if (!jenkinsFacade.hasPermission(Item.CONFIGURE, project)) { return FormValidation.ok(); } if (!jenkinsFacade.hasPermission(Jenkins.ADMINISTER)) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } + return checkExample(example, regexp, script); + } + + FormValidation checkExample(final String example, final String regexp, final String script) { if (StringUtils.isNotBlank(example) && StringUtils.isNotBlank(regexp) && StringUtils.isNotBlank(script)) { FormValidation response = parseExample(script, example, regexp, containsNewline(regexp)); if (example.length() <= MAX_EXAMPLE_SIZE) { @@ -403,7 +436,7 @@ private FormValidation parseExample(final String script, final String example, f if (matcher.find()) { GroovyExpressionMatcher checker = new GroovyExpressionMatcher(script); Object result = checker.run(matcher, new IssueBuilder(), 0, "UI Example"); - Optional optional = (Optional) result; + Optional optional = (Optional) result; if (optional.isPresent()) { Object wrappedIssue = optional.get(); if (wrappedIssue instanceof Issue) { @@ -416,7 +449,7 @@ private FormValidation parseExample(final String script, final String example, f return FormValidation.error(Messages.GroovyParser_Error_Example_regexpDoesNotMatch()); } } - catch (Exception exception) { // catch all exceptions of the Groovy script + catch (Exception exception) { // catch all exceptions thrown by the Groovy script return FormValidation.error( Messages.GroovyParser_Error_Example_exception(exception.getMessage())); } diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScript.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScript.java index d7d58f060b..c53f09048e 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScript.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyScript.java @@ -11,7 +11,7 @@ import org.kohsuke.stapler.verb.POST; import org.jenkinsci.Symbol; import hudson.Extension; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.util.ListBoxModel; @@ -110,7 +110,7 @@ public boolean canScanConsoleLog() { */ @SuppressWarnings("unused") // Called from config.jelly @POST - public ListBoxModel doFillParserIdItems(@AncestorInPath final AbstractProject project) { + public ListBoxModel doFillParserIdItems(@AncestorInPath final BuildableItem project) { if (new JenkinsFacade().hasPermission(Item.CONFIGURE, project)) { ListBoxModel options = ParserConfiguration.getInstance().asListBoxModel(); if (options.isEmpty()) { diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/tasks/OpenTasks.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/tasks/OpenTasks.java index 2bd1e21b74..a9770b522e 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/tasks/OpenTasks.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/tasks/OpenTasks.java @@ -22,6 +22,7 @@ import hudson.Extension; import hudson.FilePath; import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Run; import hudson.util.FormValidation; @@ -279,7 +280,7 @@ public FormValidation doCheckExcludePattern(@AncestorInPath final AbstractProjec * @param low * tag identifiers indicating low priority * @param ignoreCase - * if case should be ignored during matching + * if the case should be ignored during matching * @param asRegexp * if the identifiers should be treated as regular expression * @@ -287,7 +288,7 @@ public FormValidation doCheckExcludePattern(@AncestorInPath final AbstractProjec */ @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") @POST - public FormValidation doCheckExample(@AncestorInPath final AbstractProject project, + public FormValidation doCheckExample(@AncestorInPath final BuildableItem project, @QueryParameter final String example, @QueryParameter final String high, @QueryParameter final String normal, diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/filter/RegexpFilterTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/filter/RegexpFilterTest.java index 9cf40d2b54..13f8ab4b1c 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/filter/RegexpFilterTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/filter/RegexpFilterTest.java @@ -7,7 +7,7 @@ import edu.hm.hafner.analysis.Report; import edu.hm.hafner.analysis.Report.IssueFilterBuilder; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import io.jenkins.plugins.analysis.core.filter.IncludeType.DescriptorImpl; @@ -48,7 +48,7 @@ void issue54035() { @Test void shouldValidatePattern() { JenkinsFacade jenkinsFacade = mock(JenkinsFacade.class); - when(jenkinsFacade.hasPermission(Item.CONFIGURE, (AbstractProject) null)).thenReturn(true); + when(jenkinsFacade.hasPermission(Item.CONFIGURE, (BuildableItem) null)).thenReturn(true); RegexpFilterDescriptor descriptor = new DescriptorImpl(jenkinsFacade); assertThat(descriptor.doCheckPattern(null, null)).isOk().hasMessage(Messages.pattern_blank()); diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/ToolSelectionDescriptorTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/ToolSelectionDescriptorTest.java index bb8cc77051..394a50a303 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/ToolSelectionDescriptorTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/model/ToolSelectionDescriptorTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import hudson.model.Job; import hudson.util.ComboBoxModel; @@ -64,7 +64,7 @@ private ToolSelectionDescriptor createDescriptor(final String[] elements, final JenkinsFacade jenkinsFacade = mock(JenkinsFacade.class); when(jenkinsFacade.getAllJobs()).thenReturn(Lists.list(job)); ToolSelectionDescriptor.setJenkinsFacade(jenkinsFacade); - when(jenkinsFacade.hasPermission(Item.CONFIGURE, (AbstractProject) null)).thenReturn(hasPermission); + when(jenkinsFacade.hasPermission(Item.CONFIGURE, (BuildableItem) null)).thenReturn(hasPermission); return toolSelectionDescriptor; } } diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/core/util/QualityGateTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/core/util/QualityGateTest.java index 3b835d9d5e..0aab4017bc 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/core/util/QualityGateTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/core/util/QualityGateTest.java @@ -4,7 +4,7 @@ import edu.hm.hafner.util.SerializableTest; -import hudson.model.AbstractProject; +import hudson.model.BuildableItem; import hudson.model.Item; import io.jenkins.plugins.analysis.core.util.QualityGate.QualityGateDescriptor; @@ -24,7 +24,7 @@ class QualityGateTest extends SerializableTest { @Test void shouldValidateThreshold() { JenkinsFacade jenkinsFacade = mock(JenkinsFacade.class); - when(jenkinsFacade.hasPermission(Item.CONFIGURE, (AbstractProject) null)).thenReturn(true); + when(jenkinsFacade.hasPermission(Item.CONFIGURE, (BuildableItem) null)).thenReturn(true); QualityGateDescriptor descriptor = new QualityGateDescriptor(jenkinsFacade); diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/RegisteredParserTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/RegisteredParserTest.java index b98c188dc0..93527a42cf 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/RegisteredParserTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/RegisteredParserTest.java @@ -7,8 +7,7 @@ import edu.hm.hafner.analysis.parser.checkstyle.CheckStyleParser; -import hudson.model.AbstractProject; -import hudson.model.Item; +import jenkins.model.Jenkins; import io.jenkins.plugins.analysis.warnings.RegisteredParser.Descriptor; import io.jenkins.plugins.util.JenkinsFacade; @@ -73,15 +72,14 @@ class DescriptorTest { @Test void shouldPopulateListOfParsers() { JenkinsFacade jenkins = mock(JenkinsFacade.class); - AbstractProject job = mock(AbstractProject.class); - when(jenkins.hasPermission(Item.CONFIGURE, job)).thenReturn(true); + when(jenkins.hasPermission(Jenkins.READ)).thenReturn(true); Descriptor descriptor = new Descriptor(jenkins); assertThat(descriptor.getId()).isEqualTo(Descriptor.ANALYSIS_MODEL_ID); - assertThat(descriptor.doFillAnalysisModelIdItems(job)).extracting(o -> o.value).first().isEqualTo("acu-cobol"); + assertThat(descriptor.doFillAnalysisModelIdItems()).extracting(o -> o.value).first().isEqualTo("acu-cobol"); - when(jenkins.hasPermission(Item.CONFIGURE, job)).thenReturn(false); - assertThat(descriptor.doFillAnalysisModelIdItems(job)).isEmpty(); + when(jenkins.hasPermission(Jenkins.READ)).thenReturn(false); + assertThat(descriptor.doFillAnalysisModelIdItems()).isEmpty(); } } } diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParserTest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParserTest.java index 8cec7d5940..c34981aada 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParserTest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/groovy/GroovyParserTest.java @@ -71,7 +71,7 @@ private void matchMultiLine(final String multiLineRegexp) throws IOException { assertThat(parser.hasMultiLineSupport()).as("Wrong multi line support guess").isTrue(); DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckExample(textToMatch, multiLineRegexp, script)).isOk(); + assertThat(descriptor.checkExample(textToMatch, multiLineRegexp, script)).isOk(); IssueParser instance = parser.createParser(); Run run = mock(Run.class); @@ -112,8 +112,6 @@ void shouldThrowExceptionDueToMissingName() { assertThat(groovyParser.isValid()).isFalse(); assertThatIllegalArgumentException().isThrownBy(groovyParser::createParser) .withMessageContaining("Name is not valid"); - - verifyThatValidationIsSkippedIfUserHasNoPermissions(groovyParser); } @Test @@ -122,8 +120,6 @@ void shouldThrowExceptionDueToBrokenScript() { assertThat(groovyParser.isValid()).isFalse(); assertThatIllegalArgumentException().isThrownBy(groovyParser::createParser) .withMessageContaining("Script is not valid"); - - verifyThatValidationIsSkippedIfUserHasNoPermissions(groovyParser); } @Test @@ -132,15 +128,6 @@ void shouldThrowExceptionDueToBrokenRegExp() { assertThat(groovyParser.isValid()).isFalse(); assertThatIllegalArgumentException().isThrownBy(groovyParser::createParser) .withMessageContaining("RegExp is not valid"); - - groovyParser.setJenkinsFacade(mock(JenkinsFacade.class)); - assertThat(groovyParser.isValid()).isTrue(); - } - - private void verifyThatValidationIsSkippedIfUserHasNoPermissions(final GroovyParser groovyParser) { - groovyParser.setJenkinsFacade(mock(JenkinsFacade.class)); - assertThat(groovyParser.isValid()).isTrue(); - assertThatNoException().isThrownBy(groovyParser::createParser); } @Test @@ -164,39 +151,39 @@ void shouldDetectSingleLineRegularExpression() { void shouldAcceptOnlyNonEmptyStringsAsName() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckName(null)).isError(); - assertThat(descriptor.doCheckName(StringUtils.EMPTY)).isError(); - assertThat(descriptor.doCheckName("Java Parser 2")).isOk(); + assertThat(descriptor.checkName(null)).isError(); + assertThat(descriptor.checkName(StringUtils.EMPTY)).isError(); + assertThat(descriptor.checkName("Java Parser 2")).isOk(); } @Test void shouldRejectInvalidRegularExpressions() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckRegexp(null)).isError(); - assertThat(descriptor.doCheckRegexp(StringUtils.EMPTY)).isError(); - assertThat(descriptor.doCheckRegexp("one brace (")).isError(); - assertThat(descriptor.doCheckRegexp("backslash \\")).isError(); + assertThat(descriptor.checkRegexp(null)).isError(); + assertThat(descriptor.checkRegexp(StringUtils.EMPTY)).isError(); + assertThat(descriptor.checkRegexp("one brace (")).isError(); + assertThat(descriptor.checkRegexp("backslash \\")).isError(); - assertThat(descriptor.doCheckRegexp("^.*[a-z]")).isOk(); + assertThat(descriptor.checkRegexp("^.*[a-z]")).isOk(); } @Test void shouldRejectInvalidScripts() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckScript(null)).isError(); - assertThat(descriptor.doCheckScript(StringUtils.EMPTY)).isError(); - assertThat(descriptor.doCheckScript("Hello World")).isError(); + assertThat(descriptor.checkScript(null)).isError(); + assertThat(descriptor.checkScript(StringUtils.EMPTY)).isError(); + assertThat(descriptor.checkScript("Hello World")).isError(); - assertThat(descriptor.doCheckScript(toString("parser.groovy"))).isOk(); + assertThat(descriptor.checkScript(toString("parser.groovy"))).isOk(); } @Test void shouldFindOneIssueWithValidScriptAndRegularExpression() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckExample(SINGLE_LINE_EXAMPLE, SINGLE_LINE_REGEXP, + assertThat(descriptor.checkExample(SINGLE_LINE_EXAMPLE, SINGLE_LINE_REGEXP, toString("parser.groovy"))).isOk(); } @@ -204,7 +191,7 @@ void shouldFindOneIssueWithValidScriptAndRegularExpression() { void shouldReportErrorWhenNoMatchesAreFoundInExample() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckExample("this is a warning message", SINGLE_LINE_REGEXP, + assertThat(descriptor.checkExample("this is a warning message", SINGLE_LINE_REGEXP, toString("parser.groovy"))).isError(); } @@ -212,7 +199,7 @@ void shouldReportErrorWhenNoMatchesAreFoundInExample() { void shouldReportErrorWhenRegularExpressionHasIllegalMatchAccess() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckExample(SINGLE_LINE_EXAMPLE, "^\\s*(.*):(\\d+):(.*)$", + assertThat(descriptor.checkExample(SINGLE_LINE_EXAMPLE, "^\\s*(.*):(\\d+):(.*)$", toString("parser.groovy"))).isError(); } @@ -220,7 +207,7 @@ void shouldReportErrorWhenRegularExpressionHasIllegalMatchAccess() { void shouldAcceptMultiLineRegularExpression() { DescriptorImpl descriptor = createDescriptor(); - assertThat(descriptor.doCheckExample(MULTI_LINE_EXAMPLE, MULTI_LINE_REGEXP, + assertThat(descriptor.checkExample(MULTI_LINE_EXAMPLE, MULTI_LINE_REGEXP, toString("multiline.groovy"))).isOk(); }