Skip to content

Commit

Permalink
Merge pull request #228 from uchitsa/qulice-maven-plugin-0.23.0
Browse files Browse the repository at this point in the history
Update qulice-maven-plugin to v0.23.0
  • Loading branch information
yegor256 authored Jan 16, 2025
2 parents 6d6f216 + eaee373 commit f7f57c6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<plugin>
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<version>0.22.0</version>
<version>0.23.0</version>
<configuration>
<excludes combine.children="append">
<exclude>findbugs:.*</exclude>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/jcabi/ssh/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
* )
* ).exec("echo 'Hello, world!'");</pre>
*
* @since 1.0
* @see <a href="http://www.yegor256.com/2014/09/02/java-ssh-client.html">article by Yegor Bugayenko</a>
* @since 1.0
*/
@Immutable
public interface Shell {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/ssh/Ssh.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.</p>
*
* @since 1.0
* @see <a href="http://www.yegor256.com/2014/09/02/java-ssh-client.html">article by Yegor Bugayenko</a>
* @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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/ssh/SshByPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/jcabi/ssh/ExecutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/jcabi/ssh/SshByPasswordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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;
}
}
9 changes: 8 additions & 1 deletion src/test/java/com/jcabi/ssh/SshITCaseTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @since 1.0
* @checkstyle JavadocMethodCheck (1000 lines)
*/
@SuppressWarnings("PMD.JUnitTestClassShouldBeFinal")
abstract class SshITCaseTemplate {

/**
Expand All @@ -59,6 +60,7 @@ abstract class SshITCaseTemplate {
@Test
void executesCommandOnServer() throws Exception {
MatcherAssert.assertThat(
"should starts with 'jeff'",
new Shell.Plain(
this.shell()
).exec("whoami"),
Expand All @@ -69,6 +71,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(),
Expand All @@ -83,6 +86,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()),
Expand All @@ -92,6 +96,7 @@ void consumesInputStream() throws Exception {
Matchers.equalTo(0)
);
MatcherAssert.assertThat(
"should starts with 'Hello'",
stdout.toString(),
Matchers.startsWith("Hello")
);
Expand All @@ -104,6 +109,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))
);
Expand All @@ -116,6 +122,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))
);
Expand All @@ -135,7 +142,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();
}

Expand Down
16 changes: 9 additions & 7 deletions src/test/java/com/jcabi/ssh/SshTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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'\\'''")
);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}

0 comments on commit f7f57c6

Please sign in to comment.