Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into JENKINS-46132
  • Loading branch information
duemir committed Dec 19, 2017
2 parents b28c11e + 1e4d189 commit 735f1b2
Show file tree
Hide file tree
Showing 35 changed files with 116 additions and 405 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
@@ -1 +1 @@
buildPlugin()
buildPlugin(jenkinsVersions: [null, '2.89.1'])
18 changes: 12 additions & 6 deletions pom.xml
Expand Up @@ -29,7 +29,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.23</version>
<version>3.2</version>
<relativePath />
</parent>

<artifactId>support-core</artifactId>
Expand All @@ -40,11 +41,11 @@
<description>
This plugin provides a common set of classes to assist in generating support bundles.
</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Support+Core+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/Support+Core+Plugin</url>
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand All @@ -63,20 +64,25 @@
<scm>
<connection>scm:git:git://github.com/jenkinsci/support-core-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/support-core-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/support-core-plugin</url>
<url>https://github.com/jenkinsci/support-core-plugin</url>
<tag>HEAD</tag>
</scm>

<properties>
<jenkins.version>2.46.3</jenkins.version>
<java.level>7</java.level>
</properties>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand Down
Expand Up @@ -26,14 +26,14 @@ public class AsyncResultCache<T> implements Runnable {
private final Node node;
private final String name;

public static <V, T extends java.lang.Throwable> V get(Node node, WeakHashMap<Node, V> cache, Callable<V,T> operation, String name, V defaultIfNull)
public static <V, T extends java.lang.Throwable> V get(Node node, WeakHashMap<Node, V> cache, /*MasterToSlave*/Callable<V,T> operation, String name, V defaultIfNull)

throws IOException {
V result = get(node, cache, operation, name);
return result == null ? defaultIfNull : result;
}

public static <V, T extends java.lang.Throwable> V get(Node node, WeakHashMap<Node, V> cache, Callable<V,T> operation, String name)
public static <V, T extends java.lang.Throwable> V get(Node node, WeakHashMap<Node, V> cache, /*MasterToSlave*/Callable<V,T> operation, String name)

throws IOException {
if (node == null) return null;
Expand Down
Expand Up @@ -27,7 +27,6 @@
import com.cloudbees.jenkins.support.api.Component;
import com.cloudbees.jenkins.support.api.SupportProvider;

import com.cloudbees.jenkins.support.util.Helper;
import hudson.Extension;
import hudson.model.RootAction;
import hudson.security.ACL;
Expand Down Expand Up @@ -175,7 +174,7 @@ public void doDownload(StaplerRequest req, StaplerResponse rsp) throws ServletEx

@RequirePOST
public void doGenerateAllBundles(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
final Jenkins instance = Helper.getActiveInstance();
final Jenkins instance = Jenkins.getInstance();
instance.getAuthorizationStrategy().getACL(instance).checkPermission(CREATE_BUNDLE);

JSONObject json = req.getSubmittedForm();
Expand Down
40 changes: 10 additions & 30 deletions src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java
Expand Up @@ -31,7 +31,6 @@
import com.cloudbees.jenkins.support.api.SupportProvider;
import com.cloudbees.jenkins.support.api.SupportProviderDescriptor;
import com.cloudbees.jenkins.support.impl.ThreadDumps;
import com.cloudbees.jenkins.support.util.Helper;
import com.codahale.metrics.Histogram;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -47,7 +46,6 @@
import hudson.model.Node;
import hudson.model.PeriodicWork;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Future;
import hudson.remoting.VirtualChannel;
import hudson.security.ACL;
Expand All @@ -67,7 +65,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -102,6 +99,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import jenkins.security.MasterToSlaveCallable;

/**
* Main entry point for the support plugin.
Expand Down Expand Up @@ -160,7 +158,7 @@ public SupportPlugin() {
public SupportProvider getSupportProvider() {
if (supportProvider == null) {
// if this is not set, pick the first one that we can get our hands on
for (Descriptor<SupportProvider> d : Helper.getActiveInstance().getDescriptorList(SupportProvider.class)) {
for (Descriptor<SupportProvider> d : Jenkins.getInstance().getDescriptorList(SupportProvider.class)) {
if (d instanceof SupportProviderDescriptor) {
try {
supportProvider = ((SupportProviderDescriptor) (d)).newDefaultInstance();
Expand All @@ -179,7 +177,7 @@ public SupportProvider getSupportProvider() {
* @return the wrking directory that the support-core plugin uses to write out files.
*/
public static File getRootDirectory() {
return new File(Helper.getActiveInstance().getRootDir(), SUPPORT_DIRECTORY_NAME);
return new File(Jenkins.getInstance().getRootDir(), SUPPORT_DIRECTORY_NAME);
}


Expand Down Expand Up @@ -245,7 +243,7 @@ public static void setLogLevel(String level) {
public static void setLogLevel(Level level) {
SupportPlugin instance = getInstance();
instance.handler.setLevel(level);
for (Node n : Helper.getActiveInstance().getNodes()) {
for (Node n : Jenkins.getInstance().getNodes()) {
Computer c = n.toComputer();
if (c == null) {
continue;
Expand All @@ -262,11 +260,11 @@ public static void setLogLevel(Level level) {
}

public static SupportPlugin getInstance() {
return Helper.getActiveInstance().getPlugin(SupportPlugin.class);
return Jenkins.getInstance().getPlugin(SupportPlugin.class);
}

public static ExtensionList<Component> getComponents() {
return Helper.getActiveInstance().getExtensionList(Component.class);
return Jenkins.getInstance().getExtensionList(Component.class);
}

public static void writeBundle(OutputStream outputStream) throws IOException {
Expand Down Expand Up @@ -609,7 +607,7 @@ public static class LogHolder {
private static final SupportLogHandler SLAVE_LOG_HANDLER = new SupportLogHandler(256, 2048, 8);
}

private static class LogInitializer implements Callable<Void, RuntimeException> {
private static class LogInitializer extends MasterToSlaveCallable<Void, RuntimeException> {
private static final long serialVersionUID = 1L;
private static final Logger ROOT_LOGGER = Logger.getLogger("");
private final FilePath rootPath;
Expand Down Expand Up @@ -640,30 +638,18 @@ public Void call() {
return null;
}

/** {@inheritDoc} */
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// TODO: do we have to verify some role?
}

}

public static class LogFetcher implements Callable<List<LogRecord>, RuntimeException> {
public static class LogFetcher extends MasterToSlaveCallable<List<LogRecord>, RuntimeException> {
private static final long serialVersionUID = 1L;

public List<LogRecord> call() throws RuntimeException {
return new ArrayList<LogRecord>(LogHolder.SLAVE_LOG_HANDLER.getRecent());
}

/** {@inheritDoc} */
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// TODO: do we have to verify some role?
}

}

public static class LogUpdater implements Callable<Void, RuntimeException> {
public static class LogUpdater extends MasterToSlaveCallable<Void, RuntimeException> {

private static final long serialVersionUID = 1L;

Expand All @@ -678,12 +664,6 @@ public Void call() throws RuntimeException {
return null;
}

/** {@inheritDoc} */
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// TODO: do we have to verify some role?
}

}

@Extension
Expand Down Expand Up @@ -820,7 +800,7 @@ public boolean accept(File dir, String name) {
public static class GlobalConfigurationImpl extends GlobalConfiguration {

public boolean isSelectable() {
return Helper.getActiveInstance().getDescriptorList(SupportProvider.class).size() > 1;
return Jenkins.getInstance().getDescriptorList(SupportProvider.class).size() > 1;
}

public SupportProvider getSupportProvider() {
Expand Down
Expand Up @@ -3,11 +3,9 @@
import com.cloudbees.jenkins.support.AsyncResultCache;
import com.cloudbees.jenkins.support.SupportLogFormatter;
import hudson.model.Node;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
import org.jenkinsci.remoting.RoleChecker;

import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -16,6 +14,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import jenkins.security.MasterToSlaveCallable;

/**
* Content of a command output. You can only instantiate this content with
Expand All @@ -29,7 +28,7 @@ private CommandOutputContent(String name, String value) {
super(name, value);
}

public static class CommandLauncher implements Callable<String, RuntimeException> {
public static class CommandLauncher extends MasterToSlaveCallable<String, RuntimeException> {
final String[] command;

private CommandLauncher(String... command) {
Expand All @@ -48,12 +47,6 @@ public String call() {
pw.flush();
return bos.toString();
}

/** {@inheritDoc} */
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// TODO: do we have to verify some role?
}
}

private static String getNodeName(Node node) {
Expand Down
Expand Up @@ -24,7 +24,6 @@

package com.cloudbees.jenkins.support.api;

import com.cloudbees.jenkins.support.util.Helper;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.security.ACL;
import hudson.security.Permission;
Expand Down Expand Up @@ -86,7 +85,7 @@ public String getDisplayPermissions() {
* @return {@code true} if the current authentication can include this component in a bundle.
*/
public boolean isEnabled() {
ACL acl = Helper.getActiveInstance().getAuthorizationStrategy().getRootACL();
ACL acl = Jenkins.getInstance().getAuthorizationStrategy().getRootACL();
if (acl != null) {
Authentication authentication = Jenkins.getAuthentication();
assert authentication != null;
Expand Down
Expand Up @@ -25,7 +25,6 @@

import com.cloudbees.jenkins.support.api.Component;
import com.cloudbees.jenkins.support.api.Container;
import com.cloudbees.jenkins.support.util.Helper;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.security.Permission;
Expand Down Expand Up @@ -64,7 +63,7 @@ public String getDisplayName() {

@Override
public void addContents(@NonNull Container container) {
File[] agentDirs = new File(Helper.getActiveInstance().getRootDir(), "nodes").listFiles();
File[] agentDirs = new File(Jenkins.getInstance().getRootDir(), "nodes").listFiles();
if (agentDirs == null) {
return;
}
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.cloudbees.jenkins.support.api.Component;
import com.cloudbees.jenkins.support.api.Container;
import com.cloudbees.jenkins.support.util.Helper;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.security.Permission;
Expand Down Expand Up @@ -34,7 +33,7 @@ public String getDisplayName() {

@Override
public void addContents(@NonNull Container container) {
Jenkins jenkins = Helper.getActiveInstance();
Jenkins jenkins = Jenkins.getInstance();
File configFile = new File(jenkins.getRootDir(), "config.xml");
if (configFile.exists()) {
container.add(
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.cloudbees.jenkins.support.api.Component;
import com.cloudbees.jenkins.support.api.Container;
import com.cloudbees.jenkins.support.util.Helper;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.security.Permission;
Expand Down Expand Up @@ -34,7 +33,7 @@ public String getDisplayName() {

@Override
public void addContents(@NonNull Container container) {
Jenkins jenkins = Helper.getActiveInstance();
Jenkins jenkins = Jenkins.getInstance();
if (jenkins != null) {
File dir = jenkins.getRootDir();
File[] files = dir.listFiles(new FilenameFilter() {
Expand Down

0 comments on commit 735f1b2

Please sign in to comment.