diff -r 02806dcfe965 groovy.grails/manifest.mf --- a/groovy.grails/manifest.mf Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grails/manifest.mf Mon Oct 26 14:25:17 2009 +0100 @@ -3,5 +3,5 @@ OpenIDE-Module: org.netbeans.modules.groovy.grails OpenIDE-Module-Layer: org/netbeans/modules/groovy/grails/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/groovy/grails/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.19 +OpenIDE-Module-Specification-Version: 1.20 diff -r 02806dcfe965 groovy.grails/src/org/netbeans/modules/groovy/grails/api/ExecutionSupport.java --- a/groovy.grails/src/org/netbeans/modules/groovy/grails/api/ExecutionSupport.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grails/src/org/netbeans/modules/groovy/grails/api/ExecutionSupport.java Mon Oct 26 14:25:17 2009 +0100 @@ -119,15 +119,20 @@ }; } - public Callable createSimpleCommand(final String command, final GrailsProjectConfig config, - final String... arguments) { + public Callable createSimpleCommand(final String command, + final GrailsProjectConfig config, final String... arguments) { + return createSimpleCommand(command, false, config, arguments); + } + + public Callable createSimpleCommand(final String command, final boolean debug, + final GrailsProjectConfig config, final String... arguments) { return new Callable() { public Process call() throws Exception { File directory = FileUtil.toFile(config.getProject().getProjectDirectory()); GrailsPlatform.CommandDescriptor descriptor = GrailsPlatform.CommandDescriptor.forProject( - command, directory, config, arguments, null); + command, directory, config, arguments, null, debug); return platform.createCommand(descriptor).call(); } }; diff -r 02806dcfe965 groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsPlatform.java --- a/groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsPlatform.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsPlatform.java Mon Oct 26 14:25:17 2009 +0100 @@ -56,7 +56,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; @@ -81,7 +80,6 @@ import org.openide.util.NbPreferences; import org.openide.util.Parameters; import org.openide.util.RequestProcessor; -import org.openide.util.Utilities; /** * Class providing the access to basic Grails runtime routines. diff -r 02806dcfe965 groovy.grailsproject/nbproject/project.xml --- a/groovy.grailsproject/nbproject/project.xml Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/nbproject/project.xml Mon Oct 26 14:25:17 2009 +0100 @@ -15,6 +15,15 @@ + org.netbeans.api.debugger.jpda + + + + 2 + 2.20 + + + org.netbeans.api.java @@ -91,7 +100,7 @@ - 1.17 + 1.20 diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsActionProvider.java --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsActionProvider.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsActionProvider.java Mon Oct 26 14:25:17 2009 +0100 @@ -168,7 +168,7 @@ ProjectInformation inf = project.getLookup().lookup(ProjectInformation.class); String displayName = inf.getDisplayName() + " (run-app)"; // NOI18N - ExecutionDescriptor descriptor = project.getCommandSupport().getRunDescriptor(); + ExecutionDescriptor descriptor = project.getCommandSupport().getRunDescriptor(debug); ExecutionService service = ExecutionService.newService(callable, descriptor, displayName); service.run(); diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsProject.java --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsProject.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/GrailsProject.java Mon Oct 26 14:25:17 2009 +0100 @@ -70,6 +70,7 @@ import org.netbeans.modules.groovy.grailsproject.completion.ControllerCompletionProvider; import org.netbeans.modules.groovy.grailsproject.completion.DomainCompletionProvider; import org.netbeans.modules.groovy.grailsproject.config.BuildConfig; +import org.netbeans.modules.groovy.grailsproject.debug.GrailsDebugger; import org.netbeans.modules.groovy.grailsproject.ui.TemplatesImpl; import org.netbeans.modules.groovy.support.spi.GroovyFeature; import org.netbeans.spi.project.AuxiliaryConfiguration; @@ -222,7 +223,8 @@ new DomainCompletionProvider(), logicalView, //Logical view of project implementation cpProvider, - new GrailsProjectConfig(this) + new GrailsProjectConfig(this), + new GrailsDebugger(this) ); } return lookup; diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/Bundle.properties --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/Bundle.properties Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/Bundle.properties Mon Oct 26 14:25:17 2009 +0100 @@ -53,7 +53,7 @@ LBL_ResolvePlugins=Resolve Plugins -CTL_GrailsCommandAction=Run Grails Command... +CTL_GrailsCommandAction=Run/Debug Grails Command... #Run/Debug Grails Command... LBL_ResolvingPluginsLabel=Resolving Project Plugins ... diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/GrailsCommandAction.java --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/GrailsCommandAction.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/actions/GrailsCommandAction.java Mon Oct 26 14:25:17 2009 +0100 @@ -39,20 +39,18 @@ package org.netbeans.modules.groovy.grailsproject.actions; -import org.netbeans.modules.groovy.grailsproject.commands.*; -import java.awt.event.ActionEvent; import java.net.URL; import java.util.concurrent.Callable; -import javax.swing.AbstractAction; import org.netbeans.api.extexecution.ExecutionDescriptor; import org.netbeans.api.extexecution.ExecutionService; -import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; import org.netbeans.modules.groovy.grails.api.ExecutionSupport; import org.netbeans.modules.groovy.grails.api.GrailsProjectConfig; import org.netbeans.modules.groovy.grails.api.GrailsPlatform; import org.netbeans.modules.groovy.grailsproject.GrailsProject; import org.netbeans.modules.groovy.grailsproject.GrailsServerState; +import org.netbeans.modules.groovy.grailsproject.commands.GrailsCommandChooser; +import org.netbeans.modules.groovy.grailsproject.commands.GrailsCommandSupport; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; @@ -97,9 +95,10 @@ Callable callable; ExecutionDescriptor descriptor; + final boolean debug = commandDescriptor.isDebug(); + if (GrailsPlatform.IDE_RUN_COMMAND.equals(commandDescriptor.getGrailsCommand().getCommand())) { final GrailsServerState serverState = project.getLookup().lookup(GrailsServerState.class); - final boolean debug = false; Process process = null; if (serverState != null && serverState.isRunning()) { if (!debug /*|| debug == serverState.isDebug()*/) { @@ -134,11 +133,13 @@ } }; - descriptor = project.getCommandSupport().getRunDescriptor(); + descriptor = project.getCommandSupport().getRunDescriptor(debug); } else { callable = ExecutionSupport.getInstance().createSimpleCommand( - commandDescriptor.getGrailsCommand().getCommand(), GrailsProjectConfig.forProject(project), params); - descriptor = project.getCommandSupport().getDescriptor(commandDescriptor.getGrailsCommand().getCommand()); + commandDescriptor.getGrailsCommand().getCommand(), debug, + GrailsProjectConfig.forProject(project), params); + descriptor = project.getCommandSupport().getDescriptor( + commandDescriptor.getGrailsCommand().getCommand(), debug); } ExecutionService service = ExecutionService.newService(callable, descriptor, displayName); service.run(); diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.form --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.form Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.form Mon Oct 26 14:25:17 2009 +0100 @@ -1,15 +1,9 @@
- - - - - - - - - + + + @@ -29,6 +23,7 @@ + @@ -62,7 +57,9 @@ - + + + @@ -162,5 +159,12 @@ + + + + + + + diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.java --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandChooser.java Mon Oct 26 14:25:17 2009 +0100 @@ -402,7 +402,6 @@ // //GEN-BEGIN:initComponents private void initComponents() { - debugCheckbox = new javax.swing.JCheckBox(); rakeTaskLabel = new javax.swing.JLabel(); taskParamLabel = new javax.swing.JLabel(); matchingTaskLabel = new javax.swing.JLabel(); @@ -412,8 +411,7 @@ rakeTaskField = new javax.swing.JTextField(); rakeTaskHint = new javax.swing.JLabel(); taskParametersComboBox = new javax.swing.JComboBox(); - - org.openide.awt.Mnemonics.setLocalizedText(debugCheckbox, org.openide.util.NbBundle.getMessage(GrailsCommandChooser.class, "GrailsCommandChooser.debugCheckbox.text")); // NOI18N + debugCheckbox = new javax.swing.JCheckBox(); rakeTaskLabel.setLabelFor(rakeTaskField); org.openide.awt.Mnemonics.setLocalizedText(rakeTaskLabel, org.openide.util.NbBundle.getMessage(GrailsCommandChooser.class, "GrailsCommandChooser.rakeTaskLabel.text")); // NOI18N @@ -423,7 +421,7 @@ matchingTaskLabel.setLabelFor(matchingTaskList); org.openide.awt.Mnemonics.setLocalizedText(matchingTaskLabel, org.openide.util.NbBundle.getMessage(GrailsCommandChooser.class, "GrailsCommandChooser.matchingTaskLabel.text")); // NOI18N - matchingTaskList.setFont(new java.awt.Font("Monospaced", 0, 12)); + matchingTaskList.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N matchingTaskList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); matchingTaskList.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { @@ -448,6 +446,8 @@ taskParametersComboBox.setEditable(true); taskParametersComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + org.openide.awt.Mnemonics.setLocalizedText(debugCheckbox, org.openide.util.NbBundle.getMessage(GrailsCommandChooser.class, "GrailsCommandChooser.debugCheckbox.text")); // NOI18N + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -456,6 +456,7 @@ .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, matchingTaskSP, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, debugCheckbox) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(rakeTaskLabel) @@ -481,7 +482,9 @@ .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(matchingTaskLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(matchingTaskSP, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE) + .add(matchingTaskSP, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(debugCheckbox) .addContainerGap()) ); }// //GEN-END:initComponents diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandSupport.java --- a/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandSupport.java Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/commands/GrailsCommandSupport.java Mon Oct 26 14:25:17 2009 +0100 @@ -62,12 +62,15 @@ import org.netbeans.api.extexecution.input.InputProcessor; import org.netbeans.api.extexecution.input.InputProcessors; import org.netbeans.api.extexecution.input.LineProcessor; +import org.netbeans.api.extexecution.input.LineProcessors; +import org.netbeans.api.project.ProjectInformation; import org.netbeans.modules.groovy.grails.api.ExecutionSupport; import org.netbeans.modules.groovy.grails.api.GrailsProjectConfig; import org.netbeans.modules.groovy.grails.api.GrailsPlatform; import org.netbeans.modules.groovy.grailsproject.GrailsProject; import org.netbeans.modules.groovy.grailsproject.GrailsServerState; import org.netbeans.modules.groovy.grailsproject.actions.RefreshProjectRunnable; +import org.netbeans.modules.groovy.grailsproject.debug.GrailsDebugger; import org.netbeans.modules.groovy.support.api.GroovySettings; import org.netbeans.modules.web.client.tools.api.JSToNbJSLocationMapper; import org.netbeans.modules.web.client.tools.api.LocationMappersFactory; @@ -82,6 +85,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileRenameEvent; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; import org.openide.windows.InputOutput; @@ -120,12 +124,16 @@ return commands; } - public ExecutionDescriptor getRunDescriptor() { - return getDescriptor(GrailsPlatform.IDE_RUN_COMMAND); + public ExecutionDescriptor getRunDescriptor(boolean debug) { + return getDescriptor(GrailsPlatform.IDE_RUN_COMMAND, debug); } public ExecutionDescriptor getDescriptor(String command) { - return getDescriptor(command, null, false); + return getDescriptor(command, false); + } + + public ExecutionDescriptor getDescriptor(String command, boolean debug) { + return getDescriptor(command, null, debug); } public ExecutionDescriptor getDescriptor(String command, InputProcessorFactory outFactory) { @@ -138,38 +146,69 @@ ExecutionDescriptor descriptor = RUN_DESCRIPTOR; InputProcessorFactory urlFactory = new InputProcessorFactory() { public InputProcessor newInputProcessor(InputProcessor defaultProcessor) { + LineProcessor lineProcessor = null; + if (debug) { + lineProcessor = LineProcessors.proxy( + new ServerOutputProcessor(project, debug), + new DebugOutputProcessor(project)); + } else { + lineProcessor = new ServerOutputProcessor(project, debug); + } + return InputProcessors.proxy(defaultProcessor, - InputProcessors.bridge(new ServerURLProcessor(project, debug))); + InputProcessors.bridge(lineProcessor)); } }; - if (outFactory != null) { - descriptor = descriptor.outProcessorFactory(new ProxyInputProcessorFactory(urlFactory, outFactory)); - } else { - descriptor = descriptor.outProcessorFactory(urlFactory); - } + descriptor = descriptor.outProcessorFactory( + createInputProcessorFactory(urlFactory, outFactory)); return descriptor; - } else if ("shell".equals(command)) { // NOI18N + } + + InputProcessorFactory debugFactory = null; + if (debug) { + debugFactory = new InputProcessorFactory() { + + public InputProcessor newInputProcessor(InputProcessor defaultProcessor) { + return InputProcessors.proxy(defaultProcessor, + InputProcessors.bridge(new DebugOutputProcessor(project))); + } + }; + } + + if ("shell".equals(command)) { // NOI18N ExecutionDescriptor descriptor = RUN_DESCRIPTOR.postExecution(new RefreshProjectRunnable(project)) .errProcessorFactory(ANSI_STRIPPING); - if (outFactory != null) { - descriptor = descriptor.outProcessorFactory(new ProxyInputProcessorFactory(ANSI_STRIPPING, outFactory)); - } else { - descriptor = descriptor.outProcessorFactory(ANSI_STRIPPING); - } + + descriptor = descriptor.outProcessorFactory( + createInputProcessorFactory(ANSI_STRIPPING, outFactory, debugFactory)); return descriptor; } else { ExecutionDescriptor descriptor = GRAILS_DESCRIPTOR.postExecution(new RefreshProjectRunnable(project)) .errProcessorFactory(ANSI_STRIPPING); - if (outFactory != null) { - descriptor = descriptor.outProcessorFactory(new ProxyInputProcessorFactory(ANSI_STRIPPING, outFactory)); - } else { - descriptor = descriptor.outProcessorFactory(ANSI_STRIPPING); - } + + descriptor = descriptor.outProcessorFactory( + createInputProcessorFactory(ANSI_STRIPPING, outFactory, debugFactory)); return descriptor; } } + private InputProcessorFactory createInputProcessorFactory(InputProcessorFactory... factories) { + List real = new ArrayList(3); + for (InputProcessorFactory factory : factories) { + if (factory != null) { + real.add(factory); + } + } + if (real.isEmpty()) { + return null; + } + if (real.size() == 1) { + return real.get(0); + } + return new ProxyInputProcessorFactory(real.toArray(new InputProcessorFactory[real.size()])); + } + public void refreshGrailsCommands() { Callable callable = ExecutionSupport.getInstance().createSimpleCommand("help", // NOI18N GrailsProjectConfig.forProject(project)); @@ -323,14 +362,53 @@ } } - private static class ServerURLProcessor implements LineProcessor { + private static class DebugOutputProcessor implements LineProcessor { + + private static final Pattern DEBUGGER_PATTERN = + Pattern.compile("Listening\\s+for\\s+transport\\s+(\\w+)\\s+at\\s+address:\\s+([0-9]+).*"); + + private final GrailsProject project; + + private boolean debugging; + + public DebugOutputProcessor(GrailsProject project) { + this.project = project; + } + + public void processLine(String line) { + Matcher matcher = DEBUGGER_PATTERN.matcher(line); + if (!debugging && matcher.matches()) { + debugging = true; + + try { + String name = project.getLookup().lookup(ProjectInformation.class).getDisplayName(); + GrailsDebugger debuger = project.getLookup().lookup(GrailsDebugger.class); + if (debuger != null) { + debuger.attachDebugger(name, matcher.group(1), "localhost", matcher.group(2)); // NOI18N + } + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + } + } + + public void reset() { + // noop + } + + public void close() { + // noop + } + } + + private static class ServerOutputProcessor implements LineProcessor { private final GrailsProject project; private final boolean debug; private boolean running; - public ServerURLProcessor(GrailsProject project, boolean debug) { + public ServerOutputProcessor(GrailsProject project, boolean debug) { this.project = project; this.debug = debug; } diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/debug/GrailsDebugger.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/debug/GrailsDebugger.java Mon Oct 26 14:25:17 2009 +0100 @@ -0,0 +1,118 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.groovy.grailsproject.debug; + +import java.util.HashMap; +import java.util.Map; +import org.netbeans.api.debugger.jpda.JPDADebugger; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.project.Project; +import org.openide.filesystems.FileUtil; +import org.openide.util.RequestProcessor; + +/** + * + * @author Petr Hejl + */ +public class GrailsDebugger { + + private final Project nbproject; + + public GrailsDebugger(Project prj) { + nbproject = prj; + } + + public void attachDebugger(String name, final String transport, + final String host, final String address) throws Exception { + + final Object[] lock = new Object [1]; + ClassPath sourcePath = Utils.createSourcePath(nbproject); + ClassPath jdkSourcePath = Utils.createJDKSourcePath(nbproject); + + final Map properties = new HashMap(); + properties.put("sourcepath", sourcePath); //NOI18N + properties.put("name", name); //NOI18N + properties.put("jdksources", jdkSourcePath); //NOI18N + properties.put("baseDir", FileUtil.toFile(nbproject.getProjectDirectory())); // NOI18N + + synchronized(lock) { + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + synchronized(lock) { + try { + // VirtualMachineManagerImpl can be initialized + // here, so needs to be inside RP thread. + if (transport.equals("dt_socket")) //NOI18N + try { + JPDADebugger.attach( + host, + Integer.parseInt(address), + new Object[] {properties} + ); + } catch (NumberFormatException e) { + throw new Exception( + "address attribute must specify port " + //NOI18N + "number for dt_socket connection"); //NOI18N + } else + JPDADebugger.attach( + address, + new Object[] {properties} + ); + } catch (Throwable e) { + lock[0] = e; + } finally { + lock.notify(); + } + } + } + }); + try { + lock.wait(); + } catch (InterruptedException e) { + throw e; + } + if (lock[0] != null) { + throw new Exception("", (Throwable) lock[0]); + } + + } + } + +} diff -r 02806dcfe965 groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/debug/Utils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/debug/Utils.java Mon Oct 26 14:25:17 2009 +0100 @@ -0,0 +1,198 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2008 Sun Microsystems, Inc. + */ + + +package org.netbeans.modules.groovy.grailsproject.debug; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.api.project.Project; +import org.netbeans.modules.groovy.grails.api.GrailsProjectConfig; +import org.netbeans.modules.groovy.grailsproject.GrailsProject; +import org.netbeans.spi.java.classpath.PathResourceImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileUtil; + +/** + * various debugger related utility methods. + * @author mkleint + */ +public class Utils { + + /** Creates a new instance of Utils */ + private Utils() { + } + +// static MethodBreakpoint createBreakpoint(String stopClassName) { +// MethodBreakpoint breakpoint = MethodBreakpoint.create( +// stopClassName, +// "*" //NOI18N +// ); +// breakpoint.setHidden(true); +// DebuggerManager.getDebuggerManager().addBreakpoint(breakpoint); +// return breakpoint; +// } + + public static File[] convertStringsToNormalizedFiles(Collection strings) { + File[] fos = new File[strings.size()]; + int index = 0; + Iterator it = strings.iterator(); + while (it.hasNext()) { + String str = (String)it.next(); + File fil = new File(str); + fil = FileUtil.normalizeFile(fil); + fos[index] = fil; + index++; + } + return fos; + } + + static ClassPath createSourcePath(Project project) { + GrailsProject grailsProject = project.getLookup().lookup(GrailsProject.class); + + Set urls = new HashSet(); + urls.addAll(grailsProject.getSourceRoots().getRootURLs()); + // this is dup of above line in fact + urls.addAll(grailsProject.getTestSourceRoots().getRootURLs()); + + return ClassPathSupport.createClassPath(urls.toArray(new URL[urls.size()])); + } + + static ClassPath createJDKSourcePath(Project nbproject) { + GrailsProjectConfig config = nbproject.getLookup().lookup(GrailsProjectConfig.class); + JavaPlatform jp = config.getJavaPlatform(); + if (jp == null) { + jp = JavaPlatformManager.getDefault().getDefaultPlatform(); + } + if (jp != null) { + return jp.getSourceFolders(); + } + return ClassPathSupport.createClassPath(new URL[0]); + } + + private static ClassPath convertToClassPath(File[] roots) { + List l = new ArrayList(); + for (int i = 0; i < roots.length; i++) { + URL url = Utils.fileToURL(roots[i]); + l.add(url); + } + URL[] urls = l.toArray(new URL[l.size()]); + return ClassPathSupport.createClassPath(urls); + } + + /** + * This method uses SourceForBinaryQuery to find sources for each + * path item and returns them as ClassPath instance. All path items for which + * the sources were not found are omitted. + * + */ + private static ClassPath convertToSourcePath(File[] fs) { + List lst = new ArrayList(); + Set existingSrc = new HashSet(); + for (int i = 0; i < fs.length; i++) { + URL url = Utils.fileToURL(fs[i]); + try { + FileObject[] srcfos = SourceForBinaryQuery.findSourceRoots(url).getRoots(); + for (int j = 0; j < srcfos.length; j++) { + if (FileUtil.isArchiveFile(srcfos[j])) { + srcfos [j] = FileUtil.getArchiveRoot(srcfos [j]); + } + try { + url = srcfos[j].getURL(); + if (!url.toExternalForm().endsWith("/")) { + url = new URL(url.toExternalForm() + "/"); + } + } catch (FileStateInvalidException ex) { + ErrorManager.getDefault().notify + (ErrorManager.EXCEPTION, ex); + continue; + } catch (MalformedURLException ex) { + ErrorManager.getDefault().notify + (ErrorManager.EXCEPTION, ex); + continue; + } + if (url == null) { + continue; + } + if (!existingSrc.contains(url)) { + lst.add(ClassPathSupport.createResource(url)); + existingSrc.add(url); + } + } // for + } catch (IllegalArgumentException ex) { + //TODO?? + } + } + return ClassPathSupport.createClassPath(lst); + } + + + + static URL fileToURL(File file) { + try { + URL url; + url = file.toURI().toURL(); + if (FileUtil.isArchiveFile(url)) { + url = FileUtil.getArchiveRoot(url); + } + if (!url.toExternalForm().endsWith("/")) { //NOI18N + url = new URL(url.toExternalForm() + "/"); //NOI18N + } + return url; + } catch (MalformedURLException ex) { + ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex); + return null; + } + } + +} diff -r 02806dcfe965 groovy.support/nbproject/project.properties --- a/groovy.support/nbproject/project.properties Fri Oct 23 20:11:27 2009 +0400 +++ b/groovy.support/nbproject/project.properties Mon Oct 26 14:25:17 2009 +0100 @@ -1,4 +1,5 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 +cp.extra=${tools.jar} nbm.homepage=http://wiki.netbeans.org/groovy -nbm.module.author=Martin Adamek, Matthias Schmidt +nbm.module.author=Martin Adamek, Petr Hejl, Matthias Schmidt diff -r 02806dcfe965 groovy.support/src/org/netbeans/modules/groovy/support/debug/GroovyEvaluator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/groovy.support/src/org/netbeans/modules/groovy/support/debug/GroovyEvaluator.java Mon Oct 26 14:25:17 2009 +0100 @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.groovy.support.debug; + +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.api.debugger.jpda.InvalidExpressionException; +import org.netbeans.api.debugger.jpda.JPDADebugger; +import org.netbeans.spi.debugger.ContextProvider; +import org.netbeans.spi.debugger.jpda.Evaluator; + +/** + * + * @author Petr Hejl + */ +@Evaluator.Registration(language="GROOVY") +public class GroovyEvaluator implements Evaluator { + + private static final Logger LOGGER = Logger.getLogger(GroovyEvaluator.class.getName()); + + private final JPDADebugger debugger; + + public GroovyEvaluator (ContextProvider lookupProvider) { + debugger = lookupProvider.lookupFirst(null, JPDADebugger.class); + } + + public Result evaluate(Expression expression, final Context context) throws InvalidExpressionException { + LOGGER.log(Level.FINE, "Groovy evaulator evaluating {0}", expression.getExpression()); + + return new Result(context.getContextVariable()); + } + +} diff -r 02806dcfe965 groovy.support/src/org/netbeans/modules/groovy/support/debug/GroovyExpression.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/groovy.support/src/org/netbeans/modules/groovy/support/debug/GroovyExpression.java Mon Oct 26 14:25:17 2009 +0100 @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2009 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.groovy.support.debug; + +/** + * + * @author Petr Hejl + */ +public class GroovyExpression { + +}