Merge pull request #4262 from StefanSpieker/replace_getActiveInstance

Replaced deprecated getActiveInstance() with get()
This commit is contained in:
Oleg Nenashev authored and GitHub committed 2019-11-22 10:25:21 +01:00
commit eedf2a4e2a
39 files changed
+57 -60

No files matched your search

+4 -4
View File
@@ -633,7 +633,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
protected @Nonnull Set<String> loadPluginsFromWar(@Nonnull String fromPath, @CheckForNull FilenameFilter filter) {
Set<String> names = new HashSet();
ServletContext context = Jenkins.getActiveInstance().servletContext;
ServletContext context = Jenkins.get().servletContext;
Set<String> plugins = Util.fixNull(context.getResourcePaths(fromPath));
Set<URL> copiedPlugins = new HashSet<>();
Set<URL> dependencies = new HashSet<>();
@@ -697,7 +697,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
String dependencySpec = manifest.getMainAttributes().getValue("Plugin-Dependencies");
if (dependencySpec != null) {
String[] dependencyTokens = dependencySpec.split(",");
ServletContext context = Jenkins.getActiveInstance().servletContext;
ServletContext context = Jenkins.get().servletContext;
for (String dependencyToken : dependencyTokens) {
if (dependencyToken.endsWith(";resolution:=optional")) {
@@ -709,7 +709,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
String artifactId = artifactIdVersionPair[0];
VersionNumber dependencyVersion = new VersionNumber(artifactIdVersionPair[1]);
PluginManager manager = Jenkins.getActiveInstance().getPluginManager();
PluginManager manager = Jenkins.get().getPluginManager();
VersionNumber installedVersion = manager.getPluginVersion(manager.rootDir, artifactId);
if (installedVersion != null && !installedVersion.isOlderThan(dependencyVersion)) {
// Do not downgrade dependencies that are already installed.
@@ -1376,7 +1376,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
}
response.add(pluginInfo);
}
for (UpdateSite site : Jenkins.getActiveInstance().getUpdateCenter().getSiteList()) {
for (UpdateSite site : Jenkins.get().getUpdateCenter().getSiteList()) {
for (UpdateSite.Plugin plugin: site.getAvailables()) {
JSONObject pluginInfo = allPlugins.get(plugin.name);
if(pluginInfo == null) {
+1 -1
View File
@@ -1251,7 +1251,7 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
@RequirePOST
public HttpResponse doDoUninstall() throws IOException {
Jenkins jenkins = Jenkins.getActiveInstance();
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);
archive.delete();
+1 -1
View File
@@ -85,7 +85,7 @@ public class CLIAction implements UnprotectedRootAction, StaplerProxy {
}
public void doCommand(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.READ);
// Strip trailing slash
@@ -242,10 +242,10 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
sc.setAuthentication(auth = getTransportAuthentication());
if (!(this instanceof HelpCommand || this instanceof WhoAmICommand))
Jenkins.getActiveInstance().checkPermission(Jenkins.READ);
Jenkins.get().checkPermission(Jenkins.READ);
p.parseArgument(args.toArray(new String[0]));
if (!(this instanceof HelpCommand || this instanceof WhoAmICommand))
Jenkins.getActiveInstance().checkPermission(Jenkins.READ);
Jenkins.get().checkPermission(Jenkins.READ);
LOGGER.log(Level.FINE, "Invoking CLI command {0}, with {1} arguments, as user {2}.",
new Object[] {getName(), args.size(), auth.getName()});
int res = run();
@@ -502,7 +502,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
*/
protected void registerOptionHandlers() {
try {
for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.getActiveInstance().pluginManager.uberClassLoader,Class.class)) {
for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.get().pluginManager.uberClassLoader,Class.class)) {
Type t = Types.getBaseClass(c, OptionHandler.class);
CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t,0)), c);
}
@@ -47,7 +47,7 @@ public class CancelQuietDownCommand extends CLICommand {
@Override
protected int run() throws Exception {
Jenkins.getActiveInstance().doCancelQuietDown();
Jenkins.get().doCancelQuietDown();
return 0;
}
}
@@ -47,7 +47,7 @@ public class ClearQueueCommand extends CLICommand {
@Override
protected int run() throws Exception {
Jenkins.getActiveInstance().getQueue().clear();
Jenkins.get().getQueue().clear();
return 0;
}
@@ -50,7 +50,7 @@ public class CopyJobCommand extends CLICommand {
public String dst;
protected int run() throws Exception {
Jenkins jenkins = Jenkins.getActiveInstance();
Jenkins jenkins = Jenkins.get();
if (jenkins.getItemByFullName(dst)!=null) {
throw new IllegalStateException("Job '"+dst+"' already exists");
@@ -45,7 +45,7 @@ public class CreateJobCommand extends CLICommand {
public String name;
protected int run() throws Exception {
Jenkins h = Jenkins.getActiveInstance();
Jenkins h = Jenkins.get();
if (h.getItemByFullName(name)!=null) {
throw new IllegalStateException("Job '"+name+"' already exists");
@@ -52,7 +52,7 @@ public class CreateNodeCommand extends CLICommand {
@Override
protected int run() throws Exception {
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Computer.CREATE);
final Node newNode = (Node) Jenkins.XSTREAM2.fromXML(stdin);
@@ -49,7 +49,7 @@ public class CreateViewCommand extends CLICommand {
@Override
protected int run() throws Exception {
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(View.CREATE);
View newView;
@@ -54,7 +54,7 @@ public class DeleteJobCommand extends CLICommand {
protected int run() throws Exception {
boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
final HashSet<String> hs = new HashSet<>(jobs);
@@ -54,7 +54,7 @@ public class DeleteNodeCommand extends CLICommand {
protected int run() throws Exception {
boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
final HashSet<String> hs = new HashSet<>(nodes);
@@ -59,7 +59,7 @@ public class DisconnectNodeCommand extends CLICommand {
@Override
protected int run() throws Exception {
boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
final HashSet<String> hs = new HashSet<>(nodes);
@@ -59,7 +59,7 @@ public class GroovyCommand extends CLICommand {
protected int run() throws Exception {
// this allows the caller to manipulate the JVM state, so require the execute script privilege.
Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS);
Jenkins.get().checkPermission(Jenkins.RUN_SCRIPTS);
Binding binding = new Binding();
binding.setProperty("out",new PrintWriter(stdout,true));
@@ -67,7 +67,7 @@ public class GroovyCommand extends CLICommand {
binding.setProperty("stdout",stdout);
binding.setProperty("stderr",stderr);
GroovyShell groovy = new GroovyShell(Jenkins.getActiveInstance().getPluginManager().uberClassLoader, binding);
GroovyShell groovy = new GroovyShell(Jenkins.get().getPluginManager().uberClassLoader, binding);
groovy.run(loadScript(),"RemoteClass",remaining.toArray(new String[0]));
return 0;
}
@@ -60,7 +60,7 @@ public class GroovyshCommand extends CLICommand {
@Override
protected int run() {
// this allows the caller to manipulate the JVM state, so require the admin privilege.
Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS);
Jenkins.get().checkPermission(Jenkins.RUN_SCRIPTS);
// this being remote means no jline capability is available
System.setProperty("jline.terminal", UnsupportedTerminal.class.getName());
@@ -85,12 +85,12 @@ public class GroovyshCommand extends CLICommand {
Binding binding = new Binding();
// redirect "println" to the CLI
binding.setProperty("out", new PrintWriter(stdout,true));
binding.setProperty("hudson", Jenkins.getActiveInstance()); // backward compatibility
binding.setProperty("jenkins", Jenkins.getActiveInstance());
binding.setProperty("hudson", Jenkins.get()); // backward compatibility
binding.setProperty("jenkins", Jenkins.get());
IO io = new IO(new BufferedInputStream(stdin),stdout,stderr);
final ClassLoader cl = Jenkins.getActiveInstance().pluginManager.uberClassLoader;
final ClassLoader cl = Jenkins.get().pluginManager.uberClassLoader;
Closure registrar = new Closure(null, null) {
private static final long serialVersionUID = 1L;
@@ -51,7 +51,7 @@ public class HelpCommand extends CLICommand {
@Override
protected int run() throws Exception {
if (!Jenkins.getActiveInstance().hasPermission(Jenkins.READ)) {
if (!Jenkins.get().hasPermission(Jenkins.READ)) {
throw new AccessDeniedException("You must authenticate to access this Jenkins.\n"
+ CLI.usage());
}
@@ -49,7 +49,7 @@ public class ListJobsCommand extends CLICommand {
public String name;
protected int run() throws Exception {
Jenkins h = Jenkins.getActiveInstance();
Jenkins h = Jenkins.get();
final Collection<TopLevelItem> jobs;
// If name is given retrieve jobs for the given view.
@@ -54,7 +54,7 @@ public class QuietDownCommand extends CLICommand {
@Override
protected int run() throws Exception {
Jenkins.getActiveInstance().doQuietDown(block, timeout);
Jenkins.get().doQuietDown(block, timeout);
return 0;
}
}
@@ -60,7 +60,7 @@ public class ReloadJobCommand extends CLICommand {
protected int run() throws Exception {
boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
final HashSet<String> hs = new HashSet<>(jobs);
@@ -94,7 +94,7 @@ public class ViewOptionHandler extends OptionHandler<View> {
@CheckForNull
public View getView(final String name) {
ViewGroup group = Jenkins.getActiveInstance();
ViewGroup group = Jenkins.get();
View view = null;
final StringTokenizer tok = new StringTokenizer(name, "/");
@@ -172,7 +172,7 @@ public abstract class AsyncAperiodicWork extends AperiodicWork {
} else {
lastRotateMillis = System.currentTimeMillis();
// migrate old log files the first time we start-up
File oldFile = new File(Jenkins.getActiveInstance().getRootDir(), f.getName());
File oldFile = new File(Jenkins.get().getRootDir(), f.getName());
if (oldFile.isFile()) {
File newFile = new File(f.getParentFile(), f.getName() + ".1");
if (!newFile.isFile()) {
@@ -157,7 +157,7 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
} else {
lastRotateMillis = System.currentTimeMillis();
// migrate old log files the first time we start-up
File oldFile = new File(Jenkins.getActiveInstance().getRootDir(), f.getName());
File oldFile = new File(Jenkins.get().getRootDir(), f.getName());
if (oldFile.isFile()) {
File newFile = new File(f.getParentFile(), f.getName() + ".1");
if (!newFile.isFile()) {
@@ -1475,7 +1475,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
}
if ((!proposedName.equals(nodeName))
&& Jenkins.getActiveInstance().getNode(proposedName) != null) {
&& Jenkins.get().getNode(proposedName) != null) {
throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name");
}
@@ -645,7 +645,7 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable,
if (isApplicable(actualType, json)) {
LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {actualType.getName(), json});
try {
final Descriptor descriptor = Jenkins.getActiveInstance().getDescriptor(actualType);
final Descriptor descriptor = Jenkins.get().getDescriptor(actualType);
if (descriptor != null) {
return descriptor.newInstance(Stapler.getCurrentRequest(), json);
} else {
@@ -671,7 +671,7 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable,
if (isApplicable(targetTypeErasure, json)) {
LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {targetTypeErasure.getName(), json});
try {
return Jenkins.getActiveInstance().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json);
return Jenkins.get().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json);
} catch (Exception x) {
LOGGER.log(Level.WARNING, "falling back to default instantiation " + targetTypeErasure.getName() + " " + json, x);
}
@@ -257,7 +257,7 @@ public class DownloadService {
*/
public List<String> getUrls() {
List<String> updateSites = new ArrayList<>();
for (UpdateSite site : Jenkins.getActiveInstance().getUpdateCenter().getSiteList()) {
for (UpdateSite site : Jenkins.get().getUpdateCenter().getSiteList()) {
String siteUrl = site.getUrl();
int baseUrlEnd = siteUrl.indexOf("update-center.json");
if (baseUrlEnd != -1) {
@@ -327,7 +327,7 @@ public class DownloadService {
public FormValidation updateNow() throws IOException {
List<JSONObject> jsonList = new ArrayList<>();
boolean toolInstallerMetadataExists = false;
for (UpdateSite updatesite : Jenkins.getActiveInstance().getUpdateCenter().getSiteList()) {
for (UpdateSite updatesite : Jenkins.get().getUpdateCenter().getSiteList()) {
String site = updatesite.getMetadataUrlForDownloadable(url);
if (site == null) {
return FormValidation.warning("The update site " + updatesite.getId() + " does not look like an update center");
+1 -1
View File
@@ -548,7 +548,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
public Map<JobPropertyDescriptor, JobProperty<? super JobT>> getProperties() {
Map result = Descriptor.toMap((Iterable) properties);
if (logRotator != null) {
result.put(Jenkins.getActiveInstance().getDescriptorByType(BuildDiscarderProperty.DescriptorImpl.class), new BuildDiscarderProperty(logRotator));
result.put(Jenkins.get().getDescriptorByType(BuildDiscarderProperty.DescriptorImpl.class), new BuildDiscarderProperty(logRotator));
}
return result;
}
@@ -72,7 +72,7 @@ public class OverallLoadStatistics extends LoadStatistics {
@Override
protected Iterable<Node> getNodes() {
return Jenkins.getActiveInstance().getNodes();
return Jenkins.get().getNodes();
}
@Override
@@ -5140,7 +5140,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
*/
@Restricted(NoExternalUse.class)
public @CheckForNull static VersionNumber getStoredVersion() {
return toVersion(Jenkins.getActiveInstance().version);
return toVersion(Jenkins.get().version);
}
/**
@@ -102,7 +102,7 @@ public class UnlabeledLoadStatistics extends LoadStatistics {
private static class UnlabeledNodesIterator extends Iterators.FilterIterator<Node> {
protected UnlabeledNodesIterator() {
super(Jenkins.getActiveInstance().getNodes().iterator());
super(Jenkins.get().getNodes().iterator());
}
@Override
@@ -46,7 +46,7 @@ public class GroovyHookScript {
@Deprecated
public GroovyHookScript(String hook) {
this(hook, Jenkins.getActiveInstance());
this(hook, Jenkins.get());
}
private GroovyHookScript(String hook, Jenkins j) {