Jun 072013

Much has been written about the NetBeans Platform. But the ultimate resource still remains the source code of the Platform itself! I have used plenty of open source libraries over the years. And I have ventured into the source code numerous times. Quite often the experience is one that leaves one dazed and confused. But I have found that the NetBeans source code is well structured and easy to follow. So even on your very first adventure, you can gain much wisdom! ūüôā

Reading source code is like reading a Physics text book. You can try to keep all of that information in your head, or you can experience it in practice. So in most cases, the easy way to find an answer is to debug into the source instead of just perusing it.

How to set up the source code to be able to debug into it, depends on what type of project you are working with. For Ant-based module projects, download the source code of the same version as the platform that you are building on, and configure the platform to use it in the NetBeans Platform Manager (Tools > NetBeans Platforms). This gives you access to all of the source code in all of the modules.

For Maven-based projects, you have to attach the source code for each of the dependencies. In project view, right-click on one of the NetBeans module dependencies and choose Download Sources.

Now put a breakpoint somewhere in your own module to start from. So for example, if you wanted to explorer the behaviour of the TopComponent class, put a breakpoint into the constructor of a TopComponent subclass (created using the Window wizard). And step into for example the setName() method.

Using this methodology, you can explore how the platform loads and uses things like nodes and actions and windows. That will provide you with much deeper insight into how these things work!

Robert Bracko (robert [dot] bracko [at] vip [dot] hr) explored the behaviour of an old third party IDE module from the 6.9.1 days. He sent me the following points, describing his fascinating first adventure!

  1. Downloaded NB 6.9.1 (Build Type: Release) from https://netbeans.org/downloads/6.9.1/zip.html:
    1. netbeans-6.9.1-201007282301-ml-javase.zip (description: NetBeans 6.9.1 Java SE OS Independent Zip/English)
      Extracted (not installed!) into directory netbeans-6.9.1-201007282301-ml-javase
    2. netbeans-6.9.1-201007282301-src.zip
      Extracted into directory netbeans-6.9.1-201007282301-src
  2. Inside Development IDE (NB 7.3), added platform nb691 as new NB platform, based on directory netbeans-6.9.1-201007282301-ml-javase\netbeans.
    Sources linked for that platform, based on directory netbeans-6.9.1-201007282301-src
    So far so good¬†ūüôā
  3. Project opened inside Development IDE: KoalaLayoutSupport. Project properties changed: NetBeans platform set to nb691
    Attempt to build the project fails:
    The following error occurred while executing this line:
    X:\netbeans\netbeans-6.9.1-201007282301-ml-javase\netbeans\harness\testcoverage.xml:22: C:\Program Files\NetBeans 7.3\harness\testcoverage\cobertura does not exist.What is strange here is that error message refers to C:\Program Files\NetBeans 7.3 directory. Why does it look into NB 7.3 installation directory?
    Next step was to investigate exactly what’s going on during build process. So I’ve selected project’s node Important Files > Build Script and from the pop-up menu chose Debug Targer > netbeans. I found out that file¬†nbproject/build-impl.xml¬†refers to file¬†nbproject/private/platform-private.properties¬†which further defines property¬†user.properties.file¬†with value¬†C:\\Documents and Settings\\Administrator\\Application Data\\NetBeans\\7.3\\build.properties. Nothing wrong with that, right? Because at the same time debugger’s variables-window shows that property¬†nbplatform.active¬†contains value¬†nb691, so the whole process of building should be (at least I think so) controlled by NB 6.9.1. platform.
    But then one suspicious thing:¬†build-impl.xml¬†tries to define the property¬†harness.dir¬†with value¬†nbplatform.${nbplatform.active}.harness.dir. After having executed that line, debugger’s variables-window shows the value¬†C:\Program Files\NetBeans 7.3/harness¬†for that variable! And that’s obviously wrong.
    So the next step was to change harness dir for platform nb691. I have done that through NB Platform Manager: inside tab Harness, choosing “Harness supplied with Platform” instead of “Harness supplied with IDE”. And then the build passed OK!¬†ūüôā
  4. Next thing, module debugging. Breakpoint set inside of module’s class works OK, also a breakpoint set inside of a class of NB 6.9.1 source. But… For the latter one, debugger’s variable window shows the error message “variable information not available,¬†source compiled without -g option”. I know what it means but how to resolve it?….. For me it’s rather important to see how NB Form Editor source code interact with my module…

Thanks for sharing, Robert! Some questions still remain unanswered in the steps above. Stay tuned for more about his next adventure!

  6 Responses to “The Ultimate NetBeans Platform Resource”

  1. Interesting article. Nice to see someone tries at least to compile our KoalaLayout ūüėČ

  2. Hermien, thank you for involving me in ūüôā

    Jean-Marc, your source was of great help for me while developing another custom layout-manager. Thanks for sharing!

    • You’re welcome. I am just standing on shoulders of giants. I took my inspiration in this project: http://developer.berlios.de/projects/nblayoutpack/
      Whitout this project I wouldn’t have managed to create this plugin.

      Just for information, what kind of layout are you writing a plugin for?

      • It’s an extension to AbsoluteLayout. It provides the possibility to define user-defined grid and snap components to it. So pretty much similar to your layout manager, only the grid is not defined by number of rows and columns but through array of x,y coordinates.
        And I must admit, your team was the only one that produced and shared a layout manager that really works; all other that exist on net are just useless…

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">