Fix and continue.
authorTomas Zezula <tzezula@netbeans.org>
Tue, 04 Feb 2014 17:52:17 +0100
changeset 18154335ea09dddc2
parent 18153 5ed4e5e97446
child 18155 f12ee1e34504
Fix and continue.
dew4nb/nbproject/project.xml
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ApplyCodeChangesHandler.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugMessageType.java
dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java
     1.1 --- a/dew4nb/nbproject/project.xml	Tue Feb 04 13:57:07 2014 +0100
     1.2 +++ b/dew4nb/nbproject/project.xml	Tue Feb 04 17:52:17 2014 +0100
     1.3 @@ -95,6 +95,15 @@
     1.4                      </run-dependency>
     1.5                  </dependency>
     1.6                  <dependency>
     1.7 +                    <code-name-base>org.netbeans.modules.java.project</code-name-base>
     1.8 +                    <build-prerequisite/>
     1.9 +                    <compile-dependency/>
    1.10 +                    <run-dependency>
    1.11 +                        <release-version>1</release-version>
    1.12 +                        <specification-version>1.58</specification-version>
    1.13 +                    </run-dependency>
    1.14 +                </dependency>
    1.15 +                <dependency>
    1.16                      <code-name-base>org.netbeans.modules.java.source</code-name-base>
    1.17                      <build-prerequisite/>
    1.18                      <compile-dependency/>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/ApplyCodeChangesHandler.java	Tue Feb 04 17:52:17 2014 +0100
     2.3 @@ -0,0 +1,139 @@
     2.4 +/*
     2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 + *
     2.7 + * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
     2.8 + *
     2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    2.10 + * Other names may be trademarks of their respective owners.
    2.11 + *
    2.12 + * The contents of this file are subject to the terms of either the GNU
    2.13 + * General Public License Version 2 only ("GPL") or the Common
    2.14 + * Development and Distribution License("CDDL") (collectively, the
    2.15 + * "License"). You may not use this file except in compliance with the
    2.16 + * License. You can obtain a copy of the License at
    2.17 + * http://www.netbeans.org/cddl-gplv2.html
    2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    2.19 + * specific language governing permissions and limitations under the
    2.20 + * License.  When distributing the software, include this License Header
    2.21 + * Notice in each file and include the License file at
    2.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    2.23 + * particular file as subject to the "Classpath" exception as provided
    2.24 + * by Oracle in the GPL Version 2 section of the License file that
    2.25 + * accompanied this code. If applicable, add the following below the
    2.26 + * License Header, with the fields enclosed by brackets [] replaced by
    2.27 + * your own identifying information:
    2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    2.29 + *
    2.30 + * If you wish your version of this file to be governed by only the CDDL
    2.31 + * or only the GPL Version 2, indicate your decision by adding
    2.32 + * "[Contributor] elects to include this software in this distribution
    2.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    2.34 + * single choice of license, a recipient has the option to distribute
    2.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    2.36 + * to extend the choice of license to its licensees as provided above.
    2.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    2.38 + * Version 2 license, then the option applies only if the new code is
    2.39 + * made subject to such option by the copyright holder.
    2.40 + *
    2.41 + * Contributor(s):
    2.42 + *
    2.43 + * Portions Copyrighted 2014 Sun Microsystems, Inc.
    2.44 + */
    2.45 +
    2.46 +package org.netbeans.modules.dew4nb.services.debugger;
    2.47 +
    2.48 +import java.util.Arrays;
    2.49 +import javax.swing.SwingUtilities;
    2.50 +import org.netbeans.api.annotations.common.NonNull;
    2.51 +import org.netbeans.api.annotations.common.NullAllowed;
    2.52 +import org.netbeans.api.java.project.JavaProjectConstants;
    2.53 +import org.netbeans.api.project.FileOwnerQuery;
    2.54 +import org.netbeans.api.project.Project;
    2.55 +import org.netbeans.modules.dew4nb.endpoint.AsyncRequestHandler;
    2.56 +import org.netbeans.modules.dew4nb.endpoint.EndPoint;
    2.57 +import org.netbeans.modules.dew4nb.endpoint.RequestHandler;
    2.58 +import org.netbeans.modules.dew4nb.endpoint.Status;
    2.59 +import org.netbeans.modules.dew4nb.spi.WorkspaceResolver;
    2.60 +import org.netbeans.spi.project.ActionProgress;
    2.61 +import org.netbeans.spi.project.ActionProvider;
    2.62 +import org.openide.filesystems.FileObject;
    2.63 +import org.openide.util.Lookup;
    2.64 +import org.openide.util.Parameters;
    2.65 +import org.openide.util.lookup.Lookups;
    2.66 +import org.openide.util.lookup.ServiceProvider;
    2.67 +
    2.68 +/**
    2.69 + *
    2.70 + * @author Tomas Zezula
    2.71 + */
    2.72 +@ServiceProvider(service = RequestHandler.class)
    2.73 +public class ApplyCodeChangesHandler extends AsyncRequestHandler<DebugAction, DebugMessageType> {
    2.74 +
    2.75 +    public ApplyCodeChangesHandler () {
    2.76 +        super(DebugerModels.END_POINT, DebugMessageType.apply, DebugAction.class);
    2.77 +    }
    2.78 +
    2.79 +    @Override
    2.80 +    protected Status handle(@NonNull final DebugAction request, @NonNull final EndPoint.Env env) {
    2.81 +        Parameters.notNull("request", request); //NOI18N
    2.82 +        Parameters.notNull("env", env);    //NOI18N
    2.83 +        if (request.getType() != DebugMessageType.apply) {
    2.84 +            throw new IllegalArgumentException("Wrong request type: " + request.getType()); //NOI18N
    2.85 +        }
    2.86 +        final int sessionId = request.getSession();
    2.87 +        Status result = Status.not_found;
    2.88 +        final WorkspaceResolver.Context ctx = ActiveSessions.getInstance().getContext(sessionId);
    2.89 +        if (ctx != null) {
    2.90 +            final WorkspaceResolver wr = WorkspaceResolver.getDefault();
    2.91 +            if (wr == null) {
    2.92 +                throw new IllegalStateException("No WorkspaceResolver");    //NOI18N
    2.93 +            }
    2.94 +            final FileObject file = wr.resolveFile(ctx);
    2.95 +            if (file != null) {
    2.96 +                final Project prj = FileOwnerQuery.getOwner(file);
    2.97 +                if (prj != null) {
    2.98 +                    final ActionProgress progress = new ActionProgress() {
    2.99 +                        @Override
   2.100 +                        protected void started() {
   2.101 +                        }
   2.102 +                        @Override
   2.103 +                        public void finished(final boolean success) {
   2.104 +                            final ApplyCodeChangesResult res = new ApplyCodeChangesResult();                            
   2.105 +                            res.setType(request.getType());
   2.106 +                            res.setState(request.getState());
   2.107 +                            res.setStatus(Status.done);
   2.108 +                            res.setResult(success);
   2.109 +                            env.sendObject(res);
   2.110 +                        }
   2.111 +                    };
   2.112 +                    final Lookup lkp = Lookups.fixed(file, prj, progress);
   2.113 +                    final ActionProvider ap = prj.getLookup().lookup(ActionProvider.class);
   2.114 +                    if (supportsFix(ap, lkp)) {
   2.115 +                        SwingUtilities.invokeLater(new Runnable() {
   2.116 +                            @Override
   2.117 +                            public void run() {
   2.118 +                                ap.invokeAction(null, lkp);
   2.119 +                            }
   2.120 +                        });
   2.121 +                    }
   2.122 +                    result = Status.accepted;
   2.123 +                }
   2.124 +            }
   2.125 +        }
   2.126 +        return result;
   2.127 +    }
   2.128 +
   2.129 +    private static boolean supportsFix(
   2.130 +            @NullAllowed final ActionProvider ap,
   2.131 +            @NonNull final Lookup lkp) {
   2.132 +        Parameters.notNull("lkp", lkp); //NOI18N
   2.133 +        if (ap == null) {
   2.134 +            return false;
   2.135 +        }
   2.136 +        if (!Arrays.asList(ap.getSupportedActions()).contains(
   2.137 +                JavaProjectConstants.COMMAND_DEBUG_FIX)) {
   2.138 +            return false;
   2.139 +        }
   2.140 +        return ap.isActionEnabled(JavaProjectConstants.COMMAND_DEBUG_FIX, lkp);
   2.141 +    }
   2.142 +}
     3.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugMessageType.java	Tue Feb 04 13:57:07 2014 +0100
     3.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugMessageType.java	Tue Feb 04 17:52:17 2014 +0100
     3.3 @@ -55,6 +55,7 @@
     3.4      stepIn,
     3.5      stepOut,
     3.6      eval,
     3.7 +    apply,
     3.8      suspended,
     3.9      disconnected
    3.10  }
     4.1 --- a/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java	Tue Feb 04 13:57:07 2014 +0100
     4.2 +++ b/dew4nb/src/org/netbeans/modules/dew4nb/services/debugger/DebugerModels.java	Tue Feb 04 17:52:17 2014 +0100
     4.3 @@ -95,6 +95,15 @@
     4.4      static final class EvalResultModel {
     4.5      }
     4.6  
     4.7 +    @Model(className = "ApplyCodeChangesResult", properties = {
     4.8 +        @Property(name = "status", type = Status.class),
     4.9 +        @Property(name = "type", type = DebugMessageType.class),
    4.10 +        @Property(name = "state", type = String.class),
    4.11 +        @Property(name = "result", type = boolean.class)
    4.12 +    })
    4.13 +    static final class ApplyCodeChangesResultModel {
    4.14 +    }
    4.15 +
    4.16      @Model(className = "ContinueResult", properties = {
    4.17          @Property(name = "status", type = Status.class),
    4.18          @Property(name = "type", type = DebugMessageType.class),