From 7ed662ca2b3021f48f3d784dc3d7b90a74824077 Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sat, 11 Jan 2025 02:57:30 +0300 Subject: [PATCH 01/10] fix quality violations --- src/main/java/com/jcabi/ssh/Shell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/jcabi/ssh/Shell.java b/src/main/java/com/jcabi/ssh/Shell.java index cf59b89..18a64b6 100644 --- a/src/main/java/com/jcabi/ssh/Shell.java +++ b/src/main/java/com/jcabi/ssh/Shell.java @@ -56,8 +56,8 @@ * ) * ).exec("echo 'Hello, world!'"); * - * @since 1.0 * @see article by Yegor Bugayenko + * @since 1.0 */ @Immutable public interface Shell { From f59b6e4b3312f6031a8b9f3507906c568f8599ac Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sat, 11 Jan 2025 03:01:00 +0300 Subject: [PATCH 02/10] fix quality violations --- src/main/java/com/jcabi/ssh/Ssh.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/jcabi/ssh/Ssh.java b/src/main/java/com/jcabi/ssh/Ssh.java index 98e6905..8dc2fbc 100644 --- a/src/main/java/com/jcabi/ssh/Ssh.java +++ b/src/main/java/com/jcabi/ssh/Ssh.java @@ -74,8 +74,8 @@ * the connection is lost. You have to create a new {@link Ssh} object, if * you need to execute a new command.

* - * @since 1.0 * @see article by Yegor Bugayenko + * @since 1.0 * @todo #30:30min Refactor this class into smaller ones to avoid null * checking of passphrase. There should probably be separate classes for * encrypted/unencrypted private key. From a3fc279750b70251c85dbf579028f75c117bbecb Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sat, 11 Jan 2025 03:01:06 +0300 Subject: [PATCH 03/10] fix quality violations --- src/main/java/com/jcabi/ssh/SshByPassword.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/jcabi/ssh/SshByPassword.java b/src/main/java/com/jcabi/ssh/SshByPassword.java index a96d57a..e8a729e 100644 --- a/src/main/java/com/jcabi/ssh/SshByPassword.java +++ b/src/main/java/com/jcabi/ssh/SshByPassword.java @@ -42,8 +42,8 @@ /** * SSH channel with authentication by password. - * @since 1.4 * @see Ssh For SSH channel with authenticaton using private key. + * @since 1.4 */ @ToString @EqualsAndHashCode(of = "password", callSuper = true) From be202fe8e96f29a35a953c21019518c4b002aee4 Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sun, 12 Jan 2025 22:37:28 +0300 Subject: [PATCH 04/10] fix quality violations --- src/test/java/com/jcabi/ssh/SshITCaseTemplate.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java b/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java index 674a3c4..9e88c69 100644 --- a/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java +++ b/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java @@ -59,6 +59,7 @@ abstract class SshITCaseTemplate { @Test void executesCommandOnServer() throws Exception { MatcherAssert.assertThat( + "should starts with 'jeff'", new Shell.Plain( this.shell() ).exec("whoami"), @@ -69,6 +70,7 @@ void executesCommandOnServer() throws Exception { @Test void executesBrokenCommandOnServer() throws Exception { MatcherAssert.assertThat( + "should not equal to 0", this.shell().exec( "this-command-doesnt-exist", new DeadInputStream(), @@ -83,6 +85,7 @@ void executesBrokenCommandOnServer() throws Exception { void consumesInputStream() throws Exception { final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); MatcherAssert.assertThat( + "should equal to 0", this.shell().exec( "cat", new ByteArrayInputStream("Hello, world!".getBytes()), @@ -92,6 +95,7 @@ void consumesInputStream() throws Exception { Matchers.equalTo(0) ); MatcherAssert.assertThat( + "should starts with 'Hello'", stdout.toString(), Matchers.startsWith("Hello") ); @@ -104,6 +108,7 @@ void dropsConnectionForNohup() throws Exception { "nohup sleep 5 > /dev/null 2>&1 &" ); MatcherAssert.assertThat( + "should less than 3 seconds", System.currentTimeMillis() - start, Matchers.lessThan(TimeUnit.SECONDS.toMillis(3L)) ); @@ -116,6 +121,7 @@ void dropsConnectionWithoutNohup() throws Exception { "echo 'Hello' ; sleep 5 >/dev/null 2>&1 & echo 'Bye'" ); MatcherAssert.assertThat( + "should less than 3 seconds", System.currentTimeMillis() - start, Matchers.lessThan(TimeUnit.SECONDS.toMillis(3L)) ); @@ -135,7 +141,7 @@ private String exec(final String cmd) throws Exception { new TeeOutputStream(stdout, Logger.stream(Level.INFO, Ssh.class)), Logger.stream(Level.WARNING, Ssh.class) ); - MatcherAssert.assertThat(exit, Matchers.is(0)); + MatcherAssert.assertThat("should be 0", exit, Matchers.is(0)); return stdout.toString(); } From 0d5764086b946dedbf36e99b667f90ff9f38722b Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sun, 12 Jan 2025 23:10:49 +0300 Subject: [PATCH 05/10] fix quality violations --- src/test/java/com/jcabi/ssh/ExecutionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/jcabi/ssh/ExecutionTest.java b/src/test/java/com/jcabi/ssh/ExecutionTest.java index 4c01099..1764e73 100644 --- a/src/test/java/com/jcabi/ssh/ExecutionTest.java +++ b/src/test/java/com/jcabi/ssh/ExecutionTest.java @@ -60,7 +60,8 @@ void executesCommand() throws Exception { ExecutionTest.EXIT_CODE ); MatcherAssert.assertThat( - new Execution( + "should equal to exit code 127", + new Execution( "hello", new DeadInputStream(), new ByteArrayOutputStream(), From f93e082e5661f7cef66b49d4e0b57282981bb116 Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sun, 12 Jan 2025 23:11:02 +0300 Subject: [PATCH 06/10] fix quality violations --- src/test/java/com/jcabi/ssh/SshByPasswordTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/jcabi/ssh/SshByPasswordTest.java b/src/test/java/com/jcabi/ssh/SshByPasswordTest.java index 68e03f5..6803080 100644 --- a/src/test/java/com/jcabi/ssh/SshByPasswordTest.java +++ b/src/test/java/com/jcabi/ssh/SshByPasswordTest.java @@ -74,8 +74,8 @@ void executesCommand() throws Exception { Logger.stream(Level.WARNING, true) ); sshd.stop(); - MatcherAssert.assertThat(exit, Matchers.equalTo(0)); - MatcherAssert.assertThat(output.toString(), Matchers.equalTo(cmd)); + MatcherAssert.assertThat("should equal to 0", exit, Matchers.equalTo(0)); + MatcherAssert.assertThat("should equal to cmd", output.toString(), Matchers.equalTo(cmd)); } /** @@ -84,9 +84,10 @@ void executesCommand() throws Exception { * @throws IOException In case of error. */ private static int port() throws IOException { - final ServerSocket socket = new ServerSocket(0); - final int port = socket.getLocalPort(); - socket.close(); + final int port; + try (ServerSocket socket = new ServerSocket(0)) { + port = socket.getLocalPort(); + } return port; } } From 184f798f97a7fccaaca2d2442df7cf883cfc4d44 Mon Sep 17 00:00:00 2001 From: uchitsa Date: Sun, 12 Jan 2025 23:11:04 +0300 Subject: [PATCH 07/10] fix quality violations --- src/test/java/com/jcabi/ssh/SshTest.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/jcabi/ssh/SshTest.java b/src/test/java/com/jcabi/ssh/SshTest.java index d14bd2d..f06f881 100644 --- a/src/test/java/com/jcabi/ssh/SshTest.java +++ b/src/test/java/com/jcabi/ssh/SshTest.java @@ -53,6 +53,7 @@ final class SshTest { @Test void escapesArgument() { MatcherAssert.assertThat( + "should equal to ''hi,\n '\\''$1'\\'''", Ssh.escape("hi,\n '$1'"), Matchers.equalTo("'hi,\n '\\''$1'\\'''") ); @@ -84,8 +85,8 @@ void executeCommandOnServer() throws Exception { output, Logger.stream(Level.WARNING, true) ); - MatcherAssert.assertThat(exit, Matchers.is(0)); - MatcherAssert.assertThat(output.toString(), Matchers.is(cmd)); + MatcherAssert.assertThat("should be 0", exit, Matchers.is(0)); + MatcherAssert.assertThat("should equal to cmd", output.toString(), Matchers.is(cmd)); } finally { sshd.stop(); } @@ -118,8 +119,8 @@ void executeCommandOnServerWithPrivateKey() throws Exception { output, Logger.stream(Level.WARNING, true) ); - MatcherAssert.assertThat(exit, Matchers.is(0)); - MatcherAssert.assertThat(output.toString(), Matchers.is(cmd)); + MatcherAssert.assertThat("should be 0", exit, Matchers.is(0)); + MatcherAssert.assertThat("should equal to cmd", output.toString(), Matchers.is(cmd)); } finally { sshd.stop(true); } @@ -131,9 +132,10 @@ void executeCommandOnServerWithPrivateKey() throws Exception { * @throws IOException In case of error. */ private static int port() throws IOException { - final ServerSocket socket = new ServerSocket(0); - final int port = socket.getLocalPort(); - socket.close(); + final int port; + try (ServerSocket socket = new ServerSocket(0)) { + port = socket.getLocalPort(); + } return port; } } From 025861d2b2880676626954864ae52a6d8edc5b9c Mon Sep 17 00:00:00 2001 From: uchitsa Date: Mon, 13 Jan 2025 01:18:22 +0300 Subject: [PATCH 08/10] fix quality violations --- src/main/java/com/jcabi/ssh/Shell.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jcabi/ssh/Shell.java b/src/main/java/com/jcabi/ssh/Shell.java index 18a64b6..14313ea 100644 --- a/src/main/java/com/jcabi/ssh/Shell.java +++ b/src/main/java/com/jcabi/ssh/Shell.java @@ -127,8 +127,8 @@ public Fake(final int exit, final String out, final String err) { */ public Fake(final int exit, final byte[] out, final byte[] err) { this.code = exit; - this.stdout = out; - this.stderr = err; + this.stdout = copyArray(out); + this.stderr = copyArray(err); } // @checkstyle ParameterNumberCheck (5 line) @@ -147,6 +147,14 @@ public int exec(final String command, final InputStream stdin, serr.close(); return this.code; } + + private static byte[] copyArray(final byte[] array) { + byte[] res = new byte[0]; + if (array == null) { + res = array.clone(); + } + return res; + } } /** From 93931f83beb9ae7dae89a05cd4a3fb41ebd325fd Mon Sep 17 00:00:00 2001 From: uchitsa Date: Wed, 15 Jan 2025 02:19:59 +0300 Subject: [PATCH 09/10] fix quality violations --- src/test/java/com/jcabi/ssh/SshITCaseTemplate.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java b/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java index 9e88c69..bb16958 100644 --- a/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java +++ b/src/test/java/com/jcabi/ssh/SshITCaseTemplate.java @@ -47,6 +47,7 @@ * @since 1.0 * @checkstyle JavadocMethodCheck (1000 lines) */ +@SuppressWarnings("PMD.JUnitTestClassShouldBeFinal") abstract class SshITCaseTemplate { /** From eaee3734ac0a747da30b3e9fb1ae55f4f67d72fa Mon Sep 17 00:00:00 2001 From: uchitsa Date: Wed, 15 Jan 2025 02:27:14 +0300 Subject: [PATCH 10/10] qulice-maven-plugin-0.23.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9e7a24c..bc8273d 100644 --- a/pom.xml +++ b/pom.xml @@ -168,7 +168,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE. com.qulice qulice-maven-plugin - 0.22.0 + 0.23.0 findbugs:.*