Initial attempt to start and connect to NetBeans JavaScript debugger debugger
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 30 Mar 2013 07:55:27 +0100
branchdebugger
changeset 968615c4158fbbb
parent 904 8da928058d88
Initial attempt to start and connect to NetBeans JavaScript debugger
ide/debugger/pom.xml
ide/debugger/src/main/java/org/apidesign/bck2brwsr/debugger/DebugBck2Brwsr.java
ide/debugger/src/main/nbm/manifest.mf
ide/debugger/src/main/resources/org/apidesign/bck2brwsr/debugger/Bundle.properties
ide/pom.xml
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ide/debugger/pom.xml	Sat Mar 30 07:55:27 2013 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     1.6 +    <modelVersion>4.0.0</modelVersion>
     1.7 +    <parent>
     1.8 +        <artifactId>ide</artifactId>
     1.9 +        <groupId>org.apidesign.bck2brwsr</groupId>
    1.10 +        <version>0.6-SNAPSHOT</version>
    1.11 +    </parent>
    1.12 +
    1.13 +    <groupId>org.apidesign.bck2brwsr.ide</groupId>
    1.14 +    <artifactId>debugger</artifactId>
    1.15 +    <version>0.6-SNAPSHOT</version>
    1.16 +    <packaging>nbm</packaging>
    1.17 +
    1.18 +    <name>Debugger</name>
    1.19 +
    1.20 +    <properties>
    1.21 +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    1.22 +        <netbeans.run.params.ide/>
    1.23 +        <netbeans.run.params>${netbeans.run.params.ide}</netbeans.run.params>
    1.24 +    </properties>
    1.25 +
    1.26 +    <repositories>
    1.27 +        <!--
    1.28 +        Repository hosting NetBeans modules, especially APIs.
    1.29 +        Versions are based on IDE releases, e.g.: RELEASE691
    1.30 +        To create your own repository, use: nbm:populate-repository
    1.31 +        -->
    1.32 +        <repository>
    1.33 +            <id>netbeans</id>
    1.34 +            <name>NetBeans</name>
    1.35 +            <url>http://bits.netbeans.org/maven2/</url>
    1.36 +            <snapshots>
    1.37 +                <enabled>false</enabled>
    1.38 +            </snapshots>
    1.39 +        </repository>
    1.40 +    </repositories>
    1.41 +
    1.42 +    <dependencies>
    1.43 +        <dependency>
    1.44 +            <groupId>org.netbeans.api</groupId>
    1.45 +            <artifactId>org-netbeans-api-annotations-common</artifactId>
    1.46 +        </dependency>
    1.47 +        <dependency> 
    1.48 +            <groupId>org.netbeans.modules</groupId>
    1.49 +            <artifactId>org-netbeans-modules-web-browser-api</artifactId>
    1.50 +        </dependency>
    1.51 +        <dependency>
    1.52 +            <artifactId>org-openide-util</artifactId>
    1.53 +            <groupId>org.netbeans.api</groupId>
    1.54 +            <type>jar</type>
    1.55 +        </dependency>
    1.56 +        <dependency>
    1.57 +            <artifactId>org-openide-util-lookup</artifactId>
    1.58 +            <groupId>org.netbeans.api</groupId>
    1.59 +            <type>jar</type>
    1.60 +        </dependency>
    1.61 +        <dependency>
    1.62 +            <artifactId>org-netbeans-modules-projectapi</artifactId>
    1.63 +            <groupId>org.netbeans.api</groupId>
    1.64 +            <type>jar</type>
    1.65 +        </dependency>
    1.66 +        <dependency>
    1.67 +            <groupId>org.netbeans.modules</groupId>
    1.68 +            <artifactId>org-netbeans-modules-web-webkit-debugging</artifactId>
    1.69 +            <version>RELEASE73</version>
    1.70 +        </dependency>
    1.71 +        <dependency>
    1.72 +            <groupId>org.netbeans.api</groupId>
    1.73 +            <artifactId>org-openide-awt</artifactId>
    1.74 +            <version>RELEASE73</version>
    1.75 +        </dependency>
    1.76 +        <dependency>
    1.77 +            <groupId>org.netbeans.modules</groupId>
    1.78 +            <artifactId>org-netbeans-modules-web-javascript-debugger</artifactId>
    1.79 +            <version>RELEASE73</version>
    1.80 +        </dependency>
    1.81 +        <dependency>
    1.82 +            <groupId>org.netbeans.api</groupId>
    1.83 +            <artifactId>org-netbeans-api-debugger</artifactId>
    1.84 +            <version>RELEASE73</version>
    1.85 +        </dependency>
    1.86 +    </dependencies>
    1.87 +
    1.88 +    <build>
    1.89 +        <plugins>
    1.90 +            <plugin>
    1.91 +                <groupId>org.codehaus.mojo</groupId>
    1.92 +                <artifactId>nbm-maven-plugin</artifactId>
    1.93 +                <version>3.9</version>
    1.94 +                <extensions>true</extensions>
    1.95 +                <configuration>
    1.96 +                    <moduleDependencies>
    1.97 +                        <dependency> 
    1.98 +                            <id>org.netbeans.modules:org-netbeans-modules-web-browser-api</id> 
    1.99 +                            <type>impl</type> 
   1.100 +                            <explicitValue>org.netbeans.modules.web.browser.api = 20130326-ee33814e2cc6</explicitValue> 
   1.101 +                        </dependency> 
   1.102 +                        <dependency> 
   1.103 +                            <id>org.netbeans.modules:org-netbeans-modules-web-webkit-debugging</id> 
   1.104 +                            <type>impl</type> 
   1.105 +                            <explicitValue>org.netbeans.modules.web.webkit.debugging = 20130326-ee33814e2cc6</explicitValue> 
   1.106 +                        </dependency> 
   1.107 +                        <dependency> 
   1.108 +                            <id>org.netbeans.modules:org-netbeans-modules-web-common</id> 
   1.109 +                            <type>impl</type> 
   1.110 +                            <explicitValue>org.netbeans.modules.web.common = 20130326-ee33814e2cc6</explicitValue> 
   1.111 +                        </dependency> 
   1.112 +                    </moduleDependencies>
   1.113 +                </configuration>
   1.114 +            </plugin>
   1.115 +
   1.116 +            <plugin>
   1.117 +                <!-- NetBeans 6.9+ requires JDK 6 -->
   1.118 +                <groupId>org.apache.maven.plugins</groupId>
   1.119 +                <artifactId>maven-compiler-plugin</artifactId>
   1.120 +                <version>2.5.1</version>
   1.121 +                <configuration>
   1.122 +                    <source>1.6</source>
   1.123 +                    <target>1.6</target>
   1.124 +                </configuration>
   1.125 +            </plugin>
   1.126 +
   1.127 +            <plugin>
   1.128 +                <groupId>org.apache.maven.plugins</groupId>
   1.129 +                <artifactId>maven-jar-plugin</artifactId>
   1.130 +                <version>2.4</version>
   1.131 +                <configuration>
   1.132 +                    <!-- to have the jar plugin pickup the nbm generated manifest -->
   1.133 +                    <useDefaultManifestFile>true</useDefaultManifestFile>
   1.134 +                </configuration>
   1.135 +            </plugin>
   1.136 +        </plugins>
   1.137 +    </build>
   1.138 +</project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/ide/debugger/src/main/java/org/apidesign/bck2brwsr/debugger/DebugBck2Brwsr.java	Sat Mar 30 07:55:27 2013 +0100
     2.3 @@ -0,0 +1,101 @@
     2.4 +/**
     2.5 + * Back 2 Browser Bytecode Translator
     2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, version 2 of the License.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program. Look for COPYING file in the top folder.
    2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 + */
    2.21 +package org.apidesign.bck2brwsr.debugger;
    2.22 +
    2.23 +import java.awt.event.ActionEvent;
    2.24 +import java.awt.event.ActionListener;
    2.25 +import java.net.MalformedURLException;
    2.26 +import java.net.URL;
    2.27 +import org.netbeans.api.debugger.Session;
    2.28 +import org.netbeans.api.project.Project;
    2.29 +import org.netbeans.modules.web.browser.api.BrowserSupport;
    2.30 +import org.netbeans.modules.web.browser.api.WebBrowser;
    2.31 +import org.netbeans.modules.web.browser.api.WebBrowsers;
    2.32 +import org.netbeans.modules.web.webkit.debugging.api.WebKitDebugging;
    2.33 +import org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory;
    2.34 +import org.openide.awt.ActionID;
    2.35 +import org.openide.awt.ActionReference;
    2.36 +import org.openide.awt.ActionRegistration;
    2.37 +import org.openide.awt.HtmlBrowser;
    2.38 +import org.openide.util.Exceptions;
    2.39 +import org.openide.util.Lookup;
    2.40 +
    2.41 +/**
    2.42 + *
    2.43 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.44 + */
    2.45 +@ActionID(category = "Debug", id = "org.apidesign.bck2brwsr.Debug")
    2.46 +@ActionRegistration(displayName = "Bck2brwsr debugger", asynchronous = true)
    2.47 +@ActionReference(path = "Menu/DebugProject", position = 33333)
    2.48 +public final class DebugBck2Brwsr implements ActionListener {
    2.49 +    private final Project project;
    2.50 +    
    2.51 +    public DebugBck2Brwsr(Project p) {
    2.52 +        this.project = p;
    2.53 +    }
    2.54 +    
    2.55 +
    2.56 +    @Override
    2.57 +    public void actionPerformed(ActionEvent e) {
    2.58 +        try {
    2.59 +            URL url = new URL("http://localhost:8383/HTML5Application/index.html");
    2.60 +            BrowserSupport.getDefaultEmbedded().load(url, project.getProjectDirectory());
    2.61 +            /*
    2.62 +            for (WebBrowser web : WebBrowsers.getInstance().getAll(true)) {
    2.63 +            HtmlBrowser.Impl impl = web.getHtmlBrowserFactory().createHtmlBrowserImpl();
    2.64 +            WebKitDebugging wkd = impl.getLookup().lookup(WebKitDebugging.class);
    2.65 +            if (wkd != null) {
    2.66 +            impl.setURL(url);
    2.67 +            Session session = startSession(wkd, project.getLookup());
    2.68 +            System.err.println("debugging : " + session.getCurrentLanguage());
    2.69 +            return;
    2.70 +            }
    2.71 +            //            Collection<? extends Object> res = pane.getLookup().lookupAll(Object.class);
    2.72 +            System.err.println("res: " + wkd);
    2.73 +            }
    2.74 +             */
    2.75 +        } catch (MalformedURLException ex) {
    2.76 +            Exceptions.printStackTrace(ex);
    2.77 +        }
    2.78 +    }
    2.79 +
    2.80 +    private static Session startSession(WebKitDebugging wkd, Lookup context) {
    2.81 +        final String sevenThree = "org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory";
    2.82 +        final String sevenFour = "org.netbeans.modules.web.webkit.debugging.spi.JavaScriptDebuggerFactory";
    2.83 +        
    2.84 +        Class<?> cls;
    2.85 +        try {
    2.86 +            cls = Class.forName(sevenFour);
    2.87 +        } catch (ClassNotFoundException ex1) {
    2.88 +            try {
    2.89 +                cls = Class.forName(sevenThree);
    2.90 +            } catch (ClassNotFoundException ex) {
    2.91 +                throw new IllegalStateException("Can't start debug session", ex);
    2.92 +            }
    2.93 +        }
    2.94 +        
    2.95 +        Object inst = Lookup.getDefault().lookup(cls);
    2.96 +
    2.97 +        try {
    2.98 +            java.lang.reflect.Method m = cls.getMethod("createDebuggingSession", WebKitDebugging.class, Lookup.class);
    2.99 +            return (Session)m.invoke(inst, wkd, context);
   2.100 +        } catch (Exception ex) {
   2.101 +            throw new IllegalStateException(ex);
   2.102 +        }
   2.103 +    }
   2.104 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/ide/debugger/src/main/nbm/manifest.mf	Sat Mar 30 07:55:27 2013 +0100
     3.3 @@ -0,0 +1,2 @@
     3.4 +Manifest-Version: 1.0
     3.5 +OpenIDE-Module-Localizing-Bundle: org/apidesign/bck2brwsr/debugger/Bundle.properties
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/ide/debugger/src/main/resources/org/apidesign/bck2brwsr/debugger/Bundle.properties	Sat Mar 30 07:55:27 2013 +0100
     4.3 @@ -0,0 +1,23 @@
     4.4 +#
     4.5 +# Back 2 Browser Bytecode Translator
     4.6 +# Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 +#
     4.8 +# This program is free software: you can redistribute it and/or modify
     4.9 +# it under the terms of the GNU General Public License as published by
    4.10 +# the Free Software Foundation, version 2 of the License.
    4.11 +#
    4.12 +# This program is distributed in the hope that it will be useful,
    4.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 +# GNU General Public License for more details.
    4.16 +#
    4.17 +# You should have received a copy of the GNU General Public License
    4.18 +# along with this program. Look for COPYING file in the top folder.
    4.19 +# If not, see http://opensource.org/licenses/GPL-2.0.
    4.20 +#
    4.21 +
    4.22 +# Localized module labels. Defaults taken from POM (<name>, <description>, <groupId>) if unset.
    4.23 +#OpenIDE-Module-Name=
    4.24 +#OpenIDE-Module-Short-Description=
    4.25 +#OpenIDE-Module-Long-Description=
    4.26 +#OpenIDE-Module-Display-Category=
     5.1 --- a/ide/pom.xml	Wed Mar 27 16:51:21 2013 +0100
     5.2 +++ b/ide/pom.xml	Sat Mar 30 07:55:27 2013 +0100
     5.3 @@ -12,6 +12,7 @@
     5.4    <packaging>pom</packaging>
     5.5    <name>IDE Support</name>
     5.6    <modules>
     5.7 +    <module>debugger</module>
     5.8      <module>editor</module>
     5.9    </modules>
    5.10  </project>