3
votes

I'm working on a build script in the Flash Builder version of Eclipse. This build script needs to import launch configuration .launch files into the user's workspace. However there doesn't seem to be an available ANT var for determining the workspace location. While stepping through the available vars with intellisense I noticed that ${osgi.instance.area} does point to my current workspace but when I tried to echo it back in a running ant script it just spat out "${osgi.instance.area}" and not the path.

Any help would be greatly appreciated. Thank you!!!

3

3 Answers

0
votes

If anyone is curious here is how I achieved this, however this is specifically tailored to Flash Builder/Flex Builder (as that's what our team uses) and unfortunately I could never get the ${eclipse.home} property to work in Ant so I had to use ${eclipse.pdebuild.scripts} to get at the installation directory:

    <property name="install_loc" value=""/>

    <!-- find the eclipse install location -->
    <script language="javascript">

        <![CDATA[

        // Because ${eclipse.home} is not available, determine the install
        // location using the pdebuild.scripts location

        self.log("Looking for Eclipse installation...");
        var base = project.getProperty("eclipse.pdebuild.scripts");
        var path_pieces = base.split("/");
        var path = "";
        outterLoop: for(var i = path_pieces.length; i >= 0; --i)
        {
            if(path_pieces[i] == "Adobe Flash Builder 4" || path_pieces[i] == "Adobe Flex Builder 3")
            {
                // After determining which array item refers to the Adobe Flash Builder or Flex Builder
                // installation, start at the beginning of the array and count up to that point, adding
                // paths as you go.
                var k = 0;
                while( k <= i )
                {
                    path += path_pieces[k] + "/";
                    ++k;
                }

                break outterLoop;
            }
        }

        // TODO: MAKE SURE THE PATH IS NOT EMPTY
        self.log("Install path found at: " + path);

        project.setProperty("install_loc", path);

        ]]>

    </script>

    <loadfile
          property="workspace_prefs"
          srcFile="${install_loc}configuration/.settings/org.eclipse.ui.ide.prefs">
    </loadfile>

    <property name="workspace_loc" value=""/>

    <scriptdef name="find-workspace" language="javascript">

        <attribute name="workspace_data"/>

        <![CDATA[

        // Find and return the workspace location

        self.log("Looking for Eclipse workspace...");
        var defs = attributes.get("workspace_data").split("=");
        var loc = defs[defs.length - 1];
        self.log("Workspace found: " + loc);
        project.setProperty("workspace_loc", loc);

        ]]>

    </scriptdef>

    <find-workspace workspace_data="${workspace_prefs}" />

</target>
0
votes

FWIW, I think this may give you similar functionality to the javascript part of your solution. The regular expression may be too simplistic for real-world use.

<pathconvert property="install_loc" dirsep="/">
    <path location="${eclipse.pdebuild.scripts}"/>
    <regexpmapper from="(^.*/Adobe [^/]*)" to="\1/"/>
</pathconvert>

For reference: Ant pathconvert and mapper docs.

0
votes

This worked for me with a regular Eclipse installation, providing the script is run in Eclipse's own JVM:

<eclipse.convertPath resourcepath="workspace_loc:/" property="eclipse.workspace.home"/>

In order to denote an Ant script should run in Eclipse's own JVM, open the "External Tools Configurations..." dialog, choose your script from the left panel, go to the "JRE" tab, and choose the obvious radio button.

Amnon Grossman