Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-71414] Add DataBoundConstructor and Symbol to FolderConfigFileProperty #277

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ ConfigFileStore getStore() {
// TODO only add property when its really needed (eg. don't add it if there is no config to be saved)
FolderConfigFileProperty folderConfigFileProperty = folder.getProperties().get(FolderConfigFileProperty.class);
if(folderConfigFileProperty == null) {
folderConfigFileProperty = new FolderConfigFileProperty(folder);
folderConfigFileProperty = new FolderConfigFileProperty();
try {
folder.addProperty(folderConfigFileProperty);
} catch (IOException e) {
Original file line number Diff line number Diff line change
@@ -6,31 +6,49 @@
import hudson.Extension;
import hudson.model.*;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.ConfigByIdComparator;
import org.jenkinsci.plugins.configfiles.ConfigByNameComparator;
import org.jenkinsci.plugins.configfiles.ConfigFileStore;
import org.jenkinsci.plugins.configfiles.ConfigProviderComparator;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class FolderConfigFileProperty extends AbstractFolderProperty<AbstractFolder<?>> implements ConfigFileStore {

private static Comparator<Config> COMPARATOR = new ConfigByIdComparator();

private static ConfigProviderComparator CONFIGPROVIDER_COMPARATOR = new ConfigProviderComparator();

private Collection<Config> configs = new TreeSet<>(COMPARATOR);
private Collection<Config> configs;

private transient AbstractFolder<?> owner;
/*package*/ FolderConfigFileProperty() {
this((Collection<Config>) null);
}

@Deprecated
/*package*/ FolderConfigFileProperty(AbstractFolder<?> owner) {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
this((Collection<Config>)null);
setOwner(owner);
}

@DataBoundConstructor
public FolderConfigFileProperty(Collection<Config> configs) {
if(configs != null) {
this.configs = configs
.stream()
.collect(Collectors.toCollection(() -> new TreeSet<>(COMPARATOR)));
} else {
this.configs = new TreeSet<>(COMPARATOR);
}
}

@Override
public Collection<Config> getConfigs() {
return configs;
@@ -116,6 +134,7 @@ public FolderConfigFileProperty reconfigure(StaplerRequest req, JSONObject form)
}

@Extension(optional = true)
@Symbol("folderConfigFile")
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
public static class DescriptorImpl extends AbstractFolderPropertyDescriptor {

@Override