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
EITHER
Set environment variable ANT_HOME, add a property to you Maven:
<property name="ant.home" value="${env.ANT_HOME}" /> and add a parameter vmlauncher="true" to your Ant Exec part.
OR
Exec ksh instead of script name with a script as a parameter. I mean:
<exec dir="${project.basedir}" executable="ksh" failonerror="true">
<arg value="${project.basedir}/livraison/outils/0_init_livraison.ksh">
</exec>
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 :)
Related
I'm trying to unzip a .zip - File with a build-timestamp suffix appended using the maven-antrun-plugin. The var "finalName" is set in the effective pom.xml:
<finalName>XXXXXXX-server-5.20.0-SNAPSHOT-2022_11_29_14_45</finalName>
Using plugin version 3.1.0 (also tried 3.0.0 with the same outcome) it fails:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:3.1.0:run (Unzip Server) on project XXXXXXX-server: An Ant BuildException has occured: src 'C:\Dev\XXXXXXX-maven\XXXXXXX-server\target\${finalName}' doesn't exist.
[ERROR] around Ant part ...<unzip src="C:\Dev\XXXXXXX-maven\XXXXXXX-server\target/${finalName}" dest="C:/DEV/XXXXXXX/runOnline" />... # 7:99 in C:\Dev\XXXXXXX-maven\XXXXXXX-server\target\antrun\build-main.xml
Problem is clear: the variable finalName is not substituted(aka known).
...
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Unzip Server</id>
<phase>package</phase>
<configuration>
<target>
<delete dir="${project.exec.directory}" includeemptydirs="true" />
<mkdir dir="${project.exec.directory}" />
<echo message="unzipping Server -${project.exec.directory}" />
<unzip src="${project.build.directory}/${finalname}" dest="${project.exec.directory}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
...
Same snippet as above using wildcard-operator * does not work either:
<unzip src="${project.build.directory}/*.zip" dest="${project.exec.directory}" />
ends up not finding the *.zip (which actually exists in that directory at antrun execution time):
An Ant BuildException has occured: src 'C:\Dev\XXXXXXX-maven\XXXXXXX-server\target\*.zip' doesn't exist.
Any suggestions without using another plugin/mechanism?
Thank you :-)
Developing on Windows 10 I have a Java project in Maven that has a Linux "launcher" shell script for the FooBar utility stored in the repository at src/bin/foobar.sh. It uses resource filtering to substitute in the correct executable JAR path so that what gets built is a foobar.sh script that launches the executable JAR in the same directory.
The POM uses org.apache.maven.plugins:maven-antrun-plugin:1.8 to enable the executable flag on the foobar.sh script in the target/bin directory (which has been already been copied using Maven resource filtering, with that directory path stored in the ${binOutputDirectory} property):
<chmod dir="${binOutputDirectory}" includes="**/*.sh" perm="+x" />
Then it renames the foobar.sh file to simply foobar (i.e. it removes the extension) to follow best practices for shell scripts:
<move todir="${binOutputDirectory}">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>
You can see e.g. globalmentor-root pom.xml at c31ae410143f86ebf2bf10467214214d87b2eb61 for the full POM source code. Actual child POMs will simply enable the AntRun operations by providing their executions an appropriate phase like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>set-shell-scripts-executable</id>
<phase>process-resources</phase>
</execution>
<execution>
<id>remove-shell-script-extensions</id>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
The essential part of that is working fine, and I wind up with a foobar file in my distributable ZIP file, with its executable flag enabled as desired. Unfortunately I also wind up with the original foobar.sh file as well, and I can see in target/bin (where the .sh extension gets removed) that both files are there as well. So it would appear that AntRun <move> is behaving as <copy>.
To see this in action, build the Guise Mummy 0.1.0 project and look in the cli/target/bin directory; you'll see that guise.sh has not been deleted.
To work around the problem, I can add an extraneous <delete> command; this will successfully remove foobar.sh. (The difference in <fileset> syntax is irrelevant; I switched only because it was more concise.)
<move todir="${binOutputDirectory}">
<fileset dir="${binOutputDirectory}" includes="**/*.sh"/>
<mapper type="glob" from="*.sh" to="*" />
</move>
<delete>
<fileset dir="${binOutputDirectory}" includes="**/*.sh"/>
</delete>
Why is AntRun <move> by itself not removing the original target/bin/foobar.sh file after it copies it to target/bin/foobar as part of the move operation?
Upgrading to org.apache.maven.plugins:maven-antrun-plugin:3.1.0 seems to have fixed the problem. When I created this question I had been using v1.8. I can only suppose that org.apache.maven.plugins:maven-antrun-plugin:1.8 is buggy.
Noticed in the pom, within the antrun goals, you are modifying permissions of the .sh script. This does not confirm if the shell script is writeable, it may be read-only:
<execution>
<id>set-shell-scripts-executable</id>
<!--
Enable execute permission for the shell scripts in `${binOutputDirectory}`.
Enable by specifying a phase (e.g. `process-resources`) in child POM.
-->
<phase>none</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<chmod dir="${binOutputDirectory}" includes="**/*.sh" perm="+x" />
</target>
</configuration>
</execution>
Try the following, apply the overwrite attribute, like so:
(overwrite overwrite existing files even if the destination files are newer)
<move todir="${binOutputDirectory}" overwrite="true">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>
If that does not work, also add the force attribute, like so:
(force Overwrite read-only destination files)
<move todir="${binOutputDirectory}" overwrite="true" force="true">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>
I try to use property with maven-antrun-plugin.
But it seems to be blocked in some case (I had the similar problem with exec-maven-plugin :
It work with sudo mvn package : The script 0_init_livraison.ksh is executed. After this, execution, antrun asked me a question "Souhaitez-vous continuer ?" If the answer is yes, the build can continue. If the answer is no the script send an error message and the build is stopped.
It don't work with sudo mvn release:prepare : antrun ask the question and the build stay blocked (regardless of my answer)
I need to do a release
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="false"
resultproperty="sortieInitScript">
<arg line="${project.name} ${project.version} ${ancienneVersion}" />
<redirector errorproperty="redirector.err" />
</exec>
<echo message="Resultat ${sortieInitScript}, Message ${redirector.err}"/>
<input message=" Souhaitez-vous Continuer ? "
validargs="o,n"
addproperty="procedureChoix" />
<fail message="ARRET VOLONTAIRE DE LA PROCEDURE !!">
<condition>
<equals arg1="${procedureChoix}" arg2="n" />
</condition>
</fail>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Here the concerned part of my 0_init_livraison.ksh :
...
echo -e "\n| FIN DU SCIPT "
echo -e " ============================================================"
echo "warning" 1>&2
The last lines of my console when i do a sudo mvn package :
[exec] | FIN DU SCIPT
[exec] ============================================================
[exec]
[echo] Resultat 0, Message warning
Souhaitez-vous Continuer ? (o, n)
o
[INFO] Executed tasks (<- this last line doesn't appear with mvn release:prepare. But it appears with mvn package)
...
Do i miss something with release command ?
Thanks for the reading :)
I'm using the Dojo build utility (i.e. shrinksafe) from Maven to build Dojo JavaScript template widgets into one file. For some reason, when I do the build it substitutes the ${id} tag in the HTML template snippets I use with the Maven project id (group/artifact/package/version):
'my/application/ui/Calculator':function(){
require({cache:{
'url:my/application/ui/templates/Calculator.html':"<div class=\"${baseClass}\">\r\n<div id=\"my.app:noddy-calc:war:1.0.0-RELEASE_button\"
instead of:
'my/application/ui/Calculator':function(){
require({cache:{
'url:my/application/ui/templates/Calculator.html':"<div class=\"${baseClass}\">\r\n<div id=\"${id}_button\"
Has anyone come across this weird behaviour and (more importantly) is there any way of preventing it?
In the Maven pom, I'm using the ant plugin to run shrinksafe:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
...
<executions>
<execution>
<tasks>
<java classname="org.mozilla.javascript.tools.shell.Main" fork="true" maxmemory="512m" failonerror="true" classpath="${js.build.directory}/util/shrinksafe/js.jar;${js.build.directory}/util/closureCompiler/compiler.jar;${js.build.directory}/util/shrinksafe/shrinksafe.jar">
<arg value="${js.build.directory}/dojo/dojo.js"/>
<arg value="baseUrl=${js.build.directory}/dojo"/>
<arg value="load=build"/>
<arg line="--profile ${dojo.build.profileFile}"/>
</java>
</tasks>
I have a situation where we wrap a jar with JSmooth to get an suitable exe file.
This has traditionally been built by ant, and as part of our general mavenification the current, short-term solution has been to use maven-antrun-plugin to set a property and invoke ant.
Unfortunately this approach fails when building on Unix (as there is no X11 display available) and the solution is to invoke the JVM with -Djava.awt.headless=true. I would like to do this in my pom.xml but cannot identify where to do this.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<!-- create one-jar and exefy it -->
<property name="maven.project.build.finalName" value="${project.build.finalName}" />
<!-- note: fails on headless Linux for now -->
<ant />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
It is ok to fork a new JVM directly but not to rely on platform specifics.
How can I do this correctly?
As far as I know, the solution without forking JVM is to use MAVEN_OPT
export MAVEN_OPTS="-Djava.awt.headless=true"
Since -D is JVM option, you had to specify it to maven directly. You cannot (once again, from what I know) pass it as internal argument (and there isn't any configuration option that allow it)
So, using MAVEN_OPT parameter become the right way to do it.
EDIT 1:
You can have a glance here using better-maven2-antrun-plugin
http://code.google.com/p/better-maven2-antrun-plugin/wiki/Usage
EDIT 2:
Can can maybe help maven-antrun developpement providing them a way to specify those parameters, like maven-compiler-plugin. This would be the best way if you really want to use pom informations.
The ant manual has a section titled "Running Ant via Java" that shows how to do just what you want. A slightly tweaked version of their example is reproduced below:
<java
classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="${basedir}"
taskname="headless-ant"
>
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="-Dbasedir=${basedir}"/>
<jvmarg value="-Djava.awt.headless=true"/>
</java>
If you put that snippet in place of the <ant> element in your snippet, it should do the trick.