Apache NetBeans
Apache NetBeans
Latest release

Apache NetBeans 24

Download

How fix module dependencies automatically?

The harness already has a fixdependencies task with only one purpose: replace obsoleted modules with new ones like it happened when Lookup was separated into its own module. In normal applications you might need to manually modify or remove then add the module you changed version for. If the project is really big and complex this can be a nightmare. I went ahead and enhanced the task so it can be more useful.

Basically the current task just replaces obsolete modules with its new version.

To use it add this to your suite’s build.xml:

<target name="fix-dependencies" description="Removes unused compilation dependencies on other modules.">
        <echo>Fixing dependencies for suite...</echo>
        <!--Define custom task-->
        <taskdef resource="org/netbeans/nbbuild/taskdefs.properties">
            <classpath>
                <pathelement location="${harness.dir}/tasks.jar"/>
            </classpath>
        </taskdef>
        <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask">
            <classpath>
                <pathelement location="${suite.dir}/../tools/AntelopeTasks_3.5.3.jar"/>
            </classpath>
        </taskdef>
        <echo>Create the ant script...</echo>
        <!--Create the ant script-->
        <echo file="versions.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<project name="Fix Versions" basedir="." default="fix">
    <taskdef resource="org/netbeans/nbbuild/taskdefs.properties">
            <classpath>
                <pathelement location="${harness.dir}/tasks.jar"/>
            </classpath>
    </taskdef>
    <target name="fix">
        <property name="build.compiler.deprecation" value="false" />
        <fixdependencies antfile="../../build.xml"
                        buildtarget="netbeans" cleantarget="clean" failonerror="true" sanitycheck="false">]]>
        </echo>
        <!--Now update the versions to fix-->
        <for list="${modules}" delimiter=":" param="cur" trim="true">
            <sequential>
                <!--Read properties-->
                <property file="@{cur}/manifest.mf" prefix="@{cur}"/><!--Major release and implementation version are here-->
                <if>
                    <contains string="${@{cur}.OpenIDE-Module}" substring="/"/>
                    <then>
                        <length string="${@{cur}.OpenIDE-Module}" property="@{cur}.length.dist" />
                        <stringutil string="${@{cur}.OpenIDE-Module}"
                        property="@{cur}.OpenIDE-Module.indexOf">
                            <indexof string="/"/>
                        </stringutil>
                        <math result="@{cur}.after" operand1="1" operation="+"
                        operand2="${@{cur}.OpenIDE-Module.indexOf}" datatype="int"/>
                        <substring text="${@{cur}.OpenIDE-Module}"
                        start="${@{cur}.after}"
                        end="${@{cur}.length.dist}"
                        property="@{cur}.release-version" />
                        <substring text="${@{cur}.OpenIDE-Module}" start="0"
                        end="${@{cur}.OpenIDE-Module.indexOf}"
                        property="@{cur}.OpenIDE-Module" />
                    </then>
                </if>
                <property file="@{cur}/nbproject/project.properties" prefix="@{cur}."/><!--Spec version is here-->
                <if>
                    <or>
                        <isset property="@{cur}.release-version"/>
                        <isset property="@{cur}.spec.version.base"/>
                    </or>
                    <then>
                        <echo file="versions.xml" append="true"><![CDATA[
                <replace codenamebase="]]>${@{cur}.OpenIDE-Module}<![CDATA[" addcompiletime="true">
                    <module codenamebase="]]>${@{cur}.OpenIDE-Module}</echo>
                        <if>
                            <isset property="@{cur}.spec.version.base"/>
                            <then>
                                <echo file="versions.xml" append="true"><![CDATA[" spec="]]>${@{cur}.spec.version.base}<![CDATA["]]></echo>
                            </then>
                            <else>
                                <echo file="versions.xml" append="true"><![CDATA[/>]]>
                                </echo>
                            </else>
                        </if>
                        <if>
                            <isset property="@{cur}.release-version"/>
                            <then>
                                <echo file="versions.xml" append="true"><![CDATA[ release="]]>${@{cur}.release-version}<![CDATA["/>]]>
                                </echo>
                            </then>
                            <else>
                                <echo file="versions.xml" append="true"><![CDATA[/>]]>
                                </echo>
                            </else>
                        </if>
                        <echo file="versions.xml" append="true"><![CDATA[
                </replace>]]>
                        </echo>
                    </then>
                </if>
            </sequential>
        </for>
        <echo file="versions.xml" append="true"><![CDATA[
            <fileset dir="nbproject" >
                <include name="project.xml" />
            </fileset>
        </fixdependencies>
    </target>
</project>]]>
        </echo>
        <echo>Create the ant script...Done!</echo>
        <!--Now update modules-->
        <echo>Fixing module dependencies...</echo>
        <subant target="module-fix-dependencies">
            <fileset dir="." includes="**/build.xml" excludes="build.xml"/>
        </subant>
        <echo>Fixing module dependencies...Done!</echo>
        <delete file="versions.xml"/>
        <!--Run NB fix dependencies in all modules as well-->
        <echo>Fixing NB dependencies for suite...</echo>
        <subant target="fix-dependencies" buildpath="${modules}" inheritrefs="false" inheritall="false"/>
        <echo>Fixing NB dependencies for suite...Done!</echo>
        <echo>Fixing dependencies for suite...Done!</echo>
    </target>

    <target name="module-fix-dependencies">
        <ant antfile= "${suite.dir}/versions.xml" target="fix"/>
    </target>

And add this to all your module’s build.xml:

<!--Add this to have the module-fix-dependencies target work from within each module-->
    <import file="${suite.dir}/build.xml"/>

Explanation

fix-dependencies task will do the following:

  • Create an ant file named versions.xml by gathering the current module’s version information.

  • versions.xml uses the fixdependencies target (modified) to update all module dependencies.

  • Run the versions.xml file from within each module (using subant)

  • Delete the versions.xml file when done.

  • Call NetBeans fix-dependencies task

Doesn’t look like much but it’s a lot of work.

Note: You need to have defined the if task (from ant-contrib) to use the targets above. Also you’ll need antelope library: http://antelope.tigris.org/