Skip to content

Commit

Permalink
[FIXED JENKINS-45456] Reduce Java warnings of the plugin and remove u…
Browse files Browse the repository at this point in the history
…se of deprecated Hudson.getInstance()
  • Loading branch information
mmusenbr committed Jul 11, 2017
1 parent 8423c82 commit 8224c8a
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 16 deletions.
Expand Up @@ -13,7 +13,6 @@
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.Result;
import hudson.plugins.android_emulator.sdk.AndroidSdk;
Expand All @@ -27,6 +26,7 @@
import hudson.util.ForkOutputStream;
import hudson.util.FormValidation;
import hudson.util.NullStream;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
Expand All @@ -44,7 +44,6 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringWriter;
import java.net.ServerSocket;
Expand Down Expand Up @@ -173,7 +172,7 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
throws IOException, InterruptedException {
final PrintStream logger = listener.getLogger();
if (descriptor == null) {
descriptor = Hudson.getInstance().getDescriptorByType(DescriptorImpl.class);
descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
}

// Substitute environment and build variables into config
Expand Down
Expand Up @@ -4,7 +4,6 @@
import hudson.matrix.MatrixConfiguration;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.Executor;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.Queue.BuildableItem;
Expand All @@ -15,6 +14,7 @@
import hudson.model.queue.SubTask;

import hudson.plugins.android_emulator.AndroidEmulator.DescriptorImpl;
import jenkins.model.Jenkins;

/**
* This QueueTaskDispatcher prevents any one Android emulator instance from being executed more than
Expand Down Expand Up @@ -43,13 +43,13 @@ public CauseOfBlockage canTake(Node node, Task task) {
}

// If the AndroidEmulator uses workspace-local emulators, we don't care.
DescriptorImpl descriptor = Hudson.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
if (descriptor != null && descriptor.shouldKeepInWorkspace) {
return null;
}

// Check for builds in the queue which have the same emulator config as this task
Queue queue = Hudson.getInstance().getQueue();
Queue queue = Jenkins.getInstance().getQueue();
for (BuildableItem item : queue.getBuildableItems()) {
Task queuedTask = item.task;
if (task == queuedTask) {
Expand Down
Expand Up @@ -7,7 +7,6 @@
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.EnvironmentContributingAction;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.plugins.android_emulator.AndroidEmulator;
Expand All @@ -22,6 +21,7 @@
import hudson.tasks.Builder;
import hudson.util.ForkOutputStream;
import jenkins.MasterToSlaveFileCallable;
import jenkins.model.Jenkins;
import net.dongliu.apk.parser.ApkParser;
import net.dongliu.apk.parser.bean.ApkMeta;

Expand Down Expand Up @@ -55,7 +55,7 @@ protected static AndroidSdk getAndroidSdk(AbstractBuild<?, ?> build, Launcher la
BuildListener listener) throws IOException, InterruptedException {
boolean shouldInstallSdk = true;
boolean keepInWorkspace = false;
DescriptorImpl descriptor = Hudson.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
if (descriptor != null) {
shouldInstallSdk = descriptor.shouldInstallSdk;
keepInWorkspace = descriptor.shouldKeepInWorkspace;
Expand Down Expand Up @@ -290,6 +290,8 @@ protected static boolean uninstallApk(AbstractBuild<?, ?> build, Launcher launch
*/
private static String getPackageIdForApk(FilePath apkPath) throws IOException, InterruptedException {
return apkPath.act(new MasterToSlaveFileCallable<String>() {
private static final long serialVersionUID = 1L;

public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return getApkMetadata(f).getPackageName();
}
Expand Down
Expand Up @@ -163,6 +163,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
private static String getWorkspacePath(FilePath workspace) throws IOException,
InterruptedException {
return workspace.act(new MasterToSlaveFileCallable<String>() {
private static final long serialVersionUID = 1L;

public String invoke(File f, VirtualChannel channel) throws IOException {
return f.getCanonicalPath();
}
Expand Down
Expand Up @@ -148,7 +148,7 @@ public String getHelpFile() {
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
public boolean isApplicable(@SuppressWarnings("rawtypes") Class<? extends AbstractProject> jobType) {
return true;
}

Expand Down
@@ -1,6 +1,5 @@
package hudson.plugins.android_emulator.snapshot;

import hudson.Extension;
import hudson.Functions;
import hudson.model.Descriptor;
import hudson.plugins.android_emulator.Messages;
Expand Down
@@ -1,6 +1,5 @@
package hudson.plugins.android_emulator.snapshot;

import hudson.Extension;
import hudson.Functions;
import hudson.model.Descriptor;
import hudson.plugins.android_emulator.Messages;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/hudson/plugins/android_emulator/util/Utils.java
Expand Up @@ -51,22 +51,22 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;

import static hudson.plugins.android_emulator.AndroidEmulator.log;

public class Utils {

private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
private static final Pattern REVISION = Pattern.compile("(\\d++).*");

/**
* Retrieves the configured Android SDK root directory.
*
* @return The configured Android SDK root, if any. May include un-expanded variables.
*/
public static String getConfiguredAndroidHome() {
DescriptorImpl descriptor = Hudson.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
if (descriptor != null) {
return descriptor.androidHome;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public AndroidSdk call() throws IOException {
*/
public static ValidationResult validateAndroidHome(File sdkRoot, boolean fromWebConfig) {
// This can be used to check the existence of a file on the server, so needs to be protected
if (fromWebConfig && !Hudson.getInstance().hasPermission(Hudson.ADMINISTER)) {
if (fromWebConfig && !Jenkins.getInstance().hasPermission(Hudson.ADMINISTER)) {
return ValidationResult.ok();
}

Expand Down
Expand Up @@ -52,9 +52,10 @@ public FormValidation getFormValidation() {
} else {
return FormValidation.error(message);
}
case OK:
default:
return FormValidation.ok();
}

return FormValidation.ok();
}

public boolean isFatal() {
Expand Down

0 comments on commit 8224c8a

Please sign in to comment.