Skip to content

Commit

Permalink
fixed a couple of deprecation warnings (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSpieker authored Jul 16, 2024
1 parent 888fa83 commit 277d812
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/sshslaves/SSHConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context,
}
return new StandardUsernameListBoxModel()
.includeMatchingAs(
ACL.SYSTEM,
ACL.SYSTEM2,
context,
StandardUsernameCredentials.class,
Collections.singletonList(SSHLauncher.SSH_SCHEME),
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/hudson/plugins/sshslaves/SSHLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.NamingThreadFactory;
import hudson.util.NullStream;
import java.util.Collections;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -825,7 +824,7 @@ private void copySlaveJarUsingSCP(TaskListener listener, String workingDirectory
}

// delete the agent jar as we do with SFTP
connection.exec("rm " + workingDirectory + SLASH_AGENT_JAR, new NullStream());
connection.exec("rm " + workingDirectory + SLASH_AGENT_JAR, OutputStream.nullOutputStream());

Check warning on line 827 in src/main/java/hudson/plugins/sshslaves/SSHLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 827 is not covered by tests

// SCP it to the agent. hudson.Util.ByteArrayOutputStream2 doesn't work for this. It pads the byte array.
listener.getLogger().println(Messages.SSHLauncher_CopyingAgentJar(getTimestamp()));
Expand Down Expand Up @@ -1253,7 +1252,7 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath AccessControlled co
int portValue = Integer.parseInt(port);
return new StandardUsernameListBoxModel()
.includeMatchingAs(
ACL.SYSTEM,
ACL.SYSTEM2,
jenkins,
StandardUsernameCredentials.class,
Collections.singletonList(
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/hudson/plugins/sshslaves/SSHLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
Expand Down Expand Up @@ -78,13 +79,15 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class SSHLauncherTest {

@ClassRule
public static BuildWatcher buildWatcher = new BuildWatcher();

@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();

@Rule
public JenkinsRule j = new JenkinsRule();

Expand Down Expand Up @@ -167,7 +170,7 @@ private void checkRoundTrip(String host) throws Exception {
SSHLauncher launcher = new SSHLauncher(host, 123, "dummyCredentialId");
launcher.setSshHostKeyVerificationStrategy(new KnownHostsFileKeyVerificationStrategy());
assertEquals(host.trim(), launcher.getHost());
DumbSlave agent = new DumbSlave("agent", j.createTmpDir().getPath(), launcher);
DumbSlave agent = new DumbSlave("agent", temporaryFolder.newFolder().getAbsolutePath(), launcher);
j.jenkins.addNode(agent);

HtmlPage p = j.createWebClient().getPage(agent, "configure");
Expand Down Expand Up @@ -251,7 +254,7 @@ public void trackCredentialsWithUsernameAndPassword() throws Exception {
launcher.setLaunchTimeoutSeconds(5);
launcher.setRetryWaitTime(5);
launcher.setMaxNumRetries(2);
DumbSlave agent = new DumbSlave("agent", j.createTmpDir().getPath(), launcher);
DumbSlave agent = new DumbSlave("agent", temporaryFolder.newFolder().getAbsolutePath(), launcher);

Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(credentials);
assertThat("No fingerprint created until use", fingerprint, nullValue());
Expand Down Expand Up @@ -279,7 +282,7 @@ public void trackCredentialsWithUsernameAndPrivateKey() throws Exception {
launcher.setLaunchTimeoutSeconds(5);
launcher.setRetryWaitTime(5);
launcher.setMaxNumRetries(2);
DumbSlave agent = new DumbSlave("agent", j.createTmpDir().getPath(), launcher);
DumbSlave agent = new DumbSlave("agent", temporaryFolder.newFolder().getAbsolutePath(), launcher);

Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(credentials);
assertThat("No fingerprint created until use", fingerprint, nullValue());
Expand Down Expand Up @@ -456,7 +459,7 @@ private DumbSlave getPermanentAgentHostNotExist() throws Descriptor.FormExceptio
launcher.setLaunchTimeoutSeconds(5);
launcher.setRetryWaitTime(1);
launcher.setMaxNumRetries(3);
return new DumbSlave("agent", j.createTmpDir().getPath(), launcher);
return new DumbSlave("agent", temporaryFolder.newFolder().getAbsolutePath(), launcher);
}

private void fakeCredentials(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import org.htmlunit.html.HtmlPage;

import hudson.model.Node.Mode;
import hudson.plugins.sshslaves.SSHLauncher;
import hudson.slaves.DumbSlave;
import hudson.slaves.RetentionStrategy;
Expand Down Expand Up @@ -82,15 +81,15 @@ public void testSubmitNotAuthorised() throws Exception {
try {
Object server = newSshServer();
assertNotNull(server);
Class keyPairProviderClass = newKeyPairProviderClass();
Class<?> keyPairProviderClass = newKeyPairProviderClass();
Object provider = newProvider();
assertNotNull(provider);
Object factory = newFactory();
assertNotNull(factory);
Class commandFactoryClass = newCommandFactoryClass();
Class<?> commandFactoryClass = newCommandFactoryClass();
Object commandFactory = newCommandFactory(commandFactoryClass);
assertNotNull(commandFactory);
Class commandAuthenticatorClass = newCommandAuthenticatorClass();
Class<?> commandAuthenticatorClass = newCommandAuthenticatorClass();
Object authenticator = newAuthenticator(commandAuthenticatorClass);
assertNotNull(authenticator);

Expand All @@ -106,9 +105,9 @@ public void testSubmitNotAuthorised() throws Exception {
}

SSHLauncher launcher = new SSHLauncher("localhost", port, "dummyCredentialId", null, "xyz", null, null, 30, 1, 1, new ManuallyTrustedKeyVerificationStrategy(true));
DumbSlave agent = new DumbSlave("test-agent", "SSH Test agent",
temporaryFolder.newFolder().getAbsolutePath(), "1", Mode.NORMAL, "",
launcher, RetentionStrategy.NOOP, Collections.emptyList());
DumbSlave agent = new DumbSlave("test-agent", temporaryFolder.newFolder().getAbsolutePath(), launcher);
agent.setNodeDescription("SSH Test agent");
agent.setRetentionStrategy(RetentionStrategy.NOOP);

jenkins.getInstance().addNode(agent);
SlaveComputer computer = (SlaveComputer) jenkins.getInstance().getComputer("test-agent");
Expand Down Expand Up @@ -136,7 +135,7 @@ public void testSubmitNotAuthorised() throws Exception {
}

private Object newSshServer() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class serverClass;
Class<?> serverClass;
try {
serverClass = Class.forName("org.apache.sshd.SshServer");
} catch (ClassNotFoundException e) {
Expand All @@ -146,8 +145,8 @@ private Object newSshServer() throws ClassNotFoundException, NoSuchMethodExcepti
return serverClass.getDeclaredMethod("setUpDefaultServer", null).invoke(null);

Check warning on line 145 in src/test/java/hudson/plugins/sshslaves/verifiers/TrustHostKeyActionTest.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:testCompile

NORMAL: non-varargs call of varargs method with inexact argument type for last parameter;
}

private Class newKeyPairProviderClass() throws ClassNotFoundException {
Class keyPairProviderClass;
private Class<?> newKeyPairProviderClass() throws ClassNotFoundException {
Class<?> keyPairProviderClass;
try {
keyPairProviderClass = Class.forName("org.apache.sshd.common.KeyPairProvider");
} catch (ClassNotFoundException e) {
Expand All @@ -158,7 +157,7 @@ private Class newKeyPairProviderClass() throws ClassNotFoundException {
}

private Object newProvider() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class providerClass;
Class<?> providerClass;
try {
providerClass = Class.forName("org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider");
} catch (ClassNotFoundException e) {
Expand All @@ -169,7 +168,7 @@ private Object newProvider() throws ClassNotFoundException, NoSuchMethodExceptio
}

private Object newFactory() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class factoryClass;
Class<?> factoryClass;
try {
factoryClass = Class.forName("org.apache.sshd.server.auth.UserAuthPassword$Factory");
} catch (ClassNotFoundException e) {
Expand All @@ -179,18 +178,18 @@ private Object newFactory() throws ClassNotFoundException, NoSuchMethodException
return factoryClass.getConstructor().newInstance();
}

private Class newCommandFactoryClass() throws ClassNotFoundException {
private Class<?> newCommandFactoryClass() throws ClassNotFoundException {
return Class.forName("org.apache.sshd.server.command.CommandFactory");
}

private Object newCommandFactory(Class commandFactoryClass) throws ClassNotFoundException, IllegalArgumentException {
private Object newCommandFactory(Class<?> commandFactoryClass) throws ClassNotFoundException, IllegalArgumentException {
return java.lang.reflect.Proxy.newProxyInstance(
commandFactoryClass.getClassLoader(),
new java.lang.Class[]{commandFactoryClass},
(proxy, method, args) -> {

if (method.getName().equals("createCommand")) {
Class commandClass;
Class<?> commandClass;
try {
commandClass = Class.forName("org.apache.sshd.server.command.UnknownCommand");
} catch (ClassNotFoundException e) {
Expand All @@ -204,8 +203,8 @@ private Object newCommandFactory(Class commandFactoryClass) throws ClassNotFound
});
}

private Class newCommandAuthenticatorClass() throws ClassNotFoundException {
Class passwordAuthenticatorClass;
private Class<?> newCommandAuthenticatorClass() throws ClassNotFoundException {
Class<?> passwordAuthenticatorClass;
try {
passwordAuthenticatorClass = Class.forName("org.apache.sshd.server.PasswordAuthenticator");
} catch(ClassNotFoundException e) {
Expand All @@ -215,7 +214,7 @@ private Class newCommandAuthenticatorClass() throws ClassNotFoundException {
return passwordAuthenticatorClass;
}

private Object newAuthenticator(Class passwordAuthenticatorClass) throws ClassNotFoundException, IllegalArgumentException {
private Object newAuthenticator(Class<?> passwordAuthenticatorClass) throws ClassNotFoundException, IllegalArgumentException {
return java.lang.reflect.Proxy.newProxyInstance(
passwordAuthenticatorClass.getClassLoader(),
new java.lang.Class[]{passwordAuthenticatorClass},
Expand All @@ -229,7 +228,7 @@ private Object newAuthenticator(Class passwordAuthenticatorClass) throws ClassNo
});
}

private Object invoke(Object target, String methodName, Class[] parameterTypes, Object[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
private Object invoke(Object target, String methodName, Class<?>[] parameterTypes, Object[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return target.getClass().getMethod(methodName, parameterTypes).invoke(target, args);
}
}

0 comments on commit 277d812

Please sign in to comment.