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
Show file tree
Hide file tree
Changes from 4 commits
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
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,41 @@
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(null);
}

/*package*/ FolderConfigFileProperty(AbstractFolder<?> owner) {
setOwner(owner);
@DataBoundConstructor
public FolderConfigFileProperty(Collection<Config> configs) {
if(configs != null) {

Check warning on line 37 in src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 37 is only partially covered, one branch is missing
this.configs = configs

Check warning on line 38 in src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 38 is not covered by tests
.stream()

Check warning on line 39 in src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 39 is not covered by tests
.collect(Collectors.toCollection(() -> new TreeSet<>(COMPARATOR)));

Check warning on line 40 in src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 40 is not covered by tests
} else {
this.configs = new TreeSet<>(COMPARATOR);
}
}

@Override
Expand Down Expand Up @@ -116,6 +128,7 @@
}

@Extension(optional = true)
@Symbol("folderConfigFiles")
public static class DescriptorImpl extends AbstractFolderPropertyDescriptor {

@Override
Expand Down