I want to update the content of a file from my local folder to svn, note that the file exists on svn.
first I am checking out with depth empty.
then I run update on the script
<svn refid="svn.settings" logFile="${directory}/checkout_log.log">
<checkout url="${svn_path}"
destpath="${full_path}"
revision="HEAD" depth="empty"
/>
<update recurse="false" revision="HEAD" dir="D:\Update\SVNCheckout\T\" file= "test.sql" />
</svn>
however In the log file its sayes
Skipped 'test.sql'
Summary of conflicts:
Skipped paths: 1
<Update> finished.
ok I understand there is conflict , however how I can svn resolve the script
To avoid conflicts it is better to first check out, then modify the checked out file and then try to check it in. If this fails, then remove all temporary files and try it again.
The overall procedure looks like this (using Ant Contrib as an extension to plain Ant):
<var name="finished" value="false" />
<for list="1,2,3,4,5,5,6,7,8,9,10" param="trynr">
<sequential>
<if>
<equals arg1="${finished}" arg2="false" />
<then>
<echo message="#########################################" />
<echo message="# trynr=#{trynr}" />
<echo message="#########################################" />
<trycatch property="errormsg" reference="exceptionObject">
<try>
<!-- Delete old checked out files -->
<delete .../>
<!-- Check out the file -->
<!-- Modify the file -->
<!-- Commit the file -->
<var name="finished" value="true" />
</try>
<catch>
<echo message="Update failed." />
<echo message="Error message: ${errormsg}" />
<if>
<equals arg1="#{trynr}" arg2="10" />
<then>
<echo message="Giving up after #{trynr} attempts." />
<fail message="Unable to update file. Giving up after #{trynr} attempts." />
</then>
<else>
<echo message="Trying again in 2 seconds ..." />
<sleep seconds="2"/>
</else>
</if>
</catch>
</trycatch>
</then>
<else />
</if>
</sequential>
</for>
Related
I am currently using a ruby gem SASS in order to convert my *.scss files to *.css files on a large project. Here is a mockup of the code I am using:
<?xml version="1.0"?>
<!-- scss to CSS -->
<project name="StackOverflowScssCss" default="sass-compile-to-css" basedir=".">
<property file="build.properties" />
<target name="sass-compile-to-css">
<echo message="Compiling scss files to css..." />
<!-- create the css destination dir if it doesn't already exist -->
<property name="css-dest" location="${css.dir}" />
<echo message="Creating directory at ${css.dir} [if it doesn't yet exist]" />
<mkdir dir="${css-dest}" />
<!-- create subdirs if necessary -->
<echo message="Creating css directories (and temporary .css files) for .scss to be compiled..." />
<touch mkdirs="true">
<fileset dir="${sass.dir}" includes="**/*.scss" excludes="**/_*" />
<mapper type="glob" from="*.scss" to="${css.dir}/*.css" />
</touch>
<echo message="Running sass executable against sass files and compiling to CSS directory [${css-dest}] " />
<!-- run sass executable -->
<apply executable="sass" dest="${css-dest}" verbose="true" force="true" failonerror="true">
<arg value="--unix-newlines" />
<!-- Disable creation of map file. THIS SHOULD BE A FLAG -->
<arg value="--sourcemap=none" />
<srcfile />
<targetfile />
<fileset dir="${sass.dir}" includes="**/*.scss" excludes="**/_*" />
<mapper type="glob" from="*.scss" to="*.css" />
</apply>
<echo message="Done compiling scss files!" />
</target>
</project>
Ultimately I want to remove the ruby dependency so I have been looking at this libsass maven plugin. I know that there are many options for libsass but I am trying to stick strictly to Java. Does anyone have any experience with doing this? I don't want to run Node.js, Sass.js ot anything, and I have racked my brain all day on how to do this. Any help is much appreciated!
There is a Java wrapper that can be used with Maven.
If you really want to stick with Java you could either
Use that wrapper and run the mvn task from inside your ant script (see here)
Adapt that wrapper and build your own Ant Task out of it
I ended up using a JRuby dependency in order to run on the JVM. My code is as follows:
<!-- Jruby Dependent SCSS to CSS conversion -->
<path id="JRuby">
<fileset file="packages/jruby-complete-1.7.20.1.jar"/> <!-- Location of JRuby jar file -->
</path>
<target name="compileSass" depends="cleanSass">
<echo message="Compiling scss files..." />
<!-- JRuby Script to convert files into new directory -->
<property name="filesIn" value="${dir.scss}/**/[^_]*.scss" />
<property name="projectDirectory" value="${user.dir}"/>
<script language="ruby" classpathref="JRuby">
<![CDATA[
require ($project.getProperty('projectDirectory')) + '/packages/sass-3.4.14/lib/sass'
require ($project.getProperty('projectDirectory')) + '/packages/sass-3.4.14/lib/sass/exec'
files = Dir.glob($project.getProperty('filesIn'))
files.each do
| file |
newOutDir = File.dirname(file).sub! 'scss', 'css'
FileUtils::mkdir_p newOutDir
puts "[sass compiler] From:" + file
puts "[sass compiler] To:" + newOutDir + "/" + File.basename(file, ".*") + ".css"
opts = Sass::Exec::SassScss.new(["--load-path", File.dirname(file), file, File.join(newOutDir, File.basename(file, ".*") + ".css")], 'scss')
opts.parse
end
]]>
</script>
<echo message="Done compiling scss files!" />
</target>
<target name="cleanSass">
<echo message="removing .css files..." />
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${dir.css}" includes="**/*.css" />
</delete>
<echo message="removing .css.map files..." />
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${dir.css}" includes="**/*.css.map" />
</delete>
</target>
I am trying to build my project. Here is my build.xml
<?xml version="1.0"?>
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="WMCOMMONINFRASTRUCTURE-WMINFRASTRUCTURE" default="dist">
<import file="../build.xml" />
<property file="../../build.properties" />
<!-- ===================================================================
- init - initialization for this submodule
- ==================================================================== -->
<target name="init" depends="module-init">
<!-- Submodule properties -->
<property name="submodule.name" value="wminfra" />
<property name="dist.jar.name" value="wminfra-${version}.jar" />
<property name="dist.jar" value="${root.dist.dir}/${dist.jar.name}" />
<!-- Submodule paths -->
<path id="submodule.path">
<path refid="common.path" />
</path>
<path id="test.path">
<path refid="submodule.path" />
<path refid="test.root.path" />
</path>
</target>
<target name="prepare" depends="init">
<mkdir dir="${root.build.dir}" />
<mkdir dir="${root.dist.dir}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${test-classes.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${api.dir}" />
<mkdir dir="${test.docs.dir}" />
<!--<ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[revision].[ext]" sync="true"/>-->
<ivy:retrieve sync="true"/>
</target>
<!-- ===================================================================
- clean - clean all build remnants from this submodule
- ==================================================================== -->
<target name="clean" depends="init">
<echo message="cleaning ${module.name}-${submodule.name}" />
<delete file="${warArtifacts.dir}/${dist.jar.name}" />
<delete file="${earArtifacts.dir}/${dist.jar.name}" />
<delete file="${dist.jar}" />
<delete dir="${build.dir}" />
</target>
<!-- ===================================================================
- checkstyle - ensures all non-generated code meets the company
-
- =================================================================== -->
<target name="checkstyle" depends="init">
<echo message="verifying code adheres to coding standards..." />
<!-- doesn't do anything yet -->
</target>
<!-- ===================================================================
- compile - compile Java source files
- =================================================================== -->
<target name="compile" depends="checkstyle,compile-sources" />
<!-- ===================================================================
- dist - create distribution jars (which will be used for deployment)
- =================================================================== -->
<target name="dist" depends="compile">
<jar jarfile="${dist.jar}">
<fileset dir="${classes.dir}">
<include name="**/*.class" />
</fileset>
<fileset dir="${resources.dir}">
<include name="**/*.*" />
</fileset>
</jar>
<!-- we want the dist jar in the ear file, so copy it over to the
ear staging directory: -->
<copy toDir="${earArtifacts.dir}" file="${dist.jar}" />
<!-- we also want it available to the web application: -->
<copy toDir="${warArtifacts.dir}" file="${dist.jar}" />
<ivy:publish resolver="local" pubrevision="${version}" status="integration" forcedeliver="true" overwrite="true"/>
<echo message="project ${ant.project.name} published locally with version ${version}" />
<delete file="${root.dist.dir}/${dist.jar.name}"/>
</target>
<!-- ===================================================================
- deploy - recreates the platform ear file with only the changes made
- in this submodule, and then deploys this newly created ear
- file, replacing any old one that existed previously.
- =================================================================== -->
<target name="deploy" depends="dist,undeploy,quick-deploy" />
<!-- ===================================================================
- all - everything
- =================================================================== -->
<target name="all" depends="deploy" />
</project>
The above written
<ivy:publish resolver="local" pubrevision="${version}" status="integration" forcedeliver="true" overwrite="true"/>
line gives the error.
My build.properties file is as follows:
project.name=FCPBMain\12.0.1
delta.name=DELTA
root.base.dir=C:/CORE_DELTA/${project.name}
settings.localRepository=C:/FCPBRepository/12.0.1
tomcat.local=D:/apache-tomcat-6.0.35
version=12.0.1
root.artifact.dir=${root.base.dir}
root.src.dir=.
#ivy properties
ivy.user.dir=C:/WmIvyRepository/12.0.1
#ivy shared repository properties
ivy.shared.dir=\\\\iflblw-wm-21/WMIvyRepository/cache
#ivy shared repository ivy.xml retrieve pattern
ivy.shared.ivy.pattern=[organisation]/[module]/ivy-[revision].xml
#ivy shared repository artifact retrieve pattern
ivy.shared.artifact.pattern=[organisation]/[module]/[type]s/[artifact].[ext]
#Added by MP for more deployment options
#Choose the target server
deploy.tomcat=true
deploy.weblogic=false
deploy.weblogic92=false
deploy.websphere=false
#Choose the ear file creation option
deploy.bankonly=false
deploy.custonly=false
deploy.both=true
#True if to be build without integration with core banking
#False when integratiion is done
fcpbkernelserviceadaptor.build=true
#MP: choose the options for customer login sso options
customerlogin.sso=false
I have done the following things:
set ant options as
set ANT_OPTS=-Xmx1024m -XX:MaxPermSize=512m
set path in environment variables as
C:\Program Files\Java\jdk1.6.0_13;C:\Program Files\Java\jdk1.6.0_13\jre\bin;D:\product\11.2.0\dbhome_1\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;D:\Ant1.7.1\bin;
set ANT_home as environment variable.
When the above xml file is tried to be built, the following directory structure is created successfully C:\CORE_DELTA\FCPBMain12.0.1\build\dist.
In this dist folder earArtifacts, warArtifacts, ivy-12.0.1.xml and wminfra-12.0.1.jar is created. Out of which, the ivy.xml file is always of 0KB, it's empty.
Guess, the problem is in \1 part of project.name property value - it is interpreted as an escape sequence. In my case, same error was caused by non-ASCII symbol ≤ in comment.
Is there a way to include or exclude certain files based on a condition in Apache Ant (1.8.3)? For instance, I have a macrodef that takes an attribute. I would like to include certain files if the attribute's value matches xyz:
<macrodef name="pkgmacro">
<attribute name="myattr" />
<sequential>
<zip destfile="${dist}/#{myattr}.war">
<fileset dir="${dist}/webapp" >
<include name="**/#{myattr}/**" />
<exclude name="WEB-INF/config/**" />
<!-- if #{myattr} = "xyz", then
<include name="PATH/TO/file.xml" />
-->
</fileset>
<zipfileset dir="${ear}/#{myattr}/WEB-INF/" includes="*.xml" prefix="WEB-INF/" />
</zip>
</sequential>
</macrodef>
For instance, if myattr value is xyz, I would like to include the commented file in portion above.
Fileset can use nested include/exlucde patternsets with if/unless
Attribute. The pattern is included/excluded when a named property is set or not, so no ant addons needed.Some snippet :
<project>
<!-- property that triggers your include/exclude
maybe set via condition in some other target .. -->
<property name="foo" value="bar"/>
<macrodef name="pkgmacro">
<attribute name="myattr" />
<sequential>
<fileset dir="C:/whatever" id="foobar">
<!-- alternatively
<include name="*.bat" unless="#{myattr}"/>
-->
<include name="*.bat" if="#{myattr}"/>
</fileset>
<!-- print fileset contents -->
<echo>${toString:foobar}</echo>
</sequential>
</macrodef>
<pkgmacro myattr="foo"/>
</project>
--EDIT after comment --
The if/unless attribute after include name/exclude name checks whether the given value is a property which is set (when using if="..") or not set (when using unless="..") in the ant project scope - it doesn't check for a specific value.
<include name="*.xml" unless="foo"/>
means include is only active if no property named foo is set in your project
<include name="*.xml" if="foo"/>
means include is only active if property named foo is set in your project
Works fine for me , used Ant 1.7.1, had no Ant 1.8.x around right now :
<project>
<echo>$${ant.version} => ${ant.version}</echo>
<macrodef name="pkgmacro">
<attribute name="myattr"/>
<sequential>
<condition property="pass">
<equals arg1="#{myattr}" arg2="xyz" />
</condition>
<fileset dir="C:/whatever" id="foobar">
<include name="*.bat" if="pass" />
</fileset>
<echo>${toString:foobar}</echo>
</sequential>
</macrodef>
<pkgmacro myattr="xyz"/>
</project>
output :
[echo] ${ant.version} => Apache Ant version 1.7.1 compiled on June 27 2008
[echo] switchant.bat;foobar.bat;foo.bat
-- EDIT after comment --
Using serveral include patterns works fine :
...
<fileset dir="C:/whatever" id="foobar">
<include name="*.xml" if="pass" />
<include name="*.bat" if="pass"/>
<include name="**/*.txt" if="pass"/>
</fileset>
...
maybe you're using the wrong patterns ?
-- EDIT after comment --
Here is the reference to <local> task which is needed to work with the properties in the current scope, in this case, <sequential>:
<macrodef name="pkgmacro">
<attribute name="myattr"/>
<sequential>
<!-- make property pass mutable -->
<local name="pass"/>
<condition property="pass">
<equals arg1="#{myattr}" arg2="xyz" />
</condition>
<fileset dir="C:/whatever" id="foobar">
<include name="*.xml" if="pass" />
<include name="*.bat" if="pass" />
<include name="**/*.txt" if="pass" />
</fileset>
<!-- print value of property pass and fileset contents -->
<echo>$${pass} = ${pass}${line.separator}${toString:foobar}</echo>
</sequential>
</macrodef>
if you can use ant-contrib, then try this:
<contrib:if>
<equals arg1="${myattr}" arg2="xyz" />
<then>
<include name="PATH/TO/file.xml" />
</then>
</contrib:if>
if you can't use ant-contrib, try this:
http://jaysonlorenzen.wordpress.com/2010/03/10/apache-ant-if-else-condition-without-ant-contrib/
I have a default log4j properties file to which I want to append an application specific configuration. The file is contained (with other files) within a .zip file. I use Ant to unzip the contents of the zip (including the log4j properties). I want to append the line when the unzip happens. Is this possible?
<unzip dest="some.dest">
<fileset refid="some.fileset" />
<!-- Append a line to 'log4j.properties` file -->
</unzip>
Maybe the solution is just to echo after I've unzipped.
You can use the Ant "echo" task with the "append" flag:
<echo file="log4j.properties" append="true">${line.separator}</echo>
Echo task doc here for further reference:
http://ant.apache.org/manual/Tasks/echo.html
No need to unzip the whole zipfile, use
if log4j.properties resides in rootdirectory of zip :
<project>
<!-- unzip log4j.properties only -->
<unzip src="foo.zip" dest=".">
<patternset>
<include name="log4j.properties" />
</patternset>
</unzip>
<!-- put new key in or overwrite if already existing -->
<propertyfile file="log4j.properties">
<entry key="log4j.logger.com.foobar.xyz" value="ERROR" />
</propertyfile>
<!-- update zip with modified log4j.properties -->
<zip destfile="foo.zip" update="true">
<fileset dir="." includes="log4j.properties" />
</zip>
</project>
else if log4j.properties resides in any subfolder of zip :
<project>
<!-- unzip log4j.properties only -->
<unzip src="foo.zip" dest=".">
<patternset>
<include name="**/log4j.properties" />
</patternset>
</unzip>
<fileset dir="." includes="**/log4j.properties" id="foo"/>
<!-- put new key in or overwrite if already existing -->
<propertyfile file="${toString:foo}">
<entry key="log4j.logger.com.foobar.xyz" value="ERROR" />
</propertyfile>
<!-- update zip with modified log4j.properties -->
<zip destfile="foo.zip" update="true">
<fileset dir="." includes="${toString:foo}" />
</zip>
</project>
I want to sign two dozen jar files using jarsigner, giving the password only once.
Giving multiple files to jarsigner is not possible, according to the man page and using a for-loop on the command line still forces me to input the password for every file.
I would prefer a solution for the command line, but would be okay with ant/maven solution.
System is Linux.
How do I sign a dozen jar-files, giving the password only once?
Here is a snippet from the Ant build file for PSCode - it signs a slew of Jars. The trick is in the foreach element.
<target name="createjars"
depends="compile"
description="Jars the compiled classes">
<mkdir dir="${build}/jar/" />
<foreach target="jar.package" param="package" inheritall="true">
<path>
<dirset dir="${src}/java/org/pscode" includes="**/*" />
</path>
</foreach>
</target>
..and..
<target name='jar.package'>
<script language='javascript'>
<![CDATA[
prop = pscode.getProperty('package');
index1 = prop.lastIndexOf('pscode') + 7;
index2 = prop.length();
prop1 = prop;
path = prop1.substring( index1, index2 );
path2 = path.replaceAll('\\\\','/');
pscode.setProperty('path', path2 );
name = path2.replaceAll('/','.');
pscode.setProperty('jar.name', name + '.jar' );
]]>
</script>
<xmlproperty file="${src}/java/org/pscode/${path}/manifest.xml" />
<!-- echo message='jar.name: ${jar.name} *** ${application.title}' / -->
<if>
<not>
<uptodate targetfile='${build}/dist/lib/${jar.name}' >
<srcfiles dir= '${build}/share/org/pscode/${path}' includes='*.class'/>
</uptodate>
</not>
<then>
<jar
destfile='${build}/dist/lib/${jar.name}'
index='true'
update='true'>
<manifest>
<attribute name="Implementation-Title" value="${application.title}" />
<attribute name="Implementation-Vendor" value="${vendor}" />
<attribute name="Implementation-Vendor-Id" value="org.pscode" />
<attribute name='Implementation-Version' value='${now}' />
</manifest>
<fileset dir='${build}/share'>
<include name='org/pscode/${path}/*.class' />
</fileset>
<fileset dir='${src}/java'>
<include name='org/pscode/${path}/*.png' />
<include name='org/pscode/${path}/*.jpg' />
<include name='org/pscode/${path}/*.gif' />
<include name='org/pscode/${path}/*.xml' />
<include name='org/pscode/${path}/*.html' />
<include name='org/pscode/${path}/*.ser' />
</fileset>
</jar>
</then>
</if>
<!-- If the Jar is updated, any previous signatures will be invalid, it
needs to be signed again. We cannot use the issigned condition since
that merely checks if a Jar is signed, not if the digital signatures are
valid. -->
<exec
executable='${jar.signer}'
resultproperty='jar.signer.result.property'
outputproperty='jar.signer.output.property'>
<arg value='-verify' />
<arg value='${build}/dist/lib/${jar.name}' />
</exec>
<if>
<or>
<not>
<equals arg1='${jar.signer.result.property}' arg2='0' />
</not>
<or>
<contains
string='${jar.signer.output.property}'
substring='unsigned'
casesensitive='false' />
<or>
<contains
string='${jar.signer.output.property}'
substring='SecurityException'
casesensitive='false' />
</or>
</or>
</or>
<then>
<signjar
jar='${build}/dist/lib/${jar.name}'
alias='pscode'
storepass='${sign.password}'
force='true'
verbose='${verbose}'
keystore='${user.home}/${sign.pathfilename}' />
</then>
</if>
</target>
Just for the records: jarsigner is able to read the keystore and key passwords from a file or from an environment variable, using the -keypass / -storepass command line option together with the :file or the :env modifier.
So, it's possible to put each of the passwords in a file (in my example: ~/.storepass and ~/.keypass) and use a for loop like this to sign all jars in the current directory using the key key_alias:
for i in ./*.jar; do jarsigner -storepass:file ~/.storepass -keypass:file ~/.keypass "$i" key_alias;done
To make jarsigner read the passwords from an env variable, you'll have to create those variables first:
export storepass="mystorepassword"
export keypass="mykeypassword"
Now, the loop would look like:
for i in ./*.jar; do jarsigner -storepass:env storepass -keypass:env keypass jarfile.jar key_alias;done