Netbeans Platform: excluding locales from zip and installer distribution

This article explains how to prevent Netbeans RCP from packaging unwanted locales into the zip distribution and installers.

This article originally appeared on https://techtavern.wordpress.com

Current situation:

  • The default Netbeans RCP build always includes all localization jars from the harness directory: Russian, Chinese, Japanese and Brazilian Portuguese.
  • Netbeans project properties and branding properties lack configuration to select bundled languages.
  • The build templates did not foresee features to exclude locales.

Problem:

  • Annoying long build times. Proportional to the number of jars, build time increases by five if all default languages are included.
  • Larger distributable artifact size. Localization jars take about 500kB.

Solution:

  • Netbeans Ant build is reasonably organized by build templates. And Ant allows overriding targets inherited from templates.
  • We override the build-zip target. This target generates the .zip distribution artifact, which also serves a input for the installer.

The modified script:

The original build-zip target (netbeans 8.0) is found in the harness directory of your Netbeans installation. We place an adapted copy into the build.xml of your application root directory, thus overriding the behavior of the original target. The red lines were added to prevent adding localization for Russian, Chinese and Japanese.

<target name="build-zip" depends="build,build-launchers" description="Builds a ZIP distribution of the suite, launchers, and selected modules from the platform.">
    <echo message="Custom Build ZIP" />
   <mkdir dir="${dist.dir}"/>
   <!-- pathfileset does not support 'prefix' and 'filemode' parameters,
        we have to copy them to temp location -->
   <tempfile property="temp.dir.nbexec" destdir="${suite.build.dir}" deleteonexit="true" prefix="nbexec"/>
   <tempfile property="temp.dir.rest" destdir="${suite.build.dir}" deleteonexit="delete" prefix="rest"/>
   <subant genericantfile="${harness.dir}/suite.xml" target="copy-cluster" inheritrefs="true">
       <property name="dest.dir" value="${temp.dir.rest}"/>
       <property name="nbexec.dir" value="${temp.dir.nbexec}"/>
       <property name="build.dir" value="${suite.build.dir}"/>
       <resources refid="zip.platform.clusters"/>
   </subant>
   <zip destfile="${dist.dir}/${app.name}.zip">
       <zipfileset dir="${build.launcher.dir}/bin/" filemode="755" prefix="${app.name}/bin"/>
       <zipfileset dir="${build.launcher.dir}/etc/" prefix="${app.name}/etc"/>
       <zipfileset dir="${temp.dir.nbexec}" filemode="755" prefix="${app.name}"/>
       <zipfileset dir="${temp.dir.rest}" prefix="${app.name}"><exclude name="config/Modules/*.xml_hidden"/>
           <exclude name="**/*_ja.jar" />
           <exclude name="**/*_ru.jar" />
           <exclude name="**/*_zh_CN.jar" />
       </zipfileset>  

       <!-- Yes, the doubled app.name is a bit ugly, but better than the alternative; cf. #66441: -->
       <zipfileset dir="${cluster}" prefix="${app.name}/${app.name}">
           <exclude name="config/Modules/*.xml_hidden"/>
           <exclude name="**/*_ja.jar" />
           <exclude name="**/*_ru.jar" />
           <exclude name="**/*_zh_CN.jar" />
       </zipfileset>            
   </zip>
</target>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: