Skip to content

Commit 7ec805e

Browse files
committed
added debug capability
1 parent 6282e0b commit 7ec805e

File tree

4 files changed

+83
-22
lines changed

4 files changed

+83
-22
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,36 @@ If you don't have PyCharm you can get it from here: https://www.jetbrains.com/py
3333
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
3434
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
3535
<properties>
36+
3637
<!-- The address of the Quali server on which to deploy, mandatory -->
3738
<entry key="serverRootAddress">localhost</entry>
39+
3840
<!-- The port of the Quali server on which to deploy, defaults to "8029" -->
3941
<entry key="port">8029</entry>
42+
4043
<!-- The unique name of the driver as seen on the portal management, mandatory -->
4144
<entry key="driverUniqueName">driverUniqueName</entry>
45+
4246
<!-- The server admin username, password and domain to use when deploying, defaults to "admin","admin" and "Global" -->
4347
<entry key="username">admin</entry>
4448
<entry key="password">admin</entry>
4549
<entry key="domain">Global</entry>
50+
4651
<!-- Simple patterns to filter when sending the driver to the server separated by semicolons (e.g. "file.xml;logs/"),
4752
on top of the patterns specified here the plugin will automatically filter the "deployment/" and ".idea/" folders and the "deployment.xml" file -->
4853
<entry key="fileFilters">dont_upload_me.xml</entry>
54+
4955
<!-- The folder to refer to as the project source root (if specified, the folder will be zipped
5056
and deployed instead of the whole project), defaults to the root project folder -->
5157
<entry key="sourceRootFolder">src/MyDriver/</entry>
58+
59+
<!-- Decides whether to run the driver from the current project directory for debugging purposes, defaults to "false" -->
60+
<entry key="runFromLocalProject">false</entry>
61+
62+
<!-- When `runFromLocalProject` is enabled, decides whether to wait for a debugger to attach
63+
before running any Python driver code, defaults to "false" -->
64+
<entry key="waitForDebugger">false</entry>
65+
5266
</properties>
5367
```
5468

src/com/qualisystems/pythonDriverPlugin/DriverPublisherSettings.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66

77
public class DriverPublisherSettings {
88

9-
String serverRootAddress;
10-
int port;
11-
String driverUniqueName;
12-
String username;
13-
String password;
14-
String domain;
15-
String[] fileFilters;
16-
String sourceRootFolder;
17-
189
private static final String[] DefaultFileFilters = new String[] { ".idea", "deployment", "deployment.xml" };
1910

11+
public String serverRootAddress;
12+
public int port;
13+
public String driverUniqueName;
14+
public String username;
15+
public String password;
16+
public String domain;
17+
public String[] fileFilters;
18+
public String sourceRootFolder;
19+
public boolean waitForDebugger;
20+
public boolean runFromLocalProject;
21+
2022
public static DriverPublisherSettings fromProperties(Properties deploymentProperties) throws IllegalArgumentException {
2123

2224
if (!deploymentProperties.containsKey("driverUniqueName"))
@@ -34,6 +36,8 @@ public static DriverPublisherSettings fromProperties(Properties deploymentProper
3436
settings.password = deploymentProperties.getProperty("password", "admin");
3537
settings.domain = deploymentProperties.getProperty("domain", "Global");
3638
settings.sourceRootFolder = deploymentProperties.getProperty("sourceRootFolder", null);
39+
settings.waitForDebugger = Boolean.parseBoolean(deploymentProperties.getProperty("waitForDebugger", "false"));
40+
settings.runFromLocalProject = Boolean.parseBoolean(deploymentProperties.getProperty("runFromLocalProject", "false"));
3741

3842
String fileFiltersValue = deploymentProperties.getProperty("fileFilters", "");
3943

src/com/qualisystems/pythonDriverPlugin/QualiPublishDriverAction.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,31 @@
99
import com.intellij.openapi.progress.Task;
1010
import com.intellij.openapi.project.Project;
1111
import com.intellij.openapi.ui.Messages;
12+
import com.sun.org.apache.xpath.internal.operations.Bool;
1213
import org.jetbrains.annotations.NotNull;
1314

1415
import java.io.*;
1516
import java.net.UnknownHostException;
17+
import java.nio.ByteBuffer;
18+
import java.nio.charset.StandardCharsets;
1619
import java.nio.file.Files;
1720
import java.nio.file.Path;
1821
import java.nio.file.Paths;
22+
import java.util.HashMap;
23+
import java.util.Map;
1924
import java.util.Properties;
2025

2126
public class QualiPublishDriverAction extends AnAction {
2227

2328
public static final String DeploymentSettingsFileName = "deployment.xml";
29+
public static final String DebugSettingsFileName = "debug.xml";
30+
31+
public static final String DebugSettingsFormatString =
32+
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
33+
"<properties>\n" +
34+
"<entry key=\"loadFrom\">%s</entry>\n" +
35+
"<entry key=\"waitForDebugger\">%s</entry>\n" +
36+
"</properties>\n";
2437

2538
@Override
2639
public void actionPerformed(AnActionEvent anActionEvent) {
@@ -84,11 +97,11 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
8497

8598
_settings = getDeploymentSettingsFromFile(deploymentSettingsFile);
8699

100+
File zippedProjectFile = zipProjectFolder(project.getBasePath(), _settings);
101+
87102
ResourceManagementService resourceManagementService =
88103
ResourceManagementService.OpenConnection(_settings.serverRootAddress, _settings.port, _settings.username, _settings.password, _settings.domain);
89104

90-
File zippedProjectFile = zipProjectFolder(project.getBasePath(), _settings);
91-
92105
resourceManagementService.updateDriver(_settings.driverUniqueName, zippedProjectFile);
93106

94107
} catch (Exception e) {
@@ -101,7 +114,16 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
101114

102115
private File zipProjectFolder(String directory, DriverPublisherSettings settings) throws IOException {
103116

104-
ZipHelper zipHelper = new ZipHelper(settings.fileFilters);
117+
Map<String, ByteBuffer> extras = new HashMap<>();
118+
119+
if (settings.runFromLocalProject) {
120+
121+
String debugSettingsFileContent = String.format(DebugSettingsFormatString, directory, Boolean.toString(settings.waitForDebugger));
122+
123+
extras.put(DebugSettingsFileName, StandardCharsets.UTF_8.encode(debugSettingsFileContent));
124+
}
125+
126+
ZipHelper zipHelper = new ZipHelper(extras, settings.fileFilters);
105127

106128
Path deploymentFilePath = Paths.get(directory, "deployment", settings.driverUniqueName + ".zip");
107129

src/com/qualisystems/pythonDriverPlugin/ZipHelper.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
package com.qualisystems.pythonDriverPlugin;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
5-
import java.io.FileOutputStream;
6-
import java.io.IOException;
3+
import java.io.*;
4+
import java.nio.ByteBuffer;
75
import java.nio.file.Files;
86
import java.nio.file.Paths;
7+
import java.util.HashMap;
8+
import java.util.Map;
99
import java.util.zip.ZipEntry;
1010
import java.util.zip.ZipOutputStream;
1111

1212
public class ZipHelper {
1313

1414
private final String[] _filters;
15+
private final Map<String, ByteBuffer> _extraFiles;
1516

16-
public ZipHelper(String... filters) {
17+
public ZipHelper(Map<String, ByteBuffer> extraFiles, String... filters) {
1718

1819
if (filters == null)
1920
filters = new String[0];
2021

22+
if (extraFiles == null)
23+
extraFiles = new HashMap<>();
24+
2125
_filters = filters;
26+
_extraFiles = extraFiles;
27+
}
28+
29+
public ZipHelper(String... filters) {
30+
31+
this(null, filters);
2232
}
2333

2434
public void zipDir(String dirName, String nameZipFile) throws IOException {
@@ -33,6 +43,10 @@ public void zipDir(String dirName, String nameZipFile) throws IOException {
3343

3444
initialAddFolderToZip(dirName, zip);
3545

46+
for (Map.Entry<String, ByteBuffer> extraFile : _extraFiles.entrySet()) {
47+
addFileToZip("", extraFile.getKey(), zip, false, new ByteArrayInputStream(extraFile.getValue().array(),extraFile.getValue().arrayOffset(), extraFile.getValue().limit()));
48+
}
49+
3650
zip.close();
3751
fW.close();
3852
}
@@ -47,23 +61,29 @@ private void initialAddFolderToZip(String srcFolder, ZipOutputStream zip) throws
4761
}
4862

4963
private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
64+
5065
File folder = new File(srcFolder);
66+
5167
if (folder.list().length == 0) {
68+
5269
addFileToZip(path , srcFolder, zip, true);
53-
}
54-
else {
70+
71+
} else {
5572
for (String fileName : folder.list()) {
5673
if (path.equals("")) {
5774
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
58-
}
59-
else {
75+
} else {
6076
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
6177
}
6278
}
6379
}
6480
}
6581

6682
private void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
83+
addFileToZip(path, srcFile, zip, flag, null);
84+
}
85+
86+
private void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag, InputStream fileDataStream) throws IOException {
6787

6888
File folder = new File(srcFile);
6989

@@ -88,7 +108,8 @@ private void addFileToZip(String path, String srcFile, ZipOutputStream zip, bool
88108
byte[] buf = new byte[1024];
89109
int len;
90110

91-
FileInputStream in = new FileInputStream(srcFile);
111+
InputStream in = fileDataStream == null ? new FileInputStream(srcFile) : fileDataStream;
112+
92113
zip.putNextEntry(new ZipEntry(nameInZip));
93114

94115
while ((len = in.read(buf)) > 0)

0 commit comments

Comments
 (0)