Thursday Dec 07, 2006

Test Libraries Node for NetBeans Module Project

Tomas Musil (our QA specialist) yesterday contributed Test libraries node for NetBeans module project. It simplifies editing classpath for tests.Thanks to Tomas contribution, you don't need to edit project.xml for setting classpaths of tests manually. New test dependency can be added from popup of test libraries node.

Add Unit Test Dependency action shows Add dependency dialog.

The dialog has the same behaviour like dialog or adding module dependency. Test library dependency also contains customizer. It can be shown from popup of test library node.

Tuesday Dec 05, 2006

NetBeans Tea-Team

Few developers and me from NetBeans core team very often drink tea. We drink different kind of tea - green, yellow, black, pu erh, etc. Yesterday architect of our tea-team (the "enfant terrible") took pictures of us.

Who is on the picture? On the left side is sitting Milos Kleint. He develops Maven 2 plugin. Besides him is Martin Krauskopf. Martin is now working on debugger for JRuby. On the right side is laughing Radim Kubacki. He takes care of performance of NetBeans IDE.

Other developers are so kind to boil water.
Our editor VIP - Mila Metelka:

Retouche EXPERT - Tomas Zezula:

BTW he fixed me today bug.

Tuesday Sep 19, 2006

Command Line Parsing API in NetBeans Platform

Jaroslav Tulach integrated Command Line Parsing API to NetBeans platform this week. The API was already tested in DVB Central project.

I wrote simple OptionProcessor in few minutes:

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.netbeans.api.sendopts.CommandException;
import org.netbeans.spi.sendopts.Env;
import org.netbeans.spi.sendopts.Option;
import org.netbeans.spi.sendopts.OptionProcessor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;

public class MyOptions  extends OptionProcessor {
    private static Option message = Option.requiredArgument(Option.NO_SHORT_NAME, "message");
    public Set

The MyOptions processor is register in META-INF/sevices. The registration can by done by META-INF/services browser. The MyOptions provider display first parameter of -message parameter in message dialog box. For Example

./netbeans --message Hello
shows Hello message.

Friday Sep 15, 2006

META-INF/services Browser for NBM project

Together with Jaroslav Tulach we are developing META-INF/services browser for NetBeans module project. In short META-INF services node was added to Important files node:

The META-INF services node has two children nodes:

  • <Exported Services> - services exported by module.
  • <All Services> - services from NetBeans platform and all modules in module suite.
The Service can be added from pop-up menu of Service type by clicking to Add New Service item. It shows Add Service dialog:

Full class name of Service is typed to Class name text field. The class name of new service can be also selected in packages view. The package view will be shown after clicking on Browse button:

Already installed service can be masked/unmasked from default Lookup by Delete menu item on service instance in All Services view.

Details about this feature are in issue #66606. We want to integrate it to Milestone 4 NetBeans build.

Thursday Sep 14, 2006

Run only tests which uses your code

NetBeans test distribution allows to run tests for modules which requires a specific module on runtime testing classpath. For Example you have built test distribution for 'org-openide-filesystems' and 'org-netbeans-modules-masterfs' NetBeans modules.

Use case 1: You want to run test with 'org-openide-filesystems' module on runtime testing classpath:

     ant unit -Dtest.required.modules=org-openide-filesystems.jar -Dnetbeans.dest.dir=netbeans_installation_dir
It runs both modules - 'org-openide-modules-masterfs.jar' and 'org-openide-filesystems.jar'.

Use case 2: You want to run test with 'org-netbeans-modules-masterfs' module on runtime classpath:

     ant unit -Dtest.required.modules=org-netbeans-modules-masterfs.jar -Dnetbeans.dest.dir=netbeans_installation_dir
It runs tests only for org-netbeans-modules-masterfs module because org-netbeans-modules-masterfs module is not on runtime testing classpath of org-openide-filesystems module.

Thursday Sep 07, 2006

Using velocity templates in NBM projects

Many people asked me how to use velocity template in their NetBeans module projects. So there is short example. Velocity libraries are wrapped to org-apache-velocity.nbm NetBeans module.

First time you need to install the module to NetBeans platform. Now we can start to write Velocity module. Add org-apache-velocity on classpath of module. Example class with generating code is below:

public class SimpleTemplate {  
    /\*\* Write generated code to target document
    public static void apply(Writer t,String vmTemplate,Map beans) {
        try {
            VelocityContext context = VTResourceLoader.getContext();
            for (Iterator bIt = beans.keySet().iterator() ; bIt.hasNext() ;) {
                String name = (String);
                Object bean = beans.get(name);
                context.put(name, bean);
            Template template = Velocity.getTemplate(vmTemplate);
            if (t == null) {
                throw new IllegalStateException(" no target defined ");
            template.merge(context, t);
        } catch (Exception e) {
            Logger.getAnonymousLogger().log(Level.SEVERE,"Exception during generating templates",e);
The velocity template is present in velocity/templates folder of layer.xml :
      <folder name="velocity"> 
        <folder name="templates">
             <file name="template.vm" url="Simple.vm"/>

Map of java objects is parameter for templates. Only one bean is used in our example:
public class SimpleBean {
    private String name;

    public String getName() {
        return name;

    public void setName(String name) { = name;

A template.vm example : = $
We can write action with body:
    public void performAction() {
        // TODO implement action body
        InputOutput io = IOProvider.getDefault().getIO("template test",true);
        Map map = new HashMap();
        SimpleBean sb = new SimpleBean();
It prints to output window transformed template: = Text

Wednesday Sep 06, 2006

Test Dependencies of NetBeans Modules Moved to Project.xml

Test Dependencies of NetBeans module project are defined in nbproject/ for previous versions of NetBeans.The test dependencies can be also added to project.xml for projects of NetBeans 6.x. The new variant is recommended. The test dependencies allows to define:

  • Compile and runtime dependency to module.
  • Compile and runtime dependency for tests of modules.
  • Recursive dependecy to module.

For migrating test dependencies from to project.xml was implemented fix-test-dependencies ant tasks in NetBeans module project. You can do it from command line:

cd your_nbm_project_dir
ant fix-test-dependencies

GUI for adding/removing test dependencies has not yet been implemented. I hope it will be available early. It can by done only manually by editing project.xml file. The tags for test dependencies (defined in xml schema) are described below:

        <! -- Dependencies for a source root with tests: -->
            Name of test type. Normally you will use 'unit'.
   modules also support 'qa-functional' test-type.
            <!-- A dependency on a module or its tests: -->
                <!-- Identification of module our tests depend upon: -->
                <!-- Include also transitive module dependencies of that module: -->
                <!-- Always available when running, but to include at compile time also: -->
                <!-- To request the tests of that module, rather than itself: -->

Source root for a test type:
{project.dir}/test/unit/src - source root for unit test

For example you have three modules with code name bases A,B,C. A depends on B, B depends on C. You want to add test dependencies to unit test type of module D:

Use case 1: Runtime dependency on module.
  • Runtime classpath is D+A.
  • Compile classpath is D.

Use case 2: Runtime dependency on a module and its recursive runtime classpath.
  • Runtime classpath is A+B+C+D.
  • Compile classpath is D.

Use case 3: Compile and runtime dependency on a module its recursive runtime classpath.
  • Runtime classpath is A+B+C+D.
  • Compile classpath is A+B+C+D.

Use case 4: Compile and runtime dependency on a module, its recursive runtime classpath and tests.
  • Runtime classpath is A+B+C+D + A/unit tests.
  • Compile classpath is A+B+C+D + A/unit tests.

Friday Sep 01, 2006

Binary Test Distribution For NetBeans IDE

I'm finishing binary test distribution for NetBeans IDE. The test distribution won't be available for NetBeans 5.5 because it's too late to do it. The distribution will be available for NetBeans 6.0 build on download page, I hope. Quality Engineering team got idea to distribute NetBeans with its test binaries few years ago. We decided after a while to spend time to remove cvs dependencies on running tests and create files layout for test binaries.

To build test distribution is very simple now. You only need to checkout cvs files for NetBeans dev build, build ide and test distribution:

cvs co standard_nowww
cd nbbuild
ant build-test-dist

Ant needs more memory for building tests than is default value. So increase it by overring ANT_OPTS environment variable.

The property ignore compilation failures because few tests are still uncompilable. It is curious that some test are uncompilable. Why developer write tests if the test is uncompilable after a while. IMHO all the tests will have to be run daily if continuos integration is dream. I hope it will be solved as soon as possible.

The tests are built into nbbuild/build/testdist folder and packed to nbbuild/build/ file. In the root folder of test distribution is short README.txt file. It contains description how to run tests. For example when you want to run all test(qa-functional and unit), you need only run ant :

ant all -Dnetbeans.dest.dir="${netbeans.home}"

The netbeans.dest.dir property contains directory with NetBeans installation. Te result of testrun is formated to html files. The html files are available in:

  • unit/results - for unit tests
  • qa-functional/results - for qa-functional tests

More details about binary test distribution are here.

Sunday Aug 20, 2006

Floating Windows In NetBeans

NetBeans 6.0 Milestone 2 build contains Floating windows feature. A window (TopComponent) can be undocked by dragging the window's title bar outside the NetBeans IDE. UI specification is available here. The specifacation also coontans few flash demos. For examle :

The feauture is also part of NetBeans platform. If you want to use it in your rich-client applications on top of the NetBeans Platform you need to rebuild it against NetBeans 6.0 M2 platform. I tried it for Paint Application tutorial. Screenshot is below.

Wednesday Jul 12, 2006

Fullscreen mode in NetBeans platform

I've already blogged about fullscreen mode here. The fullscreen mode feature has been integrated into NetBeans 6.0 development daily builds.

It is very easy to add this feature to already written application based on NetBeans platform. If the application is compiled against NetBeans 6.0dev platform View|Full Screen menu item will be added automatically. Screenshot with NetBeans FeedReader in fullscreen mode is shown below.

The fullscreen mode works for JNLP application too.

Thursday Jun 22, 2006

P2P programming

Few years ago has been introduced XP programming. A part of XP programming was pair programming. What is pair programming? Two developers are programming together on one computer. They are reviewing their ideas in one time. It rapidly increased quality of code.

Pair and XP programming is applicable to small teams. It is quite difficult to use XP methods on project where are for example hundreds developers. What is missing here? The developers didn't provide inter team communication about their codes. It is really difficult to share knowledge among all the developers.

Another way how to review the code is send commit logs to public mailing list. The commit logs are read only inside small team because it is not effective if the developers checks commit logs from many developers.

An inspiration how to solve this problem can be P2P data sharing. P2P data sharing was invented in order to reduce load of server. Big file is split to many small parts. Different parts are distributed to different users(nodes). If the node download his part he can redistribute the parts to different users. For each node in P2P network is computed ration uploaded/downloaded. When the ratio is very small the node got smaller priority for downloading files than node with bigger priority.

We can map P2P networking problem to code review problem. A node is developer. A developer commits code.Other developers reviews his code. It is the same like P2P network. The download is reviewing his code. The upload is reviewing of other's developer code. If the developers doesn't review code. No one is interested in review his code because the commit log is on the end of list with commits for code review.

The commits log are sent to different groups of developers. How to distinguish the developers? There are few metrics: -A developer uses a API. The API owner is in commit logs. The api usage is in commit log of the the user. The owner of API do the review. -He uses the API for long time I got many reviews. He is experienced API user. He can do review of code which uses the API or do the review to API developer Sent the same count of commit logs to different developers.

The reviewer must mark the reviewed code:

  • The code is good
  • The code is wrong

He can also add comments to review.

For the code review can be created a plugin to IDE.

The P2P programming can be used for code evaluation between different projects if they uses the same API or export API. For example first group develops WEB framework. The second group develops web application. The second group uses the framework of the first group. The first group do review of the code of the second group. After a while third group of developers started use the API of the first group. The code of third group will can review second group because they are experiences users of the framework.

Please let me know if already exists software project similar to P2P programming.

Wednesday Jun 14, 2006

Netbeans met GWT and more GWT components

I wrote about my first experience with GWT in my last blog. Yesterday I experimented with GWT application in NetBeans. The new GWT plugin contains GWT project type. It is now easy build, run and debug GWT projects in NetBeans. The code completion with javadoc is also available. Tomas will publish his plugin early, I hope.

On are more GWT components. My favorite is Auto-Completion Textbox. It allows to add Code completion to Texbox on web page. The AutoCompleteTextBox component extends TextBox class. It adds to TextBox one new useful method:

public void setCompletionItems(CompletionItems items)
The CoompletionItems type is code completion provider:
public interface CompletionItems {
         \* Returns an array of all completion items matching
         \* @param match The user-entered text all compleition items have to match
         \* @return      Array of strings
        public String[] getCompletionItems(String match);
I wrote a simple application with AutoCompleteTextBox. The class with GWT EntryPoint is below. It shows code completion for names.
public class Main implements EntryPoint {
    class NameCompletionItem implements CompletionItems {
        public String[] getCompletionItems(String match) {
            ArrayList list = new ArrayList();
            String values[] =  new String[]{"roumen","radim","xzajo","geertjan","lukas"}; 
            String lowerMatch = match.toLowerCase();
            for (int i = 0 ; i < values.length ; i++) {
                String value = values[i];
                if (value.startsWith(lowerMatch)) {
            String retVals [] = new String[list.size()];
            for (int i = 0 ; i < list.size() ; i++) {
               retVals[i] = (String) list.get(i); 
            return retVals;
    public void onModuleLoad() {
        AutoCompletionTexBox textBox = new AutoCompletionTexBox();
        textBox.setCompletionItems(new NameCompletionItem());

Conversion between ArrayList and array of Strings doesn't work on client side of GWT (Collection.toArray(Object[] array). The gwt compiler shows an error. Therefore I used the for loop. Screenshot with code completion in browser is below.

Friday Jun 09, 2006

GWT - revolution in web application development

Few my friends were talking about Google Web Toolkit GWT last week. There are too many MVC frameworks for web application development in java world - JSF, Struts, Spring, Tapestry, JSF, etc. It is not normal that one other tool can so quickly impressed java developers. I had to look at GWT too. GWT answers to question which I've heard many times:

Why not to develop the web application in the same way like desktop application?

By using GWT you can develop web application in the same way like swing application. The similar parts are below:
  1. Entry point for java application is Main class. It is EntryPointClass for GWT application.
  2. Swing and GWT represents all UI components a java class.
  3. Registration handlers are done by event listeners. For example listening on clicking of JButton.
  4. Components is registered to panel. A panel contains layout.
  5. You can show dialogs and change components on desktop for swing or in web browser for GWT.
  6. Swing app can be run on different platform. GWT application can be show in different web browsers.
Web browser doesn't contain support for java in html pages. GWT compiles java bytecode on client side of application to AJAX. There is development cycle for GWT application:
  1. Use your favorite Java IDE to write and debug an application in the Java language, using as many (or as few) GWT libraries as you find useful.
  2. Use GWT's Java-to-JavaScript compiler to distill your application into a set of JavaScript and HTML files that you can serve with any web server.
  3. Confirm that your application works in each browser that you want to support, which usually takes no additional work.

GWT solves communication between client and server side. It use proprietary Remote Procedure Calls. A service is represented by interface. Server side implements the interface and JavaScript is generated for client side. It leads developers to separate model, view and controller. GWT RPC is kind of SOA. Only with one difference. It doesn't use redundant (and slow ) SOAP protocol. Developer doesn't need to write jsp pages and servlets anymore.

There is no support for GWT application development in NetBeans. I hope GWT NetBeans project type be implemented early. And I may be someone will answer to another question:

Why not to generate GWT java code with NetBeans Matisse editor?

Wednesday May 31, 2006

Testing memory leaks with assertGC

I was talking about assertSize in one of previous entry about testing. NbTestCase class contains more useful methods. Today I will be talking about assertGC method. The assertGC method tests tries to run garbage collect with different methods and then scan if exists path to reference in memory by using insane library. Look at simple example:

public class LeakTest extends NbTestCase {
    public LeakTest(java.lang.String testName) {
    public void testLeak() {
        String obj = new String("test1");
        WeakReference ref = new WeakReference(obj);
        obj = null; 
        obj = new String("test2");
        ref = new WeakReference(obj);
    public static Test suite() {
        TestSuite suite = new NbTestSuite(LeakTest.class);
        return suite;

First asertGC passed because in JVM exists only WeakReference for object String("test1"). The second assertGC failed because the reference obj holds String("test2").

Friday May 26, 2006

XTest testing framework flash

Jiri Skrivanek updated documentation how to use XTest framework in NetBeans IDE. XTest is extension of JUnit 3.x. It was designed to help develops tests for NetBeans platform. The flash demo is available here. Updated tutorial for XTest is on this page.

Many people in NetBeans asked me why not to switch to TestNG with annotations. To tell you truth xtest already has more features than TestNG now. Xtest has also few disadvantages. It is difficult to configure it. The authors of xtest never wrote tests. Only Jiri Skrivanek, the last owner, writes tests. Maybe he is the right person who fix problems with xtest.

Why we still use Xtest for testing NetBeans? There are few reasons:

  • Over 4000 already written tests. Why to rewrite them or simulate the environment?
  • Ability to store results to database
  • Test4u infrastructure runs daily on different platforms and JDKs
  • Used for responsiveness and performance testing




« July 2016