Skip to content

Commit

Permalink
Added support for multiple configs
Browse files Browse the repository at this point in the history
During testing I only had a project with a single config so I didn't catch it only writing the the first config it matches against, for now we just write the same tree args to all the configs but it would probably pretty easy to make per folder configs where the config name is in the folder
  • Loading branch information
BeardyKing committed Dec 3, 2023
1 parent 49dcfb1 commit 534d760
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ public void updateClargData(String inCommandLineArguments) {
System.out.println(workspaceFile.getName());

// if we don't resolve environment variable we will have extra "<" and ">" which will break the XML in workspace.xml
inCommandLineArguments = inCommandLineArguments.replace("<", "&lt;");
inCommandLineArguments = inCommandLineArguments.replace(">", "&gt;");
inCommandLineArguments = inCommandLineArguments.replaceAll("<", "&lt;");
inCommandLineArguments = inCommandLineArguments.replaceAll(">", "&gt;");

try {
String xmlContent = new String(workspaceFile.contentsToByteArray(), workspaceFile.getCharset());
String tagToSearch = "<configuration name=";
String attributeToSearch = "type=\"CMakeRunConfiguration\"";
if (xmlContent.contains(tagToSearch) && xmlContent.contains(attributeToSearch)) {
int startIndex = xmlContent.indexOf(tagToSearch);

int startIndex = 0;
while ((startIndex = xmlContent.indexOf(tagToSearch, startIndex)) != -1) {
int endIndex = xmlContent.indexOf(">", startIndex) + 1;
String configurationContent = xmlContent.substring(startIndex, endIndex);

Expand All @@ -74,13 +75,14 @@ public void updateClargData(String inCommandLineArguments) {

if (matcher.find()) {
String match = matcher.group();
configurationContent = configurationContent.replace(match, "PROGRAM_PARAMS=\"" + inCommandLineArguments + "\"");
configurationContent = configurationContent.replaceAll(match, "PROGRAM_PARAMS=\"" + inCommandLineArguments + "\"");
} else {
// likely did not find `PROGRAM_PARAMS` as it doesn't exist in the XML file
// so add `PROGRAM_PARAMS` to `configuration` in the workspace virtual file
configurationContent = configurationContent.replace(">", " PROGRAM_PARAMS=\"" + inCommandLineArguments + "\">");
configurationContent = configurationContent.replaceAll(">", " PROGRAM_PARAMS=\"" + inCommandLineArguments + "\">");
}
xmlContent = xmlContent.substring(0, startIndex) + configurationContent + xmlContent.substring(endIndex);
startIndex = endIndex;
}

Application application = ApplicationManager.getApplication();
Expand All @@ -98,6 +100,7 @@ public void updateClargData(String inCommandLineArguments) {
}
}


public CLArgumentTree() {
JBTabbedPane tabbedPane = new JBTabbedPane();
tabbedPane.addTab("CL Args", createTreeTab());
Expand Down

0 comments on commit 534d760

Please sign in to comment.