4 Replies Latest reply on Jan 2, 2018 9:50 PM by jasong RSS
    jasong Creator

    Eclipse / Ant Build Number into metadata.xml

    I am working on an extension package but am fairly new to Eclipse and Ant. I am looking for a way to add a build number into the build process, which ultimately will update the JAR and the metadata.xml file before including it in the zip.


    I think I have step one working right - added this line to my build-extension.xml script

    <buildnumber file="${config.dir}/build.number"/>


    Now that there is the Eclipse extension which seems to control that top line based on the project properties, I would think this isn't that hard to do but I'm at a loss as to how to do it. I am guessing it has something to do with the manifest portion:


      <attribute name="Built-By" value="${extension.package.vendor}"/>
      <attribute name="Build-Date" value="${NOW}"/>
      <section name="${extension.package.name}">
           <attribute name="Package-Title" value="${extension.package.title}"/>
           <attribute name="Package-Version" value="${extension.package.version}"/>
           <attribute name="Package-Vendor" value="${extension.package.vendor}"/>



    Worth noting that it appears that this is not working right anyway, as if you look at the compiled JAR's manifest, you see this

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.9.4
    Created-By: 1.8.0_66-b18 (Oracle Corporation)
    Built-By: ${extension.package.vendor}
    Build-Date: 2016-01-08 09:41:43
    Name: ${extension.package.name}
    Package-Title: ${extension.package.title}
    Package-Version: ${extension.package.version}
    Package-Vendor: ${extension.package.vendor}


    If I add the following properties to my build-extensions.xml then this cleans up, but it's not tied to the project in any way that I can tell, this is just cheating.


    <property name="extension.package.vendor" value="Me"/>
    <property name="extension.package.title" value="MyPackageName"/>
    <property name="extension.package.name" value="MyPackageName"/>
    <property name="extension.package.version" value="0.0"/>


    But once thats working, I can change the one line for the manifest to do this to get my build number in the manifest. So that's good, but again, it's not wired to anything.

    <attribute name="Package-Version" value="${extension.package.version}.b${build.number}"/>


    That makes the Manifest look ok but, again, it does not appear to be connected to the project itself, nor does the metadata.xml get updated by any means so as far as ThWx is concerned it's unchanged.

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.9.4
    Created-By: 1.8.0_66-b18 (Oracle Corporation)
    Built-By: Devicify
    Build-Date: 2016-01-08 09:44:08
    Name: MyPackageName
    Package-Title: MyPackageName
    Package-Version: 0.0.b82
    Package-Vendor: Me


    So none of that is really glued together automatically, and then I am still missing how to possibly update the "packageVersion" property in the metadata.xml file

    <ExtensionPackage dependsOn="" description="whatever" minimumThingWorxVersion="6.6.0" name="MyPackageName" packageVersion="0.0.1" vendor="Me">


    What I would hope exists is some ability to write/adjust the Version property in the package using the build number, which would hopefully just magically change the metadata.xml as it seems to do, and then be able to use those project properties to write to the JAR manifest.


    Any thoughts anyone?

      • Re: Eclipse / Ant Build Number into metadata.xml
        larryl Newbie

        Changes made to ThingWorx 6.6 restrict the Extension package metadata.xml package version to semantic versioning syntax of the form "MM:mm:pp".

        Previous convention was to append build numbers to the version.


        To facilitate the need to build an extension with internal build number information, an new 'buildNumber' aspect was added to the metadata.xml file. 

        For example: packageVersion="1.0.0" minimumThingWorxVersion="6.6.2" buildNumber="myBetaRelease"

        This new build number is also displayed in the ThingWorxMonitor "Manage Extensions" page.


        I'm not an Ant expert either, but there should be away for Ant to update the metadata 'buildNumber' property.

        • Re: Eclipse / Ant Build Number into metadata.xml
          brue Apprentice

          We do not have any support for the buildNumber attribute in the plugin at the moment. However, you are on the right track by using Ant's buildnumber task to generate a new number each time you build. What's missing is the "glue" you're talking about that would take the value from the file "build.number" and set a property also called "build.number". This property would then need to be used to update the metadata.xml file with "buildNumber=${build.number}" similar to what Larry pointed out on the ExtensionPackage node.


          Unfortunately, since we don't have this functionality currently, it would be up to you to get that build number into metadata.xml. Here's something you could try:

          1. Manually edit metadata.xml with the addition of buildNumber="@build.number@" onto the ExtensionPackage node.
          2. Keep your buildnumber task as you have it in your build.xml, but possibly rename your build.number file because Ant will also use that same name for the property. Just for clarity between the file name and the property. I will use build.txt in the next step.
          3. Add the Ant Replace task to replace @build.number@ in the metadata.xml file. The following should be the first line inside the package-extension target.
            1. <replace file="<path_to_build_number_file>/build.txt" token="@build.number@" value=${build.number}/>
          4. Add the following to the build-jars target for the manifest info.
            1. <attribute name="Package-BuildNumber" value="${build.number}"/>



          Hopefully this helps! Let us know how it goes.

            • Re: Eclipse / Ant Build Number into metadata.xml
              jasong Creator

              Thank you so much for this reply. This got me started - final solution looks similar but with a different <replace> task for ant, since I think what you were recommending there only worked once and would need to be reset (by another replace task or manually)


              I used this replace task instead, which matches on whatever current value is there in buildNumber


              <replaceregexp file="${config.dir}/metadata.xml"