Zipping sub folders into separate zip files - maven

I have a directory structure like this:
Parent
|->A
|->B
|->*
and I need to zip it like so:
Dest
|->A.zip
|->B.zip
|->*.zip
Where the * means that I don't know what are the names of the sub-folders.
How can I do this?
I'm working with a maven project but I don't mind using the antrun plugin

Here is another solution that I like since it doesn't require antcontrib:
<target name="zipContentPackage">
<basename property="dir.name" file="${file_name}"/>
<echo message="Zipping folder: ${dir.name}"/>
<zip destfile="${zip_dir}/${dir.name}.zip" basedir="${file_name}"/>
</target>
<target name="-wrapper-zipContentPackage">
<antcall target="zipContentPackage" inheritAll="true">
<param name="file_name" value="${basedir}" />
</antcall>
</target>
<target name="packageContent">
<delete dir="${zip_dir}"/>
<mkdir dir="${zip_dir}"/>
<subant genericantfile="${ant.file}" target="-zipContentPackage" inheritall="true">
<dirset dir="${content_dir}" includes="*" />
</subant>
</target>
Notes:
I used sagioto's code to illustrate
This isn't the most efficient solution

I ended up using foreach of antcontrib
<target name="init">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.compile.classpath"/>
</target>
<target name="packageContent" depends="init">
<delete dir="${zip_dir}"/>
<mkdir dir="${zip_dir}"/>
<foreach target="zipContentPackage" param="file_name">
<path>
<dirset dir="${content_dir}" includes="*"/>
</path>
</foreach>
</target>
<target name="zipContentPackage">
<basename property="dir.name" file="${file_name}"/>
<echo message="Zipping folder: ${dir.name}"/>
<zip destfile="${zip_dir}/${dir.name}.zip" basedir="${file_name}"/>
</target>

Related

Weblogic WsdlcTask for gradle

I am looking for the weblogic.wsee.tools.anttasks.WsdlcTask for gradle. All I could find so far was an example for Ant.
Importing the ant script with ant.importBuild "wsdlc_build.xml" works perfectly fine in my gradle build script, but I would prefer writing the task in gradle. Has someone already found a solution for this?
My ant script:
<project name="WebServices" basedir=".">
<property name="build.wls.home" value="C:\User\wls\"/>
<path id="weblogic.tools.path">
<fileset dir="${build.wls.home}/wlserver/server/lib">
<include name="weblogic.jar" />
</fileset>
</path>
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask" classpathref="weblogic.tools.path"/>
<target name="build_opera">
<wsdlc failOnError="true"
srcWsdl="WebContent/WEB-INF/wsdls/OperaService.wsdl"
destImplDir="src"
destJwsDir="WebContent/WEB-INF/lib"
packageName="server.opera.webservice.service"
verbose="on" debug="on"
type="JAXWS">
</wsdlc>
</target>
<target name="build_nez">
<wsdlc
failOnError="true"
srcWsdl="WebContent/WEB-INF/wsdls/NezService.wsdl"
destImplDir="src"
destJwsDir="WebContent/WEB-INF/lib"
packageName="server.nez.webservice.service"
srcPortName="NezSoapPort"
type="JAXWS">
</wsdlc>
</target>
<target name="build_nezp">
<wsdlc
failOnError="true"
srcWsdl="WebContent/WEB-INF/wsdls/NezpService.wsdl"
destImplDir="src"
destJwsDir="WebContent/WEB-INF/lib"
packageName="server.nezp.webservice.service"
srcPortName="NezPSoapPort"
type="JAXWS">
</wsdlc>
</target>

How to execute the Environment Variables (env.) from Teamcity in Nant script

I am using TeamCity to build the.Net Solution using Nant script and everything works fine if I hard Code the solution path. I want to use Environment Variables from TeamCity (env.) to be used as Solution Path -->env.solution.path----- C:\a\testteamcity\Demo\deptest.sln inside Nant script test.build file:
<?xml version="1.0"?>
<project name ="first Nant file" default="compile-solution" >
<property name="bin.folder.svn" value="C:\a\testteamcity\Demo\bin123"/>
<property name="bin.folder.sln" value="C:\cicheckout\webapp\bin"/>
<target name="compile-solution">
<exec program="C:\Program Files (x86)\MSBuild\12.0\Bin\Msbuild.exe" verbose="true" >
<arg line="${environment::get-variable('env.solution.path')}" />
<arg value="/p:Configuration=Release" />
</exec>
<copy todir="${bin.folder.sln}" overwrite="true" failonerror="true">
<fileset basedir="${bin.folder.svn}">
</fileset>
</copy>
</target>
</project>
Error:Unexpected token 'Punctuation'.
Expression: ${environment::get-variable(‘env.solution.path’)}
Any Help would be great.Thanks
Create system.solution.path --> C:\a\testteamcity\demo\deptest.sln under System Properties (system.) in Teamcity and in Nant script-->
<?xml version="1.0"?>
<project name ="Build-Solution" default="build-solution" >
<property name="solution.path" value="${system.solution.path}" dynamic="true" unless="${property::exists('solution.path')}"/>
<!-- Build solution -->
<target name="build-solution">
<exec program="C:\Program Files (x86)\MSBuild\12.0\Bin\Msbuild.exe" verbose="true" >
<arg line="${solution.path}" />
<arg value="/p:Configuration=Release" />
</exec>
</target>
</project>

Read properties file and substitute the value in template file through Ant script

I have two files local.properties.template and other is test.properties file.
local.properties.tamplate looks like
dir.source=#deploy.dir#/data/source
dir.storage=#deploy.dir#/data/storage
dir.reports=#deploy.dir#/data/reports
dir.scripts=#deploy.dir#/data/scripts
dir.dictionary=#deploy.dir#/data/dictionary
moveit.dir=#moveit.dir#
moveit.enabled=#moveit.enabled#
moveit.host=#moveit.host#
moveit.path=#moveit.path#
moveit.user=#moveit.user#
moveit.pass=#moveit.pass#
moveit.root=#moveit.root#
moveit.url=#moveit.url#
and test.properties looks like
moveit.dir=D:\\data\\moveit
moveit.enabled=false
moveit.host=thmdsdev0.tsh.tho.com
moveit.path=/moveitdmz
moveit.user=muttt
moveit.pass=ssss
moveit.root=/Home/MeaningfulUse
moveit.url=https://thmdsdev00.tsh.tho.com/moveitdmz
I want through ant to read the value from test.properties for e.g moveit.user and paste it or add in the local.properties.template in place of #moveit.user# and same for all variables.Then I will change the name of local.properties.template file to local.properties and move it other folder
If I understand your question right, you can use Filter Chain and Replace Tokens to achieve this effect. For example:
<copy file="${PROP.your.path}/local.properties.template"
tofile="${PROP.your.path.destination}/local.properties"
overwrite="true">
<filterchain>
<replacetokens>
<token key="#moveit.dir#" value="${moveit.dir}"/>
<token key="#moveit.dir2#" value="${moveit.dir2}"/>
</replacetokens>
</filterchain>
</copy>
I created the ant script in below manner and it is working fine.
<project name="replace_and_copy" basedir="." default="usage">
<!--taskdef resource="net/sf/antcontrib/antcontrib.properties"/-->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<macrodef name="copy-and-filter">
<sequential>
<copy tofile="local_for_test_copy.properties" file="templates/local.properties.test.template" overwrite="true">
<filterset recurse="true">
<filtersfile file="Properties/${deploy.env}/local_for_${deploy.env}.properties"/>
</filterset>
</copy>
</sequential>
</macrodef>
<target name="env.copy.local.props">
<copy-and-filter />
<for param="host" list="${deploy.host}">
<sequential>
<copy todir="\\#{host}\${deploy.path}\conf\"
file="local_for_test_copy.properties"
overwrite="true"/>
</sequential>
</for>
</target>
</project>

Exclude file types in teamcity artifacts

I'm just about to setup teamcity for the first time on my own. Very nice and simple in most ways I have to say. However, I have one issue that I haven't manage to solve and find any information about.
When I wanna publish my artifacts I want to exclude some file types.
example:
%system.agent.work.dir%\trunk\Source\Projects\Webproject.Web/Controllers => Webproject.Web/Controllers
However, I don't want to copy all the .cs files in the folder. I just need the folder.
Is it possible to copy just the folder and not the content, and then copy what ever content I need? Or can I exclude files if I copy a directory?
You can add a MSBUILD target which prepares the "deployment" package for you. I have the following (may need some changes for your project):
<Target Name="Publish" DependsOnTargets="Build" Condition="'$(WebProjectOutputDir)'!=''">
<RemoveDir Directories="$(WebProjectOutputDir)" ContinueOnError="true" />
<!-- Log tasks -->
<Message Text="Publishing web application for $(MSBuildProjectName)" />
<Message Text="WebProjectOutputDir: $(WebProjectOutputDir)" />
<!-- Create the _PublishedWebsites\app\bin folder -->
<MakeDir Directories="$(WebProjectOutputDir)\bin" />
<!-- Copy build outputs to _PublishedWebsites\app\bin folder -->
<Copy SourceFiles="#(IntermediateAssembly)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(AddModules)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(IntermediateOutputPath)$(_SGenDllName)" DestinationFolder="$(WebProjectOutputDir)\%(Content.SubFolder)%(Content.RecursiveDir)" SkipUnchangedFiles="true" Condition="'$(_SGenDllCreated)'=='true'" />
<Copy SourceFiles="$(IntermediateOutputPath)$(TargetName).pdb" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true'" />
<Copy SourceFiles="#(DocFileItem)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DocumentationFileProduced)'=='true'" />
<Copy SourceFiles="#(IntermediateSatelliteAssembliesWithTargetPath)" DestinationFiles="#(IntermediateSatelliteAssembliesWithTargetPath->'$(WebProjectOutputDir)\bin\%(Culture)\$(TargetName).resources.dll')" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(ReferenceComWrappersToCopyLocal); #(ResolvedIsolatedComModules); #(_DeploymentLooseManifestFile); #(NativeReferenceFile)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<!-- copy any referenced assemblies to _PublishedWebsites\app\bin folder -->
<Copy SourceFiles="#(ReferenceCopyLocalPaths)" DestinationFiles="#(ReferenceCopyLocalPaths->'$(WebProjectOutputDir)\bin\%(DestinationSubDirectory)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<!-- Copy content files recursively to _PublishedWebsites\app\ folder -->
<Copy SourceFiles="#(Content)" DestinationFolder="$(WebProjectOutputDir)\%(Content.RelativeDir)" />
<!-- Copy items that have been marked to be copied to the bin folder -->
<Copy SourceFiles="#(_SourceItemsToCopyToOutputDirectory)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(_SourceItemsToCopyToOutputDirectoryAlways)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="false" />
</Target>
So, in the TC build, I use the MSBUILD builder like this:
Targets: Rebuild;Publish
Command line parameters: /p:WebProjectOutputDir="%system.teamcity.build.workingDir%\Website"
You can then use the Website directory as your artifact.

In an ANT build.xml file, how can I iterate over the items in the ${env} variable?

This is in a Windows XP environment.
I'm trying to install and edit some files that have default settings. I want to update these settings use items from ${env}
Using foreach from ant-contrib, you could iterate over ${env} like:
<target name="run">
<foreach item="String" in="${env.CLASSPATH}" delim=";" property="x">
<echo message="${x}" />
</foreach>
</target>
I was able to do this with NAnt:
<target name="run">
<foreach item="String" in="${environment::get-variable('CLASSPATH')}" delim=";" property="x">
<echo message="${x}" />
</foreach>
</target>

Resources