Skip to content

Commit

Permalink
Merge pull request apache#7931 from matthiasblaesing/cdt_debug_windows
Browse files Browse the repository at this point in the history
JS CDT Debugger: Improve path handling and remember connection settings
  • Loading branch information
matthiasblaesing authored Dec 9, 2024
2 parents 9897ef7 + 8d789ca commit 7f230e8
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ javac.release=11
javadoc.arch=${basedir}/arch.xml

is.eager=true
spec.version.base=1.3.0
spec.version.base=1.4.0
4 changes: 2 additions & 2 deletions webcommon/javascript.cdtdebug.ui/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.0</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void notifyCurrentFrame(CallFrame cf) {
return ;
}
topFrameShown = false;
EditorUtils.showFrameLine(dbg, cf, true);
annotationProcessor.execute(() -> EditorUtils.showFrameLine(dbg, cf, true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
Expand All @@ -38,9 +40,12 @@
import org.openide.filesystems.FileChooserBuilder;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

public class AttachCustomizer extends javax.swing.JPanel {

private static final Logger LOG = Logger.getLogger(ConnectController.class.getName());

private final ConnectController controller;
private final ConnectProperties cproperties = new ConnectProperties();
private final ValidityDocumentListener validityDocumentListener = new ValidityDocumentListener();
Expand All @@ -51,6 +56,7 @@ public class AttachCustomizer extends javax.swing.JPanel {
public AttachCustomizer() {
controller = new ConnectController();
initComponents();
controller.init();
portTextField.getDocument().addDocumentListener(validityDocumentListener);
localSourcesTextField.getDocument().addDocumentListener(validityDocumentListener);
serverPathTextField.getDocument().addDocumentListener(validityDocumentListener);
Expand Down Expand Up @@ -272,7 +278,7 @@ public void changedUpdate(DocumentEvent e) {

public class ConnectController implements PersistentController {

private static final String V8_ATTACH_PROPERTIES = "v8_attach_settings";
private static final String CDT_ATTACH_PROPERTIES = "cdt_attach_settings";
private static final String PROP_HOST = "host";
private static final String PROP_PORT = "port";
private static final String PROP_HAS_SOURCES = "hasSources";
Expand All @@ -290,18 +296,19 @@ public String getDisplayName() {
@Override
public boolean load(Properties props) {
assert !SwingUtilities.isEventDispatchThread();
final Properties attachProps = props.getProperties(V8_ATTACH_PROPERTIES);
final Properties attachProps = props.getProperties(CDT_ATTACH_PROPERTIES);
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
hostTextField.setText(attachProps.getString(PROP_HOST, ""));
portTextField.setText(Integer.toString(attachProps.getInt(PROP_PORT, 0)));
hostTextField.setText(attachProps.getString(PROP_HOST, "localhost"));
portTextField.setText(Integer.toString(attachProps.getInt(PROP_PORT, 9229)));
localSourcesCheckBox.setSelected(attachProps.getBoolean(PROP_HAS_SOURCES, false));
String localPath = attachProps.getString(PROP_LOCAL_PATH, "");
localSourcesTextField.setText(localPath);
String serverPath = attachProps.getString(PROP_SERVER_PATH, "");
serverPathTextField.setText(serverPath);
localSourcesCheckBoxActionPerformed(null);
}
});
} catch (InterruptedException | InvocationTargetException ex) {
Expand All @@ -312,13 +319,15 @@ public void run() {

@Override
public void save(Properties props) {
final Properties attachProps = props.getProperties(V8_ATTACH_PROPERTIES);
final Properties attachProps = props.getProperties(CDT_ATTACH_PROPERTIES);
if (SwingUtilities.isEventDispatchThread()) {
saveToProps(attachProps);
saveToProps(Properties.getDefault().getProperties(CDT_ATTACH_PROPERTIES));
} else {
try {
SwingUtilities.invokeAndWait(() -> {
saveToProps(attachProps);
saveToProps(Properties.getDefault().getProperties(CDT_ATTACH_PROPERTIES));
});
} catch (InterruptedException | InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
Expand Down Expand Up @@ -350,7 +359,12 @@ public boolean ok() {
try {
Connector.connect(cp, null);
} catch (IOException ioex) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(ioex.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE));
LOG.log(Level.INFO, "Failed to connect", ioex);
String message = ioex.getLocalizedMessage();
if(message == null) {
message = ioex.toString();
}
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
return false;
}
return true;
Expand Down Expand Up @@ -393,6 +407,9 @@ public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}

public void init() {
RequestProcessor.getDefault().execute(() -> load(Properties.getDefault()));
}
}

private static final class ConnectProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.awt.datatransfer.Transferable;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.netbeans.lib.chrome_devtools_protocol.debugger.CallFrame;
import org.netbeans.modules.javascript.cdtdebug.CDTDebugger;
Expand Down Expand Up @@ -189,7 +191,16 @@ public String getDisplayName(Object node) throws UnknownTypeException {
static String getScriptName(ScriptsHandler scriptsHandler, CallFrame cf) {
CDTScript script = scriptsHandler.getScript(cf.getLocation().getScriptId());
if (script != null) {
String scriptName = script.getUrl().getPath();
String urlString = script.getUrl();
String scriptName = urlString;
try {
URI url = new URI(urlString);
if(url.getPath() != null) {
scriptName = url.getPath();
}
} catch (URISyntaxException ex) {
return urlString;
}
if (scriptName == null) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion webcommon/javascript.cdtdebug/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ javac.release=11
javadoc.arch=${basedir}/arch.xml

is.autoload=true
spec.version.base=1.3.0
spec.version.base=1.4.0
4 changes: 2 additions & 2 deletions webcommon/javascript.cdtdebug/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.0</specification-version>
<release-version>2</release-version>
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
*/
package org.netbeans.modules.javascript.cdtdebug;

import java.net.URI;
import java.util.Objects;
import org.netbeans.lib.chrome_devtools_protocol.debugger.ScriptFailedToParse;
import org.netbeans.lib.chrome_devtools_protocol.debugger.ScriptParsed;

public class CDTScript {
private final String scriptId;
private final URI url;
private final String url;
private final int startLine;
private final int startColumn;
private final int endLine;
Expand Down Expand Up @@ -59,7 +58,7 @@ public String getScriptId() {
return scriptId;
}

public URI getUrl() {
public String getUrl() {
return url;
}

Expand Down
Loading

0 comments on commit 7f230e8

Please sign in to comment.