【问题标题】:Handle spaces in xml interface parameter passing处理xml接口参数传递中的空格
【发布时间】:2016-10-07 20:26:22
【问题描述】:

我们有一个系统,它的某些路径名中包含空格。由于它们是核心代码的一部分,它们不能重命名。在调用命令行命令的工具中处理这个问题只是添加双引号集。

但是,我还没有在 Build Forge 适配器使用的 xml 代码中找到解决此问题的方法。

例如,当尝试让适配器执行以下命令时:

cleartool describe "foo bar"@@\main\1

代码如下:

<match pattern="^(.*?)\@\@(.*?)$"> 

<run command="cc_describe" params="$1 $2"/>

<command name="cc_describe">
    <execute>
         pushd cleartool desc $1@@$2;
    </execute>
</command>

假设 $1 = "foo bar" 和 $2 = "\main\1"

在执行时,第二个参数 - 当然 - 会被忽略,因为第一个参数包含一个空格:

Preparsing Command Set: [pushd cleartool desc $1@@$2], using Params: 'foo bar main\1'.
Command Set Parsed To: [pushd cleartool desc "foo@@bar"] 

我尝试通过在调用命令中添加双引号来解决此问题:

<run command="cc_describe" params="&quot;$1&quot; $2"/>

双引号使其进入命令,但没有区别:

Preparsing Command Set: [pushd cleartool desc $1@@$2], using Params: '"foo bar" \main\1'.
Command Set Parsed To: [pushd cleartool desc "foo@@bar"] 

尝试的解决方案:将@@移动到调用命令,将其从接收命令中删除并添加附加参数(以便能够处理1个空格):

<run command="cc_describe" params="$1@@$2"/>

<command name="cc_describe">
    <execute>
         pushd cleartool desc $1$2$3;
   </execute> 
</command>

执行结果:

Preparsing Command Set: [pushd cleartool desc $1@@$2$3], using Params: 'foo bar \main\1'.
Command Set Parsed To: [pushd cleartool desc "foobar@@\main\1"] 

【问题讨论】:

    标签: xml clearcase buildforge


    【解决方案1】:

    通常,参数应该在整个引号之间:

    cleartool describe "foo bar@@\main\1"
    

    然后,如果您的脚本需要考虑文件名和 extended pathname,那么它的作用就是将该参数在 the @@ 部分周围一分为二。

    阅读“What is an Adaptor in Build Forge?”(pdf,来自the help page)后,基于perl,检查是否可以使用all参数而不是前两个。
    电话仍然是$1$2(我也会添加@@):

    <run command="cc_describe" params="$1 @@ $2"/>
    

    如您所见,在cc_describe 命令块中,$1$2 只能代表文件名的一部分,因为空间问题。
    尝试使用$*(bash 风格)或join('', @ARGV)(perl 风格)连接参数(无论它们的数量是多少)。
    连接参数后,以文件的完整扩展路径名结束,其中包括空格。

    【讨论】:

    • 扩展路径名从不包含空格,所以我只在文件名两边加上了双引号。即使我找到一种方法让适配器连接两个参数(并在调用命令中包含@@),当文件名包含空格时,cc_describe 块仍然会丢失传递的参数。
    • @Jozef “如果我能找到一种方法让适配器连接两个参数(并在调用命令中包含 @@)”:如果 不是连接两个参数,而是连接cc_describe块内的所有参数。
    • 适配器的功能不包括连接方法。所有可用命令的列表:ibm.com/support/knowledgecenter/SSB2MV_8.0.0/…
    • @Jozef Ids 是否有可能将完整的参数字符串写入文件,并从命令块中读取该文件? (我在这里尝试另一种方法)
    • @Jozef 当然,您可以发布(并接受)您自己的答案:这将使他人受益。
    【解决方案2】:

    我使用@VonC 建议让它工作。这是一种迂回的方式,但它确实有效!仍然需要对其进行一些改进(例如不使用相同的临时文件)。

    这是 Build Forge ClearCase 代码更改适配器的相关部分。

    <run command="cc_changes" params="$LAST_RUN $DEV_VIEW $VOB_TAG $DEV_STREAM" server="" dir="/" timeout="720"/>
    
    <command name="cc_changes">
        <execute>
            cleartool startview $2
            cleartool mount $3
            <!-- Store the output of the find command in a text file -->
            pushd \\view${DirSep}$2 &amp;&amp; cleartool find .$3 -all -cview -version "{created_since($1)" -print &gt; %temp%\changes.txt
        <!-- Change each space to a = -->
        perl -pi~ -e "s/ /=/g" %temp%\changes.txt
        type %temp%\changes.txt
        </execute>
        <!-- Loop through the results and call the cc_describe command for each entry -->
        <resultsblock>
            <match pattern="^(.*?)\@\@(.*?)$">
                <run command="cc_describe" params="${DEV_VIEW} $1 $2" server="" dir="/" timeout="720"/>
            </match>
        </resultsblock>
    </command>
    
    <command name="cc_describe">
        <execute>
            <!-- Store the cleartool subcommand and the file name in a text file --> 
            echo desc -fmt "${ExpVar}En:${ExpVar}Vn:${ExpVar}Nd:${ExpVar}u:${ExpVar}c" "$2@@$3" &gt; %temp%\change.txt
            <!-- Change the =s back to spaces -->
            perl -pi~ -e "s/=/ /g"  %temp%\change.txt
            <!-- Pipe the text file into the cleartool command -->
            pushd \\view${DirSep}$1 &amp;&amp; cleartool &lt; %temp%\change.txt
        </execute>
        <resultsblock>
            <!-- For each match in the output, we add information to the BOM -->
            <match pattern="^(.*?):(.*?):(.*?):(.*?):(.*?)$">
                <bom category="Source" section="changes">
                    <field name="file" text="$1"/>
                    <field name="version" text="$2"/>
                    <field name="date" text="$3"/>
                    <field name="user" text="$4"/>
                    <field name="comment" text="$5"/>
                </bom>
                <adduser group="MyChangers" user="${NOTIFICATION_GROUP}"/>
                <setenv name="Changes" value="$4 - $1&lt;br/&gt;" type="temp append"/>
            </match>
        </resultsblock>
     </command>
    

    【讨论】:

      猜你喜欢
      • 2018-08-11
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 2013-11-18
      • 2010-12-11
      • 1970-01-01
      相关资源
      最近更新 更多