Wednesday September 20, 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 Helloshows Hello message. Posted by xzajo ( Sep 20 2006, 12:25:45 AM CEST ) Permalink Comments [10]
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.
Add New Service item. It shows Add Service dialog:

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:

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.
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.
Posted by xzajo
( Sep 14 2006, 06:05:17 PM CEST )
Permalink
Comments [4]
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)bIt.next();
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"/>
</folder>
</folder>
public class SimpleBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
template.vm example :
simple.name = $simple.nameWe 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();
sb.setName("Text");
map.put("simple",sb);
SimpleTemplate.apply(io.getOut(),"template.vm",map);
}
It prints to output window transformed template:
simple.name = TextPosted by xzajo ( Sep 07 2006, 03:56:47 PM CEST ) Permalink Comments [6]
Test Dependencies of NetBeans Modules Moved to Project.xml
Test Dependencies of NetBeans module project are defined in nbproject/project.properties 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:
For migrating test dependencies from project.properties 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:
<test-dependencies>
<! -- Dependencies for a source root with tests: -->
<test-type>
<!--
Name of test type. Normally you will use 'unit'.
netbeans.org modules also support 'qa-functional' test-type.
-->
<name>unit</name>
<!-- A dependency on a module or its tests: -->
<test-dependency>
<!-- Identification of module our tests depend upon: -->
<code-name-base>org.netbeans.modules.java.project</code-name-base>
<!-- Include also transitive module dependencies of that module: -->
<recursive/>
<!-- Always available when running, but to include at compile time also: -->
<compile-dependency/>
<!-- To request the tests of that module, rather than itself: -->
<test/>
</test-dependency>
</test-type>
</test-dependencies>
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:
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>A</code-name-base>
</test-dependency>
</testtype>
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>A</code-name-base>
<recursive/>
</test-dependency>
</testtype>
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>A</code-name-base>
<compile-dependency/>
<recursive/>
</test-dependency>
</testtype>
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>A</code-name-base>
<compile-dependency/>
<recursive/>
<test/>
</test-dependency>
</testtype>
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 ant build-test-dist -Dtest.fail.on.error=false
Ant needs more memory for building tests than is default value. So increase it by overring ANT_OPTS environment variable.
ANT_OPTS=-Xmx512mThe property
test.fail.on.error 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/testdist.zip 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:
More details about binary test distribution are here.
Posted by xzajo ( Sep 01 2006, 02:32:17 PM CEST ) Permalink Comments [4]