Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Contributor

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.

Suggested change
<version>3.1.1</version>
<version>3.6.0</version>

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

<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
Copy link
Contributor

Choose a reason for hiding this comment

The 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>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.2.0</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. 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>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use mvn spotless:apply rather than performing manual formatting of the files. The Jenkins plugin parent pom provides spotless with a configuration that works well for Jenkins plugins. It is enabled in this plugin.

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());
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/jenkins/docker/DockerTransientNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public DockerComputer createComputer() {

@Nullable
@Override
public ProvisioningActivity.Id getId() {
public final ProvisioningActivity.Id getId() {
return provisioningId;
}

Expand All @@ -184,7 +184,7 @@ private interface ILogger {

@Override
@Restricted(NoExternalUse.class)
public void _terminate(final TaskListener listener) {
public final void _terminate(final TaskListener listener) {
final ILogger tl = createILoggerForTaskListener(listener);
try {
terminate(tl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ enum ArgumentVariables {
private final String name;
private final String description;

ArgumentVariables(String name, String description) {
ArgumentVariables(final String name, final String description) {
this.name = name;
this.description = description;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/jenkins/docker/package-info.java
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;
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static DockerAPI defaultApi() {
"Must either specify dockerHost/credentialsId, or define at least one Docker cloud");
}

private void invokeBody(DockerTransientNode node, TaskListener listener) {
private void invokeBody(final DockerTransientNode node, final TaskListener listener) {
this.nodeName = node.getNodeName();
FilePath ws = null;
Computer computer = null;
Expand Down Expand Up @@ -256,7 +256,7 @@ public void stop(@NonNull Throwable cause) throws Exception {
private static class Callback extends BodyExecutionCallback.TailCall {
private final String nodeName;

public Callback(Node node) {
Callback(Node node) {
this.nodeName = node.getNodeName();
}

Expand Down
Loading