Debugger endpoint.
authorTomas Zezula <tzezula@netbeans.org>
Tue, 28 Jan 2014 22:26:21 +0100
changeset 181250d69935534b3
parent 18124 03e0b3965817
child 18126 7e7868b5ad70
Debugger endpoint.
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/AttachHandler.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ContinueHandler.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugEndPoint.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugMessageType.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/SetBreakpointsHandler.java
dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacEndPoint.java
dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacMessageType.java
     1.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/AttachHandler.java	Tue Jan 28 22:00:22 2014 +0100
     1.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/AttachHandler.java	Tue Jan 28 22:26:21 2014 +0100
     1.3 @@ -48,9 +48,6 @@
     1.4  import org.netbeans.modules.dew4nb.endpoint.EndPoint;
     1.5  import org.netbeans.modules.dew4nb.endpoint.RequestHandler;
     1.6  import org.netbeans.modules.dew4nb.endpoint.Status;
     1.7 -import org.netbeans.modules.dew4nb.services.javac.Context;
     1.8 -import org.netbeans.modules.dew4nb.services.javac.JavacMessageType;
     1.9 -import org.netbeans.modules.dew4nb.services.javac.JavacQuery;
    1.10  import org.netbeans.modules.dew4nb.spi.WorkspaceResolver;
    1.11  import org.openide.filesystems.FileObject;
    1.12  import org.openide.util.Lookup;
    1.13 @@ -62,20 +59,20 @@
    1.14   * @author Tomas Zezula
    1.15   */
    1.16  @ServiceProvider(service = RequestHandler.class)
    1.17 -public class AttachHandler extends AsyncRequestHandler<JavacQuery, JavacMessageType> {
    1.18 +public class AttachHandler extends AsyncRequestHandler<DebugAction, DebugMessageType> {
    1.19  
    1.20      private static final Executor RP = new RequestProcessor(AttachHandler.class);    
    1.21  
    1.22  
    1.23      public AttachHandler() {
    1.24 -        super(DebugerModels.END_POINT, JavacMessageType.attach, JavacQuery.class);        
    1.25 +        super(DebugerModels.END_POINT, DebugMessageType.attach, DebugAction.class);
    1.26      }
    1.27  
    1.28      @Override
    1.29      @NonNull
    1.30 -    protected Status handle(@NonNull final JavacQuery request, @NonNull final EndPoint.Env env) {
    1.31 -        final JavacMessageType type = request.getType();
    1.32 -        if (type != JavacMessageType.attach) {
    1.33 +    protected Status handle(@NonNull final DebugAction request, @NonNull final EndPoint.Env env) {
    1.34 +        final DebugMessageType type = request.getType();
    1.35 +        if (type != DebugMessageType.attach) {
    1.36              throw new IllegalStateException("Wrong message type:" + type);  //NOI18N
    1.37          }
    1.38          final Context ctx = request.getContext();
     2.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ContinueHandler.java	Tue Jan 28 22:00:22 2014 +0100
     2.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ContinueHandler.java	Tue Jan 28 22:26:21 2014 +0100
     2.3 @@ -49,8 +49,6 @@
     2.4  import org.netbeans.modules.dew4nb.endpoint.BasicRequestHandler;
     2.5  import org.netbeans.modules.dew4nb.endpoint.RequestHandler;
     2.6  import org.netbeans.modules.dew4nb.endpoint.Status;
     2.7 -import org.netbeans.modules.dew4nb.services.javac.JavacMessageType;
     2.8 -import org.netbeans.modules.dew4nb.services.javac.JavacQuery;
     2.9  import org.netbeans.modules.dew4nb.spi.WorkspaceResolver;
    2.10  import org.openide.util.Parameters;
    2.11  import org.openide.util.lookup.ServiceProvider;
    2.12 @@ -60,22 +58,22 @@
    2.13   * @author Tomas Zezula
    2.14   */
    2.15  @ServiceProvider(service=RequestHandler.class)
    2.16 -public class ContinueHandler extends BasicRequestHandler<JavacQuery, JavacMessageType, ContinueResult> {
    2.17 +public class ContinueHandler extends BasicRequestHandler<DebugAction, DebugMessageType, ContinueResult> {
    2.18  
    2.19      public ContinueHandler() {
    2.20 -        super(DebugerModels.END_POINT, JavacMessageType.cont, JavacQuery.class, ContinueResult.class);
    2.21 +        super(DebugerModels.END_POINT, DebugMessageType.cont, DebugAction.class, ContinueResult.class);
    2.22      }
    2.23  
    2.24      @Override
    2.25      @NonNull
    2.26 -    protected Status handle(@NonNull final JavacQuery request, @NonNull final ContinueResult response) {
    2.27 +    protected Status handle(@NonNull final DebugAction request, @NonNull final ContinueResult response) {
    2.28          Parameters.notNull("request", request); //NOI18N
    2.29          Parameters.notNull("response", response);   //NOI18N
    2.30 -        if (request.getType() != JavacMessageType.cont) {
    2.31 +        if (request.getType() != DebugMessageType.cont) {
    2.32              throw new IllegalStateException("Invalid message type: " + request.getType());  //NOI18N
    2.33          }
    2.34          Status status = Status.not_found;
    2.35 -        final int sessionId = request.getOffset();
    2.36 +        final int sessionId = request.getSession();
    2.37          final WorkspaceResolver.Context ctx = ActiveSessions.getInstance().getContext(sessionId);
    2.38          if (ctx != null) {
    2.39              final Session debugSession = ActiveSessions.getInstance().getDebugSession(sessionId);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugEndPoint.java	Tue Jan 28 22:26:21 2014 +0100
     3.3 @@ -0,0 +1,63 @@
     3.4 +/*
     3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 + *
     3.7 + * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
     3.8 + *
     3.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    3.10 + * Other names may be trademarks of their respective owners.
    3.11 + *
    3.12 + * The contents of this file are subject to the terms of either the GNU
    3.13 + * General Public License Version 2 only ("GPL") or the Common
    3.14 + * Development and Distribution License("CDDL") (collectively, the
    3.15 + * "License"). You may not use this file except in compliance with the
    3.16 + * License. You can obtain a copy of the License at
    3.17 + * http://www.netbeans.org/cddl-gplv2.html
    3.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    3.19 + * specific language governing permissions and limitations under the
    3.20 + * License.  When distributing the software, include this License Header
    3.21 + * Notice in each file and include the License file at
    3.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    3.23 + * particular file as subject to the "Classpath" exception as provided
    3.24 + * by Oracle in the GPL Version 2 section of the License file that
    3.25 + * accompanied this code. If applicable, add the following below the
    3.26 + * License Header, with the fields enclosed by brackets [] replaced by
    3.27 + * your own identifying information:
    3.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    3.29 + *
    3.30 + * If you wish your version of this file to be governed by only the CDDL
    3.31 + * or only the GPL Version 2, indicate your decision by adding
    3.32 + * "[Contributor] elects to include this software in this distribution
    3.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    3.34 + * single choice of license, a recipient has the option to distribute
    3.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    3.36 + * to extend the choice of license to its licensees as provided above.
    3.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    3.38 + * Version 2 license, then the option applies only if the new code is
    3.39 + * made subject to such option by the copyright holder.
    3.40 + *
    3.41 + * Contributor(s):
    3.42 + *
    3.43 + * Portions Copyrighted 2014 Sun Microsystems, Inc.
    3.44 + */
    3.45 +
    3.46 +package org.netbeans.modules.dew4nb.services.debugger;
    3.47 +
    3.48 +import org.netbeans.modules.dew4nb.endpoint.EndPoint;
    3.49 +import org.openide.util.lookup.ServiceProvider;
    3.50 +
    3.51 +/**
    3.52 + *
    3.53 + * @author Tomas Zezula
    3.54 + */
    3.55 +@ServiceProvider(service = EndPoint.class)
    3.56 +public final class DebugEndPoint extends EndPoint<DebugAction, DebugMessageType> {
    3.57 +
    3.58 +    public DebugEndPoint() {
    3.59 +        super(DebugerModels.END_POINT, DebugAction.class, DebugMessageType.class);
    3.60 +    }    
    3.61 +
    3.62 +    @Override
    3.63 +    protected DebugMessageType getRequestKind(DebugAction query) {
    3.64 +        return query.getType();
    3.65 +    }
    3.66 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugMessageType.java	Tue Jan 28 22:26:21 2014 +0100
     4.3 @@ -0,0 +1,53 @@
     4.4 +/*
     4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.6 + *
     4.7 + * Copyright 2014 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 2014 Sun Microsystems, Inc.
    4.44 + */
    4.45 +
    4.46 +package org.netbeans.modules.dew4nb.services.debugger;
    4.47 +
    4.48 +/**
    4.49 + *
    4.50 + * @author Tomas Zezula
    4.51 + */
    4.52 +public enum DebugMessageType {
    4.53 +    attach,
    4.54 +    breakpoints,
    4.55 +    cont
    4.56 +}
     5.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java	Tue Jan 28 22:00:22 2014 +0100
     5.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java	Tue Jan 28 22:26:21 2014 +0100
     5.3 @@ -45,7 +45,6 @@
     5.4  import net.java.html.json.Model;
     5.5  import net.java.html.json.Property;
     5.6  import org.netbeans.modules.dew4nb.endpoint.Status;
     5.7 -import org.netbeans.modules.dew4nb.services.javac.JavacMessageType;
     5.8  
     5.9  /**
    5.10   *
    5.11 @@ -53,16 +52,25 @@
    5.12   */
    5.13  public final class DebugerModels {
    5.14  
    5.15 -    static final String END_POINT = "javac"; //NOI18N
    5.16 +    static final String END_POINT = "debug"; //NOI18N
    5.17  
    5.18      private DebugerModels() {
    5.19          throw new IllegalStateException("No instance allowed.");    //NOI18N
    5.20      }
    5.21  
    5.22 +    @Model(className = "DebugAction", properties = {
    5.23 +        @Property(name = "type", type = DebugMessageType.class),
    5.24 +        @Property(name = "state", type = String.class),
    5.25 +        @Property(name = "context", type = Context.class),
    5.26 +        @Property(name = "session", type = int.class),
    5.27 +        @Property(name = "data", type = String.class, array = true)
    5.28 +    })
    5.29 +    static final class DebugActionModel {
    5.30 +    }
    5.31  
    5.32      @Model(className = "AttachResult", properties = {
    5.33          @Property(name = "status", type = Status.class),
    5.34 -        @Property(name = "type", type = JavacMessageType.class),
    5.35 +        @Property(name = "type", type = DebugMessageType.class),
    5.36          @Property(name = "state", type = String.class),
    5.37          @Property(name = "id", type = int.class)
    5.38      })
    5.39 @@ -72,7 +80,7 @@
    5.40  
    5.41      @Model(className = "SetBreakpointsResult", properties = {
    5.42          @Property(name = "status", type = Status.class),
    5.43 -        @Property(name = "type", type = JavacMessageType.class),
    5.44 +        @Property(name = "type", type = DebugMessageType.class),
    5.45          @Property(name = "state", type = String.class),
    5.46      })
    5.47      static final class SetBreakpointsResultModel {
    5.48 @@ -80,10 +88,18 @@
    5.49  
    5.50      @Model(className = "ContinueResult", properties = {
    5.51          @Property(name = "status", type = Status.class),
    5.52 -        @Property(name = "type", type = JavacMessageType.class),
    5.53 +        @Property(name = "type", type = DebugMessageType.class),
    5.54          @Property(name = "state", type = String.class),
    5.55      })
    5.56      static final class ContinueResultModel {
    5.57      }
    5.58  
    5.59 +    @Model(className = "Context", properties = {
    5.60 +        @Property(name="user", type=String.class),
    5.61 +        @Property(name = "workspace", type = String.class),
    5.62 +        @Property(name = "path", type = String.class)
    5.63 +    })
    5.64 +    static final class ContextModel {
    5.65 +    }
    5.66 +
    5.67  }
     6.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/SetBreakpointsHandler.java	Tue Jan 28 22:00:22 2014 +0100
     6.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/SetBreakpointsHandler.java	Tue Jan 28 22:26:21 2014 +0100
     6.3 @@ -50,8 +50,6 @@
     6.4  import org.netbeans.modules.dew4nb.endpoint.BasicRequestHandler;
     6.5  import org.netbeans.modules.dew4nb.endpoint.RequestHandler;
     6.6  import org.netbeans.modules.dew4nb.endpoint.Status;
     6.7 -import org.netbeans.modules.dew4nb.services.javac.JavacMessageType;
     6.8 -import org.netbeans.modules.dew4nb.services.javac.JavacQuery;
     6.9  import org.netbeans.modules.dew4nb.spi.WorkspaceResolver;
    6.10  import org.openide.filesystems.FileObject;
    6.11  import org.openide.util.Lookup;
    6.12 @@ -63,61 +61,58 @@
    6.13   * @author Tomas Zezula
    6.14   */
    6.15  @ServiceProvider(service = RequestHandler.class)
    6.16 -public class SetBreakpointsHandler extends BasicRequestHandler<JavacQuery, JavacMessageType, SetBreakpointsResult> {
    6.17 +public class SetBreakpointsHandler extends BasicRequestHandler<DebugAction, DebugMessageType, SetBreakpointsResult> {
    6.18      
    6.19      private static final Logger LOG = Logger.getLogger(SetBreakpointsHandler.class.getName());
    6.20  
    6.21      public SetBreakpointsHandler() {
    6.22 -        super(DebugerModels.END_POINT, JavacMessageType.breakpoints, JavacQuery.class, SetBreakpointsResult.class);
    6.23 +        super(DebugerModels.END_POINT, DebugMessageType.breakpoints, DebugAction.class, SetBreakpointsResult.class);
    6.24      }
    6.25  
    6.26      @Override
    6.27 -    protected Status handle(@NonNull final JavacQuery request, @NonNull final SetBreakpointsResult response) {
    6.28 +    protected Status handle(@NonNull final DebugAction request, @NonNull final SetBreakpointsResult response) {
    6.29          Parameters.notNull("request", request); //NOI18N
    6.30          Parameters.notNull("response", response);   //NOI18N;
    6.31 -        if (request.getType() != JavacMessageType.breakpoints) {
    6.32 +        if (request.getType() != DebugMessageType.breakpoints) {
    6.33              throw new IllegalStateException("Wrong message type: " + request.getType());    //NOI18N
    6.34          }
    6.35          Status status = Status.not_found;
    6.36 -        final int sessionId = request.getOffset();
    6.37 +        final int sessionId = request.getSession();
    6.38          final WorkspaceResolver.Context ctx = ActiveSessions.getInstance().getContext(sessionId);
    6.39 -        if (ctx != null) {
    6.40 -            final String lines = request.getJava();
    6.41 -            if (lines != null) {
    6.42 -                final WorkspaceResolver resolver = Lookup.getDefault().lookup(WorkspaceResolver.class);
    6.43 -                if (resolver == null) {
    6.44 -                    throw new IllegalStateException("No WorkspaceResolver."); //NOI18N
    6.45 -                }
    6.46 -                final DebuggerManager dbm = DebuggerManager.getDebuggerManager();
    6.47 -                for (String line : lines.split(",")) {  //NOI18N
    6.48 -                    final int separator = line.lastIndexOf(':');    //NOI18N
    6.49 -                    if (separator > 0 && separator < line.length() - 1) {
    6.50 -                        try {
    6.51 -                            final String path = line.substring(0, separator);
    6.52 -                            final String lineStr = line.substring(separator+1);
    6.53 -                            final int lineNo = Integer.parseInt(lineStr);
    6.54 -                            final FileObject file = resolver.resolveFile(new WorkspaceResolver.Context(ctx.getUser(), ctx.getWorkspace(), path));
    6.55 -                            if (file != null) {
    6.56 -                                final LineBreakpoint lb = LineBreakpoint.create(file.toURL().toExternalForm(), lineNo);
    6.57 -                                dbm.addBreakpoint(lb);
    6.58 -                            } else {
    6.59 -                                LOG.log(
    6.60 -                                    Level.WARNING,
    6.61 -                                    "Ignoring breakpoint in unresolvable file: {0}",   //NOI18N
    6.62 -                                    line);
    6.63 -                            }
    6.64 -                        } catch (NumberFormatException nfe) {
    6.65 +        if (ctx != null) {            
    6.66 +            final WorkspaceResolver resolver = Lookup.getDefault().lookup(WorkspaceResolver.class);
    6.67 +            if (resolver == null) {
    6.68 +                throw new IllegalStateException("No WorkspaceResolver."); //NOI18N
    6.69 +            }
    6.70 +            final DebuggerManager dbm = DebuggerManager.getDebuggerManager();
    6.71 +            for (String line : request.getData()) {
    6.72 +                final int separator = line.lastIndexOf(':');    //NOI18N
    6.73 +                if (separator > 0 && separator < line.length() - 1) {
    6.74 +                    try {
    6.75 +                        final String path = line.substring(0, separator);
    6.76 +                        final String lineStr = line.substring(separator+1);
    6.77 +                        final int lineNo = Integer.parseInt(lineStr);
    6.78 +                        final FileObject file = resolver.resolveFile(new WorkspaceResolver.Context(ctx.getUser(), ctx.getWorkspace(), path));
    6.79 +                        if (file != null) {
    6.80 +                            final LineBreakpoint lb = LineBreakpoint.create(file.toURL().toExternalForm(), lineNo);
    6.81 +                            dbm.addBreakpoint(lb);
    6.82 +                        } else {
    6.83                              LOG.log(
    6.84                                  Level.WARNING,
    6.85 -                                "Ignoring breakpoint with wrong line number: {0}",   //NOI18N
    6.86 +                                "Ignoring breakpoint in unresolvable file: {0}",   //NOI18N
    6.87                                  line);
    6.88                          }
    6.89 -                    } else {
    6.90 +                    } catch (NumberFormatException nfe) {
    6.91                          LOG.log(
    6.92                              Level.WARNING,
    6.93 -                            "Ignoring wrong breakpoint: {0}",   //NOI18N
    6.94 +                            "Ignoring breakpoint with wrong line number: {0}",   //NOI18N
    6.95                              line);
    6.96                      }
    6.97 +                } else {
    6.98 +                    LOG.log(
    6.99 +                        Level.WARNING,
   6.100 +                        "Ignoring wrong breakpoint: {0}",   //NOI18N
   6.101 +                        line);
   6.102                  }
   6.103              }
   6.104              status = Status.done;
     7.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacEndPoint.java	Tue Jan 28 22:00:22 2014 +0100
     7.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacEndPoint.java	Tue Jan 28 22:26:21 2014 +0100
     7.3 @@ -53,7 +53,7 @@
     7.4  public final class JavacEndPoint extends EndPoint<JavacQuery, JavacMessageType> {    
     7.5  
     7.6      public JavacEndPoint() {
     7.7 -        super("javac", JavacQuery.class, JavacMessageType.class);
     7.8 +        super(JavacModels.END_POINT, JavacQuery.class, JavacMessageType.class);
     7.9      }    
    7.10  
    7.11      @Override
     8.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacMessageType.java	Tue Jan 28 22:00:22 2014 +0100
     8.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/javac/JavacMessageType.java	Tue Jan 28 22:26:21 2014 +0100
     8.3 @@ -47,9 +47,5 @@
     8.4      autocomplete,
     8.5      symbols,
     8.6      checkForErrors,
     8.7 -    compile,
     8.8 -    //debugger
     8.9 -    attach,
    8.10 -    breakpoints,
    8.11 -    cont
    8.12 +    compile    
    8.13  }