如何在Maven Antrun插件中执行输入任务 [英] How to do input task in maven antrun plugin

查看:125
本文介绍了如何在Maven Antrun插件中执行输入任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Maven项目,并且试图运行外部脚本. 在此外部脚本中,我使用read命令来提出问题并获得答案.

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.

如果我使用 exec -maven-plugin

但是,但是,但是:

  • 如果我执行 sudo mvn软件包,则我的脚本不会在读取命令时停止.
  • 如果我使用exec-maven-plugin执行 sudo mvn release:prepare ,我的脚本不会在读取命令时停止.
  • 如果我使用maven-antrun-plugin执行 sudo mvn release:prepare ,则我的脚本不会在读取命令时停止.
  • 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 :)

我试图使用读取命令的其他语法来更改脚本的第一行(#/usr/bin/bash,sh,...)...

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 ???

这是我pom.xml的相关部分

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>

这是我的0_init_livraison.ksh的相关部分

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

当我执行sudo mvn软件包时控制台的最后一行(然后,什么也没有发生.由于无限的while循环,它似乎被阻塞了)

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

感谢您的阅读:)

我尝试将属性与maven-antrun-plugin一起使用. 但是我有一个类似的问题: antrun输入任务不起作用在mvn发布期间:准备操作

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

推荐答案

我尝试使用Exec ksh而不是脚本名称,并以脚本作为参数,但是没有用. 我试图设置ANT_HOME变量,但是没有用.

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.

但是我改变了思维方式: 建立依赖于控制台的构建存在很大问题,因为围绕Maven的大多数集成工具都假定自动运行,因此无法使用它.这种Maven项目在Jenkins,Netbeans等方面会遇到问题.他们迫不及待要手动回答.

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清洁包装-Dforcer = oui MVN发行版:准备-Darguments = -Dforcer = oui

这是我pom.xml的一部分:

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>

这里有一个在检测到问题时在我的0_init_livraison.ksh脚本中调用的函数:

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

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

所以我的问题解决了.

无论如何,谢谢您的建议:)

Anyway, thank's for your suggestions :)

这篇关于如何在Maven Antrun插件中执行输入任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆