Skip to content

Commit

Permalink
Groovy for conditional breakpoints, watch expressions, logical structure
Browse files Browse the repository at this point in the history
and the Debug Console view

for #568 #569
  • Loading branch information
eric-milles committed Jun 29, 2023
1 parent 6965fc2 commit cc114a5
Show file tree
Hide file tree
Showing 13 changed files with 1,371 additions and 1,500 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,11 +28,10 @@
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.internal.core.util.Util;
import org.osgi.framework.BundleContext;
import org.osgi.service.prefs.BackingStoreException;

public class Activator extends Plugin {

Expand Down Expand Up @@ -108,8 +107,8 @@ public void setGroovyCompilerLevel(IProject project, String level) {
preferences.put(GROOVY_COMPILER_LEVEL, level);
try {
preferences.flush();
} catch (BackingStoreException e) {
Util.log(e);
} catch (org.osgi.service.prefs.BackingStoreException e) {
getLog().log(new Status(0x4, PLUGIN_ID, null, e));
}
}
}
Expand All @@ -131,8 +130,8 @@ public void setScriptFilters(IEclipsePreferences preferences, String value) {
preferences.put(GROOVY_SCRIPT_FILTERS, value);
try {
preferences.flush();
} catch (BackingStoreException e) {
Util.log(e);
} catch (org.osgi.service.prefs.BackingStoreException e) {
getLog().log(new Status(0x4, PLUGIN_ID, null, e));
}
}

Expand Down
2 changes: 1 addition & 1 deletion checkstyleConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@
</module>
<module name="RegexpSingleline">
<property name="message" value="Groovy property notation should be used instead of accessors" />
<property name="format" value="^(?!\s*\|(?!\|)).*(?&lt;!\b\p{Upper}\w{0,99}\s{0,99})\.(get\p{Upper}\p{Alnum}*\(\s*\)|set\p{Upper}\p{Alnum}*\([^,]+\))(?!;?[&apos;&quot;](?:,|$))" />
<property name="format" value="^(?!\s*\|(?!\|)).*(?&lt;!\b\p{Upper}\w{0,99}\s{0,99})\.(get(?!Class|Super|This)\p{Upper}\p{Alnum}*\(\s*\)|set(?!Class|Super|This)\p{Upper}\p{Alnum}*\([^,]+\))(?!;?[&apos;&quot;](?:,|$))" />
<property name="fileExtensions" value="groovy" />
<property name="id" value="groovyPropertyAccess" />
</module>
Expand Down
6 changes: 5 additions & 1 deletion ide/org.codehaus.groovy.eclipse.ui/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<classpath>
<classpathentry kind="src" path="src" output="bin"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="org/eclipse/jdt/debug/eval/*"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,11 @@
*/
package org.codehaus.groovy.eclipse;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.codehaus.groovy.eclipse.adapters.ClassFileEditorAdapterFactory;
import org.codehaus.groovy.eclipse.adapters.GroovyIFileEditorInputAdapterFactory;
import org.codehaus.groovy.eclipse.core.preferences.PreferenceConstants;
Expand All @@ -29,6 +34,10 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchListener;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
import org.eclipse.jdt.internal.ui.JavaPlugin;
Expand Down Expand Up @@ -122,6 +131,7 @@ public void start(BundleContext context) throws Exception {
adapterManager.registerAdapters(new GroovyJavaDebugElementAdapterFactory(), IJavaStackFrame.class);
adapterManager.registerAdapters(new GroovyIFileEditorInputAdapterFactory(), IFileEditorInput.class);

if (Boolean.parseBoolean(System.getProperty("eclipse.groovy.debug", "true"))) addDebugLaunchListener();
if (getPreferenceStore().getBoolean(PreferenceConstants.GROOVY_DEBUG_FORCE_DEBUG_OPTIONS_ON_STARTUP)) {
new GroovyDebugOptionsEnforcer().maybeForce(getPreferenceStore());
}
Expand All @@ -143,6 +153,32 @@ public void stop(BundleContext context) throws Exception {
}
}

private void addDebugLaunchListener() {
DebugPlugin.getDefault().getLaunchManager().addLaunchListener(new ILaunchListener() {
@Override
public void launchAdded(ILaunch launch) {
}

@Override
public void launchChanged(ILaunch launch) {
for (IDebugTarget target : launch.getDebugTargets()) {
if (target instanceof org.eclipse.jdt.debug.core.IJavaDebugTarget) try { //@formatter:off
if (ReflectionUtils.throwableGetPrivateField(target.getClass(), "fEngines", target) == null) {
ReflectionUtils.throwableSetPrivateField(target.getClass(), "fEngines", target, evalEngineInterceptor(target));
}
} catch (Exception e) {
logError("Error installing evaluation engine hooks", e);
}
//@formatter:on
}
}

@Override
public void launchRemoved(ILaunch launch) {
}
});
}

private void addMonospaceFontListener() {
junitMono = new EnsureJUnitFont();
try {
Expand Down Expand Up @@ -213,4 +249,47 @@ public void logError(String message, Throwable error) {
private void log(int severity, String message, Throwable cause) {
getLog().log(new Status(severity, PLUGIN_ID, message, cause));
}

//--------------------------------------------------------------------------

private static Object evalEngineInterceptor(IDebugTarget target) {
return Collections.synchronizedMap(new AbstractMap<org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.debug.eval.IAstEvaluationEngine>() {

private Set<Entry<org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.debug.eval.IAstEvaluationEngine>> entries = new HashSet<>(2);

@Override
public Set<Entry<org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.debug.eval.IAstEvaluationEngine>> entrySet() {
return entries;
}

@Override
public org.eclipse.jdt.debug.eval.IAstEvaluationEngine get(Object key) {
if (!containsKey(key) && key instanceof org.eclipse.jdt.core.IJavaProject) {
org.eclipse.jdt.core.IJavaProject javaProject = (org.eclipse.jdt.core.IJavaProject) key;
if (org.codehaus.jdt.groovy.model.GroovyNature.hasGroovyNature(javaProject.getProject())) {
org.eclipse.jdt.debug.eval.IAstEvaluationEngine evalEngine =
new org.codehaus.groovy.eclipse.debug.EvaluationEngine(javaProject, (org.eclipse.jdt.debug.core.IJavaDebugTarget) target);
entries.add(new SimpleEntry<>(javaProject, evalEngine));
return evalEngine;
}
}
return super.get(key);
}

@Override
public org.eclipse.jdt.debug.eval.IAstEvaluationEngine put(org.eclipse.jdt.core.IJavaProject key, org.eclipse.jdt.debug.eval.IAstEvaluationEngine value) {
if (org.codehaus.jdt.groovy.model.GroovyNature.hasGroovyNature(key.getProject())) {
value.dispose();
value = new org.codehaus.groovy.eclipse.debug.EvaluationEngine(key, (org.eclipse.jdt.debug.core.IJavaDebugTarget) target);
}
for (Entry<org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.debug.eval.IAstEvaluationEngine> entry : entrySet()) {
if (entry.getKey().equals(key)) {
return entry.setValue(value);
}
}
entries.add(new SimpleEntry<>(key, value));
return null;
}
});
}
}
Loading

0 comments on commit cc114a5

Please sign in to comment.