【问题标题】:Find workspace location using ANT使用 ANT 查找工作区位置
【发布时间】:2010-05-13 15:58:21
【问题描述】:

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

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

【问题讨论】:

    标签: apache-flex eclipse ant workspace flash-builder


    【解决方案1】:

    如果有人在这里好奇我是如何做到这一点的,但是这是专门为 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>
    

    【讨论】:

      【解决方案2】:

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

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

      供参考:Ant pathconvertmapper 文档。

      【讨论】:

      • 我一进办公室就试一试。谢谢马丁!
      【解决方案3】:

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

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

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

      阿姆农·格罗斯曼

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-24
        • 2013-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多