Skip to content

Commit

Permalink
[FIXED JENKINS-10363] Override defaults in manage jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
bap2000 committed Jul 21, 2011
1 parent 02b5bc5 commit 9e99dd1
Show file tree
Hide file tree
Showing 30 changed files with 1,262 additions and 29 deletions.
Expand Up @@ -73,14 +73,6 @@ public String getDisplayName() {
return Messages.retry_descriptor_displayName();
}

public int getDefaultRetries() {
return Retry.DEFAULT_RETRIES;
}

public long getDefaultRetryDelay() {
return Retry.DEFAULT_RETRY_DELAY;
}

public FormValidation doCheckRetries(@QueryParameter final String value) {
return FormValidation.validateNonNegativeInteger(value);
}
Expand Down
Expand Up @@ -32,14 +32,16 @@
import hudson.tasks.Publisher;
import hudson.util.CopyOnWriteList;
import hudson.util.FormValidation;
import hudson.util.VersionNumber;
import jenkins.plugins.publish_over.BPBuildInfo;
import jenkins.plugins.publish_over.BPInstanceConfig;
import jenkins.plugins.publish_over.BPPlugin;
import jenkins.plugins.publish_over.BPPluginDescriptor;
import jenkins.plugins.publish_over.JenkinsCapabilities;
import jenkins.plugins.publish_over_ftp.BapFtpHostConfiguration;
import jenkins.plugins.publish_over_ftp.BapFtpPublisherPlugin;
import jenkins.plugins.publish_over_ftp.Messages;
import jenkins.plugins.publish_over_ftp.options.FtpDefaults;
import jenkins.plugins.publish_over_ftp.options.FtpPluginDefaults;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand All @@ -54,10 +56,17 @@ public class BapFtpPublisherPluginDescriptor extends BuildStepDescriptor<Publish
/** null - prevent complaints from xstream */
private Class hostConfigClass;
private final CopyOnWriteList<BapFtpHostConfiguration> hostConfigurations = new CopyOnWriteList<BapFtpHostConfiguration>();
private FtpDefaults defaults;

public BapFtpPublisherPluginDescriptor() {
super(BapFtpPublisherPlugin.class);
load();
if (defaults == null)
defaults = new FtpPluginDefaults();
}

public FtpDefaults getDefaults() {
return defaults;
}

public String getDisplayName() {
Expand All @@ -83,18 +92,24 @@ public BapFtpHostConfiguration getConfiguration(final String name) {

public boolean configure(final StaplerRequest request, final JSONObject formData) {
hostConfigurations.replaceBy(request.bindJSONToList(BapFtpHostConfiguration.class, formData.get("instance")));
if (isEnableOverrideDefaults())
defaults = request.bindJSON(FtpDefaults.class, formData.getJSONObject("defaults"));
save();
return true;
}

public boolean canSetMasterNodeName() {
return Hudson.getVersion().isOlderThan(new VersionNumber(BPInstanceConfig.MASTER_GETS_NODE_NAME_IN_VERSION));
return JenkinsCapabilities.missing(JenkinsCapabilities.MASTER_HAS_NODE_NAME);
}

public String getDefaultMasterNodeName() {
return BPInstanceConfig.DEFAULT_MASTER_NODE_NAME;
}

public boolean isEnableOverrideDefaults() {
return JenkinsCapabilities.available(JenkinsCapabilities.SIMPLE_DESCRIPTOR_SELECTOR);
}

public BapFtpPublisherDescriptor getPublisherDescriptor() {
return Hudson.getInstance().getDescriptorByType(BapFtpPublisherDescriptor.class);
}
Expand All @@ -103,10 +118,18 @@ public BapFtpHostConfigurationDescriptor getHostConfigurationDescriptor() {
return Hudson.getInstance().getDescriptorByType(BapFtpHostConfigurationDescriptor.class);
}

public FtpPluginDefaults.FtpPluginDefaultsDescriptor getPluginDefaultsDescriptor() {
return Hudson.getInstance().getDescriptorByType(FtpPluginDefaults.FtpPluginDefaultsDescriptor.class);
}

public jenkins.plugins.publish_over.view_defaults.BPInstanceConfig.Messages getCommonFieldNames() {
return new jenkins.plugins.publish_over.view_defaults.BPInstanceConfig.Messages();
}

public jenkins.plugins.publish_over.view_defaults.manage_jenkins.Messages getCommonManageMessages() {
return new jenkins.plugins.publish_over.view_defaults.manage_jenkins.Messages();
}

public FormValidation doTestConnection(final StaplerRequest request, final StaplerResponse response) {
final BapFtpHostConfiguration hostConfig = request.bindParameters(BapFtpHostConfiguration.class, "");
final BPBuildInfo buildInfo = createDummyBuildInfo();
Expand Down Expand Up @@ -135,6 +158,8 @@ public Object readResolve() {
// nuke the legacy config
msg = null;
hostConfigClass = null;
if (defaults == null)
defaults = new FtpPluginDefaults();
return this;
}

Expand Down
@@ -0,0 +1,53 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.plugins.publish_over_ftp.options;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;

public abstract class FtpDefaults implements Describable<FtpDefaults>, ExtensionPoint, FtpOptions {

public static DescriptorExtensionList<FtpDefaults, FtpDefaultsDescriptor> all() {
return Hudson.getInstance().<FtpDefaults, FtpDefaultsDescriptor>getDescriptorList(FtpDefaults.class);
}

public FtpDefaultsDescriptor getDescriptor() {
return (FtpDefaultsDescriptor) Hudson.getInstance().getDescriptor(getClass());
}

public static abstract class FtpDefaultsDescriptor extends Descriptor<FtpDefaults> {

protected FtpDefaultsDescriptor() { }

protected FtpDefaultsDescriptor(Class<? extends FtpDefaults> clazz) {
super(clazz);
}

}

}
@@ -0,0 +1,42 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.plugins.publish_over_ftp.options;

import jenkins.plugins.publish_over.options.InstanceConfigOptions;
import jenkins.plugins.publish_over.options.ParamPublishOptions;
import jenkins.plugins.publish_over.options.PublisherLabelOptions;
import jenkins.plugins.publish_over.options.PublisherOptions;
import jenkins.plugins.publish_over.options.RetryOptions;

public interface FtpOptions {

InstanceConfigOptions getInstanceConfig();
ParamPublishOptions getParamPublish();
PublisherOptions getPublisher();
PublisherLabelOptions getPublisherLabel();
RetryOptions getRetry();
FtpTransferOptions getTransfer();

}
@@ -0,0 +1,125 @@
/*
* The MIT License
*
* Copyright (C) 2010-2011 by Anthony Robinson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.plugins.publish_over_ftp.options;

import hudson.Extension;
import jenkins.plugins.publish_over.options.InstanceConfigOptions;
import jenkins.plugins.publish_over.options.ParamPublishOptions;
import jenkins.plugins.publish_over.options.PublisherLabelOptions;
import jenkins.plugins.publish_over.options.PublisherOptions;
import jenkins.plugins.publish_over.options.RetryOptions;
import jenkins.plugins.publish_over.view_defaults.manage_jenkins.Messages;
import org.kohsuke.stapler.DataBoundConstructor;

public class FtpOverrideDefaults extends FtpDefaults {

private final FtpOverrideInstanceConfigDefaults overrideInstanceConfig;
private final FtpOverrideParamPublishDefaults overrideParamPublish;
private final FtpOverridePublisherDefaults overridePublisher;
private final FtpOverridePublisherLabelDefaults overridePublisherLabel;
private final FtpOverrideRetryDefaults overrideRetry;
private final FtpOverrideTransferDefaults overrideTransfer;

@DataBoundConstructor
public FtpOverrideDefaults(final FtpOverrideInstanceConfigDefaults overrideInstanceConfig,
final FtpOverrideParamPublishDefaults overrideParamPublish,
final FtpOverridePublisherDefaults overridePublisher,
final FtpOverridePublisherLabelDefaults overridePublisherLabel,
final FtpOverrideRetryDefaults overrideRetry,
final FtpOverrideTransferDefaults overrideTransfer) {
this.overrideInstanceConfig = overrideInstanceConfig;
this.overrideParamPublish = overrideParamPublish;
this.overridePublisher = overridePublisher;
this.overridePublisherLabel = overridePublisherLabel;
this.overrideRetry = overrideRetry;
this.overrideTransfer = overrideTransfer;
}

// prevent the property type being clobbered in the descriptor map by using different names from the IF
public FtpOverrideInstanceConfigDefaults getOverrideInstanceConfig() {
return overrideInstanceConfig;
}

public FtpOverrideParamPublishDefaults getOverrideParamPublish() {
return overrideParamPublish;
}

public FtpOverridePublisherDefaults getOverridePublisher() {
return overridePublisher;
}

public FtpOverridePublisherLabelDefaults getOverridePublisherLabel() {
return overridePublisherLabel;
}

public FtpOverrideRetryDefaults getOverrideRetry() {
return overrideRetry;
}

public FtpOverrideTransferDefaults getOverrideTransfer() {
return overrideTransfer;
}

public InstanceConfigOptions getInstanceConfig() {
return overrideInstanceConfig;
}

public ParamPublishOptions getParamPublish() {
return overrideParamPublish;
}

public PublisherOptions getPublisher() {
return overridePublisher;
}

public PublisherLabelOptions getPublisherLabel() {
return overridePublisherLabel;
}

public RetryOptions getRetry() {
return overrideRetry;
}

public FtpTransferOptions getTransfer() {
return overrideTransfer;
}

@Extension
public static class FtpOverrideDefaultsDescriptor extends FtpDefaultsDescriptor {

private static final FtpPluginDefaults PLUGIN_DEFAULTS = new FtpPluginDefaults();

@Override
public String getDisplayName() {
return Messages.defaults_overrideDefaults();
}

public FtpPluginDefaults getPluginDefaults() {
return PLUGIN_DEFAULTS;
}

}

}

0 comments on commit 9e99dd1

Please sign in to comment.