What is this build.xml doing? - ant

I am learning build.xml and am confused by the following code:
<macrodef name="a-test">
<attribute name="port" default="${PORT}"/> #1
<junit printsummary=...
<env key="PORT" value="#{port}" /> #2
...
when I run java with commandLine including -DPORT=8080 and then in java code I get port value 8080 by calling
String port = System.getenv(PORT).
What is the above build.xml doing? So far I know $ is to represent a property while # is to represent an attribute. Besides, the above code is the only place where PORT and port appear. What happens here so that port value are finally obtained in java code? Thanks.
The other question, what is the difference btw. using "env key" and using "sysproperty"? according to http://etutorials.org/Programming/Java+extreme+programming/Chapter+3.+Ant/3.6+Passing+Arguments+to+a+Buildfile/
sysproperty can be use to parse argument -D to java code, while env key is used to do the same thing right? Thanks.
Is there any detailed document about build.xml? the one I google from internet describer things so briefly.

What you see is macrodef in ant. There will be another place in build.xml(or other build.xml) where this is called by like
<a-test port=<value> ..

Related

How do I use environment variables in an attribute name in jboss' standalone.xml?

I understand that within a field, I can pull an environment variable with the syntax of ${env.VARIABLE_NAME}, however, whenever I try to do so within an attribute name, jboss throws an error.
What I have done, and works
<datasource jndi-name="java:/jdbc/database" pool-name="database" enabled="true" use-java-context="true">
<connection-url>${env.DS_CONNECTION_URL}</connection-url>
<driver>${env.DS_DRIVER}</driver>
</datasource>
What I want to do, which is failing
<console-handler name="CONSOLE">
<formatter>
<named-formatter name="${env.FORMATTER}"/>
</formatter>
</console-handler>
I have also tried starting without the surrounding quotes. I have created a child xml element with the value of name and the environment variable, but that has also failed.
I expect the environment variable FORMATTER to be used as the name, but instead I get the following error on attempting to start jboss.
java.lang.IllegalArgumentException: Formatter "${env.FORMATTER}" is not found
Expressions are not allowed for the named-formatter attribute. In most cases it doesn't make much sense as the formatter would have to be defined and cannot have a dynamic name.
If you look at the model description documentation you can see which attributes support expressions.
How to pass env variables to the attributes of other formatter's properties?
<meta-data>
<property name="ENV" value="${env.MY_ENVIRONMENT}"/>
</meta-data>
is not working when running
docker run -p 8081:9990 -p 8080:8080 -e MY_ENVIRONMENT="DEV" --name c1 c1img:1.1.2
I still see
..."ENV":"${env.MY_ENVIRONMENT}"...

passing value to remote ant target

I have two ant files say antFile1.xml and antFile2.xml on windows and linux machine respectively.
antFile1.xml
<target name="executeOnLinux">
<sshexec
host="${remote.host.ip}"
username="${remote.user.id}"
password="${remote.user.ssh.password}"
command="ant -f antFile2.xml 'linuxAntTarget'"
trust="true"/>
</target>
antFile2.xml
<target name="linuxAntTarget">
<input message="Enter application edition number" addproperty="editionNo"/>
<echo message="${editionNo}"/>
</target>
When I execute the the target named "executeOnLinux" from antFile1.xml from my, it connects to the linux machine and starts executing the "linuxAntTarget" from antFile2.xml file. But, as soon as it reaches to the the point where user input is required keeps waiting since I am not able to pass the input. My question is how can I pass the value to it? Is this even possible or there is any other better way of doing it?
Since Ant 1.9.4, the sshexec task provides a useSystemIn attribute:
Whether to pass the current standard input to the remote process, defaults to false
You may also try the input attribute from the same task:
A file from which the executed command's standard input is taken. This attribute is mutually exclusive with the inputstring and inputproperty attributes.
When executing more than one command via commandResource, input will be read for each command. since Ant 1.8.0

Openbravo ant build fails

I am trying to setup openbravo on eclipse environment with the above URL.
Development stack setup is done successfully. (ANT, Java, Postgresql)
At the openbravo source directory when i apply the command
ant install.source
Build failure due to errors -
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/build.xml:480: The following error occurred while executing this line:
480 <ant dir="${base.src}" target="compile.complete.development" inheritAll="true" inheritRefs="true" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:874: The following error occurred while executing this line:
874 <jvmarg line="${env.CATALINA_OPTS}" />
/home/pos/sourcecode_openbravo/Openbravo-3.0MP21/src/build.xml:880: Directory
880 <jvmarg value="-Djava.io.tmpdir=${env.CATALINA_BASE}/temp" />
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Any help would be appreciated. Thanks.
Sounds like a permission problem.
See the related section 'Permission issues' in openbravo wiki
EDIT
for the remaining issues, i believe the properties base.src, CATALINA_OPTS and CATALINA_BASE are not set properly. Check this via :
<echo>
$${base.src} => ${base.src}
$${env.CATALINA_OPTS} => ${env.CATALINA_OPTS}
$${env.CATALINA_BASE} => ${env.CATALINA_BASE}
</echo>
or simply output all available properties use :
<echoproperties/>
also consider, before using ${env.whatever} you need to use :
<property environment="env"/>
before !
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not successful for an unknown reason
Give the permission to webapps folder
sudo chmod -R 777 /var/lib/tomcat6/webapps/
/var/lib/tomcat6/webapps/openbravo/WEB-INF/lib creation was not
successful for an unknown reason
it seem permission problem. It is important to always us the correct user account to start / stop tomcat!
Conceptually there are two user accounts involved in working with Openbravo:
command-line user used to work with files & compile Openbravo
user account used by Apache Tomcat service
There are several overlapping areas in which one of the accounts needs to access and modify files from the other account in both directions.
To avoid any problems Openbravo strongly recommends to run Apache Tomcat services with the same user account which is used on command line. As that way the above topic will be perfectly solved easily.
source: http://wiki.openbravo.com/wiki/Installation/Custom/Apache_Tomcat

How to escape # in Ant SCP task

I would like to ask you for some help. How can I use an scp task when my username contains an # sign?
I tried to escape the character in many ways but it isn't working. In the following example, my username is user#host.com
<scp file="test.txt" todir=""user#host.com":password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user#host.com':password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\#host.com:password#ftp.host.com:/" trust="true" sftp="true"/>
But the output is always the same:
neither password nor keyfile for user "user has been given. Can't authenticate.
Please, is there anyway to force the task to parse this string correctly? Thank you very much.
By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.
I use the SCP task in my build.xml and it's form looks like this:
<scp file="package/ROOT.war" todir="user#example.com:~" trust="true" password="${password}"/>
Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a # symbol. The restrictions appear to be with paths that have a : or # in them as seen by this comment:
// user:password#host:/path notation
// everything upto the last # before the last : is considered
// password. (so if the path contains an # and a : it will not work)
The code doesn't seem to support this comment (as pointed out by
martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password#host:/path notation and a username with an # is causing problems?
Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.
Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful
observation:
16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working

liquibase future rollback error with sqlFile tag: File not found

I've added the future-rollback tag to my ant script. What i want to do (and I think future-rollback is what Im looking for) is to generate an sql rollback script, but without executing it (rollback script must be delivered with sql scripts is the requirement from my client).
My changelog file has many changesets, some of which contain the <sqlFile> tag.
For example:
<databaseChangeLog ...>
<include file="latest/somesqlprocedure.xml" relativeToChangelogFile="true"/>
</databaseChangelog...>
Where the latest/somesqlprocedure.xml has an sqlFile tag.
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<sqlFile path="${changelog.dir}/latest/myprocedure.sql" splitStatements="false" />
</changeSet>
</databaseChangeLog>
When I run the ant script, I get the following error
liquibase.exception.ChangeLogParseException:
Invalid Migration File: <sqlfile
path=${changelog.dir}/latest/myprocedure.sql>
- Could not find file
Does anyone has an idea of whats going on ?
This is a snippet of the build.xml file
<target name="db-future-rollback" depends="init">
<rollbackFutureDatabase
changeLogFile="${db.changelog.file}"
driver="${database.driver}"
url="${database.url}"
username="${database.username}"
password="${database.password}"
outputfile="${database.rollback.dir}"
promptOnNonLocalDatabase="${prompt.user.if.not.local.database}"
classpathref="project.classpath"
>
</rollbackFutureDatabase>
</target>
Thanks in advance.
The problem may be coming from using an absolute path in your sqlFile, rather than a classpath-relative path. The classpath relative path was what was originally supported in liquibase and is still better tested. The absolute path option was added recently, and the futureRollbackSql code may have not been patched to support it.
Can you try the sqlFile using a relative path?
As a side note, the relative path option is generally better because the filename is used in the databasechangelog table to note which changeSets have ran. If you use an absolute path, the entire path is stored and if you try to re-run the changelog from a different path (or running against the same database from a different machine), liquibase will think it is a different changeSet and try to re-run it.

Resources