-
Notifications
You must be signed in to change notification settings - Fork 324
Fix Checkstyle errors and improve code quality (final parameters, lin… #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,5 +177,56 @@ | |||||||||||||||||||||||||||||||||||
| <url>https://repo.jenkins-ci.org/public/</url> | ||||||||||||||||||||||||||||||||||||
| </pluginRepository> | ||||||||||||||||||||||||||||||||||||
| </pluginRepositories> | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| <build> | ||||||||||||||||||||||||||||||||||||
| <plugins> | ||||||||||||||||||||||||||||||||||||
| <plugin> | ||||||||||||||||||||||||||||||||||||
| <groupId>org.apache.maven.plugins</groupId> | ||||||||||||||||||||||||||||||||||||
| <artifactId>maven-checkstyle-plugin</artifactId> | ||||||||||||||||||||||||||||||||||||
| <version>3.1.1</version> | ||||||||||||||||||||||||||||||||||||
| <executions> | ||||||||||||||||||||||||||||||||||||
| <execution> | ||||||||||||||||||||||||||||||||||||
| <phase>validate</phase> | ||||||||||||||||||||||||||||||||||||
| <goals> | ||||||||||||||||||||||||||||||||||||
| <goal>check</goal> | ||||||||||||||||||||||||||||||||||||
| </goals> | ||||||||||||||||||||||||||||||||||||
| </execution> | ||||||||||||||||||||||||||||||||||||
| </executions> | ||||||||||||||||||||||||||||||||||||
| </plugin> | ||||||||||||||||||||||||||||||||||||
| <plugin> | ||||||||||||||||||||||||||||||||||||
| <groupId>com.github.spotbugs</groupId> | ||||||||||||||||||||||||||||||||||||
| <artifactId>spotbugs-maven-plugin</artifactId> | ||||||||||||||||||||||||||||||||||||
| <version>4.2.0</version> | ||||||||||||||||||||||||||||||||||||
| <executions> | ||||||||||||||||||||||||||||||||||||
| <execution> | ||||||||||||||||||||||||||||||||||||
| <goals> | ||||||||||||||||||||||||||||||||||||
| <goal>check</goal> | ||||||||||||||||||||||||||||||||||||
| </goals> | ||||||||||||||||||||||||||||||||||||
| </execution> | ||||||||||||||||||||||||||||||||||||
| </executions> | ||||||||||||||||||||||||||||||||||||
| </plugin> | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+195
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, since it is already provided by the parent pom.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| <plugin> | ||||||||||||||||||||||||||||||||||||
| <groupId>org.jenkins-ci.tools</groupId> | ||||||||||||||||||||||||||||||||||||
| <artifactId>maven-hpi-plugin</artifactId> | ||||||||||||||||||||||||||||||||||||
| <version>3.37</version> <!-- Ensure this is the latest stable version --> | ||||||||||||||||||||||||||||||||||||
| <extensions>true</extensions> | ||||||||||||||||||||||||||||||||||||
| </plugin> | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+207
to
+212
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already provided by the parent pom.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| <plugin> | ||||||||||||||||||||||||||||||||||||
| <groupId>com.diffplug.spotless</groupId> | ||||||||||||||||||||||||||||||||||||
| <artifactId>spotless-maven-plugin</artifactId> | ||||||||||||||||||||||||||||||||||||
| <version>2.17.0</version> | ||||||||||||||||||||||||||||||||||||
| <executions> | ||||||||||||||||||||||||||||||||||||
| <execution> | ||||||||||||||||||||||||||||||||||||
| <goals> | ||||||||||||||||||||||||||||||||||||
| <goal>apply</goal> | ||||||||||||||||||||||||||||||||||||
| </goals> | ||||||||||||||||||||||||||||||||||||
| </execution> | ||||||||||||||||||||||||||||||||||||
| </executions> | ||||||||||||||||||||||||||||||||||||
| <configuration> | ||||||||||||||||||||||||||||||||||||
| <java> | ||||||||||||||||||||||||||||||||||||
| <googleJavaFormat /> | ||||||||||||||||||||||||||||||||||||
| </java> | ||||||||||||||||||||||||||||||||||||
| </configuration> | ||||||||||||||||||||||||||||||||||||
| </plugin> | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+213
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed. Provided by the parent pom.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| </plugins> | ||||||||||||||||||||||||||||||||||||
| </build> | ||||||||||||||||||||||||||||||||||||
| </project> | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,24 +28,37 @@ | |
| public class DockerQueueListener extends QueueListener { | ||
|
|
||
| @Override | ||
| public void onEnterWaiting(WaitingItem wi) { | ||
| public void onEnterWaiting(final WaitingItem wi) { | ||
| final DockerJobTemplateProperty jobTemplate = getJobTemplate(wi); | ||
| if (jobTemplate != null) { | ||
| final DockerCloud cloud = DockerCloud.getCloudByName(jobTemplate.getCloudname()); | ||
| final DockerCloud cloud = | ||
| DockerCloud.getCloudByName(jobTemplate.getCloudname()); | ||
| if (cloud != null) { | ||
| final String uuid = UUID.randomUUID().toString(); | ||
| final DockerTemplate template = jobTemplate.getTemplate().cloneWithLabel(uuid); | ||
| final DockerTemplate template = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
| jobTemplate.getTemplate().cloneWithLabel(uuid); | ||
| cloud.addJobTemplate(wi.getId(), template); | ||
| wi.addAction(new DockerTemplateLabelAssignmentAction(uuid)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Called when an item leaves the queue. | ||
| * Subclasses can override this method to provide custom behavior when an item is removed from the queue. | ||
| * | ||
| * <p>When overriding this method, ensure that you: | ||
| * 1. Call the superclass's `onLeft` method if needed, to preserve the default behavior. | ||
| * 2. Handle null checks for `jobTemplate` and `cloud` objects, as they can be `null`. | ||
| * 3. Avoid making any long-running or blocking operations in this method, as it is called within Jenkins' queue management thread. | ||
| * | ||
| * @param li the {@link LeftItem} that left the queue. This parameter should not be null. | ||
| */ | ||
| @Override | ||
| public void onLeft(LeftItem li) { | ||
| public void onLeft(final LeftItem li) { | ||
| final DockerJobTemplateProperty jobTemplate = getJobTemplate(li); | ||
| if (jobTemplate != null) { | ||
| final DockerCloud cloud = DockerCloud.getCloudByName(jobTemplate.getCloudname()); | ||
| final DockerCloud cloud = | ||
| DockerCloud.getCloudByName(jobTemplate.getCloudname()); | ||
| if (cloud != null) { | ||
| cloud.removeJobTemplate(li.getId()); | ||
| } | ||
|
|
@@ -59,23 +72,26 @@ public void onLeft(LeftItem li) { | |
| * @return If the item includes a template then the template will be returned. Otherwise <code>null</code>. | ||
| */ | ||
| @CheckForNull | ||
| private static DockerJobTemplateProperty getJobTemplate(Item item) { | ||
| private static DockerJobTemplateProperty getJobTemplate(final Item item) { | ||
| if (item.task instanceof Project) { | ||
| final Project<?, ?> project = (Project<?, ?>) item.task; | ||
| final DockerJobTemplateProperty p = project.getProperty(DockerJobTemplateProperty.class); | ||
| final DockerJobTemplateProperty p = project.getProperty( | ||
| DockerJobTemplateProperty.class); | ||
| if (p != null) { | ||
| return p; | ||
| } | ||
| // backward compatibility. DockerJobTemplateProperty used to be a nested object in DockerJobProperty | ||
| final DockerJobProperty property = project.getProperty(DockerJobProperty.class); | ||
| final DockerJobProperty property = project.getProperty( | ||
| DockerJobProperty.class); | ||
| if (property != null) { | ||
| return property.getDockerJobTemplate(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private static class DockerTemplateLabelAssignmentAction extends InvisibleAction implements LabelAssignmentAction { | ||
| private static final class DockerTemplateLabelAssignmentAction extends InvisibleAction | ||
| implements LabelAssignmentAction { | ||
| private final String uuid; | ||
|
|
||
| private DockerTemplateLabelAssignmentAction(String uuid) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** | ||
| * This package contains classes related to the Jenkins pipeline integration | ||
| * for Docker, including the management of Docker nodes and steps within the pipeline. | ||
| * | ||
| * <p>The classes in this package manage Docker pipeline steps, node provisioning, | ||
| * and the execution of build jobs within Docker containers.</p> | ||
| */ | ||
| package io.jenkins.docker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the most recent release of the checkstyle plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your previous comments and guidance,
I noticed that we don't currently have a checkstyle.xml file in the repository or a clear indication of where it might be referenced. I'm wondering if there is a plan to introduce this file, or if we're using an external/shared configuration that I might have overlooked? I ran mvn spotless:apply successfully, but just wanted to make sure we're not missing any custom style rules that might come with Checkstyle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not planning to introduce checkstyle into this repository. The Jenkins plugins that I maintain do not use checkstyle. I've not found it to be valuable enough to be worth the effort to enable it.
If you're serious about enabling checkstyle in this repository, then you'll need to provide a complete implementation that includes the checkstyle settings to persuade me that it will be useful. The default checkstyle settings conflict with spotless formatting. I value spotless formatting much more than I value checkstyle warnings. If your pull request proposes to accept many new, unresolved checkstyle warnings, then I'll reject it. I'm not willing to add new warnings output because it will be a distraction and will create extra work for me to resolve the warnings.