Page inspection rewritten.
authorJan Stola <jstola@netbeans.org>
Mon, 12 Aug 2013 17:02:12 +0200
changeset 18004029f636dddcb
parent 18003 5cf7e57fd0eb
child 18005 8cfd42786d90
Page inspection rewritten.
ko4j.debugging/manifest.mf
ko4j.debugging/nbproject/project.xml
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Bundle.properties
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/CliLiveHTML.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/InspectAction.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/MessageDispatcherImpl.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/NbUserDir.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Server.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Transport.java
ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/WebKitDebuggingTransport.java
     1.1 --- a/ko4j.debugging/manifest.mf	Mon Aug 12 09:53:29 2013 +0200
     1.2 +++ b/ko4j.debugging/manifest.mf	Mon Aug 12 17:02:12 2013 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  Manifest-Version: 1.0
     1.5  OpenIDE-Module: org.netbeans.modules.ko4j.debugging
     1.6  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/ko4j/debugging/Bundle.properties
     1.7 -OpenIDE-Module-Specification-Version: 0.2
     1.8 +OpenIDE-Module-Specification-Version: 0.3
     1.9  
     2.1 --- a/ko4j.debugging/nbproject/project.xml	Mon Aug 12 09:53:29 2013 +0200
     2.2 +++ b/ko4j.debugging/nbproject/project.xml	Mon Aug 12 17:02:12 2013 +0200
     2.3 @@ -6,30 +6,12 @@
     2.4              <code-name-base>org.netbeans.modules.ko4j.debugging</code-name-base>
     2.5              <module-dependencies>
     2.6                  <dependency>
     2.7 -                    <code-name-base>org.netbeans.api.debugger</code-name-base>
     2.8 -                    <build-prerequisite/>
     2.9 -                    <compile-dependency/>
    2.10 -                    <run-dependency>
    2.11 -                        <release-version>1</release-version>
    2.12 -                        <specification-version>1.40.1</specification-version>
    2.13 -                    </run-dependency>
    2.14 -                </dependency>
    2.15 -                <dependency>
    2.16                      <code-name-base>org.netbeans.libs.json_simple</code-name-base>
    2.17                      <build-prerequisite/>
    2.18                      <compile-dependency/>
    2.19                      <run-dependency>
    2.20                          <release-version>1</release-version>
    2.21 -                        <specification-version>0.1</specification-version>
    2.22 -                    </run-dependency>
    2.23 -                </dependency>
    2.24 -                <dependency>
    2.25 -                    <code-name-base>org.netbeans.modules.maven</code-name-base>
    2.26 -                    <build-prerequisite/>
    2.27 -                    <compile-dependency/>
    2.28 -                    <run-dependency>
    2.29 -                        <release-version>2</release-version>
    2.30 -                        <specification-version>2.82</specification-version>
    2.31 +                        <specification-version>0.6</specification-version>
    2.32                      </run-dependency>
    2.33                  </dependency>
    2.34                  <dependency>
    2.35 @@ -38,25 +20,39 @@
    2.36                      <compile-dependency/>
    2.37                      <run-dependency>
    2.38                          <release-version>1</release-version>
    2.39 -                        <specification-version>1.50.1</specification-version>
    2.40 +                        <specification-version>1.54</specification-version>
    2.41                      </run-dependency>
    2.42                  </dependency>
    2.43                  <dependency>
    2.44 -                    <code-name-base>org.netbeans.modules.sendopts</code-name-base>
    2.45 +                    <code-name-base>org.netbeans.modules.web.webkit.debugging</code-name-base>
    2.46                      <build-prerequisite/>
    2.47                      <compile-dependency/>
    2.48                      <run-dependency>
    2.49 -                        <release-version>2</release-version>
    2.50 -                        <specification-version>2.27</specification-version>
    2.51 +                        <specification-version>1.27</specification-version>
    2.52                      </run-dependency>
    2.53                  </dependency>
    2.54                  <dependency>
    2.55 -                    <code-name-base>org.netbeans.modules.settings</code-name-base>
    2.56 +                    <code-name-base>org.openide.awt</code-name-base>
    2.57                      <build-prerequisite/>
    2.58                      <compile-dependency/>
    2.59                      <run-dependency>
    2.60 -                        <release-version>1</release-version>
    2.61 -                        <specification-version>1.38.1</specification-version>
    2.62 +                        <specification-version>7.59</specification-version>
    2.63 +                    </run-dependency>
    2.64 +                </dependency>
    2.65 +                <dependency>
    2.66 +                    <code-name-base>org.openide.util</code-name-base>
    2.67 +                    <build-prerequisite/>
    2.68 +                    <compile-dependency/>
    2.69 +                    <run-dependency>
    2.70 +                        <specification-version>8.33</specification-version>
    2.71 +                    </run-dependency>
    2.72 +                </dependency>
    2.73 +                <dependency>
    2.74 +                    <code-name-base>org.openide.util.lookup</code-name-base>
    2.75 +                    <build-prerequisite/>
    2.76 +                    <compile-dependency/>
    2.77 +                    <run-dependency>
    2.78 +                        <specification-version>8.22</specification-version>
    2.79                      </run-dependency>
    2.80                  </dependency>
    2.81                  <dependency>
    2.82 @@ -64,67 +60,7 @@
    2.83                      <build-prerequisite/>
    2.84                      <compile-dependency/>
    2.85                      <run-dependency>
    2.86 -                        <specification-version>1.23</specification-version>
    2.87 -                    </run-dependency>
    2.88 -                </dependency>
    2.89 -                <dependency>
    2.90 -                    <code-name-base>org.netbeans.modules.web.inspect</code-name-base>
    2.91 -                    <run-dependency/>
    2.92 -                </dependency>
    2.93 -                <dependency>
    2.94 -                    <code-name-base>org.netbeans.modules.web.webkit.debugging</code-name-base>
    2.95 -                    <build-prerequisite/>
    2.96 -                    <compile-dependency/>
    2.97 -                    <run-dependency>
    2.98 -                        <specification-version>1.23</specification-version>
    2.99 -                    </run-dependency>
   2.100 -                </dependency>
   2.101 -                <dependency>
   2.102 -                    <code-name-base>org.openide.awt</code-name-base>
   2.103 -                    <build-prerequisite/>
   2.104 -                    <compile-dependency/>
   2.105 -                    <run-dependency>
   2.106 -                        <specification-version>7.55.1</specification-version>
   2.107 -                    </run-dependency>
   2.108 -                </dependency>
   2.109 -                <dependency>
   2.110 -                    <code-name-base>org.openide.filesystems</code-name-base>
   2.111 -                    <build-prerequisite/>
   2.112 -                    <compile-dependency/>
   2.113 -                    <run-dependency>
   2.114 -                        <specification-version>8.5.1</specification-version>
   2.115 -                    </run-dependency>
   2.116 -                </dependency>
   2.117 -                <dependency>
   2.118 -                    <code-name-base>org.openide.modules</code-name-base>
   2.119 -                    <build-prerequisite/>
   2.120 -                    <compile-dependency/>
   2.121 -                    <run-dependency>
   2.122 -                        <specification-version>7.38</specification-version>
   2.123 -                    </run-dependency>
   2.124 -                </dependency>
   2.125 -                <dependency>
   2.126 -                    <code-name-base>org.openide.util</code-name-base>
   2.127 -                    <build-prerequisite/>
   2.128 -                    <compile-dependency/>
   2.129 -                    <run-dependency>
   2.130 -                        <specification-version>8.29.2</specification-version>
   2.131 -                    </run-dependency>
   2.132 -                </dependency>
   2.133 -                <dependency>
   2.134 -                    <code-name-base>org.openide.util.lookup</code-name-base>
   2.135 -                    <build-prerequisite/>
   2.136 -                    <compile-dependency/>
   2.137 -                    <run-dependency>
   2.138 -                        <specification-version>8.19.1</specification-version>
   2.139 -                    </run-dependency>
   2.140 -                </dependency>
   2.141 -                <dependency>
   2.142 -                    <code-name-base>org.openide.windows</code-name-base>
   2.143 -                    <build-prerequisite/>
   2.144 -                    <compile-dependency/>
   2.145 -                    <run-dependency>
   2.146 -                        <specification-version>6.60.1</specification-version>
   2.147 +                        <specification-version>1.30</specification-version>
   2.148                      </run-dependency>
   2.149                  </dependency>
   2.150              </module-dependencies>
     3.1 --- a/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Bundle.properties	Mon Aug 12 09:53:29 2013 +0200
     3.2 +++ b/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Bundle.properties	Mon Aug 12 17:02:12 2013 +0200
     3.3 @@ -1,1 +1,1 @@
     3.4 -OpenIDE-Module-Name=Live HTML Command Line Interface
     3.5 +OpenIDE-Module-Name=KO4J Inspection
     4.1 --- a/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/CliLiveHTML.java	Mon Aug 12 09:53:29 2013 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,179 +0,0 @@
     4.4 -/*
     4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 - *
     4.7 - * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
     4.8 - *
     4.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    4.10 - * Other names may be trademarks of their respective owners.
    4.11 - *
    4.12 - * The contents of this file are subject to the terms of either the GNU
    4.13 - * General Public License Version 2 only ("GPL") or the Common
    4.14 - * Development and Distribution License("CDDL") (collectively, the
    4.15 - * "License"). You may not use this file except in compliance with the
    4.16 - * License. You can obtain a copy of the License at
    4.17 - * http://www.netbeans.org/cddl-gplv2.html
    4.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.19 - * specific language governing permissions and limitations under the
    4.20 - * License.  When distributing the software, include this License Header
    4.21 - * Notice in each file and include the License file at
    4.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    4.23 - * particular file as subject to the "Classpath" exception as provided
    4.24 - * by Oracle in the GPL Version 2 section of the License file that
    4.25 - * accompanied this code. If applicable, add the following below the
    4.26 - * License Header, with the fields enclosed by brackets [] replaced by
    4.27 - * your own identifying information:
    4.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    4.29 - *
    4.30 - * If you wish your version of this file to be governed by only the CDDL
    4.31 - * or only the GPL Version 2, indicate your decision by adding
    4.32 - * "[Contributor] elects to include this software in this distribution
    4.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.34 - * single choice of license, a recipient has the option to distribute
    4.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    4.36 - * to extend the choice of license to its licensees as provided above.
    4.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    4.38 - * Version 2 license, then the option applies only if the new code is
    4.39 - * made subject to such option by the copyright holder.
    4.40 - *
    4.41 - * Contributor(s):
    4.42 - *
    4.43 - * Portions Copyrighted 2013 Sun Microsystems, Inc.
    4.44 - */
    4.45 -package org.netbeans.modules.ko4j.debugging;
    4.46 -
    4.47 -import java.io.Closeable;
    4.48 -import java.io.File;
    4.49 -import java.io.InputStream;
    4.50 -import java.io.PrintStream;
    4.51 -import java.util.logging.Level;
    4.52 -import java.util.logging.Logger;
    4.53 -import org.netbeans.api.debugger.Session;
    4.54 -import org.netbeans.api.project.FileOwnerQuery;
    4.55 -import org.netbeans.api.project.Project;
    4.56 -import org.netbeans.api.sendopts.CommandException;
    4.57 -import org.netbeans.modules.web.browser.api.PageInspector;
    4.58 -import org.netbeans.modules.web.browser.spi.MessageDispatcher;
    4.59 -import org.netbeans.modules.web.webkit.debugging.api.WebKitDebugging;
    4.60 -import org.netbeans.modules.web.webkit.debugging.api.WebKitUIManager;
    4.61 -import org.netbeans.modules.web.webkit.debugging.spi.Factory;
    4.62 -import org.netbeans.spi.sendopts.Arg;
    4.63 -import org.netbeans.spi.sendopts.ArgsProcessor;
    4.64 -import org.netbeans.spi.sendopts.Env;
    4.65 -import org.openide.filesystems.FileObject;
    4.66 -import org.openide.filesystems.FileUtil;
    4.67 -import org.openide.util.Exceptions;
    4.68 -import org.openide.util.Lookup;
    4.69 -import org.openide.util.NbBundle;
    4.70 -import org.openide.util.lookup.Lookups;
    4.71 -
    4.72 -/**
    4.73 - *
    4.74 - * @author Jaroslav Tulach
    4.75 - */
    4.76 -public final class CliLiveHTML implements ArgsProcessor {
    4.77 -    private static final Logger LOG = Logger.getLogger(CliLiveHTML.class.getName());
    4.78 -    private static DbgSession session;
    4.79 -    
    4.80 -    @Arg(longName = "livehtml")
    4.81 -    public String file; 
    4.82 -
    4.83 -    @NbBundle.Messages({
    4.84 -        "# {0} - the url",
    4.85 -        "MSG_InvalidURL=Invalid URL provided '{0}'",
    4.86 -        "# {0} - the file",
    4.87 -        "MSG_InvalidFile=File {0} does not exist",
    4.88 -        "# {0} - the file",
    4.89 -        "MSG_NoProject=Can't find project for {0} file"
    4.90 -    })
    4.91 -    @Override
    4.92 -    public void process(Env env) throws CommandException {
    4.93 -        FileObject fo = findFileObject(env);
    4.94 -        {
    4.95 -            DbgSession prev = session;
    4.96 -            if (prev != null) {
    4.97 -                session = null;
    4.98 -                try {
    4.99 -                    prev.close();
   4.100 -                } catch (Throwable ex) {
   4.101 -                    LOG.log(Level.INFO, "Can't close previous session",ex);
   4.102 -                }
   4.103 -            }
   4.104 -        }
   4.105 -        session = new DbgSession(fo, env);
   4.106 -    }
   4.107 -
   4.108 -    private FileObject findFileObject(Env env) throws CommandException {
   4.109 -        File f = new File(file);
   4.110 -        if (!f.exists()) {
   4.111 -            File rel = new File(env.getCurrentDirectory(), file);
   4.112 -            if (rel.exists()) {
   4.113 -                f = rel;
   4.114 -            }
   4.115 -        }
   4.116 -        if (!f.exists()) {
   4.117 -            throw new CommandException(2, Bundle.MSG_InvalidFile(file));
   4.118 -        }
   4.119 -        FileObject fo = FileUtil.toFileObject(f);
   4.120 -        if (fo == null) {
   4.121 -            throw new CommandException(2, Bundle.MSG_InvalidFile(file));
   4.122 -        }
   4.123 -        return fo;
   4.124 -    }
   4.125 -    
   4.126 -    
   4.127 -    private static class DbgSession extends MessageDispatcher 
   4.128 -    implements Closeable {
   4.129 -        private final WebKitDebuggingTransport transport;
   4.130 -        private final Session debugSession;
   4.131 -        private final WebKitDebugging webKitDebugging;
   4.132 -        
   4.133 -        DbgSession(FileObject fo, final Env env) {
   4.134 -            transport = new WebKitDebuggingTransport() {
   4.135 -                @Override
   4.136 -                protected InputStream inputStream() {
   4.137 -                    return env.getInputStream();
   4.138 -                }
   4.139 -
   4.140 -                @Override
   4.141 -                protected PrintStream outputStream() {
   4.142 -                    return env.getOutputStream();
   4.143 -                }
   4.144 -                
   4.145 -            };
   4.146 -            //        transport.setBaseUrl(url);
   4.147 -            webKitDebugging = Factory.createWebKitDebugging(transport);
   4.148 -            transport.attach();
   4.149 -            try {
   4.150 -                Thread.sleep(1000);
   4.151 -            } catch (InterruptedException ex) {
   4.152 -                Exceptions.printStackTrace(ex);
   4.153 -            }
   4.154 -    //        if (navigateToUrl) {
   4.155 -    //            webKitDebugging.getPage().navigate(url);
   4.156 -    //        }
   4.157 -            LOG.log(Level.INFO, "Initializing livehtml for {0}", fo);
   4.158 -            Project p = FileOwnerQuery.getOwner(fo);
   4.159 -            webKitDebugging.getDebugger().enable();
   4.160 -            Lookup projectContext = Lookups.singleton(p);
   4.161 -            debugSession = WebKitUIManager.getDefault().createDebuggingSession(webKitDebugging, projectContext);
   4.162 -            Lookup consoleLogger = WebKitUIManager.getDefault().createBrowserConsoleLogger(webKitDebugging, projectContext);
   4.163 -            Lookup networkMonitor = WebKitUIManager.getDefault().createNetworkMonitor(webKitDebugging, projectContext);
   4.164 -            PageInspector.getDefault().inspectPage(Lookups.fixed(webKitDebugging, p, this));
   4.165 -            LOG.log(Level.INFO, "Initialization done for {0}", fo);
   4.166 -            transport.waitFinished();
   4.167 -        }
   4.168 -
   4.169 -        @Override
   4.170 -        public void dispatchMessage( String featureId, String message ) {
   4.171 -            super.dispatchMessage( featureId, message );
   4.172 -        }
   4.173 -
   4.174 -        @Override
   4.175 -        public void close() {
   4.176 -            transport.detach();
   4.177 -            webKitDebugging.getDebugger().disable();
   4.178 -            debugSession.kill();
   4.179 -        }
   4.180 -
   4.181 -    }
   4.182 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/InspectAction.java	Mon Aug 12 17:02:12 2013 +0200
     5.3 @@ -0,0 +1,72 @@
     5.4 +/*
     5.5 + * To change this license header, choose License Headers in Project Properties.
     5.6 + * To change this template file, choose Tools | Templates
     5.7 + * and open the template in the editor.
     5.8 + */
     5.9 +package org.netbeans.modules.ko4j.debugging;
    5.10 +
    5.11 +import java.awt.event.ActionEvent;
    5.12 +import javax.swing.AbstractAction;
    5.13 +import javax.swing.Action;
    5.14 +import org.netbeans.api.project.Project;
    5.15 +import org.netbeans.spi.project.ActionProvider;
    5.16 +import org.openide.awt.ActionID;
    5.17 +import org.openide.awt.ActionReference;
    5.18 +import org.openide.awt.ActionRegistration;
    5.19 +import org.openide.util.ContextAwareAction;
    5.20 +import org.openide.util.Lookup;
    5.21 +import org.openide.util.NbBundle;
    5.22 +
    5.23 +/**
    5.24 + * 
    5.25 + * @author Jan Stola
    5.26 + */
    5.27 +@ActionID(category="Project", id="org.netbeans.modules.ko4j.debugging.InspectAction") // NOI18N
    5.28 +@ActionRegistration(displayName="#ACT_Inspect", lazy=false) // NOI18N
    5.29 +@ActionReference(path="Projects/org-netbeans-modules-maven/Actions", position=987) // NOI18N
    5.30 +@NbBundle.Messages("ACT_Inspect=Inspect") // NOI18N
    5.31 +public class InspectAction extends AbstractAction implements ContextAwareAction {
    5.32 +    private static final String INSPECT_ACTION = "inspect"; // NOI18N
    5.33 +    private Lookup context;
    5.34 +    
    5.35 +    public InspectAction() {
    5.36 +        putValue(NAME, Bundle.ACT_Inspect());
    5.37 +    }
    5.38 +
    5.39 +    private InspectAction(Lookup context) {
    5.40 +        this();
    5.41 +        this.context = context;
    5.42 +    }
    5.43 +
    5.44 +    @Override
    5.45 +    public boolean isEnabled() {
    5.46 +        boolean enable = false;
    5.47 +        if (context != null) {
    5.48 +            Project project = context.lookup(Project.class);
    5.49 +            ActionProvider provider = project.getLookup().lookup(ActionProvider.class);
    5.50 +            if (provider != null) {
    5.51 +                enable = provider.isActionEnabled(INSPECT_ACTION, context);
    5.52 +            }
    5.53 +        }
    5.54 +        return enable;
    5.55 +    }
    5.56 +
    5.57 +
    5.58 +    @Override
    5.59 +    public void actionPerformed(ActionEvent e) {
    5.60 +        Project project = context.lookup(Project.class);
    5.61 +        ActionProvider provider = project.getLookup().lookup(ActionProvider.class);
    5.62 +        if (provider != null
    5.63 +//                && Arrays.asList(provider.getSupportedActions()).contains(INSPECT_ACTION)
    5.64 +                && provider.isActionEnabled(INSPECT_ACTION, context)) {
    5.65 +            Server.getInstance().acceptClient();
    5.66 +            provider.invokeAction(INSPECT_ACTION, context);
    5.67 +        }
    5.68 +    }
    5.69 +
    5.70 +    @Override
    5.71 +    public Action createContextAwareInstance(Lookup actionContext) {
    5.72 +        return new InspectAction(actionContext);
    5.73 +    }
    5.74 +    
    5.75 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/MessageDispatcherImpl.java	Mon Aug 12 17:02:12 2013 +0200
     6.3 @@ -0,0 +1,21 @@
     6.4 +/*
     6.5 + * To change this license header, choose License Headers in Project Properties.
     6.6 + * To change this template file, choose Tools | Templates
     6.7 + * and open the template in the editor.
     6.8 + */
     6.9 +package org.netbeans.modules.ko4j.debugging;
    6.10 +
    6.11 +import org.netbeans.modules.web.browser.spi.MessageDispatcher;
    6.12 +
    6.13 +/**
    6.14 + *
    6.15 + * @author Jan Stola
    6.16 + */
    6.17 +public class MessageDispatcherImpl extends MessageDispatcher {
    6.18 +
    6.19 +    @Override
    6.20 +    protected void dispatchMessage(String featureId, String message) {
    6.21 +        super.dispatchMessage(featureId, message);
    6.22 +    }
    6.23 +
    6.24 +}
     7.1 --- a/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/NbUserDir.java	Mon Aug 12 09:53:29 2013 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,66 +0,0 @@
     7.4 -/*
     7.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 - *
     7.7 - * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
     7.8 - *
     7.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    7.10 - * Other names may be trademarks of their respective owners.
    7.11 - *
    7.12 - * The contents of this file are subject to the terms of either the GNU
    7.13 - * General Public License Version 2 only ("GPL") or the Common
    7.14 - * Development and Distribution License("CDDL") (collectively, the
    7.15 - * "License"). You may not use this file except in compliance with the
    7.16 - * License. You can obtain a copy of the License at
    7.17 - * http://www.netbeans.org/cddl-gplv2.html
    7.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.19 - * specific language governing permissions and limitations under the
    7.20 - * License.  When distributing the software, include this License Header
    7.21 - * Notice in each file and include the License file at
    7.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    7.23 - * particular file as subject to the "Classpath" exception as provided
    7.24 - * by Oracle in the GPL Version 2 section of the License file that
    7.25 - * accompanied this code. If applicable, add the following below the
    7.26 - * License Header, with the fields enclosed by brackets [] replaced by
    7.27 - * your own identifying information:
    7.28 - * "Portions Copyrighted [year] [name of copyright owner]"
    7.29 - *
    7.30 - * If you wish your version of this file to be governed by only the CDDL
    7.31 - * or only the GPL Version 2, indicate your decision by adding
    7.32 - * "[Contributor] elects to include this software in this distribution
    7.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    7.34 - * single choice of license, a recipient has the option to distribute
    7.35 - * your version of this file under either the CDDL, the GPL Version 2 or
    7.36 - * to extend the choice of license to its licensees as provided above.
    7.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    7.38 - * Version 2 license, then the option applies only if the new code is
    7.39 - * made subject to such option by the copyright holder.
    7.40 - *
    7.41 - * Contributor(s):
    7.42 - *
    7.43 - * Portions Copyrighted 2013 Sun Microsystems, Inc.
    7.44 - */
    7.45 -package org.netbeans.modules.ko4j.debugging;
    7.46 -
    7.47 -import java.io.File;
    7.48 -import org.netbeans.modules.maven.api.execute.ExecutionContext;
    7.49 -import org.netbeans.modules.maven.api.execute.LateBoundPrerequisitesChecker;
    7.50 -import org.netbeans.modules.maven.api.execute.RunConfig;
    7.51 -import org.netbeans.spi.project.ProjectServiceProvider;
    7.52 -import org.openide.modules.Places;
    7.53 -
    7.54 -/**
    7.55 - *
    7.56 - * @author Jaroslav Tulach
    7.57 - */
    7.58 -@ProjectServiceProvider(
    7.59 -    projectType = "org-netbeans-modules-maven",
    7.60 -    service = LateBoundPrerequisitesChecker.class
    7.61 -)
    7.62 -public class NbUserDir implements LateBoundPrerequisitesChecker {
    7.63 -    @Override
    7.64 -    public boolean checkRunConfig(RunConfig config, ExecutionContext con) {
    7.65 -        File ud = Places.getUserDirectory();
    7.66 -        config.setProperty("netbeans.user", ud.getAbsolutePath());
    7.67 -        return true;
    7.68 -    }
    7.69 -}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Server.java	Mon Aug 12 17:02:12 2013 +0200
     8.3 @@ -0,0 +1,58 @@
     8.4 +package org.netbeans.modules.ko4j.debugging;
     8.5 +
     8.6 +import java.io.IOException;
     8.7 +import java.net.ServerSocket;
     8.8 +import java.net.Socket;
     8.9 +import org.netbeans.modules.web.browser.api.PageInspector;
    8.10 +import org.netbeans.modules.web.webkit.debugging.api.WebKitDebugging;
    8.11 +import org.netbeans.modules.web.webkit.debugging.spi.Factory;
    8.12 +import org.openide.util.Exceptions;
    8.13 +import org.openide.util.Lookup;
    8.14 +import org.openide.util.lookup.Lookups;
    8.15 +
    8.16 +/**
    8.17 + * 
    8.18 + * @author Jan Stola
    8.19 + */
    8.20 +public class Server {
    8.21 +    private static final Server INSTANCE = new Server();
    8.22 +    private boolean started = false;
    8.23 +    private ServerSocket socket;
    8.24 +
    8.25 +    public static Server getInstance() {
    8.26 +        return INSTANCE;
    8.27 +    }
    8.28 +
    8.29 +    public void acceptClient() {
    8.30 +        ensureStarted();
    8.31 +        Thread t = new Thread(new Runnable() {
    8.32 +            @Override
    8.33 +            public void run() {
    8.34 +                try {
    8.35 +                    Socket client = socket.accept();
    8.36 +                    MessageDispatcherImpl dispatcher = new MessageDispatcherImpl();
    8.37 +                    Transport transport = new Transport(client, dispatcher);
    8.38 +                    WebKitDebugging webKit = Factory.createWebKitDebugging(transport);
    8.39 +                    Lookup context = Lookups.fixed(transport, webKit, dispatcher);
    8.40 +                    PageInspector.getDefault().inspectPage(context);
    8.41 +                } catch (IOException ioex) {
    8.42 +                    Exceptions.printStackTrace(ioex);
    8.43 +                }
    8.44 +            }
    8.45 +        });
    8.46 +        t.start();
    8.47 +    }
    8.48 +
    8.49 +    private synchronized void ensureStarted() {
    8.50 +        if (started) {
    8.51 +            return;
    8.52 +        }
    8.53 +        try {
    8.54 +            socket = new ServerSocket(9876);
    8.55 +            started = true;
    8.56 +        } catch (IOException ioex) {
    8.57 +            Exceptions.printStackTrace(ioex);
    8.58 +        }
    8.59 +    }
    8.60 +
    8.61 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/Transport.java	Mon Aug 12 17:02:12 2013 +0200
     9.3 @@ -0,0 +1,109 @@
     9.4 +/*
     9.5 + * To change this license header, choose License Headers in Project Properties.
     9.6 + * To change this template file, choose Tools | Templates
     9.7 + * and open the template in the editor.
     9.8 + */
     9.9 +package org.netbeans.modules.ko4j.debugging;
    9.10 +
    9.11 +import java.io.IOException;
    9.12 +import java.io.ObjectInputStream;
    9.13 +import java.io.ObjectOutputStream;
    9.14 +import java.net.Socket;
    9.15 +import java.net.URL;
    9.16 +import java.nio.charset.StandardCharsets;
    9.17 +import org.json.simple.JSONObject;
    9.18 +import org.json.simple.JSONValue;
    9.19 +import org.json.simple.parser.ParseException;
    9.20 +import org.netbeans.modules.web.browser.api.PageInspector;
    9.21 +import org.netbeans.modules.web.webkit.debugging.api.TransportStateException;
    9.22 +import org.netbeans.modules.web.webkit.debugging.spi.Command;
    9.23 +import org.netbeans.modules.web.webkit.debugging.spi.Response;
    9.24 +import org.netbeans.modules.web.webkit.debugging.spi.ResponseCallback;
    9.25 +import org.netbeans.modules.web.webkit.debugging.spi.TransportImplementation;
    9.26 +import org.openide.util.Exceptions;
    9.27 +
    9.28 +/**
    9.29 + *
    9.30 + * @author Jan Stola
    9.31 + */
    9.32 +public class Transport implements TransportImplementation {
    9.33 +    private ObjectInputStream input;
    9.34 +    private ObjectOutputStream output;
    9.35 +    private ResponseCallback callback;
    9.36 +    private MessageDispatcherImpl messageDispatcher;
    9.37 +    
    9.38 +    public Transport(Socket socket, MessageDispatcherImpl messageDispatcher) {
    9.39 +        try {
    9.40 +            this.messageDispatcher = messageDispatcher;
    9.41 +            input = new ObjectInputStream(socket.getInputStream());
    9.42 +            output = new ObjectOutputStream(socket.getOutputStream());
    9.43 +            Thread t = new Thread(new Runnable() {
    9.44 +                @Override
    9.45 +                public void run() {
    9.46 +                    try {
    9.47 +                        while (true) {
    9.48 +                            int length = input.readInt();
    9.49 +                            byte[] bytes = new byte[length];
    9.50 +                            input.readFully(bytes);
    9.51 +                            String message = new String(bytes, StandardCharsets.UTF_8);
    9.52 +                            JSONObject json = (JSONObject)JSONValue.parseWithException(message);
    9.53 +                            callback.handleResponse(new Response(json));
    9.54 +                        }
    9.55 +                    } catch (IOException ioex) {
    9.56 +                        ioex.printStackTrace();
    9.57 +                    } catch (ParseException pex) {
    9.58 +                        pex.printStackTrace();
    9.59 +                    }
    9.60 +                    Transport.this.messageDispatcher.dispatchMessage(PageInspector.MESSAGE_DISPATCHER_FEATURE_ID, null);
    9.61 +                }                
    9.62 +            });
    9.63 +            t.start();
    9.64 +        } catch (IOException ioex) {
    9.65 +            Exceptions.printStackTrace(ioex);
    9.66 +        }
    9.67 +    }
    9.68 +
    9.69 +    @Override
    9.70 +    public boolean attach() {
    9.71 +        return true;
    9.72 +    }
    9.73 +
    9.74 +    @Override
    9.75 +    public boolean detach() {
    9.76 +        return true;
    9.77 +    }
    9.78 +
    9.79 +    @Override
    9.80 +    public synchronized void sendCommand(Command command) throws TransportStateException {
    9.81 +        try {
    9.82 +            String message = command.toString();
    9.83 +            byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
    9.84 +            output.writeInt(bytes.length);
    9.85 +            output.write(bytes);
    9.86 +            output.flush();
    9.87 +        } catch (IOException ioex) {
    9.88 +            ioex.printStackTrace();
    9.89 +        }
    9.90 +    }
    9.91 +
    9.92 +    @Override
    9.93 +    public void registerResponseCallback(ResponseCallback callback) {
    9.94 +        this.callback = callback;
    9.95 +    }
    9.96 +
    9.97 +    @Override
    9.98 +    public String getConnectionName() {
    9.99 +        return "";
   9.100 +    }
   9.101 +
   9.102 +    @Override
   9.103 +    public URL getConnectionURL() {
   9.104 +        return null;
   9.105 +    }
   9.106 +
   9.107 +    @Override
   9.108 +    public String getVersion() {
   9.109 +        return VERSION_1;
   9.110 +    }
   9.111 +    
   9.112 +}
    10.1 --- a/ko4j.debugging/src/org/netbeans/modules/ko4j/debugging/WebKitDebuggingTransport.java	Mon Aug 12 09:53:29 2013 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,156 +0,0 @@
    10.4 -/*
    10.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 - *
    10.7 - * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
    10.8 - *
    10.9 - * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   10.10 - * Other names may be trademarks of their respective owners.
   10.11 - *
   10.12 - * The contents of this file are subject to the terms of either the GNU
   10.13 - * General Public License Version 2 only ("GPL") or the Common
   10.14 - * Development and Distribution License("CDDL") (collectively, the
   10.15 - * "License"). You may not use this file except in compliance with the
   10.16 - * License. You can obtain a copy of the License at
   10.17 - * http://www.netbeans.org/cddl-gplv2.html
   10.18 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   10.19 - * specific language governing permissions and limitations under the
   10.20 - * License.  When distributing the software, include this License Header
   10.21 - * Notice in each file and include the License file at
   10.22 - * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
   10.23 - * particular file as subject to the "Classpath" exception as provided
   10.24 - * by Oracle in the GPL Version 2 section of the License file that
   10.25 - * accompanied this code. If applicable, add the following below the
   10.26 - * License Header, with the fields enclosed by brackets [] replaced by
   10.27 - * your own identifying information:
   10.28 - * "Portions Copyrighted [year] [name of copyright owner]"
   10.29 - *
   10.30 - * If you wish your version of this file to be governed by only the CDDL
   10.31 - * or only the GPL Version 2, indicate your decision by adding
   10.32 - * "[Contributor] elects to include this software in this distribution
   10.33 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   10.34 - * single choice of license, a recipient has the option to distribute
   10.35 - * your version of this file under either the CDDL, the GPL Version 2 or
   10.36 - * to extend the choice of license to its licensees as provided above.
   10.37 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   10.38 - * Version 2 license, then the option applies only if the new code is
   10.39 - * made subject to such option by the copyright holder.
   10.40 - *
   10.41 - * Contributor(s):
   10.42 - *
   10.43 - * Portions Copyrighted 2012 Sun Microsystems, Inc.
   10.44 - */
   10.45 -package org.netbeans.modules.ko4j.debugging;
   10.46 -
   10.47 -import java.io.BufferedReader;
   10.48 -import java.io.IOException;
   10.49 -import java.io.InputStream;
   10.50 -import java.io.InputStreamReader;
   10.51 -import java.io.PrintStream;
   10.52 -import java.net.MalformedURLException;
   10.53 -import java.net.URL;
   10.54 -import java.util.logging.Level;
   10.55 -import java.util.logging.Logger;
   10.56 -import org.json.simple.JSONObject;
   10.57 -import org.json.simple.JSONValue;
   10.58 -import org.json.simple.parser.ParseException;
   10.59 -import org.netbeans.modules.web.webkit.debugging.spi.Command;
   10.60 -import org.netbeans.modules.web.webkit.debugging.spi.Response;
   10.61 -import org.netbeans.modules.web.webkit.debugging.spi.ResponseCallback;
   10.62 -import org.netbeans.modules.web.webkit.debugging.spi.TransportImplementation;
   10.63 -import org.openide.util.Exceptions;
   10.64 -import org.openide.util.RequestProcessor;
   10.65 -
   10.66 -abstract class WebKitDebuggingTransport implements TransportImplementation, Runnable {
   10.67 -    private ResponseCallback callback;
   10.68 -    private volatile String urlToLoad; // The url to be loaded to the browser
   10.69 -    
   10.70 -    private static RequestProcessor RP = new RequestProcessor("CLI debugging callback");
   10.71 -    
   10.72 -    private static final Logger LOGGER = Logger.getLogger(WebKitDebuggingTransport.class.getName());
   10.73 -    private RequestProcessor.Task task;
   10.74 -
   10.75 -    protected WebKitDebuggingTransport() {
   10.76 -    }
   10.77 -    
   10.78 -    @Override
   10.79 -    @SuppressWarnings("deprecation")
   10.80 -    public boolean attach() {
   10.81 -        task = RP.post(this);
   10.82 -        return true;
   10.83 -    }
   10.84 -
   10.85 -    @Override
   10.86 -    public boolean detach() {
   10.87 -        return true;
   10.88 -    }
   10.89 -    
   10.90 -    final void waitFinished() {
   10.91 -        if (task != null) {
   10.92 -            task.waitFinished();
   10.93 -        }
   10.94 -    }
   10.95 -
   10.96 -    @Override
   10.97 -    public void sendCommand(final Command command) {
   10.98 -        final String cmd = command.toString();
   10.99 -        assert cmd.indexOf('\n') == -1 : "No new line: " + cmd;
  10.100 -        LOGGER.log(Level.INFO, "toDebuggee: {0}", cmd);
  10.101 -        final PrintStream os = outputStream();
  10.102 -        os.println(cmd);
  10.103 -    }
  10.104 -
  10.105 -    @Override
  10.106 -    public void registerResponseCallback(ResponseCallback callback) {
  10.107 -        this.callback = callback;
  10.108 -    }
  10.109 -
  10.110 -    @Override
  10.111 -    public String getConnectionName() {
  10.112 -        return "Local connection";
  10.113 -    }
  10.114 -    
  10.115 -    @Override
  10.116 -    public URL getConnectionURL() {
  10.117 -        try {
  10.118 -            return new URL(urlToLoad);
  10.119 -        } catch (MalformedURLException ex) {
  10.120 -            throw new IllegalStateException(ex);
  10.121 -        }
  10.122 -    }
  10.123 -
  10.124 -    @Override
  10.125 -    public String getVersion() {
  10.126 -        return "1.0";
  10.127 -    }
  10.128 -    
  10.129 -    @Override
  10.130 -    public void run() {
  10.131 -        try {
  10.132 -            BufferedReader r = new BufferedReader(new InputStreamReader(inputStream()));
  10.133 -            for (;;) {
  10.134 -                String line = r.readLine();
  10.135 -                LOGGER.log(Level.INFO, "fromDebgee: {0}", line);
  10.136 -                if (line == null) {
  10.137 -                    break;
  10.138 -                }
  10.139 -                msgToIde(line);
  10.140 -            }
  10.141 -        } catch (IOException ex) {
  10.142 -            LOGGER.log(Level.INFO, "Error reading input", ex);
  10.143 -        }
  10.144 -    }
  10.145 -    
  10.146 -    private void msgToIde(String p) {
  10.147 -        try {
  10.148 -            JSONObject json = (JSONObject)JSONValue.parseWithException(p);
  10.149 -            if( null != callback )
  10.150 -                callback.handleResponse(new Response(json));
  10.151 -        } catch (ParseException ex) {
  10.152 -            Exceptions.printStackTrace(ex);
  10.153 -        }
  10.154 -    }
  10.155 -
  10.156 -    protected abstract InputStream inputStream();
  10.157 -    protected abstract PrintStream outputStream();
  10.158 -    
  10.159 -}