Skip to content
Permalink
Browse files

[FIXED JENKINS-45456] Reduce Java warnings of the plugin and remove u…

…se of deprecated Hudson.getInstance()
  • Loading branch information...
redeamer committed Jul 11, 2017
1 parent 8423c82 commit 8224c8a6d8cc35062c3b9889c5c3262c8995fdfa
@@ -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;
@@ -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;
@@ -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;
@@ -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
@@ -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;
@@ -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
@@ -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) {
@@ -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;
@@ -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;

@@ -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;
@@ -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();
}
@@ -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();
}
@@ -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;
}

@@ -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;
@@ -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;
@@ -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;
}
@@ -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();
}

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

return FormValidation.ok();
}

public boolean isFatal() {

0 comments on commit 8224c8a

Please sign in to comment.
You can’t perform that action at this time.