Skip to content
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

Use Jenkins.get() instead of deprecated method and minor improvements #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
Expand All @@ -81,7 +80,6 @@
import hudson.util.Secret;
import hudson.util.XStream2;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

/**
* The {@link DigitalOceanCloud} contains the main configuration values for running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -208,7 +209,7 @@ public void onClosed(Channel channel, IOException cause) {
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
try {
Jenkins.getInstance().removeNode(node);
Jenkins.get().removeNode(node);
} catch (Exception ee) {
ee.printStackTrace(logger);
}
Expand Down Expand Up @@ -242,7 +243,7 @@ private boolean runInitScript(final DigitalOceanComputer digitalOceanComputer, f
}

logger.println("Executing init script");
scp.put(initScript.getBytes("UTF-8"), "init.sh", "/tmp", "0700");
scp.put(initScript.getBytes(StandardCharsets.UTF_8), "init.sh", "/tmp", "0700");
Session session = conn.openSession();
session.requestDumbPTY(); // so that the remote side bundles stdout and stderr
session.execCommand(buildUpCommand(digitalOceanComputer, "/tmp/init.sh"));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/dubture/jenkins/digitalocean/Slave.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ public DigitalOceanComputer createComputer() {
* @return the DigitalOceanCloud associated with the specified cloudName
*/
public DigitalOceanCloud getCloud() {
return (DigitalOceanCloud) Jenkins.getInstance().getCloud(cloudName);
return (DigitalOceanCloud) Jenkins.get().getCloud(cloudName);
}

/**
* Get the name of the remote admin user
* @return the remote admin user, defaulting to "root"
*/
public String getRemoteAdmin() {
if (remoteAdmin == null || remoteAdmin.length() == 0)
if (remoteAdmin == null || remoteAdmin.isEmpty())
return "root";
return remoteAdmin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public boolean isInstanceCapReachedLocal(String cloudName) {
LOGGER.log(Level.INFO, "agent limit check");

int count = 0;
List<Node> nodes = Jenkins.getInstance().getNodes();
List<Node> nodes = Jenkins.get().getNodes();
for (Node n : nodes) {
if (DropletName.isDropletInstanceOfSlave(n.getDisplayName(), cloudName, name)) {
count++;
Expand Down Expand Up @@ -258,7 +258,7 @@ public Slave provision(ProvisioningActivity.Id provisioningId,
droplet.setSize(sizeId);
droplet.setRegion(new Region(regionId));
droplet.setImage(DigitalOcean.newImage(imageId));
droplet.setKeys(Arrays.asList(new Key(sshKeyId)));
droplet.setKeys(Collections.singletonList(new Key(sshKeyId)));
droplet.setInstallMonitoring(installMonitoringAgent);
droplet.setEnablePrivateNetworking(
(usePrivateNetworking == null ? false : usePrivateNetworking) || (setupPrivateNetworking == null ? false : setupPrivateNetworking)
Expand Down Expand Up @@ -484,7 +484,7 @@ public ListBoxModel doFillRegionIdItems(@RelativePath("..") @QueryParameter Stri

@SuppressWarnings("unchecked")
public Descriptor<SlaveTemplate> getDescriptor() {
return Jenkins.getInstance().getDescriptor(getClass());
return Jenkins.get().getDescriptor(getClass());
}

public String getName() {
Expand Down