You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by GitBox <gi...@apache.org> on 2017/12/09 15:15:40 UTC

[GitHub] JaroslavTulach closed pull request #319: new property jpda.attach.trigger to allow attaching debugger to exter?

JaroslavTulach closed pull request #319: new property jpda.attach.trigger to allow attaching debugger to exter?
URL: https://github.com/apache/incubator-netbeans/pull/319
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven/apichanges.xml b/maven/apichanges.xml
index e7ff96e12..5086ff9c4 100644
--- a/maven/apichanges.xml
+++ b/maven/apichanges.xml
@@ -83,6 +83,23 @@ is the proper place.
     <!-- ACTUAL CHANGES BEGIN HERE: -->
 
     <changes>
+        <change id="jpda-attach-trigger">
+           <api name="general"/>
+           <summary>Attach to Debugger on triggers</summary>
+           <version major="2" minor="127"/>
+           <date day="8" month="12" year="2017"/>
+           <author login="monacotoni"/>
+           <compatibility modification="yes" semantic="compatible"/>
+           <description>
+               <p>
+                   New property to allow  to attach debugger while goal execution is in progress:
+                   <code>ACTION_PROPERTY_JPDAATTACH_TRIGGER</code>. Read more about 
+    usage of this property in 
+    the <a href="@TOP@architecture-summary.html#property-jpda.attach.trigger">nbactions.xml file</a>.
+               </p>
+           </description>
+           <class package="org.netbeans.modules.maven.api" name="Constants"/>
+        </change>
         <change id="jpda-attach">
            <api name="general"/>
            <summary>Attach to Debugger after Goal Execution</summary>
@@ -142,26 +159,29 @@ is the proper place.
 
                 SEE projects/projectuiapi/apichanges.xml
 
--->
-    <head>
-      <title>Change History for the Maven Project API</title>
-      <link rel="stylesheet" href="prose.css" type="text/css"/>
-    </head>
-    <body>
+        -->
+        <head>
+            <title>Change History for the Maven Project API</title>
+            <link rel="stylesheet" href="prose.css" type="text/css"/>
+        </head>
+        <body>
 
-<p class="overviewlink"><a href="overview-summary.html">Overview</a></p>
+            <p class="overviewlink">
+                <a href="overview-summary.html">Overview</a>
+            </p>
 
-<h1>Introduction</h1>
+            <h1>Introduction</h1>
 
-<p>This document lists changes made to the <a href="@org-netbeans-modules-maven@/index.html">Maven Project API</a>.</p>
+            <p>This document lists changes made to the <a href="@org-netbeans-modules-maven@/index.html">Maven Project API</a>.</p>
 
-<!-- The actual lists of changes, as summaries and details: -->
-      <hr/>
-      <standard-changelists module-code-name="org.netbeans.modules.maven/1"/>
+            <!-- The actual lists of changes, as summaries and details: -->
+            <hr/>
+            <standard-changelists module-code-name="org.netbeans.modules.maven/1"/>
 
-      <hr/><p>@FOOTER@</p>
+            <hr/>
+            <p>@FOOTER@</p>
 
-    </body>
-  </htmlcontents>
+        </body>
+    </htmlcontents>
 
 </apichanges>
diff --git a/maven/arch.xml b/maven/arch.xml
index fa3789e1d..98ca1ffaa 100644
--- a/maven/arch.xml
+++ b/maven/arch.xml
@@ -286,6 +286,35 @@
         <code>address:port</code> or just port number to connect to.
         </p>
         </api>
+        <api category="stable" group="property" name="jpda.attach.trigger" type="export">
+             <p>
+             One can define following code in nbactions.xml file to start
+             a process during goal execution and attach a debugger to it
+             when the external process prints a text indicating it's ready for attaching debugger. 
+                 One example is debugging applications using <a href="https://software.intel.com/en-us/multi-os-engine" target="_blank" >Multi-OS Engine</a>:
+             </p>
+<pre>
+    &lt;action&gt;
+        &lt;actionName&gt;debug&lt;/actionName&gt;
+        &lt;goals&gt;
+            &lt;goal&gt;package&lt;/goal&gt;
+            &lt;goal&gt;moe:launch&lt;/goal&gt;
+        &lt;/goals&gt;
+        &lt;properties&gt;
+            &lt;skipTests&gt;true&lt;/skipTests&gt;
+            &lt;moe.options&gt;debug:${jpda.attach.port}&lt;/moe.options&gt;
+            &lt;jpda.attach&gt;true&lt;/jpda.attach&gt;
+            &lt;jpda.attach.trigger&gt;JDWP will wait for debugger on port&lt;/jpda.attach.trigger&gt;
+        &lt;/properties&gt;
+        &lt;activatedProfiles&gt;
+            &lt;activatedProfile&gt;moe&lt;/activatedProfile&gt;
+        &lt;/activatedProfiles&gt;
+    &lt;/action&gt;
+</pre>             
+        <p>
+        Value of <code>jpda.attach.trigger</code> property is the expected text. 
+        </p>
+        </api>
      </p>
  </answer>
 
diff --git a/maven/manifest.mf b/maven/manifest.mf
index 11dadd43b..d54d27143 100644
--- a/maven/manifest.mf
+++ b/maven/manifest.mf
@@ -1,6 +1,6 @@
 Manifest-Version: 1.0
 OpenIDE-Module: org.netbeans.modules.maven/2
-OpenIDE-Module-Specification-Version: 2.126
+OpenIDE-Module-Specification-Version: 2.127
 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/Bundle.properties
 OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml
 AutoUpdate-Show-In-Client: false
diff --git a/maven/src/org/netbeans/modules/maven/api/Constants.java b/maven/src/org/netbeans/modules/maven/api/Constants.java
index 8bed0e8e6..8c7c7591e 100644
--- a/maven/src/org/netbeans/modules/maven/api/Constants.java
+++ b/maven/src/org/netbeans/modules/maven/api/Constants.java
@@ -150,6 +150,15 @@
      * @since 2.113
      */
     public static final String ACTION_PROPERTY_JPDAATTACH_TRANSPORT = "jpda.attach.transport";
+ 
+    /**
+     * Name of a property used for checking the maven output for the approriate time to attach to
+     * {@link #ACTION_PROPERTY_JPDAATTACH_ADDRESS} address.
+     * This property is meaningful only when {@link #ACTION_PROPERTY_JPDAATTACH_ADDRESS}
+     * is defined.
+     * @since 2.127
+     */
+    public static final String ACTION_PROPERTY_JPDAATTACH_TRIGGER = "jpda.attach.trigger";
 
     /**
      * Optional property, if defined the project type will attempt to redirect meaningful
diff --git a/maven/src/org/netbeans/modules/maven/debug/DebugCheckerOutputFactory.java b/maven/src/org/netbeans/modules/maven/debug/DebugCheckerOutputFactory.java
new file mode 100644
index 000000000..15d766684
--- /dev/null
+++ b/maven/src/org/netbeans/modules/maven/debug/DebugCheckerOutputFactory.java
@@ -0,0 +1,118 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2017 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2017 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.maven.debug;
+
+import java.awt.Color;
+import java.util.Collections;
+import java.util.Set;
+import org.netbeans.api.debugger.jpda.DebuggerStartException;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.maven.api.Constants;
+import org.netbeans.modules.maven.api.execute.RunConfig;
+import org.netbeans.modules.maven.api.output.ContextOutputProcessorFactory;
+import org.netbeans.modules.maven.api.output.OutputProcessor;
+import org.netbeans.modules.maven.api.output.OutputProcessorFactory;
+import org.netbeans.modules.maven.api.output.OutputVisitor;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+
+
+@ServiceProvider(service=OutputProcessorFactory.class)
+public class DebugCheckerOutputFactory implements ContextOutputProcessorFactory {
+
+    @Override
+    public Set<? extends OutputProcessor> createProcessorsSet(Project project, RunConfig config) {
+        String trigger = config.getProperties().get(Constants.ACTION_PROPERTY_JPDAATTACH_TRIGGER);
+        if (trigger == null) {
+            return Collections.emptySet();
+        }
+        return Collections.singleton(new JPDATrigger(trigger, config));
+    }
+
+    @Override
+    public Set<? extends OutputProcessor> createProcessorsSet(Project project) {
+        return Collections.emptySet();
+    }
+
+    private static class JPDATrigger implements OutputProcessor {
+
+        private String trigger;
+        private final RunConfig cfg;
+
+        public JPDATrigger(String trigger, RunConfig cfg) {
+            this.trigger = trigger;
+            this.cfg = cfg;
+        }
+
+        @Override
+        public String[] getRegisteredOutputSequences() {
+            return new String[] { "project-execute" };
+        }
+
+        @Override
+        public void processLine(String line, OutputVisitor visitor) {
+            if (trigger != null && line.contains(trigger)) {
+                trigger = null;
+                try {
+                    DebuggerChecker.connect(cfg);
+                } catch (DebuggerStartException ex) {
+                    visitor.setLine(visitor.getLine() + " cannot connect: " + ex.getMessage());
+                    visitor.setColor(Color.red);
+                    Exceptions.printStackTrace(ex);
+                }
+            }
+        }
+
+        @Override
+        public void sequenceStart(String sequenceId, OutputVisitor visitor) {
+        }
+
+        @Override
+        public void sequenceEnd(String sequenceId, OutputVisitor visitor) {
+        }
+
+        @Override
+        public void sequenceFail(String sequenceId, OutputVisitor visitor) {
+        }
+    }
+    
+}
diff --git a/maven/src/org/netbeans/modules/maven/debug/DebuggerChecker.java b/maven/src/org/netbeans/modules/maven/debug/DebuggerChecker.java
index 0c9fdbc53..77dae6d17 100644
--- a/maven/src/org/netbeans/modules/maven/debug/DebuggerChecker.java
+++ b/maven/src/org/netbeans/modules/maven/debug/DebuggerChecker.java
@@ -215,7 +215,7 @@ protected void doReload(final RunConfig config, final String cname) {
             //cannot act on execution without a project instance..
             return true;
         }
-
+        
         boolean debug = "true".equalsIgnoreCase(config.getProperties().get(Constants.ACTION_PROPERTY_JPDALISTEN));//NOI18N
         boolean mavenDebug = "maven".equalsIgnoreCase(config.getProperties().get(Constants.ACTION_PROPERTY_JPDALISTEN)); //NOI18N
         if (debug || mavenDebug) {
@@ -288,33 +288,40 @@ protected void doReload(final RunConfig config, final String cname) {
                 res.getInputOutput().getErr().println("Missing jpda.stopclass property in action mapping definition. Cannot reload class.");
             }
         }
+        if (resultCode == 0 && config.getProperties().get(Constants.ACTION_PROPERTY_JPDAATTACH_TRIGGER) == null) {
+            try {
+                connect(config);
+            } catch (DebuggerStartException ex) {
+                ex.printStackTrace(res.getInputOutput().getErr());
+            }
+        }
+    }
+
+    static void connect(RunConfig config) throws DebuggerStartException {
         String attachToAddress = config.getProperties().get(Constants.ACTION_PROPERTY_JPDAATTACH);
-        if (attachToAddress != null && resultCode == 0) {
+        if (attachToAddress != null) {
             String transport = config.getProperties().get(Constants.ACTION_PROPERTY_JPDAATTACH_TRANSPORT);
-            try {
-                if (transport == null || "dt_socket".equals(transport)) {
-                    int colon = attachToAddress.indexOf(':');
-                    int port;
-                    try {
-                        port = Integer.parseInt(attachToAddress.substring(colon + 1));
-                    } catch (NumberFormatException ex) {
-                        LOGGER.log(Level.INFO, "Cannot parse " + attachToAddress.substring(colon + 1) + " as number", ex);
-                        return ;
-                    }
-                    String host;
-                    if (colon > 0) {
-                        host = attachToAddress.substring(0, colon);
-                    } else {
-                        host = "localhost";
-                    }
-                    JPDADebugger.attach(host, port, new Object[0]);
-                } else if ("dt_shmem".equals(transport)) {
-                    JPDADebugger.attach(attachToAddress, new Object[0]);
+            if (transport == null || "dt_socket".equals(transport)) {
+                int colon = attachToAddress.indexOf(':');
+                int port;
+                try {
+                    port = Integer.parseInt(attachToAddress.substring(colon + 1));
+                } catch (NumberFormatException ex) {
+                    final DebuggerStartException debugEx = new DebuggerStartException("Cannot parse " + attachToAddress.substring(colon + 1) + " as number");
+                    debugEx.initCause(ex);
+                    throw debugEx;
+                }
+                String host;
+                if (colon > 0) {
+                    host = attachToAddress.substring(0, colon);
                 } else {
-                    LOGGER.log(Level.INFO, "Ignoring unknown transport '"+transport+"'");
+                    host = "localhost";
                 }
-            } catch (DebuggerStartException ex) {
-                ex.printStackTrace(res.getInputOutput().getErr());
+                JPDADebugger.attach(host, port, new Object[0]);
+            } else if ("dt_shmem".equals(transport)) {
+                JPDADebugger.attach(attachToAddress, new Object[0]);
+            } else {
+                LOGGER.log(Level.INFO, "Ignoring unknown transport '"+transport+"'");
             }
         }
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services