Coreus
Coreus

Reputation: 5610

How do I retrieve Composer via Ant?

I'm trying to get make my Ant script retrieve Composer for me. Composer is a dependancy manager for PHP. According to the doc one needs to run this command: "curl -s https://getcomposer.org/installer | php" which will download Composer.phar into the directory I'm in. This works as intended when running from a terminal.

How do I setup the Ant build file for this? So far I've got this segment for the "composerget" target, but it's doesn't save the file, only output it in my command shell:

....    
<target name="composerget" description="Composer update dependencies">
    <exec executable="curl"> 
        <arg line="-s" />
            <arg line="https://getcomposer.org/installer"/>
        <arg line="| php" />
    </exec>
  </target>
....

Any help is greatly appeciated.

Upvotes: 8

Views: 2445

Answers (2)

Damien
Damien

Reputation: 1528

This will download the Composer installer, verify its signature, and run the installer:

    <target name="composer" description="Install composer">
        <exec executable="wget">
            <arg value="-O" />
            <arg value="composer-setup.sig" />
            <arg value="https://composer.github.io/installer.sig" />
        </exec>
        <exec executable="wget">
            <arg value="-O" />
            <arg value="composer-setup.php" />
            <arg value="https://getcomposer.org/installer" />
        </exec>
        <exec executable="bash">
            <arg value="-c" />
            <arg value="awk '{print $$0 &quot;  composer-setup.php&quot;}' composer-setup.sig | sha384sum --check" />
        </exec>
        <exec executable="php">
            <arg value="composer-setup.php" />
        </exec>
        <exec executable="rm">
            <arg value="composer-setup.php" />
        </exec>
        <exec executable="rm">
            <arg value="composer-setup.sig" />
        </exec>
        <exec executable="mv">
            <arg value="composer.phar" />
            <arg value="composer" />
        </exec>
    </target>

If you are using GNU Make, this is the equivalent:

all: vendor

vendor: composer composer.json composer.lock
        ./composer install

composer:
        wget -O composer-setup.sig https://composer.github.io/installer.sig
        wget -O composer-setup.php https://getcomposer.org/installer
        awk '{print $$0 "  composer-setup.php"}' composer-setup.sig | sha384sum --check
        php composer-setup.php --quiet
        rm composer-setup.*
        mv composer.phar composer

Upvotes: 0

Mez
Mez

Reputation: 24933

<target name="composerget" description="Composer update dependencies">
    <exec executable="/bin/bash">
        <arg value="-c" />
        <arg value="curl -s https://getcomposer.org/installer | php" />
    </exec>
</target>

Should do the trick.

The pipe (|) can only be used in a shell script. You're passing it as an argument to curl. So you need to execute a shell script - which you can do with bash -c and passing the command as a shell statement.

Attribution.

Upvotes: 8

Related Questions