Search code examples
maveninputreleasemaven-antrun-pluginexternal-script

How to do input task in maven antrun plugin


I created a maven project and i'm trying to run an external script. In this external script, i use read command to ask a question and get an answer.

It works if i do a sudo mvn package with exec-maven-plugin

But, but, but :

  • If i do a sudo mvn package, my script doesn't stop at read command.
  • If i do a sudo mvn release:prepare with exec-maven-plugin, my script doesn't stop at read command.
  • If i do a sudo mvn release:prepare with maven-antrun-plugin, my script doesn't stop at read command.

And obviously, i need to do a release :)

I tried to to change the first line of my script (#/usr/bin/bash, sh, ...) with other syntaxes for read command...

Is anyone have a solution to help me ???

Here the concerned part of my pom.xml

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <id>initialisation</id>
      <phase>initialize</phase>
      <configuration>
        <tasks>
        <exec dir="${project.basedir}" executable="${project.basedir}/livraison/outils/0_init_livraison.ksh" failonerror="true">
          <arg line="${project.name} ${project.version} ${ancienneVersion}" />
        </exec>
       </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Here the concerned part of my 0_init_livraison.ksh

#!/bin/ksh

echo -e "| EXECUTION DU SCIPT generation_livrable.ksh \n"

echo "SHELL : $SHELL"
boucle="boucler"
while [ $boucle -eq "boucler" ]
do
    echo -ne "  Souhaitez-vous forcer la procedure (oui/non)? "
    read rep1

    case "$rep1" in
    o|O|y|Y|oui|Oui|OUI|yes|Yes|YES)
    echo ""
    break
    ;;

    n|N|non|Non|NON|no|No|NO)
    echo -e "  Abandon de la procedure..."
    boucle=""
    exit 1
    ;;
    *) 
    echo -e "  Reponse incomprehensible.\c"
    esac
done

The last lines of my console when i do a sudo mvn package ( And then, nothing happens. It seems blocked because of an infinite while loop)

[INFO] --- maven-antrun-plugin:1.8:run (initialisation) @ MyProject---
[WARNING] Parameter tasks is deprecated, use target instead
[INFO] Executing tasks

main:
   [exec] | EXECUTION DU SCIPT generation_livrable.ksh
   [exec]
   [exec] SHELL : /bin/bash

Thanks for the reading :)

EDIT :

I tried to use property with maven-antrun-plugin. But i have a similar problem: antrun input task doesn't work during mvn release:prepare operation


Solution

  • I tried to use Exec ksh instead of script name with a script as a parameterthose but it didn't work. I tried to set ANT_HOME variable but it didn't work.

    But i changed my way of thinking : Having a build that depends on the console is extremely problematic, most integration tools around Maven will not work with it because they assume autonomous runs. This kind of maven project would encounter problems with Jenkins , Netbeans,... They cannot wait for manual answer.

    The best way is to set an option and run a command with a parameter :

    mvn clean packge -Dforcer=oui or mvn release:prepare -Darguments=-Dforcer=oui

    Here a part of my pom.xml :

    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <id>initialisation</id>
          <phase>initialize</phase>
          <configuration>
            <tasks>
              <exec executable="${outilsLivraison}/0_init_livraison.ksh" failonerror="false" resultproperty="codeRetour">
                <redirector errorproperty="message.redirector.err" />
              </exec>
              <fail message=" ARRET DE LA PROCEDURE ! VOUS POUVEZ FORCER LA PROCEDURE AVEC '-Dforcer=oui' (ou '-Darguments=-Dforcer=oui' pour une release).">
                <condition>
                  <and>
                    <equals arg1="${message.redirector.err}" arg2="warning" />
                    <not><equals arg1="${forcer}" arg2="oui" /></not>
                  </and>
                </condition>
              </fail>
              <fail message=" Erreur">
                <condition>
                  <equals arg1="${codeRetour}" arg2="1" />
                </condition>
              </fail>
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    Here a function which is called in my 0_init_livraison.ksh script when a problem is detected :

    fonc_warning(){
      echo "warning" 1>&2
    }
    

    So my problem is solved.

    Anyway, thank's for your suggestions :)