Remove first line comment in properties file in Ant 1.7.1 - ant

I have the following properties file - data.ini with the content :
A=1
B=2
C=3
D=4
I run the following code using Ant 1.7.1
<propertyfile file="data.ini">
<entry key="C" value="5" />
</propertyfile>
and get the following output in data.ini:
#Mon Jan 05 14:21:53 IST 2015
A=1
B=2
C=5
D=4
I do not want the first line - #Mon Jan 05 14:21:53 IST 2015 to be added to the properties file when I run the code.
How do I avoid it?

Since you have mention ini file, I would suggest you to take a take a look at
Removing comment in ini file writen by ant when updating the ini file

Related

is there any scriptella jruby script sample/example?

I am new scriptella user.
Is there any sample or tutorial to use jruby
as scripting language?
Thanks and Regards,
Manish
== updated after ejboy's suggesstions ==
Copied jruby.jar (1.7.4) in lib.
However scriptella failed with following exception.
Jun 14, 2013 9:31:36 AM Script /bigdisk/work/cougar/code/leopard-monitor/analytics/kpoint_usage/scriptella/scripts/jruby_sample.xml execution failed.
/etl/script[1] failed: keySet
Location: /etl/script[1]
Jun 14, 2013 9:31:36 AM <SEVERE> Scriptella bug report. Submit to issue tracker.
Scriptella version: 1.1
Exception:
scriptella.execution.EtlExecutorException: /etl/script[1] failed: keySet Location: /etl/script[1]
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:190)
at scriptella.tools.launcher.EtlLauncher.execute(EtlLauncher.java:276)
at scriptella.tools.launcher.EtlLauncher.launch(EtlLauncher.java:193)
at scriptella.tools.launcher.EtlLauncher.main(EtlLauncher.java:321)
Caused by: scriptella.core.ExceptionInterceptor$ExecutionException: /etl/script[1] failed: keySet
at scriptella.core.ExceptionInterceptor.execute(ExceptionInterceptor.java:44)
at scriptella.core.Session.execute(Session.java:103)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:227)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:183)
... 3 more
Following is my xml file.
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<description>
use jruby as scripting language.
</description>
<connection id="script-jruby" driver="script" url="out/test-out.csv"> <!-- classpath="path/to/jar:path/to/jar2"> -->
language=jruby
</connection>
<script connection-id="script-jruby">
puts "Hello world - using jruby"
</script>
</etl>
Try setting the language property to jruby and make sure the required jars are available on classpath. You can either copy them to <scriptella_home>/lib directory or include in the connection declaration:
<connection id="script" driver="script" classpath="path/to/jar:path/to/jar2">
language=jruby
</connection>

How can I remove a line with Ant replaceregexp, but not leave an empty line

I have the following text file:
Manifest-Version: 3.0.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b19 (Sun Microsystems Inc.)
Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version="1.
1.0"
Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref
Bundle-Version: 3.0.0.20121120
Bundle-Localization: plugin
Bundle-Name: %plugin.name
Bundle-Vendor: %plugin.providername
And I'm trying to use the following pattern in a replaceregexp task
regexp pattern='Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version="1.
[\s\S]*'
To end up with this:
Manifest-Version: 3.0.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b19 (Sun Microsystems Inc.)
1.0"
Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref
Bundle-Version: 3.0.0.20121120
Bundle-Localization: plugin
Bundle-Name: %plugin.name
Bundle-Vendor: %plugin.providername
The trouble is I keep getting this:
Manifest-Version: 3.0.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b19 (Sun Microsystems Inc.)
1.0"
Bundle-SymbolicName: com.qnx.doc.gestures.lib_ref
Bundle-Version: 3.0.0.20121120
Bundle-Localization: plugin
Bundle-Name: %plugin.name
Bundle-Vendor: %plugin.providername
What should my regex be to get rid of the empty line?
Thanks.
Something like this should work:
Require-Bundle: org\.eclipse\.linuxtools\.cdt\.libhover;bundle-version="1\.\s*1.0"\s*
(using \s* to match zero or more whitespace characters, which include \r and \n) but since you're dealing with a manifest file it would make more sense to use a proper manifest parser. Unfortunately the Ant <manifest> task doesn't provide a way to remove attributes, but it's pretty straightforward with a <script> task:
<property name="manifest.file" location="path/to/manifest.txt" />
<script language="javascript"><![CDATA[
importPackage(java.io);
importPackage(java.util.jar);
// read the manifest
manifestFile = new File(project.getProperty('manifest.file'));
manifest = new Manifest();
is = new FileInputStream(manifestFile);
manifest.read(is);
is.close();
// remove the offending attribute
manifest.getMainAttributes().remove(new Attributes.Name('Require-Bundle'));
// write back to the original file
os = new FileOutputStream(manifestFile);
manifest.write(os);
os.close();
]]></script>
<replaceregexp file="manifest.mf" match='Require-Bundle: org.eclipse.linuxtools.cdt.libhover;bundle-version=\"[^\"]+\"[\r\n]*' replace="" flags="m"/>
This works for me.

Jaxb binding file being ignored

I having a bit of trouble building JAXB bindings fora set of schemas and its driving me a bit batty. Here is the schema in question (it is just one of may schema in this particular build):
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xml="http://www.w3.org/XML/1998/namespace" targetNamespace="http://www.w3.org/XML/1998/namespace">
<attribute name="lang" type="language">
<annotation>
<documentation>In due course, we should install the relevant ISO 2- and 3-letter
codes as the enumerated possible values . . .</documentation>
</annotation>
</attribute>
<attribute name="space" default="preserve">
<simpleType>
<restriction base="NCName">
<enumeration value="default"/>
<enumeration value="preserve"/>
</restriction>
</simpleType>
</attribute>
<attributeGroup name="specialAttrs">
<attribute ref="xml:lang"/>
<attribute ref="xml:space"/>
</attributeGroup>
xjc is claiming that the attributes declared above are already declared elsewhere:
parsing a schema...
[ERROR] 'lang' is already defined
line 26 of file:../../gml/3.1.1/smil/xml-mod.xsd
[ERROR] (related to above error) the first definition appears here
line 88 of http://www.w3.org/2001/03/xml.xsd
[ERROR] 'space' is already defined
line 34 of file:../../gml/3.1.1/smil/xml-mod.xsd
[ERROR] (related to above error) the first definition appears here
line 95 of http://www.w3.org/2001/03/xml.xsd
[ERROR] 'specialAttrs' is already defined
line 39 of file:../../gml/3.1.1/smil/xml-mod.xsd
[ERROR] (related to above error) the first definition appears here
line 111 of http://www.w3.org/2001/03/xml.xsd
Failed to parse a schema.
Doing a bit of research would lead me to believe that the problem is that I need a binding file to resolve the duplicate attributes....and I have one :
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc">
<jaxb:bindings schemaLocation="../../gml/3.1.1/smil/xml-mod.xsd" node="/xs:schema">
<jaxb:bindings node="//xs:attribute[#name='lang']">
<jaxb:property name="langAttribute"/>
</jaxb:bindings>
<jaxb:bindings node="//xs:attribute[#name='space']">
<jaxb:property name="spaceAttribute"/>
</jaxb:bindings>
<jaxb:bindings node="//xs:attributeGroup[#name='specialAttrs']">
<jaxb:property name="specialAttrsAttribute"/>
</jaxb:bindings>
</jaxb:bindings>
Yet the problem persists. The error message with or without the bindings file is the same. I know the file is being used , because if I mess up the xpath for the node selector I get an error message. It's like xjc knows the bindings file is there but ignores it.
Here's the command line that fails to build the bindings:
C:\tools\jaxb-ri-20110512\bin\xjc -episode ..\..\..\common.ogc -d ..\..\..\src -p com.ogc.bindings -b ..\..\..\bindings.xsd -catalog ..\..\..\ogc.cat -extension sosAll.xsd
I have tried this with both the jdk6 native jaxb (2.0) and jaxb 2.2.4 (I installed the jaxb-api.jar in the endorsed directory)
XJC (bundled with JDK), ignores binding file, if the path to the binding file or the XSD / WSDL is too long.
Issue observed and confirmed on Oracle 64 bit JDK 1.6.0.45, on Windows 7 ultimate and on Linux, XJC (bundled with JDK), ignores binding file, if the path to the binding file is too long.
I did NOT have the time to do detail research on the issue; I solved my problem by simply shortening the svn checkout path. It was the most bizarre issue - I could not reproduce the problem on my Windows 8 Laptop and on Linux, but on a Windows 7 workstation, build kept on failing. I identified this issue by confirming that other then path, there is NO difference between Windows 8 LAPTOP, where the build works, vs. Windows 7 Ultimate where the path is a bit long (6 characters -> /trunk).
Problem was solved without any code, configuration, xml schema or binding file change. Posting here so that others who may run into this, have a bit of easier time then me.
i believe this is an issue with namespace collision, you dont have a namespace defined for your schema elements and it seems you are using names for your attributes that are in conflict with the ones defined in xml's schema (xml.xsd)

Removing comment in ini file writen by ant when updating the ini file

I have an ant file which updates the data in ant file due this ini file gets updated and at the top it has a comment as follows
#Thu, 07 Jul 2011 06:54:54 -0500
I don't want this comment as i am accessing this file by php using parse_ini. Due to this comment i get an failure
Comments starting with '#' are deprecated in build.ini on line 1
so is there any way so that i will not get the comment in ini file.
Thanks.
EDIT:
<propertyfile file="build.ini">
<entry key="build-number" type="int" operation="+" value="1" />
</propertyfile>
this updates my ini file build-number by +1
Martin's comment points you to a way to remove comments using replaceregexp. (I was about to show you a similar idea but using move, filterchain and striplinecomments. But the replaceregexp is more compact.)
The other suggestion I have is that since you are editing ini files, maybe you should use a task dedicated to that, rather than using the PropertyFile task. There is an IniFile taks in ant-contrib might do the job.
If the replaceregexp doesn't work for you because your file has other # comments in it and you only want to remove that top line, then try this:
<target name="test">
<propertyfile file="test.properties">
<entry key="key" value="value"/>
</propertyfile>
<move file="test.properties" tofile="test.properties.tmp">
<filterchain>
<headfilter lines="-1" skip="1"/>
</filterchain>
</move>
<move file="test.properties.tmp" tofile="test.properties"/>
</target>
Output:
$ cat test.properties
one=1
# existing comment
$ ant
Buildfile: C:\tmp\ant\build.xml
test:
[propertyfile] Updating property file: C:\tmp\ant\test.properties
[move] Moving 1 file to C:\tmp\ant
[move] Moving 1 file to C:\tmp\ant
BUILD SUCCESSFUL
Total time: 0 seconds
$ cat test.properties
one=1
# existing comment
key=value

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