Skip to content

Commit

Permalink
added debug capability
Browse files Browse the repository at this point in the history
  • Loading branch information
mastern2k3 committed Mar 10, 2016
1 parent 6282e0b commit 7ec805e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 22 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,36 @@ If you don't have PyCharm you can get it from here: https://www.jetbrains.com/py
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>

<!-- The address of the Quali server on which to deploy, mandatory -->
<entry key="serverRootAddress">localhost</entry>

<!-- The port of the Quali server on which to deploy, defaults to "8029" -->
<entry key="port">8029</entry>

<!-- The unique name of the driver as seen on the portal management, mandatory -->
<entry key="driverUniqueName">driverUniqueName</entry>

<!-- The server admin username, password and domain to use when deploying, defaults to "admin","admin" and "Global" -->
<entry key="username">admin</entry>
<entry key="password">admin</entry>
<entry key="domain">Global</entry>

<!-- Simple patterns to filter when sending the driver to the server separated by semicolons (e.g. "file.xml;logs/"),
on top of the patterns specified here the plugin will automatically filter the "deployment/" and ".idea/" folders and the "deployment.xml" file -->
<entry key="fileFilters">dont_upload_me.xml</entry>

<!-- The folder to refer to as the project source root (if specified, the folder will be zipped
and deployed instead of the whole project), defaults to the root project folder -->
<entry key="sourceRootFolder">src/MyDriver/</entry>

<!-- Decides whether to run the driver from the current project directory for debugging purposes, defaults to "false" -->
<entry key="runFromLocalProject">false</entry>

<!-- When `runFromLocalProject` is enabled, decides whether to wait for a debugger to attach
before running any Python driver code, defaults to "false" -->
<entry key="waitForDebugger">false</entry>

</properties>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

public class DriverPublisherSettings {

String serverRootAddress;
int port;
String driverUniqueName;
String username;
String password;
String domain;
String[] fileFilters;
String sourceRootFolder;

private static final String[] DefaultFileFilters = new String[] { ".idea", "deployment", "deployment.xml" };

public String serverRootAddress;
public int port;
public String driverUniqueName;
public String username;
public String password;
public String domain;
public String[] fileFilters;
public String sourceRootFolder;
public boolean waitForDebugger;
public boolean runFromLocalProject;

public static DriverPublisherSettings fromProperties(Properties deploymentProperties) throws IllegalArgumentException {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class QualiPublishDriverAction extends AnAction {

public static final String DeploymentSettingsFileName = "deployment.xml";
public static final String DebugSettingsFileName = "debug.xml";

public static final String DebugSettingsFormatString =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
"<properties>\n" +
"<entry key=\"loadFrom\">%s</entry>\n" +
"<entry key=\"waitForDebugger\">%s</entry>\n" +
"</properties>\n";

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
Expand Down Expand Up @@ -84,11 +97,11 @@ public void run(@NotNull ProgressIndicator progressIndicator) {

_settings = getDeploymentSettingsFromFile(deploymentSettingsFile);

File zippedProjectFile = zipProjectFolder(project.getBasePath(), _settings);

ResourceManagementService resourceManagementService =
ResourceManagementService.OpenConnection(_settings.serverRootAddress, _settings.port, _settings.username, _settings.password, _settings.domain);

File zippedProjectFile = zipProjectFolder(project.getBasePath(), _settings);

resourceManagementService.updateDriver(_settings.driverUniqueName, zippedProjectFile);

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

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

ZipHelper zipHelper = new ZipHelper(settings.fileFilters);
Map<String, ByteBuffer> extras = new HashMap<>();

if (settings.runFromLocalProject) {

String debugSettingsFileContent = String.format(DebugSettingsFormatString, directory, Boolean.toString(settings.waitForDebugger));

extras.put(DebugSettingsFileName, StandardCharsets.UTF_8.encode(debugSettingsFileContent));
}

ZipHelper zipHelper = new ZipHelper(extras, settings.fileFilters);

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

Expand Down
41 changes: 31 additions & 10 deletions src/com/qualisystems/pythonDriverPlugin/ZipHelper.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package com.qualisystems.pythonDriverPlugin;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipHelper {

private final String[] _filters;
private final Map<String, ByteBuffer> _extraFiles;

public ZipHelper(String... filters) {
public ZipHelper(Map<String, ByteBuffer> extraFiles, String... filters) {

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

if (extraFiles == null)
extraFiles = new HashMap<>();

_filters = filters;
_extraFiles = extraFiles;
}

public ZipHelper(String... filters) {

this(null, filters);
}

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

initialAddFolderToZip(dirName, zip);

for (Map.Entry<String, ByteBuffer> extraFile : _extraFiles.entrySet()) {
addFileToZip("", extraFile.getKey(), zip, false, new ByteArrayInputStream(extraFile.getValue().array(),extraFile.getValue().arrayOffset(), extraFile.getValue().limit()));
}

zip.close();
fW.close();
}
Expand All @@ -47,23 +61,29 @@ private void initialAddFolderToZip(String srcFolder, ZipOutputStream zip) throws
}

private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {

File folder = new File(srcFolder);

if (folder.list().length == 0) {

addFileToZip(path , srcFolder, zip, true);
}
else {

} else {
for (String fileName : folder.list()) {
if (path.equals("")) {
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
}
else {
} else {
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
}
}
}
}

private void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
addFileToZip(path, srcFile, zip, flag, null);
}

private void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag, InputStream fileDataStream) throws IOException {

File folder = new File(srcFile);

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

FileInputStream in = new FileInputStream(srcFile);
InputStream in = fileDataStream == null ? new FileInputStream(srcFile) : fileDataStream;

zip.putNextEntry(new ZipEntry(nameInZip));

while ((len = in.read(buf)) > 0)
Expand Down

0 comments on commit 7ec805e

Please sign in to comment.