Skip to content

Commit

Permalink
Merge pull request #25 from HaleyWang/develop
Browse files Browse the repository at this point in the history
support pem file
  • Loading branch information
HaleyWang authored Aug 26, 2020
2 parents 4372eba + 1cbfa08 commit 62e4427
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 8 deletions.
Binary file modified build/libs/SpringRemote-0.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/com/haleywang/putty/util/IoTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void write(String text, File file) {

try (OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream(
file), "utf-8")) {
file), StandardCharsets.UTF_8)) {
writer.write(text);

} catch (IOException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/haleywang/putty/util/SshUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public static String sendCommand(Session sesConnection, String command) throws J
InputStream commandOutput = channelExec.getInputStream();
channelExec.connect();

int endOfStreamFlag = -1;
int readByte = commandOutput.read();

while (readByte != 0xffffffff) {
while (readByte != endOfStreamFlag) {
outputBuffer.append((char) readByte);
readByte = commandOutput.read();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/haleywang/putty/view/ActionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public boolean isCellEditable(int row, int column) {
pack();
setResizable(true);
setLocationRelativeTo(omegaRemote);
searchField.requestFocus();

}

private JTextField initSearchField() {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/haleywang/putty/view/MenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ private MenuView() {
try {
ChannelSftp sftpChannel = SpringRemoteView.getInstance().openSftpChannel();
if (sftpChannel == null) {
NotificationsService.getInstance().showErrorDialog(SpringRemoteView.getInstance(), null, "Can not open sftp");
NotificationsService.getInstance().showErrorDialog(SpringRemoteView.getInstance(), null,
"Can not open sftp, no http connection is currently available.");
return;
}
new SftpDialog(SpringRemoteView.getInstance(), sftpChannel).setVisible(true);

} catch (Exception e1) {
NotificationsService.getInstance().showErrorDialog(SpringRemoteView.getInstance(), null, "Can not open sftp");
NotificationsService.getInstance().showErrorDialog(SpringRemoteView.getInstance(), null,
"Can not open sftp");
LOGGER.error("sftpBtn.addActionListener error", e1);
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/haleywang/putty/view/SpringRemoteView.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;


/**
Expand Down Expand Up @@ -281,8 +282,9 @@ public void mouseClicked(MouseEvent e) {
}


private void createAndAddPuttyPane(JTabbedPane tab, ConnectionDto connectionDto, AccountDto connectionAccount) {
private void createAndAddPuttyPane(JTabbedPane tab, ConnectionDto connectionDto, AccountDto connectionAccountIn) {
String port = StringUtils.ifBlank(connectionDto.getPort(), "22");
AccountDto connectionAccount = Optional.ofNullable(connectionAccountIn).orElse(new AccountDto());

String connectionPassword = null;
String connectionUser = null;
Expand All @@ -291,7 +293,6 @@ private void createAndAddPuttyPane(JTabbedPane tab, ConnectionDto connectionDto,
connectionPassword = connectionAccount.getPassword();
}
connectionUser = connectionDto.getUser() != null ? connectionDto.getUser() : connectionAccount.getName();

}

String pem = StringUtils.ifBlank(connectionDto.getPem(), connectionAccount.getPem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Component;


/**
* @author haley
*/
public class MyTreeCellRenderer extends DefaultTreeCellRenderer {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.haleywang.putty.dto;

import com.haleywang.putty.util.IoTool;
import org.junit.Assert;
import org.junit.Test;

public class RemoteSystemInfoTest {
Expand All @@ -10,7 +11,7 @@ public void ofDiskUsageString() {

RemoteSystemInfo remoteSystemInfo = new RemoteSystemInfo();
remoteSystemInfo.ofDiskUsageString(IoTool.read(RemoteSystemInfoTest.class, "/dto/diskUsage.txt"));
System.out.println("====> " + remoteSystemInfo);
Assert.assertNotNull(remoteSystemInfo.getDiskUsageString());

}

Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/haleywang/putty/util/AesUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public void encrypt() throws Exception {
String key = AesUtil.generateKey("bbb");
String text = "aa";
String encryptText = AesUtil.encrypt(text, key);
System.out.println("====> 1");

Assert.assertEquals(text, AesUtil.decrypt(encryptText, key));

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/haleywang/putty/util/JsonUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.haleywang.putty.util;

import com.haleywang.putty.dto.ConnectionDto;
import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;
Expand All @@ -8,5 +10,14 @@ public class JsonUtilsTest {

@Test
public void fromJson() {

ConnectionDto dto = new ConnectionDto();
dto.setName("1");
dto.setPem("/home/a.pem");

ConnectionDto dto2 = JsonUtils.fromJson(JsonUtils.toJson(dto), ConnectionDto.class);

Assert.assertEquals(dto.getPem(), dto2.getPem());
Assert.assertEquals(dto.getName(), dto2.getName());
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/haleywang/putty/util/Md5UtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.haleywang.putty.util;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;
Expand All @@ -8,5 +9,6 @@ public class Md5UtilsTest {

@Test
public void getT4MD5() {
Assert.assertEquals("f4cc399f0effd13c888e310ea2cf5399", Md5Utils.getT4Md5("123456"));
}
}
4 changes: 4 additions & 0 deletions src/test/java/com/haleywang/putty/util/PathUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.haleywang.putty.util;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;
Expand All @@ -8,9 +9,12 @@ public class PathUtilsTest {

@Test
public void isStartupFromJar() {
Assert.assertFalse(PathUtils.isStartupFromJar(PathUtilsTest.class));
}

@Test
public void getRoot() {
String p = PathUtils.getRoot();
Assert.assertTrue(p.endsWith("test"));
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/haleywang/putty/util/StringUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.haleywang.putty.util;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;
Expand All @@ -8,13 +9,25 @@ public class StringUtilsTest {

@Test
public void trim() {
Assert.assertNull(StringUtils.trim(null));
Assert.assertEquals("", StringUtils.trim(" "));
Assert.assertEquals("a b", StringUtils.trim(" a b "));
}

@Test
public void isBlank() {
Assert.assertTrue(StringUtils.isBlank(null));
Assert.assertTrue(StringUtils.isBlank(""));
Assert.assertTrue(StringUtils.isBlank(" "));
Assert.assertFalse(StringUtils.isBlank(" 1 "));
}

@Test
public void ifBlank() {
String defaultValue = "0";
Assert.assertEquals(defaultValue, StringUtils.ifBlank(null, defaultValue));
Assert.assertEquals(defaultValue, StringUtils.ifBlank("", defaultValue));
Assert.assertEquals(defaultValue, StringUtils.ifBlank(" ", defaultValue));
Assert.assertEquals("1", StringUtils.ifBlank("1", defaultValue));
}
}

0 comments on commit 62e4427

Please sign in to comment.