“org.eclipse.search” issue model was not being managed.

May 3, 2011

I ran a file search (ctrl-h) and got the search results. Double clicked on one of the hits and get an exception in Eclipse. See below.

What I did to fix? Reran the MyEclipse install and chose ‘fix current install’. Then I changed the command line that starts Eclipse to:

“C:\java\MyEclipse 9\myeclipse.exe” -clean -vm C:\java\jdk1.6.0_25\bin\javaw.exe -Xms512m -XX:PermSize=256M -XX:ReservedCodeCacheSize=64m

Haven’t seen the issue today.

Updates
5/9/2011: Still happening.
5/9/2011: Now made a change in the search preferences. Do not reuse editors. Lets see.
5/12/2011: That fixed it. Sounds like a concurrency issue in Eclipse.


org.eclipse.wst.sse.core.internal.util.Assert$AssertionFailedException: release was requested on a model that was not being managed
at org.eclipse.wst.sse.core.internal.util.Assert.isNotNull(Assert.java:124)
at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl.releaseFromEdit(ModelManagerImpl.java:1799)
at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl.releaseFromEdit(ModelManagerImpl.java:1761)
at org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.releaseFromEdit(AbstractStructuredModel.java:1044)
at org.eclipse.wst.xml.core.internal.document.DOMModelImpl.releaseFromEdit(DOMModelImpl.java:807)
at org.eclipse.wst.html.core.internal.document.DOMStyleModelImpl.releaseFromEdit(DOMStyleModelImpl.java:37)
at org.eclipse.wst.sse.ui.StructuredTextEditor.doSetInput(StructuredTextEditor.java:1849)

eclipse.buildId=unknown
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -Xms512m -XX:PermSize=256M -XX:ReservedCodeCacheSize=64m
Command-line arguments: -os win32 -ws win32 -arch x86 -Xms512m -XX:PermSize=256M -XX:ReservedCodeCacheSize=64m

MyEclipse Version 9.0.


Eclipse regex search for (.*) doesn’t work repeatably?

April 15, 2011

On a file in MyEclipse search for (.*) in regexp mode. It will find the first match sometimes. Search again, it will state no match found. However, use (.+) and it will find each line.

That is weird behavior. Same thing happens in Eclipse Helios. Tried it in an editor, GVim. Works fine. Must be a Preferences setting, or a built in limit to avoid runaway regexps.

Tried (.*?), won’t even find one match.

See also
The Incredible Suckiness of Text Editors


The incredible suckiness of text editors

March 6, 2011

This should be simple, find every instance of “txtXXXX”, where XXXX can be any string, and you want the search to be non-greedy. Hah.

Task
I needed to find these strings so I can insert them into a new file, then apply a regexp to create a bunch of source code. This is just a very elementary regular expression use: “txt.*?”

  • Notepad++: doesn’t support “?”.
  • GVim: /”txt.\{-}” ugly! and how do I reuse the results (doable but hard)
  • windows notepad: lol!
  • Eclipse IDE: “txt.*?” but, you can’t find them all and reuse the results.

Solution
Long story short, I opened a command shell and did:

type page.html | egrep -o "txt.*?"

Not perfect, I still get too much of the line containing the match, but it is at least reusable. egrep is that installed with cygwin.

I, of course, am not complaining about text editors based on this one little issue. There is a long list of pain points, as with any software type.

SlickEdit?
I remember using a great editor that really knew how to optimize a developers work, SlickEdit. This task would have been a yawn.

In SlickEdit, real standard regexps are used, the output goes to a search output panel, etc., did I mention it does real columns? Alas, it is expensive, and companies probably won’t spend on it; we’re lucky we even have jobs in this age.

Links


Java Dev Using Embedded Groovy Console in Eclipse

December 12, 2010

In development, simple but powerful tools to get at the essence of a code source in order to understand, test, and extend it is essential. This is even more important in Test Driven Development (TDD). Eclipse’s Java Debugger is for most situations, powerful enough. Eclipse has an Expressions View available in the debug perspective to execute snippets of code. The Java Development Toolkit (JDT) also has a Scrapbook facility that allows the creation, storage, and running of experimental code. And, of course, all the other features of the debugger are excellent.

However, when you need it, it’s possible to embed a script engine and have new ways of analyzing and developing code. In listing 1, an app shows the use of the ConsoleWaiter class. When the code executes the waiter.run() at line 43, it opens the Groovy Console which allows the use Groovy shell scripting in a GUI frame, see figure 1. When the console is closed the app continues executing.

Listing 1
/*
* File: ExampleApp2.java
* @author jbetancourt
* Date: 20101213T1718-5
*
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
*
* @author jbetancourt
*
*/
public class ExampleApp2 {
   static public String greeting = "Hello world!";
   private static final List<String> nodes;

   static {
        nodes = new
            ArrayList<String>(
                  Arrays.asList("one","two"));
   }

   private String title = "Example 2";

   public String getTitle(){
      return title;
   }

   /**
   * @param args command line args
   */
   public static void main(String[] args) {
      ExampleApp2 app = new ExampleApp2();

      ConsoleWaiter waiter = new ConsoleWaiter(app);

      waiter.setVar("greet", greeting);
      waiter.setVar("nodes", nodes);
      waiter.setVar("title", app.getTitle());
      waiter.run();
      System.out.println("Done!");
   }

}
screen capture of Groovy console

Console screen capture, click to view

Another screen capture, click to view

This is awesome. In one project I had to examine the contents of a Properties object. Did it have an “email” value? I was stumped when using the Eclipse debugger, it did not show all entries in the Map, at the end was “…”. Sure, I could use the Expressions window, but with the Console I could not only do a get(key), but iterate using Groovy style closures and much more.

The magic that enables this is the ConsoleWaiter.groovy class shown below in listing 2 that was written by John Green. Since a Groovy script is a Java class underneath, in Eclipse you can call Groovy from Java easily (some compiler magic).

Listing 2
/**
 * File:  ConsoleWaiter.groovy
 */

import groovy.lang.Binding;
import groovy.ui.Console;

/**
 * Provides a wrapper for the console.
 *
 * Based on source by John Green
 * Adapted from:  http://www.oehive.org/files/ConsoleWaiter.groovy
 * Released under the Eclipse Public License
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * I added methods to allow use from Java.
 *
 * The run() method launches the console and causes this thread
 * to sleep until the console's window is closed.
 * Allows easy interaction with the objects alive at a given
 * point in an application's execution, like in a debugger
 * session.
 *
 * Example 1:
<pre> * new ConsoleWaiter().run()
 *</pre>
 *

 * Example 2:
<pre> * def waiter = new ConsoleWaiter()
 * waiter.console.setVariable("node", node)
 * waiter.run()
 *</pre>
 */
class ConsoleWaiter {
 Console console
 Object source
 boolean done = false;

 /** */
 public ConsoleWaiter(Console inConsole){
    this.console = inConsole
 }

 /** */
 public ConsoleWaiter(Object source){
    console =
    new Console(getClass().classLoader,
    new Binding())
    this.source = source
    console.setVariable("source", source)
 }

 /** */
 public void setVar(String key, Object value){
    console.setVariable(key, value)
 }

 /** 	 */
 public void setVar(String key, List values){
    console.setVariable(key, values)
 }

 /** 	 */
 public void setVar(String key, Object[] values){
    console.setVariable(key, values)
 }

 /** 	 */
 public void run() {
    console.run()
    // I'm a little surprised that this exit() can be private.
    console.frame.windowClosing = this.&exit
    console.frame.windowClosed = this.&exit
    while (!done) {
       sleep 1000
    }
 }

 /** 	 */
 public boolean isDone(){
    return done;
 }

 /** 	 */
 public void exit(EventObject evt = null) {
    done = true
 }

 /** 	 */
 public Console getConsole(){
    return console;
 }
}

Eclipse Integration

The disadvantage of this approach is that you have to put extraneous code inside the tests or target class. Not only is this tedious and slow, what if code is accidentally deployed like this? A better approach is to just set a breakpoint in the code, and then have the ability to open a script console at that breakpoint, in the Java Stack Frame, that has access to the execution context and classpath. Is there an Eclipse add-in that does this? If not, there should be.

Conclusion

Shown was a simple example of embedding a Groovy console in Java code to allow scripting. Of course, this is not a new idea. It was even mentioned in an older JVM scripting language, Beanshell. Note that it is possible to instead of using a GUI console, to use the Groovy shell, InteractiveShell class. In the reading list below this approach is taken to allow remote scripting of a server hosted application.

Updates

  • Oct 10, 2011:
    Interesting tool that could be relevant: YouDebug.
  • March 20, 2012: Not exactly same scenario, but the concept of an embedded script console is found in many products. Jenkins CI Server has one and it uses Groovy. Jenkins Script Console

Further reading


Use Eclipse project dir for Unit Test data

December 4, 2010

Use the default launch configuration of a unit test in Eclipse to access Unit Test data.

Best practice is to not access test data in relative or absolute paths in the file system. Instead to use classpath resources. But, maybe you have valid reasons to want to do things your own way. Thus, you want to get at test data in a folder within your project without monkeying around with adding file paths to launch configuration and all that stuff.

Ok, who am I to diminish your mojo. Just use the current directory that Eclipse creates. Example, you have this:

class FileCompareTest extends GroovyTestCase {
       /** 	 */
       public void testSomething(){
		def aFileName = 
                 "C:\\path\\to\\projects\\data\\alpha.txt"
           // use file in test.
       }

Change it to:

class FileCompareTest extends GroovyTestCase{
       def basedir
	
       @Override
       protected void setUp() throws Exception {
           basedir = new java.io.File(".").getAbsolutePath()
       }
	
       /** 	 */
       public void testSomething(){			
           def aFileName = basedir + "\\data\\alpha.txt"
       }

Updates

17JAN11: Could basedir = System.getProperty(“user.dir”); also be used?

Related links

How to default the working directory for JUnit launch configurations in Eclipse?


MercurialEclipse error ‘dotencode’ not supported!

November 21, 2010

When using Team Mercurial to refresh an Eclipse project I got this error:   “abort: requirement ‘dotencode’ not supported!”

Strange I just updated the Intland Software’s MercurialEclipse feature and it’s running Mercurial 1.7.0.

Fix

Anyway, to fix I just went into the

plug-ins configuration: Windows -> Preferences -> Team -> Mercurial and unchecked the “Use default (built-in) Mercurial executable”.

I specified “C:\Program Files (x86)\TortoiseHg\hg.exe” or whatever is the location of the latest hg.

It worked. Hope it doesn’t break something else.

Updates

  • 2011MAR04: I updated to new Hg ver 1.8 and TortoiseHg 2.0. Had to make the change again in Eclipse. TortoiseHg 2.0, btw, looks beautiful. Nice work on the UI.

Further reading


Ralph Towner — Witchitaito


What is Eclipse’s Current Workspace?

October 7, 2010

Maybe someone knows the answer. Unless you start Eclipse with the “-showLocation” option there is no way to know what the current workspace location is.

One reason to know is that when I go to create a new project, do I specify the workspace or is the current workspace the one I want? I don’t remember if the workspace is shown or specified on project creation, will have to check.

Maybe I’m missing some internal Eclipse reason for this (similar to that crazy bug when the copyright name was changed inside Java) and there is no way for Eclipse to know this. Still, seems lame.

Update
17JAN2011: Found the answer, see below. I was on the right track. If I read the FAQ entry correctly, the current project is accessible (even though there can be many active projects), it is just not exposed in the Eclipse UI?

Further reading
What is Eclipse’s Current Workspace?

FAQ How do I access the active project?

http://dev.eclipse.org/newslists/news.eclipse.platform/msg70488.html

 


Maria Pia de Vito with John Taylor & Ralph Towner – I Knew It was you


Follow

Get every new post delivered to your Inbox.