Skip to content

Commit

Permalink
JENKINS-38872 allow ConfigProviders to backup from folder support
Browse files Browse the repository at this point in the history
  • Loading branch information
imod committed Nov 16, 2016
1 parent 9e01a1e commit 2698560
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/jenkinsci/lib/configprovider/ConfigProvider.java
Expand Up @@ -116,4 +116,16 @@ public Config newConfig(@NonNull String id) {
public abstract void clearOldDataStorage();


/**
* Tells whether this provider is able to handle configuration files stored on folder level too, or if it only supports global confuguration files.
* This flag will tell the web UI whether a file can be created on a folder.
* Defaults to <code>true</code>, overwrite if your configfiles are not support on folders.
*
* @return <code>true</code> if the provider supports configfiles stored on folder levels too.
* @see org.jenkinsci.plugins.configfiles.GlobalConfigFiles
*/
public boolean supportsFolder() {
return true;
}

}
Expand Up @@ -13,6 +13,8 @@
import java.util.*;

/**
* ConfigFileStore holding config files saved on top level (Jenkins instance).
*
* Created by domi on 17/09/16.
*/
@Extension
Expand Down
@@ -1,14 +1,11 @@
package org.jenkinsci.plugins.configfiles.folder;

import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty;
import com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor;
import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.Extension;
import hudson.Util;
import hudson.model.Action;
import hudson.model.Hudson;
import hudson.security.Permission;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import jenkins.model.TransientActionFactory;
import net.sf.json.JSONObject;
Expand All @@ -24,7 +21,6 @@
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;

public class FolderConfigFileAction implements Action, ConfigFilesUIContract {

Expand Down Expand Up @@ -72,7 +68,14 @@ public Map<ConfigProvider, Collection<Config>> getGroupedConfigs() {

@Override
public List<ConfigProvider> getProviders() {
return ConfigProvider.all();
List<ConfigProvider> all = ConfigProvider.all();
List<ConfigProvider> folderSupportedProviders = new ArrayList<>();
for (ConfigProvider p : all) {
if (p.supportsFolder()){
folderSupportedProviders.add(p);
}
}
return folderSupportedProviders;
}

@Override
Expand Down Expand Up @@ -129,6 +132,7 @@ public void doEditConfig(StaplerRequest req, StaplerResponse rsp, @QueryParamete
req.getView(this, "edit.jelly").forward(req, rsp);
}


@Override
public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter("providerId") String providerId, @QueryParameter("configId") String configId) throws IOException, ServletException {

Expand All @@ -144,7 +148,7 @@ public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter
if (error != null) {
req.setAttribute("error", error);
checkPermission(Hudson.ADMINISTER);
req.setAttribute("providers", ConfigProvider.all());
req.setAttribute("providers", getProviders());
req.setAttribute("configId", configId);
req.getView(this, "selectprovider.jelly").forward(req, rsp);
return;
Expand Down Expand Up @@ -172,7 +176,7 @@ public void doAddConfig(StaplerRequest req, StaplerResponse rsp, @QueryParameter
@Override
public void doSelectProvider(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
checkPermission(Hudson.ADMINISTER);
req.setAttribute("providers", ConfigProvider.all());
req.setAttribute("providers", getProviders());
req.setAttribute("configId", UUID.randomUUID().toString());
req.getView(this, "selectprovider.jelly").forward(req, rsp);
}
Expand Down

0 comments on commit 2698560

Please sign in to comment.