Skip to content

Commit 6654496

Browse files
committed
ATO password (partly implemented)
Moving fromone systemto another
1 parent 044ff11 commit 6654496

File tree

7 files changed

+168
-69
lines changed

7 files changed

+168
-69
lines changed

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/OpenSerialMonitorHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
7575
*/
7676
private static int getBaudRate(IProject iProject) {
7777
String setupFunctionName = "setup"; //$NON-NLS-1$
78-
String serialVariable = "Serial.begin"; //$NON-NLS-1$
78+
String functionName = "Serial.begin"; //$NON-NLS-1$
7979

8080
ICProject curProject = CoreModel.getDefault().getCModel().getCProject(iProject.getName());
8181

@@ -104,7 +104,7 @@ private static int getBaudRate(IProject iProject) {
104104
for (IIndexName name : names) {
105105
String SetupFileName = name.getFileLocation().getFileName();
106106
String SetupFileContent = FileUtils.readFileToString(new File(SetupFileName));
107-
int serialBeginStart = SetupFileContent.indexOf(serialVariable);
107+
int serialBeginStart = SetupFileContent.indexOf(functionName);
108108
if (serialBeginStart != -1) {
109109
int serialBeginStartbraket = SetupFileContent.indexOf("(", serialBeginStart); //$NON-NLS-1$
110110
if (serialBeginStartbraket != -1) {

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/PasswordManager.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package it.baeyens.arduino.tools;
22

3+
import org.eclipse.core.runtime.IStatus;
4+
import org.eclipse.core.runtime.Status;
35
import org.eclipse.equinox.security.storage.ISecurePreferences;
46
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
57
import org.eclipse.equinox.security.storage.StorageException;
68
import org.eclipse.jface.window.Window;
79
import org.eclipse.ui.PlatformUI;
810

11+
import it.baeyens.arduino.common.Common;
912
import it.baeyens.arduino.common.Const;
1013
import it.baeyens.arduino.ui.PasswordDialog;
1114

@@ -45,8 +48,7 @@ public boolean setHost(String host) {
4548
this.myLogin = node.get(Messages.security_login, null);
4649
}
4750
if (this.myPassword == null) {
48-
PasswordDialog dialog = new PasswordDialog(
49-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
51+
PasswordDialog dialog = new PasswordDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
5052
if (this.myLogin != null)
5153
dialog.setUser(this.myLogin);
5254
dialog.sethost(host);
@@ -61,14 +63,29 @@ public boolean setHost(String host) {
6163
}
6264
}
6365
} catch (StorageException e) {
64-
// TODO Auto-generated catch block
65-
e.printStackTrace();
66+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to set login info", e)); //$NON-NLS-1$
6667
return false;
6768
}
6869

6970
return true;
7071
}
7172

73+
static public void setPwd(String host, String login, String pwd) {
74+
75+
String nodename = ConvertHostToNodeName(host);
76+
ISecurePreferences root = SecurePreferencesFactory.getDefault();
77+
ISecurePreferences node = root.node(nodename);
78+
79+
try {
80+
node.put(Messages.security_login, login, false);
81+
node.put(Messages.security_password, pwd, false);
82+
} catch (StorageException e) {
83+
84+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to set login info", e)); //$NON-NLS-1$
85+
}
86+
87+
}
88+
7289
public static void ErasePassword(String host) {
7390
String nodename = ConvertHostToNodeName(host);
7491
ISecurePreferences root = SecurePreferencesFactory.getDefault();
@@ -79,8 +96,7 @@ public static void ErasePassword(String host) {
7996
}
8097

8198
} catch (StorageException e) {
82-
// ignore this error
83-
e.printStackTrace();
99+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to erase login info", e)); //$NON-NLS-1$
84100
}
85101

86102
}

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/uploaders/GenericLocalUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected static void RunConsoledCommand(MessageConsole console, String command,
4141
}
4242

4343
@Override
44-
public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer, IProgressMonitor monitor) {
44+
public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IProgressMonitor monitor) {
4545
int step = 1;
4646
String patternTag = "A.TOOLS." + this.myNAmeTag + ".STEP" + step + ".PATTERN"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4747
String commentTag = "A.TOOLS." + this.myNAmeTag + ".STEP" + step + ".NAME"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package it.baeyens.arduino.tools.uploaders;
22

33
import org.eclipse.core.resources.IFile;
4-
import org.eclipse.core.resources.IProject;
54
import org.eclipse.core.runtime.IProgressMonitor;
65

76
public abstract interface IRealUpload {
8-
abstract public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer, IProgressMonitor monitor);
7+
abstract public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IProgressMonitor monitor);
98
}

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/uploaders/SSHUpload.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import java.io.PrintStream;
66

77
import org.eclipse.core.resources.IFile;
8-
import org.eclipse.core.resources.IProject;
98
import org.eclipse.core.runtime.IProgressMonitor;
9+
import org.eclipse.core.runtime.IStatus;
10+
import org.eclipse.core.runtime.Status;
1011
import org.eclipse.ui.console.MessageConsoleStream;
1112

1213
import com.jcraft.jsch.JSch;
@@ -16,42 +17,46 @@
1617
import cc.arduino.packages.ssh.NoInteractionUserInfo;
1718
import cc.arduino.packages.ssh.SCP;
1819
import cc.arduino.packages.ssh.SSH;
20+
import it.baeyens.arduino.common.Common;
1921
import it.baeyens.arduino.common.Const;
2022
import it.baeyens.arduino.tools.PasswordManager;
2123

2224
public class SSHUpload implements IRealUpload {
23-
String myPassword;
25+
2426
String myHost;
25-
String myUser;
27+
2628
private MessageConsoleStream myHighLevelConsoleStream;
2729
private MessageConsoleStream myOutconsole;
2830
private MessageConsoleStream myErrconsole;
2931

30-
SSHUpload(MessageConsoleStream HighLevelConsoleStream, MessageConsoleStream Outconsole, MessageConsoleStream Errconsole, String password,
31-
String host, String user) {
32-
this.myPassword = password;
32+
SSHUpload(MessageConsoleStream HighLevelConsoleStream, MessageConsoleStream Outconsole, MessageConsoleStream Errconsole, String host) {
33+
3334
this.myHost = host;
34-
this.myUser = user;
35+
3536
this.myHighLevelConsoleStream = HighLevelConsoleStream;
3637
this.myErrconsole = Errconsole;
3738
this.myOutconsole = Outconsole;
3839
}
3940

4041
@Override
41-
public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer, IProgressMonitor monitor) {
42+
public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IProgressMonitor monitor) {
4243
boolean ret = true;
4344
if (usingProgrammer) {
4445
this.myHighLevelConsoleStream.println(Messages.Upload_error_network);
4546
return false;
4647
}
48+
PasswordManager pwdManager = new PasswordManager();
49+
if (!pwdManager.setHost(this.myHost)) {
50+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_login_credentials_missing + this.myHost));
51+
}
4752

4853
Session session = null;
4954
SCP scp = null;
5055
try {
5156
JSch jSch = new JSch();
52-
session = jSch.getSession(this.myUser, this.myHost, 22);
57+
session = jSch.getSession(pwdManager.getLogin(), this.myHost, 22);
5358

54-
session.setUserInfo(new NoInteractionUserInfo(this.myPassword));
59+
session.setUserInfo(new NoInteractionUserInfo(pwdManager.getPassword()));
5560
session.connect(30000);
5661

5762
scp = new SCP(session);
@@ -62,7 +67,7 @@ public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean u
6267

6368
// String additionalParams = verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet");
6469
String additionalParams = Const.EMPTY_STRING;// Common.getBuildEnvironmentVariable(myProject, myCConf, ArduinoConst.
65-
// upload.params.quiet, "");
70+
// upload.params.quiet, "");
6671

6772
// not sure why but I need to swap err and out not to get red text
6873
PrintStream stderr = new PrintStream(this.myOutconsole);

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/uploaders/UploadSketchWrapper.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import it.baeyens.arduino.common.Common;
2121
import it.baeyens.arduino.common.Const;
2222
import it.baeyens.arduino.tools.Helpers;
23-
import it.baeyens.arduino.tools.PasswordManager;
2423

2524
public class UploadSketchWrapper {
2625

@@ -58,12 +57,9 @@ public void internalUpload(IProject Project, String cConf) {
5857
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_Project_nature_unaccesible, e));
5958
}
6059

61-
String UpLoadTool = Common.getBuildEnvironmentVariable(Project, cConf,
62-
Const.get_ENV_KEY_TOOL(Const.ACTION_UPLOAD), Const.EMPTY_STRING);
63-
String MComPort = Common.getBuildEnvironmentVariable(Project, cConf, Const.ENV_KEY_JANTJE_COM_PORT,
64-
Const.EMPTY_STRING);
65-
String uploadClass = Common.getBuildEnvironmentVariable(Project, cConf,
66-
Const.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), Const.EMPTY_STRING);
60+
String UpLoadTool = Common.getBuildEnvironmentVariable(Project, cConf, Const.get_ENV_KEY_TOOL(Const.ACTION_UPLOAD), Const.EMPTY_STRING);
61+
String MComPort = Common.getBuildEnvironmentVariable(Project, cConf, Const.ENV_KEY_JANTJE_COM_PORT, Const.EMPTY_STRING);
62+
String uploadClass = Common.getBuildEnvironmentVariable(Project, cConf, Const.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), Const.EMPTY_STRING);
6763

6864
this.myConsole = Helpers.findConsole(Messages.Upload_console);
6965
this.myConsole.clearConsole();
@@ -87,23 +83,13 @@ public void internalUpload(IProject Project, String cConf) {
8783
uploadJobName = UpLoadTool;
8884
} else {
8985
this.myHighLevelConsoleStream.println(Messages.Upload_ssh);
90-
PasswordManager pwdManager = new PasswordManager();
91-
if (!pwdManager.setHost(host)) {
92-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
93-
Messages.Upload_login_credentials_missing + host));
94-
}
95-
96-
String password = pwdManager.getPassword();
97-
String login = pwdManager.getLogin();
9886

99-
realUploader = new SSHUpload(this.myHighLevelConsoleStream, this.myOutconsoleStream,
100-
this.myErrconsoleStream, password, host, login);
87+
realUploader = new SSHUpload(this.myHighLevelConsoleStream, this.myOutconsoleStream, this.myErrconsoleStream, host);
10188
uploadJobName = Const.UPLOAD_SSH;
10289
}
10390
} else if (UpLoadTool.equalsIgnoreCase(Const.UPLOAD_TOOL_TEENSY)) {
10491
this.myHighLevelConsoleStream.println(Messages.Upload_generic);
105-
realUploader = new GenericLocalUploader(UpLoadTool, Project, cConf, this.myConsole, this.myErrconsoleStream,
106-
this.myOutconsoleStream);
92+
realUploader = new GenericLocalUploader(UpLoadTool, Project, cConf, this.myConsole, this.myErrconsoleStream, this.myOutconsoleStream);
10793
uploadJobName = UpLoadTool;
10894
} else {
10995
this.myHighLevelConsoleStream.println(Messages.Upload_arduino);
@@ -122,10 +108,9 @@ public void internalUpload(IProject Project, String cConf) {
122108
protected IStatus run(IProgressMonitor monitor) {
123109
try {
124110
String uploadflag = "FuStatus"; //$NON-NLS-1$
125-
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't',
126-
'/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/',
127-
'u', 'p', 'l', 'o', 'a', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l', '?', 'u',
128-
'=' };
111+
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't', '/', 'e', 'c', 'l', 'i', 'p',
112+
's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'u', 'p', 'l', 'o', 'a', 'd', 'S', 't', 'a', 'r', 't', '.',
113+
'h', 't', 'm', 'l', '?', 'u', '=' };
129114
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
130115
int curFsiStatus = myScope.getInt(uploadflag, 0) + 1;
131116
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
@@ -143,8 +128,7 @@ protected IStatus run(IProgressMonitor monitor) {
143128
}
144129

145130
/**
146-
* UploadJobWrapper stops the serial port and restarts the serial port as
147-
* needed. in between it calls the real uploader IUploader
131+
* UploadJobWrapper stops the serial port and restarts the serial port as needed. in between it calls the real uploader IUploader
148132
*
149133
* @author jan
150134
*
@@ -170,17 +154,15 @@ protected IStatus run(IProgressMonitor monitor) {
170154
try {
171155
monitor.beginTask(Messages.Upload_uploading + " \"" + this.myProject.getName() + "\" " + this.myNAmeTag, //$NON-NLS-1$//$NON-NLS-2$
172156
2);
173-
myComPort = Common.getBuildEnvironmentVariable(this.myProject, this.myCConf,
174-
Const.ENV_KEY_JANTJE_COM_PORT, ""); //$NON-NLS-1$
157+
myComPort = Common.getBuildEnvironmentVariable(this.myProject, this.myCConf, Const.ENV_KEY_JANTJE_COM_PORT, ""); //$NON-NLS-1$
175158

176159
try {
177160
WeStoppedTheComPort = Common.StopSerialMonitor(myComPort);
178161
} catch (Exception e) {
179162
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_com_port, e));
180163
}
181-
IFile hexFile = this.myProject
182-
.getFile(new Path(this.myCConf).append(this.myProject.getName() + ".hex")); //$NON-NLS-1$
183-
if (this.myUploader.uploadUsingPreferences(hexFile, this.myProject, false, monitor)) {
164+
IFile hexFile = this.myProject.getFile(new Path(this.myCConf).append(this.myProject.getName() + ".hex")); //$NON-NLS-1$
165+
if (this.myUploader.uploadUsingPreferences(hexFile, false, monitor)) {
184166
UploadSketchWrapper.this.myHighLevelConsoleStream.println(Messages.Upload_Done);
185167
} else {
186168
UploadSketchWrapper.this.myHighLevelConsoleStream.println(Messages.Upload_failed_upload);
@@ -194,8 +176,7 @@ protected IStatus run(IProgressMonitor monitor) {
194176
Common.StartSerialMonitor(myComPort);
195177
}
196178
} catch (Exception e) {
197-
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
198-
Messages.Upload_Error_serial_monitor_restart, e));
179+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_serial_monitor_restart, e));
199180
}
200181
monitor.done();
201182
}

0 commit comments

Comments
 (0)