使用 ANT 查找工作区位置

发布于 2024-09-01 06:51:20 字数 250 浏览 9 评论 0原文

我正在 Eclipse 的 Flash Builder 版本中编写构建脚本。此构建脚本需要将启动配置 .launch 文件导入到用户的工作区中。然而,似乎没有可用的 ANT var 来确定工作空间位置。在使用智能感知逐步浏览可用变量时,我注意到 ${osgi.instance.area} 确实指向我当前的工作区,但是当我尝试在正在运行的 ant 脚本中回显它时,它只是吐出“${osgi.instance.area” }”而不是路径。

任何帮助将不胜感激。谢谢你!!!

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!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最终幸福 2024-09-08 06:51:20

如果有人好奇我是如何实现这一点的,但是这是专门为 Flash Builder/Flex Builder 量身定制的(因为我们团队使用的是它),不幸的是我永远无法让 ${eclipse.home} 属性在 Ant 中工作,所以我必须使用 ${eclipse.pdebuild.scripts} 来获取安装目录:

    <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>

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>
梦境 2024-09-08 06:51:20

FWIW,我认为这可能会为您提供与解决方案的 javascript 部分类似的功能。正则表达式对于实际使用来说可能过于简单。

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

供参考:Ant pathconvert映射器 文档。

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.

将军与妓 2024-09-08 06:51:20

如果脚本在 Eclipse 自己的 JVM 中运行,这对我来说适用于常规 Eclipse 安装:

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

为了表示 Ant 脚本应该在 Eclipse 自己的 JVM 中运行,请打开“外部工具配置...”对话框,从中选择您的脚本在左侧面板中,转到“JRE”选项卡,然后选择明显的单选按钮。

阿姆农·格罗斯曼

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文