Skip to content

Commit 98f5bdb

Browse files
author
jantje
committed
ATO is now working with security
Note that the plugin reads the pwd from the source code and stores it in the security cache after the upload. The pwd used is the pwd found in the stored cache unless no pwd was found there. This should support changing and removing pwd's without ever having to type one I also added "never and always" as options in the dialog box "build before upload"
1 parent 231314e commit 98f5bdb

File tree

9 files changed

+217
-185
lines changed

9 files changed

+217
-185
lines changed

it.baeyens.arduino.common/META-INF/MANIFEST.MF

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ Bundle-Version: 3.0.0.qualifier
66
Bundle-Activator: it.baeyens.arduino.common.Activator
77
Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.runtime,
9-
org.junit
9+
org.junit,
10+
org.eclipse.wb.core.lib,
11+
org.eclipse.cdt.core
1012
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1113
Bundle-ActivationPolicy: lazy
1214
Export-Package: it.baeyens.arduino.arduino,
1315
it.baeyens.arduino.common
1416
Import-Package: org.eclipse.cdt.core,
1517
org.eclipse.cdt.core.envvar,
18+
org.eclipse.cdt.core.index,
1619
org.eclipse.cdt.core.model,
1720
org.eclipse.cdt.core.settings.model,
1821
org.eclipse.core.resources
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package it.baeyens.arduino.common;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
6+
import org.apache.commons.io.FileUtils;
7+
import org.eclipse.cdt.core.CCorePlugin;
8+
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
9+
import org.eclipse.cdt.core.index.IIndex;
10+
import org.eclipse.cdt.core.index.IIndexBinding;
11+
import org.eclipse.cdt.core.index.IIndexName;
12+
import org.eclipse.cdt.core.index.IndexFilter;
13+
import org.eclipse.cdt.core.model.CoreModel;
14+
import org.eclipse.cdt.core.model.ICProject;
15+
import org.eclipse.core.resources.IProject;
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.core.runtime.NullProgressMonitor;
18+
19+
public class IndexHelper {
20+
/**
21+
* given a list of names from the indexer. Find a function call and return
22+
* the parameter I assume there is only one parameter and it is a string so
23+
* there are quotes
24+
*
25+
* @param names
26+
* the names provided by the indexer
27+
* @param function
28+
* the name of the function for which we are looking for a
29+
* parameter
30+
* @return the string or defaultValue if no string is found
31+
*/
32+
private static String findParameterInFunction(IIndexName[] names, String function, String defaultValue) {
33+
for (IIndexName name : names) {
34+
String SetupFileName = name.getFileLocation().getFileName();
35+
String SetupFileContent;
36+
try {
37+
SetupFileContent = FileUtils.readFileToString(new File(SetupFileName));
38+
} catch (IOException e) {
39+
return defaultValue;
40+
}
41+
SetupFileContent = SetupFileContent.replaceAll("//.*|/\\*((.|\\n)(?!=*/))+\\*/", ""); //$NON-NLS-1$ //$NON-NLS-2$
42+
int serialBeginStart = SetupFileContent.indexOf(function);
43+
if (serialBeginStart != -1) {
44+
int serialBeginStartbraket = SetupFileContent.indexOf("(", serialBeginStart); //$NON-NLS-1$
45+
if (serialBeginStartbraket != -1) {
46+
int serialBeginCloseBraket = SetupFileContent.indexOf(")", serialBeginStartbraket); //$NON-NLS-1$
47+
if (serialBeginCloseBraket != -1) {
48+
return SetupFileContent.substring(serialBeginStartbraket + 1, serialBeginCloseBraket).trim();
49+
50+
}
51+
}
52+
}
53+
}
54+
return defaultValue;
55+
56+
}
57+
58+
/**
59+
* given a project look in the source code for the line of code that sets
60+
* the password;
61+
*
62+
*
63+
*
64+
* return the password string of no_pwd_found_in_code
65+
*
66+
* @param iProject
67+
* @return
68+
*/
69+
public static String findParameterInFunction(IProject project, String parentFunctionName, String childFunctionName,
70+
String defaultValue) {
71+
72+
ICProject curProject = CoreModel.getDefault().getCModel().getCProject(project.getName());
73+
74+
IIndex index = null;
75+
try {
76+
index = CCorePlugin.getIndexManager().getIndex(curProject);
77+
index.acquireReadLock();
78+
IIndexBinding[] bindings = index.findBindings(parentFunctionName.toCharArray(), IndexFilter.ALL_DECLARED,
79+
new NullProgressMonitor());
80+
ICPPFunction parentFunction = null;
81+
for (IIndexBinding curbinding : bindings) {
82+
if (curbinding instanceof ICPPFunction) {
83+
parentFunction = (ICPPFunction) curbinding;
84+
}
85+
}
86+
87+
if (parentFunction == null) {
88+
return defaultValue;// that on found binding must be a function
89+
}
90+
91+
IIndexName[] names = index.findNames(parentFunction, org.eclipse.cdt.core.index.IIndex.FIND_DEFINITIONS);
92+
93+
return findParameterInFunction(names, childFunctionName, defaultValue);
94+
95+
} catch (CoreException | InterruptedException e) {
96+
e.printStackTrace();
97+
} finally {
98+
if (index != null) {
99+
index.releaseReadLock();
100+
}
101+
}
102+
103+
return defaultValue;
104+
}
105+
106+
}

it.baeyens.arduino.common/src/it/baeyens/arduino/common/InstancePreferences.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
import org.eclipse.core.runtime.Status;
1010
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
1111
import org.eclipse.core.runtime.preferences.InstanceScope;
12-
import org.eclipse.swt.SWT;
12+
import org.eclipse.jface.dialogs.MessageDialog;
1313
import org.eclipse.swt.widgets.Display;
14-
import org.eclipse.swt.widgets.MessageBox;
15-
import org.eclipse.swt.widgets.Shell;
16-
import org.eclipse.ui.PlatformUI;
1714
import org.osgi.service.prefs.BackingStoreException;
1815

1916
/**
20-
* ArduinoPreferences is a class containing only static methods that help managing the preferences.
17+
* ArduinoPreferences is a class containing only static methods that help
18+
* managing the preferences.
2119
*
2220
* @author jan Baeyens
2321
*
@@ -46,17 +44,19 @@ public static void setAutomaticallyIncludeLibraries(boolean value) {
4644
}
4745

4846
/***
49-
* get the stored option whether a build before the upload is wanted or not. If nothing is stored the option is ask and this method will pop up a
47+
* get the stored option whether a build before the upload is wanted or not.
48+
* If nothing is stored the option is ask and this method will pop up a
5049
* dialogbox
5150
*
52-
* @return true if a build is wanted before upload false if no build is wanted before upload
51+
* @return true if a build is wanted before upload false if no build is
52+
* wanted before upload
5353
*/
5454
public static boolean getBuildBeforeUploadOption() {
5555

5656
switch (getGlobalString(KEY_BUILD_BEFORE_UPLOAD_OPTION, "ASK")) { //$NON-NLS-1$
57-
case "YES": //$NON-NLS-1$
57+
case Const.TRUE:
5858
return true;
59-
case "NO": //$NON-NLS-1$
59+
case Const.FALSE:
6060
return false;
6161
default:
6262
break;
@@ -70,17 +70,26 @@ boolean getAnswer() {
7070

7171
@Override
7272
public void run() {
73-
Shell theShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
74-
MessageBox dialog = new MessageBox(theShell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
75-
dialog.setText(Messages.Build_before_upload);
76-
dialog.setMessage(Messages.do_you_want_to_build_before_upload);
73+
74+
MessageDialog dialog = new MessageDialog(null, Messages.Build_before_upload, null,
75+
Messages.do_you_want_to_build_before_upload, MessageDialog.QUESTION,
76+
new String[] { "Yes", "No", "Always", "Never" }, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
77+
7778
switch (dialog.open()) {
78-
case SWT.NO:
79+
case 0:
80+
this.ret = true;
81+
break;
82+
case 1:
7983
this.ret = false;
8084
break;
81-
case SWT.YES:
85+
case 2:
86+
setGlobalValue(KEY_BUILD_BEFORE_UPLOAD_OPTION, Const.TRUE);
8287
this.ret = true;
8388
break;
89+
case 3:
90+
setGlobalValue(KEY_BUILD_BEFORE_UPLOAD_OPTION, Const.FALSE);
91+
this.ret = false;
92+
break;
8493
default:
8594
this.ret = false;
8695
break;
@@ -93,7 +102,8 @@ public void run() {
93102
}
94103

95104
/**
96-
* This method reads the name of the last used arduino board from the instance preferences
105+
* This method reads the name of the last used arduino board from the
106+
* instance preferences
97107
*
98108
* @return the Arduino Board name
99109
* @author Jan Baeyens
@@ -173,7 +183,8 @@ public static void setGlobalValue(String key, String Value) {
173183
try {
174184
myScope.flush();
175185
} catch (BackingStoreException e) {
176-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type string " + key)); //$NON-NLS-1$
186+
Common.log(
187+
new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type string " + key)); //$NON-NLS-1$
177188
e.printStackTrace();
178189
}
179190
}
@@ -195,7 +206,8 @@ protected static void setGlobalValue(String key, boolean Value) {
195206
try {
196207
myScope.flush();
197208
} catch (BackingStoreException e) {
198-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type boolean " + key)); //$NON-NLS-1$
209+
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID,
210+
"failed to set global variable of type boolean " + key)); //$NON-NLS-1$
199211
e.printStackTrace();
200212
}
201213
}
@@ -206,13 +218,15 @@ protected static void setGlobalValue(String key, long Value) {
206218
try {
207219
myScope.flush();
208220
} catch (BackingStoreException e) {
209-
Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type long " + key)); //$NON-NLS-1$
221+
Common.log(
222+
new Status(IStatus.WARNING, CORE_PLUGIN_ID, "failed to set global variable of type long " + key)); //$NON-NLS-1$
210223
e.printStackTrace();
211224
}
212225
}
213226

214227
/**
215-
* This method returns the index of the last used line ending options are CR LF CR+LF none
228+
* This method returns the index of the last used line ending options are CR
229+
* LF CR+LF none
216230
*
217231
* @return the index of the last used setting
218232
*/
@@ -221,7 +235,8 @@ public static int getLastUsedSerialLineEnd() {
221235
}
222236

223237
/**
224-
* This method returns the index of the last used line ending options are CR LF CR+LF none
238+
* This method returns the index of the last used line ending options are CR
239+
* LF CR+LF none
225240
*
226241
* @return the index of the last used setting
227242
*/
@@ -278,7 +293,8 @@ public static void setConfigured() {
278293
}
279294

280295
/**
281-
* This method returns boolean whether the plugin is properly configured The plugin is configured properly if a board has been installed
296+
* This method returns boolean whether the plugin is properly configured The
297+
* plugin is configured properly if a board has been installed
282298
*
283299
* @return
284300
*/
@@ -356,8 +372,8 @@ public static void setPrivateHardwarePaths(String[] folderName) {
356372
* @return a list of all the folder locations that can contain hardware
357373
*/
358374
public static String[] getHardwarePaths() {
359-
return (getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, EMPTY_STRING) + File.pathSeparator + ConfigurationPreferences.getInstallationPath())
360-
.split(File.pathSeparator);
375+
return (getGlobalString(KEY_PRIVATE_HARDWARE_PATHS, EMPTY_STRING) + File.pathSeparator
376+
+ ConfigurationPreferences.getInstallationPath()).split(File.pathSeparator);
361377
}
362378

363379
}

it.baeyens.arduino.core/config/pre_processing_platform_default.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ build.system.path={RUNTIME.PLATFORM.PATH}/system
1212
tools.esp8266OTA={tools.esptool.network_cmd}
1313
tools.esp8266OTA.upload.pattern={tools.esptool.upload.network_pattern}
1414
esp8266.network.upload.tool=esp8266OTA
15+
TOOLS.ESPTOOL.NETWORK.PASSWORD={NETWORK.AUTH}

it.baeyens.arduino.core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import javax.jmdns.ServiceListener;
4545
import javax.jmdns.impl.DNSTaskStarter;
4646

47+
import it.baeyens.arduino.common.Const;
48+
4749
public class NetworkDiscovery implements ServiceListener {
4850

4951
private class bonour {
@@ -235,7 +237,7 @@ public static String getAddress(String name) {
235237
public static String getPort(String name) {
236238
bonour board = getBoardByName(name);
237239
if (board == null)
238-
return null;
240+
return Const.EMPTY_STRING;
239241
return board.port;
240242
}
241243

0 commit comments

Comments
 (0)