Skip to content

Commit

Permalink
Upgrade Checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Feb 10, 2025
1 parent 47217d4 commit ce6b753
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 96 deletions.
40 changes: 26 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,41 @@
</plugin>
</plugins>
</pluginManagement>
</build>
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases</url>
</repository>
</distributionManagement>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<version>3.6.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.21.2</version>
</dependency>
</dependencies>
<configuration>
<configLocation>swe_checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<consoleOutput>true</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<!--<failsOnError>true</failsOnError>-->
<configLocation>swe_checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</reporting>
</build>
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/releases</url>
</repository>
</distributionManagement>
<dependencyManagement>
<dependencies>
<dependency>
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -101,7 +103,7 @@ public boolean isRememberPasswordEnabled() {

@Override
public String getDisplayName() {
if (isRebuildAvailable()) {
if (isRebuildAvailable()) {
return "Rebuild";
} else {
return null;
Expand Down Expand Up @@ -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) {

Check warning on line 169 in src/main/java/com/sonyericsson/rebuild/RebuildAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 169 is only partially covered, 4 branches are missing
parameterizedRebuild(run, response);
} else {
response.sendRedirect(PARAMETERIZED_URL);
Expand All @@ -189,7 +190,7 @@ public void parameterizedRebuild(Run currentBuild, StaplerResponse2 response) th

List<Action> 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("../../");
}
}
Expand All @@ -206,7 +207,7 @@ public void nonParameterizedRebuild(Run currentBuild, StaplerResponse2
getProject().checkPermission(Item.BUILD);

List<Action> 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("../../");
}

Expand Down Expand Up @@ -260,7 +261,7 @@ public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws Ser
}

List<Action> 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("../../");
}
Expand All @@ -280,8 +281,7 @@ private List<Cause> constructRebuildCauses(Run<?, ?> fromBuild) {

List<Cause> 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);
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ private void copyRebuildDispatcherActions(Run<?, ?> fromBuild, List<Action> acti
actions.addAll(propagatingActions);
}

/**
/**
* Method for getting the ParameterValue instance from ParameterDefinition
* or ParamterAction.
*
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action> getPropagatingActions(Run r);

/**
* All registered {@link RebuildActionDispatcher}s.
* @return All registered {@link RebuildActionDispatcher}s.
*/
public static ExtensionList<RebuildActionDispatcher> all() {
return ExtensionList.lookup(RebuildActionDispatcher.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public Class<Run> type() {

@Override
public Collection<? extends Action> 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

Check warning on line 52 in src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: 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();
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/sonyericsson/rebuild/RebuildParameterPage.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -35,15 +35,15 @@ public class RebuildParameterPage {
public Class<?> getClazz() {
return clazz;
}

private final String page;
/**
* @return the path of jelly(or groovy) file.
*/
public String getPage() {
return page;
}

/**
* @param clazz the class for the view.
* @param page the path of jelly(or groovy) file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 42 in src/main/java/com/sonyericsson/rebuild/RebuildProjectActionFactory.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: 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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/sonyericsson/rebuild/RebuildSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RebuildSettings(boolean autoRebuild, boolean rebuildDisabled) {
public boolean getAutoRebuild() {
return autoRebuild;
}

/**
* Method returns rebuildDisabled.
*
Expand All @@ -72,7 +72,7 @@ public boolean getAutoRebuild() {
public boolean getRebuildDisabled() {
return rebuildDisabled;
}

/**
* DescriptorImpl class of JobPropertyDescriptor.
*/
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/sonyericsson/rebuild/RebuildValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 47 in src/main/java/com/sonyericsson/rebuild/RebuildValidator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 47 is only partially covered, 2 branches are missing
&& 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());

Check warning on line 52 in src/main/java/com/sonyericsson/rebuild/RebuildValidator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 51-52 are not covered by tests
}
}

@Deprecated
public boolean isApplicable(AbstractBuild build) {
return isApplicable((Run) build);
return isApplicable((Run)build);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,4 +25,4 @@

AbstractProject.Pronoun=Project
Cause.RebuildCause.ShortDescription=Rebuilds build #{0}
Cause.RebuildCause.ShortDescriptionHTML=Rebuilds build <a href="{1}">#{0}<a/>
Cause.RebuildCause.ShortDescriptionHTML=Rebuilds build <a href="{1}">#{0}<a/>
33 changes: 17 additions & 16 deletions src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -711,9 +714,7 @@ public Set<Action> getPropagatingActions(Run r) {
Set<Action> 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);
}
Expand Down
Loading

0 comments on commit ce6b753

Please sign in to comment.