1

We have a system that contains spaces in some of its path names. Since they are part of the core code, they cannot be renamed. Dealing with this in tools that invoke command line commands was just a matter of adding sets of double quotes.

However, I haven't found a way to deal with this in the xml code that's used by the Build Forge adaptor.

For example, when attempting to have the adaptor execute the following command:

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

The code would like the following:

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

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

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

Assume $1 = "foo bar" and $2 = "\main\1"

At execution time, the second parameter is - of course - ignored because the first one contains a space:

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

I tried fixing this by adding double quotes in the calling command:

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

The double quotes make it into the command, but do not make a difference:

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

Attempted solution: move @@ to the calling command, remove it from the receiving command and add additional parameter (to be able to handle 1 space):

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

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

Execution result:

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"] 
Jozef
  • 303
  • 1
  • 11

2 Answers2

1

Normally, the parameter should be between quotes in its entirety:

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

Then if your script needs to take into account a filename and an extended pathname, it is its role to split that parameter in two around the @@ part.

After reading "What is an Adaptor in Build Forge?" (pdf, from the help page), based on perl, check if you can use all parameters instead of the first two.
The call remains $1 and $2 (I would add the @@ as well):

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

As you have seen, in the cc_describe command block, $1 and $2 could only represent part of the filename, because of the space issue.
Try and see if concatenating the parameters (whatever their number), either with $* (bash style) or join('', @ARGV) (perl-style).
Once you have concatenated your parameters, you end back with the full extended pathname of the file, with its spaces included.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The extended path name never contains spaces, so I placed the double quotes around the file name only. Even if I'd find a way to get the adaptor to concatenate the two parameters (and include the @@ in the calling command), the cc_describe block would still be missing pieces of the passed parameters when the filename contains spaces. – Jozef Oct 09 '16 at 02:34
  • 1
    @Jozef "if I'd find a way to get the adaptor to concatenate the two parameters (and include the @@ in the calling command)": the all point of the answer if *not* to concatenate the two parameters, but to concatenate *all* parameters within the cc_describe block. – VonC Oct 09 '16 at 06:05
  • The adaptor's functionality does not include a concatenate method. Lsit of all commands available: http://www.ibm.com/support/knowledgecenter/SSB2MV_8.0.0/com.ibm.rational.buildforge.doc/topics/adaptor_xml__reference.html – Jozef Oct 11 '16 at 17:28
  • I tried implementing your suggestion to include the @@ in the calling command. However, spaces do not make it through because they are used to delineate parameters. See updated question. – Jozef Oct 11 '16 at 18:11
  • 1
    @Jozef Ids there any possibility to write the full parameter string to a file, and read that file from the command block? (I am trying an alternative approach here) – VonC Oct 11 '16 at 18:28
  • I'm writing it to a file as you suggested, change the spaces to another character, pass it to the command block, change those characters back to a space, and then pipe the command to the cleartool command line. Should I answer my own question so that I can include the code? – Jozef Oct 14 '16 at 20:29
  • 1
    @Jozef Sure, you can post (and accept) your own answer: that will benefit others. – VonC Oct 14 '16 at 20:30
1

I got it to work using @VonC suggestions. It's a roundabout way of doing it but it does work! Still need to make some improvements to it (such as not using the same temp files).

Here's the relevant sections of the Build Forge ClearCase code changes adaptor.

<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>
Jozef
  • 303
  • 1
  • 11