From ce6b753d4b223659119d78c3ca7aae82eae794f3 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Mon, 10 Feb 2025 12:37:24 -0800 Subject: [PATCH] Upgrade Checkstyle --- pom.xml | 40 +++++++---- .../sonyericsson/rebuild/RebuildAction.java | 25 ++++--- .../rebuild/RebuildActionDispatcher.java | 3 +- .../rebuild/RebuildActionFactory.java | 3 +- .../rebuild/RebuildParameterPage.java | 12 ++-- .../rebuild/RebuildProjectActionFactory.java | 3 +- .../sonyericsson/rebuild/RebuildSettings.java | 4 +- .../rebuild/RebuildValidator.java | 10 +-- .../sonyericsson/rebuild/Messages.properties | 6 +- .../rebuild/RebuildValidatorTest.java | 33 +++++----- swe_checkstyle.xml | 66 ++++++++----------- 11 files changed, 109 insertions(+), 96 deletions(-) diff --git a/pom.xml b/pom.xml index cc991773..64baf99f 100644 --- a/pom.xml +++ b/pom.xml @@ -60,29 +60,41 @@ - - - - maven.jenkins-ci.org - https://repo.jenkins-ci.org/releases - - - org.apache.maven.plugins maven-checkstyle-plugin - 2.8 + 3.6.0 + + + com.puppycrawl.tools + checkstyle + 10.21.2 + + - swe_checkstyle.xml - checkstyle-suppressions.xml - checkstyle.suppressions.file + true true - + swe_checkstyle.xml + + + validate + validate + + check + + + - + + + + maven.jenkins-ci.org + https://repo.jenkins-ci.org/releases + + diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java index 25675c4e..aecbab21 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildAction.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildAction.java @@ -85,6 +85,8 @@ public class RebuildAction extends AbstractRebuildAction implements RunAction2 { public static final RebuildDescriptor DESCRIPTOR = new RebuildDescriptor(); /** * RebuildAction constructor. + * + * @param run The run. */ public RebuildAction(Run run) { this.run = run; @@ -101,7 +103,7 @@ public boolean isRememberPasswordEnabled() { @Override public String getDisplayName() { - if (isRebuildAvailable()) { + if (isRebuildAvailable()) { return "Rebuild"; } else { return null; @@ -164,8 +166,7 @@ public void doIndex(StaplerRequest2 request, StaplerResponse2 response) throws I ParametersAction paramAction = run.getAction(ParametersAction.class); if (paramAction != null) { RebuildSettings settings = getProject().getProperty(RebuildSettings.class); - if (settings != null && settings.getAutoRebuild() || - request.getParameter("autorebuild") != null) { + if (settings != null && settings.getAutoRebuild() || request.getParameter("autorebuild") != null) { parameterizedRebuild(run, response); } else { response.sendRedirect(PARAMETERIZED_URL); @@ -189,7 +190,7 @@ public void parameterizedRebuild(Run currentBuild, StaplerResponse2 response) th List actions = constructRebuildActions(run, currentBuild.getAction(ParametersAction.class)); - Jenkins.get().getQueue().schedule2((Queue.Task) run.getParent(), 0, actions); + Jenkins.get().getQueue().schedule2((Queue.Task)run.getParent(), 0, actions); response.sendRedirect("../../"); } } @@ -206,7 +207,7 @@ public void nonParameterizedRebuild(Run currentBuild, StaplerResponse2 getProject().checkPermission(Item.BUILD); List actions = constructRebuildActions(run, null); - Jenkins.get().getQueue().schedule2((Queue.Task) currentBuild.getParent(), 0, actions); + Jenkins.get().getQueue().schedule2((Queue.Task)currentBuild.getParent(), 0, actions); response.sendRedirect("../../"); } @@ -260,7 +261,7 @@ public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws Ser } List actions = constructRebuildActions(run, new ParametersAction(values)); - Jenkins.get().getQueue().schedule2((Queue.Task) run.getParent(), 0, actions); + Jenkins.get().getQueue().schedule2((Queue.Task)run.getParent(), 0, actions); rsp.sendRedirect("../../"); } @@ -280,8 +281,7 @@ private List constructRebuildCauses(Run fromBuild) { List newBuildCauses = new ArrayList<>(); for (Cause buildCause : currentBuildCauses) { - if (!(buildCause instanceof Cause.UserIdCause) && - !(buildCause instanceof RebuildCause)) { + if (!(buildCause instanceof Cause.UserIdCause) && !(buildCause instanceof RebuildCause)) { newBuildCauses.add(buildCause); } } @@ -312,7 +312,7 @@ private void copyRebuildDispatcherActions(Run fromBuild, List acti actions.addAll(propagatingActions); } - /** + /** * Method for getting the ParameterValue instance from ParameterDefinition * or ParamterAction. * @@ -415,7 +415,12 @@ public RebuildParameterPage getRebuildParameterPage(ParameterValue value) { } // Check if we have a branched Jelly in the plugin. - if (getClass().getResource(String.format("/%s/%s.jelly", getClass().getCanonicalName().replace('.', '/'), value.getClass().getSimpleName())) != null) { + if (getClass() + .getResource(String.format( + "/%s/%s.jelly", + getClass().getCanonicalName().replace('.', '/'), + value.getClass().getSimpleName())) + != null) { // No provider available, use an existing view provided by rebuild plugin. return new RebuildParameterPage( getClass(), diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildActionDispatcher.java b/src/main/java/com/sonyericsson/rebuild/RebuildActionDispatcher.java index 86a25def..db39dab9 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildActionDispatcher.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildActionDispatcher.java @@ -13,12 +13,13 @@ public abstract class RebuildActionDispatcher implements ExtensionPoint { /** + * @param r The run. * @return the actions to include in the rebuild. */ public abstract Collection getPropagatingActions(Run r); /** - * All registered {@link RebuildActionDispatcher}s. + * @return All registered {@link RebuildActionDispatcher}s. */ public static ExtensionList all() { return ExtensionList.lookup(RebuildActionDispatcher.class); diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java b/src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java index b72d86d7..eb32ed65 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java @@ -49,7 +49,8 @@ public Class type() { @Override public Collection createFor(Run build) { - // TODO should this not just use RebuildAction.isRebuildAvailable? Or conversely, is that method needed if we are already filtering here? + // TODO should this not just use RebuildAction.isRebuildAvailable? Or conversely, is that method needed if we + // are already filtering here? if (build.getParent() instanceof MatrixConfiguration) { return emptyList(); } diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java b/src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java index 43bd607d..caf23000 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java @@ -1,18 +1,18 @@ /* * The MIT License - * + * * Copyright (c) 2013 IKEDA Yasuyuki - * + * * 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 @@ -35,7 +35,7 @@ public class RebuildParameterPage { public Class getClazz() { return clazz; } - + private final String page; /** * @return the path of jelly(or groovy) file. @@ -43,7 +43,7 @@ public Class getClazz() { public String getPage() { return page; } - + /** * @param clazz the class for the view. * @param page the path of jelly(or groovy) file. diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.java b/src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.java index a6fb72cd..45b09098 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.java @@ -39,7 +39,8 @@ * Rebuilds the last completed build. */ @Extension -// TODO when depending on 1.548+, switch to TransientActionFactory (also for RebuildActionFactory) and take Job not AbstractProject (again consider consolidating logic with isRebuildAvailable) +// TODO when depending on 1.548+, switch to TransientActionFactory (also for RebuildActionFactory) and take Job not +// AbstractProject (again consider consolidating logic with isRebuildAvailable) public class RebuildProjectActionFactory extends TransientProjectActionFactory { @Override diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java b/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java index 72966ace..b9378f6d 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildSettings.java @@ -63,7 +63,7 @@ public RebuildSettings(boolean autoRebuild, boolean rebuildDisabled) { public boolean getAutoRebuild() { return autoRebuild; } - + /** * Method returns rebuildDisabled. * @@ -72,7 +72,7 @@ public boolean getAutoRebuild() { public boolean getRebuildDisabled() { return rebuildDisabled; } - + /** * DescriptorImpl class of JobPropertyDescriptor. */ diff --git a/src/main/java/com/sonyericsson/rebuild/RebuildValidator.java b/src/main/java/com/sonyericsson/rebuild/RebuildValidator.java index 635cecc6..0e41f182 100644 --- a/src/main/java/com/sonyericsson/rebuild/RebuildValidator.java +++ b/src/main/java/com/sonyericsson/rebuild/RebuildValidator.java @@ -44,15 +44,17 @@ public abstract class RebuildValidator implements Serializable, ExtensionPoint { * @return true if the plug-in provides its own rebuild functionality. E.g. disable the rebuild action. */ public /*abstract*/ boolean isApplicable(Run build) { - if (Util.isOverridden(RebuildValidator.class, getClass(), "isApplicable", AbstractBuild.class) && build instanceof AbstractBuild) { - return isApplicable((AbstractBuild) build); + if (Util.isOverridden(RebuildValidator.class, getClass(), "isApplicable", AbstractBuild.class) + && build instanceof AbstractBuild) { + return isApplicable((AbstractBuild)build); } else { - throw new AbstractMethodError("you must override the new overload of isApplicable in " + getClass().getName()); + throw new AbstractMethodError("you must override the new overload of isApplicable in " + + getClass().getName()); } } @Deprecated public boolean isApplicable(AbstractBuild build) { - return isApplicable((Run) build); + return isApplicable((Run)build); } } diff --git a/src/main/resources/com/sonyericsson/rebuild/Messages.properties b/src/main/resources/com/sonyericsson/rebuild/Messages.properties index dddb4d8a..67917bc2 100644 --- a/src/main/resources/com/sonyericsson/rebuild/Messages.properties +++ b/src/main/resources/com/sonyericsson/rebuild/Messages.properties @@ -10,10 +10,10 @@ # 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 @@ -25,4 +25,4 @@ AbstractProject.Pronoun=Project Cause.RebuildCause.ShortDescription=Rebuilds build #{0} -Cause.RebuildCause.ShortDescriptionHTML=Rebuilds build #{0} \ No newline at end of file +Cause.RebuildCause.ShortDescriptionHTML=Rebuilds build #{0} diff --git a/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java b/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java index 94a56d89..8e3ad994 100644 --- a/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java +++ b/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java @@ -77,11 +77,13 @@ public class RebuildValidatorTest { * Sleep delay value. */ public static final int DELAY = 100; - + + /** + * Test harness. + */ @Rule public JenkinsRule j = new JenkinsRule(); - /** * Tests with no extensions. * @@ -96,7 +98,7 @@ public class RebuildValidatorTest { public void testNoRebuildValidatorExtension() throws IOException, InterruptedException, ExecutionException { Project projectA = j.createFreeStyleProject("testFreeStyleA"); - Build buildA = (Build) projectA.scheduleBuild2( + Build buildA = (Build)projectA.scheduleBuild2( 0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("party", @@ -120,7 +122,7 @@ public void testRebuildValidatorExtensionIsApplicableTrue() j.getInstance().getExtensionList(RebuildValidator.class).add(0, new ValidatorAlwaysApplicable()); Project projectA = j.createFreeStyleProject("testFreeStyleB"); - Build buildA = (Build) projectA.scheduleBuild2( + Build buildA = (Build)projectA.scheduleBuild2( 0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("party", @@ -144,7 +146,7 @@ public void testRebuildValidatorExtensionIsApplicableFalse() j.getInstance().getExtensionList(RebuildValidator.class).add(0, new ValidatorNeverApplicable()); Project projectA = j.createFreeStyleProject("testFreeStyleC"); - Build buildA = (Build) projectA.scheduleBuild2( + Build buildA = (Build)projectA.scheduleBuild2( 0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("party", @@ -170,7 +172,7 @@ public void testRebuildValidatorExtensionIsApplicableTrueFalse() j.getInstance().getExtensionList(RebuildValidator.class).add(0, new ValidatorNeverApplicable()); Project projectA = j.createFreeStyleProject("testFreeStyleC"); - Build buildA = (Build) projectA.scheduleBuild2( + Build buildA = (Build)projectA.scheduleBuild2( 0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("party", @@ -320,8 +322,8 @@ public void testWhenProjectWithCauseThenCauseIsCopiedAndUserIdCauseAdded() boolean hasRemoteCause = false; boolean hasUserIdCause = false; for (Action action : project.getLastCompletedBuild().getAllActions()) { - if (action instanceof CauseAction) { - for(Cause cause : ((CauseAction)action).getCauses()) { + if (action instanceof CauseAction causeAction) { + for (Cause cause : causeAction.getCauses()) { if (cause.getClass().equals(RebuildCause.class)) { hasRebuildCause = true; } @@ -381,14 +383,15 @@ public void testWhenProjectWithChainedRebuildsThenSingleUserIdCauseAndReplayCaus Thread.sleep(DELAY); } - int userIdCauseCount = 0, rebuildCauseCount = 0; + int userIdCauseCount = 0; + int rebuildCauseCount = 0; for (Action action : project.getLastCompletedBuild().getAllActions()) { - if (action instanceof CauseAction) { - for(Cause cause : ((CauseAction)action).getCauses()) { + if (action instanceof CauseAction causeAction) { + for (Cause cause : causeAction.getCauses()) { if (cause instanceof Cause.UserIdCause) { ++userIdCauseCount; - } else if(cause instanceof RebuildCause) { + } else if (cause instanceof RebuildCause) { ++rebuildCauseCount; } } @@ -684,7 +687,7 @@ public RebuildParameterPage getRebuildPage(ParameterValue value) { } public static class RebuildDispatcherTestAction implements Action { - public final boolean shouldBeCopied; + private final boolean shouldBeCopied; public RebuildDispatcherTestAction(boolean shouldBeCopied) { this.shouldBeCopied = shouldBeCopied; @@ -711,9 +714,7 @@ public Set getPropagatingActions(Run r) { Set dispatcherActions = new HashSet<>(); for (Action action : r.getAllActions()) { - if (action instanceof RebuildDispatcherTestAction) { - RebuildDispatcherTestAction testAction = (RebuildDispatcherTestAction) action; - + if (action instanceof RebuildDispatcherTestAction testAction) { if (testAction.shouldBeCopied) { dispatcherActions.add(action); } diff --git a/swe_checkstyle.xml b/swe_checkstyle.xml index 4dc1af85..d6238378 100644 --- a/swe_checkstyle.xml +++ b/swe_checkstyle.xml @@ -18,12 +18,14 @@ - - - - - - + + + + + + + + @@ -37,9 +39,6 @@ - - - @@ -70,7 +69,6 @@ - @@ -81,10 +79,6 @@ - - - - @@ -105,34 +99,30 @@ - - - - + - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - + +