Skip to content

Commit

Permalink
bump to the oldest jenkins LTS dependency (1.554.3) that allows the u…
Browse files Browse the repository at this point in the history
…se of DataBoundSetter and fix accordingly the code
  • Loading branch information
Mathieu POUSSE committed Dec 15, 2015
1 parent b95bbdf commit 5e5de00
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.532.1</version>
<version>1.554.3</version>
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
import java.io.IOException;
import java.util.Properties;

import jenkins.plugins.publish_over.BPBuildInfo;
import jenkins.plugins.publish_over.BPHostConfiguration;
import jenkins.plugins.publish_over.BapPublisher;
import jenkins.plugins.publish_over.BapPublisherException;
import jenkins.plugins.publish_over.*;
import jenkins.plugins.publish_over_ssh.descriptor.BapSshHostConfigurationDescriptor;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
Expand All @@ -45,6 +42,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

@SuppressWarnings("PMD.TooManyMethods")
public class BapSshHostConfiguration extends BPHostConfiguration<BapSshClient, BapSshCommonConfiguration>
Expand All @@ -62,37 +60,50 @@ public class BapSshHostConfiguration extends BPHostConfiguration<BapSshClient, B
private int timeout;
private boolean overrideKey;
private boolean disableExec;
private final BapSshKeyInfo keyInfo;
private BapSshKeyInfo keyInfo;

private String proxyType;
private String proxyHost;
private int proxyPort;
private String proxyUser;
private String proxyPassword;

// CSOFF: ParameterNumberCheck
@SuppressWarnings("PMD.ExcessiveParameterList") // DBC for you!
@DataBoundConstructor
public BapSshHostConfiguration(final String name, final String hostname, final String username, final String encryptedPassword,
final String remoteRootDir, final int port, final int timeout, final boolean overrideKey,
final String keyPath, final String key, final boolean disableExec, final String proxyType, final String proxyHost, final int proxyPort, final String proxyUser, final String proxyPassword) {
// CSON: ParameterNumberCheck
super(name, hostname, username, null, remoteRootDir, port);
this.timeout = timeout;
this.overrideKey = overrideKey;
keyInfo = new BapSshKeyInfo(encryptedPassword, key, keyPath);
this.disableExec = disableExec;
this.proxyType = proxyType;
this.proxyHost = proxyHost;
this.proxyPassword = proxyPassword;
this.proxyPort = proxyPort;
this.proxyUser = proxyUser;
public BapSshHostConfiguration() {
// use this constructor instead of the default w/o parameters because there is some
// business logic in there...
super(null, null, null, null, null, 0);
this.keyInfo = new BapSshKeyInfo(null, null, null);
}

@DataBoundSetter
@Override
public void setName(String name) {
super.setName(name);
}

@DataBoundSetter
@Override
public void setHostname(String hostname) {
super.setHostname(hostname);
}

@DataBoundSetter
@Override
public void setRemoteRootDir(String remoteRootDir) {
super.setRemoteRootDir(remoteRootDir);
}

@DataBoundSetter
@Override
public void setPort(int port) {
super.setPort(port);
}

public int getTimeout() {
return timeout;
}

@DataBoundSetter
public void setTimeout(final int timeout) {
this.timeout = timeout;
}
Expand All @@ -107,21 +118,31 @@ public final void setPassword(final String password) {
keyInfo.setPassphrase(password);
}

@DataBoundSetter
@Override
public final String getEncryptedPassword() {
return keyInfo.getEncryptedPassphrase();
}

@DataBoundSetter
public void setEncryptedPassword(final String encryptedPassword) {
this.keyInfo.setPassphrase(encryptedPassword);
}

public String getKeyPath() { return keyInfo.getKeyPath(); }
public void setKeyPath(final String keyPath) { keyInfo.setKeyPath(keyPath); }

public String getKey() { return keyInfo.getKey(); }
public void setKey(final String key) { keyInfo.setKey(key); }

public boolean isOverrideKey() { return overrideKey; }

@DataBoundSetter
public void setOverrideKey(final boolean overrideKey) { this.overrideKey = overrideKey; }

public boolean isDisableExec() { return disableExec; }

@DataBoundSetter
public void setDisableExec(final boolean disableExec) { this.disableExec = disableExec; }

public String getProxyType() { return proxyType; }
Expand All @@ -134,6 +155,31 @@ public final String getEncryptedPassword() {

public String getProxyPassword() {return proxyPassword; }

@DataBoundSetter
public void setProxyType(String proxyType) {
this.proxyType = proxyType;
}

@DataBoundSetter
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
}

@DataBoundSetter
public void setProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
}

@DataBoundSetter
public void setProxyUser(String proxyUser) {
this.proxyUser = proxyUser;
}

@DataBoundSetter
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
}

public boolean isEffectiveDisableExec() {
return getCommonConfig().isDisableAllExec() || disableExec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import jenkins.plugins.publish_over.BapPublisherException;
import jenkins.plugins.publish_over_ssh.helper.BapSshTestHelper;
import jenkins.plugins.publish_over_ssh.helper.RandomFile;
import org.easymock.Capture;
import jenkins.plugins.publish_over_ssh.jenkins.JenkinsTestHelper;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.junit.After;
Expand Down Expand Up @@ -440,22 +440,23 @@ public static final class BapSshHostConfigurationWithMockJSch extends BapSshHost
private final transient JSch ssh;

protected BapSshHostConfigurationWithMockJSch(final JSch ssh) {
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, TEST_PASSPHRASE, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, "", "", null, null, 0, null, null);
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, TEST_PASSPHRASE, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, "", "");
}

protected BapSshHostConfigurationWithMockJSch(final JSch ssh, final String overridePassword, final String overrideKeyPath, final String overrideKey) {
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, overridePassword, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, overrideKeyPath, overrideKey, null, null, 0, null, null);
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, overridePassword, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, overrideKeyPath, overrideKey);
}

protected BapSshHostConfigurationWithMockJSch(final JSch ssh, final String proxyType, final String proxyHost, final int proxyPort, final String proxyUser, final String proxyPassword) {
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, TEST_PASSPHRASE, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, "", "", proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
this(ssh, TEST_NAME, TEST_HOSTNAME, TEST_USERNAME, TEST_PASSPHRASE, TEST_REMOTE_ROOT, DEFAULT_PORT, DEFAULT_TIMEOUT, "", "");
JenkinsTestHelper.fillProxySettings(this, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
}

@SuppressWarnings("PMD.ExcessiveParameterList")
protected BapSshHostConfigurationWithMockJSch(final JSch ssh, final String name, final String hostname, final String username,
final String overridePassword, final String remoteRootDir, final int port, final int timeout, final String overrideKeyPath,
final String overrideKey, final String proxyType, final String proxyHost, final int proxyPort, final String proxyUser, final String proxyPassword) {
super(name, hostname, username, overridePassword, remoteRootDir, port, timeout, true, overrideKeyPath, overrideKey, false, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
final String overridePassword, final String remoteRootDir, final int port, final int timeout, final String overrideKeyPath, final String overrideKey) {
super();
JenkinsTestHelper.fill(this, name, hostname, username, overridePassword, remoteRootDir, port, timeout, true, overrideKeyPath, overrideKey, false);
this.ssh = ssh;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void testIntegration() throws Exception {
final ChannelSftp mockSftp = mock(ChannelSftp.class);
final int port = 28;
final int timeout = 3000;
final BapSshHostConfiguration testHostConfig = new BapSshHostConfiguration("testConfig", "testHostname", "testUsername", "",
"/testRemoteRoot", port, timeout, false, "", "", false,null,null,0,null,null) {
final BapSshHostConfiguration testHostConfig = new BapSshHostConfiguration() {
@Override
public JSch createJSch() {
return mockJsch;
Expand All @@ -79,6 +78,8 @@ public Object readResolve() {
return super.readResolve();
}
};
JenkinsTestHelper.fill(testHostConfig, "testConfig", "testHostname", "testUsername", "",
"/testRemoteRoot", port, timeout, false, "", "", false);
final BapSshCommonConfiguration commonConfig = new BapSshCommonConfiguration("passphrase", "key", "", false);
new JenkinsTestHelper().setGlobalConfig(commonConfig, testHostConfig);
final String dirToIgnore = "target";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@

public class JenkinsTestHelper {

public static BapSshHostConfiguration fill(final BapSshHostConfiguration toFill, final String name, final String hostname, final String username, final String encryptedPassword,
final String remoteRootDir, final int port, final int timeout, final boolean overrideKey,
final String keyPath, final String key, final boolean disableExec) {
toFill.setName(name);
toFill.setHostname(hostname);
toFill.setUsername(username);
toFill.setEncryptedPassword(encryptedPassword);
toFill.setRemoteRootDir(remoteRootDir);
toFill.setPort(port);
toFill.setTimeout(timeout);
toFill.setOverrideKey(overrideKey);
toFill.setKeyPath(keyPath);
toFill.setKey(key);
toFill.setDisableExec(disableExec);
return toFill;
}

public static BapSshHostConfiguration fillProxySettings(final BapSshHostConfiguration toFill, final String proxyType, final String proxyHost, final int proxyPort, final String proxyUser, final String proxyPassword) {
toFill.setProxyType(proxyType);
toFill.setProxyHost(proxyHost);
toFill.setProxyPort(proxyPort);
toFill.setProxyUser(proxyUser);
toFill.setProxyPassword(proxyPassword);
return toFill;
}

public static BapSshHostConfiguration prepare(final String name, final String hostname, final String username, final String encryptedPassword,
final String remoteRootDir, final int port, final int timeout, final boolean overrideKey,
final String keyPath, final String key, final boolean disableExec) {
BapSshHostConfiguration bapSshHostConfiguration = new BapSshHostConfiguration();
return fill(bapSshHostConfiguration, name, hostname, username, encryptedPassword, remoteRootDir, port, timeout, overrideKey, keyPath, key, disableExec);
}


public void setGlobalConfig(final BapSshCommonConfiguration commonConfig, final BapSshHostConfiguration... newHostConfigurations)
throws NoSuchFieldException, IllegalAccessException {
for (BapSshHostConfiguration hostConfig : newHostConfigurations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.Collections;
import java.util.List;

import static jenkins.plugins.publish_over_ssh.jenkins.JenkinsTestHelper.prepare;

@SuppressWarnings({ "PMD.SignatureDeclareThrowsException", "PMD.TooManyMethods" })
public class LegacyConfigurationTest extends HudsonTestCase {

Expand All @@ -57,8 +59,8 @@ public class LegacyConfigurationTest extends HudsonTestCase {
public void testLoadR0x1Minimal() throws Exception {
final List<BapSshHostConfiguration> configurations = getPublisherPluginDescriptor().getHostConfigurations();
assertEquals(1, configurations.size());
final BapSshHostConfiguration expected = new BapSshHostConfiguration("default", "hostname", "username", "password", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "", "", false, null,null,0,null,null);
final BapSshHostConfiguration expected = prepare("default", "hostname", "username", "password", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "", "", false);
expected.setCommonConfig(new BapSshCommonConfiguration("", "", "", false));
assertEquals(expected, configurations.get(0));

Expand Down Expand Up @@ -115,14 +117,14 @@ private void assertGlobalConfig() {
final int configDPort = 8022;
final int configDTimeout = 10000;
final BapSshHostConfiguration[] expectedConfig = new BapSshHostConfiguration[] {
new BapSshHostConfiguration(configName('a'), hostname('a'), "username.a", "password.a", "remoteDirectory.a",
DEFAULT_PORT, DEFAULT_TIMEOUT, false, "", "", false, null,null,0,null,null),
new BapSshHostConfiguration(configName('b'), hostname('b'), "username.b", "", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "/an/unencrypted/key", "", false, null,null,0,null,null),
new BapSshHostConfiguration(configName('c'), hostname('c'), "username.c", "", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "", KEY_2, false, null,null,0,null,null),
new BapSshHostConfiguration(configName('d'), hostname('d'), "username.d", "passphrase", "remoteDirectory.d",
configDPort, configDTimeout, true, "path/to/key", KEY_2, false, null,null,0,null,null)
prepare(configName('a'), hostname('a'), "username.a", "password.a", "remoteDirectory.a",
DEFAULT_PORT, DEFAULT_TIMEOUT, false, "", "", false),
prepare(configName('b'), hostname('b'), "username.b", "", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "/an/unencrypted/key", "", false),
prepare(configName('c'), hostname('c'), "username.c", "", "",
DEFAULT_PORT, DEFAULT_TIMEOUT, true, "", KEY_2, false),
prepare(configName('d'), hostname('d'), "username.d", "passphrase", "remoteDirectory.d",
configDPort, configDTimeout, true, "path/to/key", KEY_2, false)
};
final BapSshCommonConfiguration common = new BapSshCommonConfiguration("hello", COMMON_KEY, "/this/will/be/ignored", false);
for (BapSshHostConfiguration hostConfig : expectedConfig) {
Expand Down

0 comments on commit 5e5de00

Please sign in to comment.