Skip to content

Commit

Permalink
[FIXED JENKINS-38513] - FolderItemListener should handle the case whe…
Browse files Browse the repository at this point in the history
…n Folder plugin is not installed
  • Loading branch information
oleg-nenashev committed Jan 2, 2017
1 parent e6a4ff3 commit 4382b5c
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;

/**
* Locates changes in {@link AbstractFolder}s and assigns ownership accordingly.
Expand All @@ -44,13 +45,19 @@ public class FolderItemListener extends ItemListener {
private static final Logger LOGGER = Logger.getLogger(FolderItemListener.class.getName());

@Override
public void onCopied(Item src, Item item) {
public void onCopied(Item src, Item item) {
if (!isFoldersPluginEnabled()) {
return;
}
OwnershipDescription d = getPolicy().onCopied(src, item);
modifyOwnership(item, d);
}

@Override
public void onCreated(Item item) {
if (!isFoldersPluginEnabled()) {
return;
}
OwnershipDescription d = getPolicy().onCreated(item);
modifyOwnership(item, d);
}
Expand All @@ -59,6 +66,10 @@ private ItemOwnershipPolicy getPolicy() {
return OwnershipPlugin.getInstance().getConfiguration().getItemOwnershipPolicy();
}

private boolean isFoldersPluginEnabled() {
return Jenkins.getActiveInstance().getPlugin("cloudbees-folder") != null;
}

private void modifyOwnership(Item item, OwnershipDescription ownership) {
if (item instanceof AbstractFolder) {
AbstractFolder<?> folder = (AbstractFolder) item;
Expand Down

0 comments on commit 4382b5c

Please sign in to comment.