Skip to content

Commit

Permalink
Merge pull request #1155 from daspilker/instance
Browse files Browse the repository at this point in the history
Jenkins.getInstance() -> Jenkins.get()
  • Loading branch information
daspilker authored Jan 8, 2019
2 parents 86b4604 + 0093e78 commit 9fdd595
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public static void executeInContext(Runnable runnable, Context context) {
* @return a list of all registered JobDslContextExtensionPoints.
*/
public static ExtensionList<ContextExtensionPoint> all() {
return Jenkins.getInstance().getExtensionList(ContextExtensionPoint.class);
return Jenkins.get().getExtensionList(ContextExtensionPoint.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
}

public String getScriptApprovalWarning() {
return isSecurityEnabled() && !Jenkins.getInstance().hasPermission(Jenkins.RUN_SCRIPTS) ? Messages.ScriptSecurity_ScriptApprovalWarning() : "";
return isSecurityEnabled() && !Jenkins.get().hasPermission(Jenkins.RUN_SCRIPTS) ? Messages.ScriptSecurity_ScriptApprovalWarning() : "";
}

@Initializer(before = InitMilestone.PLUGINS_STARTED)
Expand All @@ -126,12 +126,12 @@ public static void addAliases() {
}

public boolean isSecurityEnabled() {
Jenkins jenkins = Jenkins.getInstance();
Jenkins jenkins = Jenkins.get();
return jenkins.isUseSecurity() && jenkins.getDescriptorByType(GlobalJobDslSecurityConfiguration.class).isUseScriptSecurity();
}

private static void removeSeedReference(String key) {
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.get().getDescriptorByType(DescriptorImpl.class);
SeedReference seedReference = descriptor.getGeneratedJobMap().remove(key);
if (seedReference != null) {
descriptor.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class EmbeddedApiDocGenerator {
.element('parameters', generateParameters(method))
.element('extension', true)

PluginWrapper plugin = Jenkins.instance.pluginManager.whichPlugin(method.declaringClass)
PluginWrapper plugin = Jenkins.get().pluginManager.whichPlugin(method.declaringClass)
if (plugin) {
signature.element('plugin', [id: plugin.shortName])
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class EmbeddedApiDocGenerator {

generateHelp(signature, model.help)

PluginWrapper plugin = Jenkins.instance.pluginManager.whichPlugin(model.type)
PluginWrapper plugin = Jenkins.get().pluginManager.whichPlugin(model.type)
if (plugin) {
signature.element('plugin', [id: plugin.shortName])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private Set<String> updateTemplates(Job seedJob, TaskListener listener,

// Collect information about the templates we loaded
final String seedJobName = seedJob.getName();
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.get().getDescriptorByType(DescriptorImpl.class);
boolean descriptorMutated = false;

// Clean up
Expand Down Expand Up @@ -466,7 +466,7 @@ private void updateGeneratedJobs(final Job seedJob, TaskListener listener,

private void updateGeneratedJobMap(Job seedJob, Set<GeneratedJob> createdOrUpdatedJobs,
Set<GeneratedJob> removedJobs) throws IOException {
DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.get().getDescriptorByType(DescriptorImpl.class);
boolean descriptorMutated = false;
Map<String, SeedReference> generatedJobMap = descriptor.getGeneratedJobMap();

Expand Down Expand Up @@ -549,10 +549,10 @@ private void updateGeneratedConfigFiles(Job seedJob, TaskListener listener,
logItems(listener, "Existing config files", existing);
logItems(listener, "Unreferenced config files", unreferenced);

if (removedConfigFilesAction == RemovedConfigFilesAction.DELETE && Jenkins.getInstance().getPluginManager().getPlugin("config-file-provider") != null) {
if (removedConfigFilesAction == RemovedConfigFilesAction.DELETE && Jenkins.get().getPluginManager().getPlugin("config-file-provider") != null) {
GlobalConfigFiles globalConfigFiles = GlobalConfigFiles.get();
for (GeneratedConfigFile unreferencedConfigFile : unreferenced) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
globalConfigFiles.remove(unreferencedConfigFile.getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public JenkinsDslScriptLoader(JobManagement jobManagement) {
protected void extractGeneratedItems(GeneratedItems generatedItems, JenkinsJobParent jobParent, ScriptRequest scriptRequest) {
super.extractGeneratedItems(generatedItems, jobParent, scriptRequest);

if (Jenkins.getInstance().getPluginManager().getPlugin("config-file-provider") != null) {
if (Jenkins.get().getPluginManager().getPlugin("config-file-provider") != null) {
GlobalConfigFiles globalConfigFiles = GlobalConfigFiles.get();
for (Object o : jobParent.getReferencedConfigs()) {
Config config = (Config) o;
if (!(scriptRequest.getIgnoreExisting() && globalConfigFiles.getById(config.id) != null)) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
globalConfigFiles.save(config);
}
generatedItems.getConfigFiles().add(new GeneratedConfigFile(config.id, config.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public void createOrUpdateView(String path, String config, boolean ignoreExistin
@Override
public void createOrUpdateUserContent(UserContent userContent, boolean ignoreExisting) {
// As in git-userContent-plugin:
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
try {
FilePath file = Jenkins.getInstance().getRootPath().child("userContent").child(userContent.getPath());
FilePath file = Jenkins.get().getRootPath().child("userContent").child(userContent.getPath());
if (!(file.exists() && ignoreExisting)) {
file.getParent().mkdirs();
file.copyFrom(userContent.getContent());
Expand Down Expand Up @@ -236,7 +236,7 @@ public String readFileInWorkspace(String relLocation) throws IOException, Interr

@Override
public String readFileInWorkspace(String jobName, String relLocation) throws IOException, InterruptedException {
Item item = Jenkins.getInstance().getItemByFullName(jobName);
Item item = Jenkins.get().getItemByFullName(jobName);
if (item instanceof AbstractProject) {
item.checkPermission(Item.WORKSPACE);
FilePath workspace = ((AbstractProject) item).getSomeWorkspace();
Expand All @@ -257,7 +257,7 @@ public String readFileInWorkspace(String jobName, String relLocation) throws IOE

@Override
public void logPluginDeprecationWarning(String pluginShortName, String minimumVersion) {
Plugin plugin = Jenkins.getInstance().getPlugin(pluginShortName);
Plugin plugin = Jenkins.get().getPlugin(pluginShortName);
if (plugin != null && plugin.getWrapper().getVersionNumber().isOlderThan(new VersionNumber(minimumVersion))) {
logDeprecationWarning(
"support for " + plugin.getWrapper().getDisplayName() + " versions older than " + minimumVersion
Expand All @@ -280,7 +280,7 @@ public void requirePlugin(String pluginShortName) {

@Override
public void requirePlugin(String pluginShortName, boolean failIfMissing) {
Plugin plugin = Jenkins.getInstance().getPlugin(pluginShortName);
Plugin plugin = Jenkins.get().getPlugin(pluginShortName);
if (plugin == null) {
failOrMarkBuildAsUnstable(
"plugin '" + pluginShortName + "' needs to be installed",
Expand All @@ -296,7 +296,7 @@ public void requireMinimumPluginVersion(String pluginShortName, String version)

@Override
public void requireMinimumPluginVersion(String pluginShortName, String version, boolean failIfMissing) {
Plugin plugin = Jenkins.getInstance().getPlugin(pluginShortName);
Plugin plugin = Jenkins.get().getPlugin(pluginShortName);
if (plugin == null) {
failOrMarkBuildAsUnstable(
"version " + version + " or later of plugin '" + pluginShortName + "' needs to be installed",
Expand All @@ -319,7 +319,7 @@ public void requireMinimumCoreVersion(String version) {

@Override
public boolean isMinimumPluginVersionInstalled(String pluginShortName, String version) {
Plugin plugin = Jenkins.getInstance().getPlugin(pluginShortName);
Plugin plugin = Jenkins.get().getPlugin(pluginShortName);
return plugin != null && !plugin.getWrapper().getVersionNumber().isOlderThan(new VersionNumber(version));
}

Expand All @@ -330,7 +330,7 @@ public boolean isMinimumCoreVersion(String version) {

@Override
public Integer getVSphereCloudHash(String name) {
Jenkins jenkins = Jenkins.getInstance();
Jenkins jenkins = Jenkins.get();
if (jenkins.getPlugin("vsphere-cloud") != null) {
for (Cloud cloud : jenkins.clouds) {
if (cloud instanceof vSphereCloud && ((vSphereCloud) cloud).getVsDescription().equals(name)) {
Expand All @@ -344,7 +344,7 @@ public Integer getVSphereCloudHash(String name) {
@Override
public void renameJobMatching(final String previousNames, String destination) throws IOException {
final ItemGroup context = lookupStrategy.getContext(project);
Collection<Job> items = Jenkins.getInstance().getAllItems(Job.class);
Collection<Job> items = Jenkins.get().getAllItems(Job.class);
Collection<Job> matchingJobs = Collections2.filter(items, new Predicate<Job>() {
@Override
public boolean apply(Job topLevelItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum LookupStrategy {
/**
* Using this naming strategy jobs with relative path names are absolute names.
*/
JENKINS_ROOT("Jenkins Root", (seedJob) -> Jenkins.getInstance()),
JENKINS_ROOT("Jenkins Root", (seedJob) -> Jenkins.get()),

/**
* Using this naming strategy jobs with relative path names are created relative
Expand Down Expand Up @@ -44,7 +44,7 @@ public <T extends Item> T getItem(Item seedJob, String path, Class<T> type) {
if (normalizePath == null) {
return null;
}
return Jenkins.getInstance().getItemByFullName(normalizePath, type);
return Jenkins.get().getItemByFullName(normalizePath, type);
}

/**
Expand All @@ -65,7 +65,7 @@ protected ItemGroup getContext(Item seedJob) {
* @return parent {@link hudson.model.ItemGroup} of the item with the given path
*/
public ItemGroup getParent(Item seedJob, String path) {
Jenkins jenkins = Jenkins.getInstance();
Jenkins jenkins = Jenkins.get();

String absolutePath;
if (path.startsWith("/")) {
Expand All @@ -91,7 +91,7 @@ public String getDisplayName() {
private final Function<Item, ItemGroup> context;

private static ItemGroup getItemGroup(String path) {
Jenkins instance = Jenkins.getInstance();
Jenkins instance = Jenkins.get();
String normalizedPath = normalizePath(path);
if (normalizedPath == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onChange(Saveable saveable, XmlFile file) {
AbstractItem project = (AbstractItem) saveable;
String possibleTemplateName = project.getName();

DescriptorImpl descriptor = Jenkins.getInstance().getDescriptorByType(DescriptorImpl.class);
DescriptorImpl descriptor = Jenkins.get().getDescriptorByType(DescriptorImpl.class);
Collection<SeedReference> seedJobReferences = descriptor.getTemplateJobMap().get(possibleTemplateName);

if (seedJobReferences.isEmpty()) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public int hashCode() {
private static class LookupProjectFunction implements Function<SeedReference, BuildableItem> {
@Override
public BuildableItem apply(SeedReference input) {
return (BuildableItem) Jenkins.getInstance().getItem(input.getSeedJobName());
return (BuildableItem) Jenkins.get().getItem(input.getSeedJobName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import jenkins.model.Jenkins
class PermissionsHelper {
static Set<String> getPermissions(String descriptorId) {
Set<String> result = []
Descriptor descriptor = Jenkins.instance.getDescriptor(descriptorId)
Descriptor descriptor = Jenkins.get().getDescriptor(descriptorId)
if (descriptor != null) {
List<PermissionGroup> allGroups = descriptor.allGroups
allGroups*.permissions.flatten().findAll { descriptor.showPermission(it) }.each {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ApiViewerActionFactory extends TransientActionFactory<Project> {

@Override
Collection<? extends Action> createFor(@Nonnull Project target) {
target.buildersList.contains(Jenkins.instance.getDescriptor(ExecuteDslScripts)) ? [new ApiViewerAction()] : []
target.buildersList.contains(Jenkins.get().getDescriptor(ExecuteDslScripts)) ? [new ApiViewerAction()] : []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ApiViewerRootAction implements RootAction {
}

private CachedFile generatePlugins() {
Collection<UpdateSite> sites = Jenkins.instance.updateCenter.sites.findAll { it.JSONObject != null }
Collection<UpdateSite> sites = Jenkins.get().updateCenter.sites.findAll { it.JSONObject != null }
long lastModified = sites*.dataTimestamp.max() ?: 0
CachedFile updateCenter = cachedPlugins
if (updateCenter == null || lastModified > updateCenter.timestamp) {
Expand All @@ -70,7 +70,7 @@ class ApiViewerRootAction implements RootAction {
}

// add plugins that are not available in the Update Center
jenkins.model.Jenkins.instance.pluginManager.plugins.each { PluginWrapper plugin ->
jenkins.model.Jenkins.get().pluginManager.plugins.each { PluginWrapper plugin ->
if (!plugins.containsKey(plugin.shortName)) {
JSONObject pluginJson = new JSONObject()
pluginJson.put('name', plugin.shortName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class SeedJobAction implements Action {
}

Item getSeedJob() {
Jenkins.instance.getItemByFullName(seedReference.seedJobName)
Jenkins.get().getItemByFullName(seedReference.seedJobName)
}

Item getTemplateJob() {
String templateJobName = seedReference.templateJobName
templateJobName == null ? null : Jenkins.instance.getItemByFullName(templateJobName)
templateJobName == null ? null : Jenkins.get().getItemByFullName(templateJobName)
}

String getDigest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SeedJobTransientActionFactory extends TransientActionFactory<Item> {
@Nonnull
@Override
Collection<? extends Action> createFor(@Nonnull Item target) {
DescriptorImpl descriptor = Jenkins.instance.getDescriptorByType(DescriptorImpl)
DescriptorImpl descriptor = Jenkins.get().getDescriptorByType(DescriptorImpl)
SeedReference seedReference = descriptor.generatedJobMap[target.fullName]
seedReference != null ? [new SeedJobAction(target, seedReference)] : []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DescribableHelper {
}

private static Class getTypeForLookup(DescribableModel model) {
Describable.isAssignableFrom(model.type) ? Jenkins.instance.getDescriptor(model.type)?.class : model.type
Describable.isAssignableFrom(model.type) ? Jenkins.get().getDescriptor(model.type)?.class : model.type
}

private static List<Descriptor> getDescriptors(Class<?> contextType) {
Expand All @@ -168,9 +168,9 @@ class DescribableHelper {

String className = contextTypeAnnotation.value()
try {
ClassLoader classLoader = Jenkins.instance.pluginManager.uberClassLoader
ClassLoader classLoader = Jenkins.get().pluginManager.uberClassLoader
Class<? extends Describable> type = classLoader.loadClass(className).asSubclass(Describable)
return Jenkins.instance.getDescriptorList(type)
return Jenkins.get().getDescriptorList(type)
} catch (ClassNotFoundException ignore) {
LOGGER.fine("can not get descriptors for '$className', class not found")
return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DescribableListContext implements Context {
*/
DescribableListContext(String type, JobManagement jobManagement) {
this(
Jenkins.instance.getExtensionList(type).collect { Descriptor d -> DescribableModel.of(d.clazz) },
Jenkins.get().getExtensionList(type).collect { Descriptor d -> DescribableModel.of(d.clazz) },
jobManagement
)
}
Expand Down

0 comments on commit 9fdd595

Please sign in to comment.