2016-10-07 21 views
1

我們有一個系統在其某些路徑名中包含空格。由於他們是核心代碼的一部分,他們不能被重命名。在調用命令行命令的工具中處理這個問題只是增加一組雙引號。處理xml接口參數中的空格傳遞

但是,我還沒有找到一種方法來處理這個由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 [email protected]@$2; 
    </execute> 
</command> 

假定$ 1 = 「富欄」 和$ 2 =「 \ main \ 1「

在執行時,第二個參數當然被忽略,因爲第一個參數包含一個空格:

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

我試圖通過在調用命令加雙引號解決這個:

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

雙引號使其進入命令,但不要有所作爲:

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

未遂解決方案:將@@移動到調用命令,將其從接收命令中移除並添加附加參數(以便能夠處理1個空格):

<run command="cc_describe" params="[email protected]@$2"/> 

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

執行結果:

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

回答

1

我使用@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" "[email protected]@$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> 
+1

再次,做得好! +1 – VonC

1

通常情況下,參數應該是其整體引號之間:

cleartool describe "foo [email protected]@\main\1" 

然後,如果你的腳本需要考慮到一個文件名和extended pathname ,它的作用是在the @@部分中分兩個參數。

閱讀「What is an Adaptor in Build Forge?」(PDF,從the help page)後,基於Perl的,請檢查您是否可以使用所有參數,而不是第2位。
呼叫保持$1$2(我想補充的@@以及):

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

正如你所看到的,在cc_describe命令塊,$1$2只能表示由於文件名的一部分,空間問題。
嘗試並看看是否連接參數(不管它們的數量),$*(bash樣式)或join('', @ARGV)(perl樣式)。
一旦你連接了你的參數,你可以返回文件的完整擴展路徑名,包含空格。

+0

擴展路徑名從不包含空格,所以我只在文件名周圍放置雙引號。 即使我找到一種方法讓適配器連接兩個參數(並且在調用命令中包含@@),cc_describe塊仍然會在文件名包含空格時丟失傳遞參數的片段。 – Jozef

+1

@Jozef「如果我找到一種方法讓適配器連接兩個參數(並在調用命令中包含@@)」:如果* not *連接兩個參數,則答案的所有點,但連接cc_describe塊中的* all *參數。 – VonC

+0

適配器的功能不包括連接方法。所有可用命令的Lsit:http://www.ibm.com/support/knowledgecenter/SSB2MV_8.0.0/com.ibm.rational.buildforge.doc/topics/adaptor_xml__reference.html – Jozef