How to clear subdirectories without removing them in NAnt?
As the result of script execution, I need a directory with the same subdirectories, but empty:
<delete>
<fileset basedir="\\${conf.server.frontend}\wwwroot">
<include name="???" />
</fileset>
</delete>
This is what you need:
<delete>
<fileset basedir="\\${conf.server.frontend}\wwwroot">
<include name="**\*" />
</fileset>
</delete>
Related
Build.xml
<project name="DikshaPortal" default="dist" basedir=".">
<description>Build file for Portalv2.0 project</description>
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="conf" location="src/conf" />
<property name="build" location="${BUILD_TARGET}/Portal" />
<property name="GUI" location="../GUI" />
<property name="dist" location="${BUILD_EXPORT}/Portal" />
<property name="BaseDir" location="../DikshaPortal-Release-2013-12-12" />
<property name="UIBaseDir" location="../Portalv2.0_FlexCompileFiles" />
<property name="history" location="${UIBaseDir}/history" />
<property name="META-INF" location="WebContent/META-INF" />
<property name="com" location="${UIBaseDir}/com" />
<property name="pages" location="${UIBaseDir}/pages" />
<property name="WEB-INF" location="WebContent/WEB-INF" />
<property name="data" location="WebContent/data" />
<property name="temp" location="WebContent/temp" />
<property name="policies" location="WebContent/assets/images/Policies" />
<property name="TPL" value="${LIBRARIES}/ThirdParty" />
<property name="apache" value="${TPL}/apache_libs" />
<path id="classpath">
<fileset dir="${TPL}" includes="*.jar" />
<fileset dir="${apache}" includes="**/*.jar" />
<fileset dir="${WEB-INF}" includes="**/*.jar" />
</path>
<target name="clean" description="Removes the temporary directories used">
<delete dir="${GUI}" />
<delete dir="${build}" />
</target>
<target name="init" depends="clean">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${dist}" />
<mkdir dir="${GUI}" />
<mkdir dir="${data}" />
<mkdir dir="${temp}" />
</target>
<target name="compile" depends="init" description="Compile the source code">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" classpathref="classpath" />
</target>
<target name="dist" depends="compile" description="generate the distribution">
<copy todir="${GUI}">
<fileset dir="${UIBaseDir}" includes="*.js,*.html,*.swf,*.jsp,favicon.png,favicon.ico" />
</copy>
<mkdir dir="${GUI}/assets/images/Policies" />
<copy todir="${GUI}/assets/images/Policies">
<fileset dir="${policies}" includes="*.*" />
</copy>
<mkdir dir="${GUI}/data" />
<copy todir="${GUI}/data">
<fileset dir="${data}" includes="**" />
</copy>
<mkdir dir="${GUI}/temp" />
<copy todir="${GUI}/temp">
<fileset dir="${temp}" includes="*.*" />
</copy>
<mkdir dir="${GUI}/history" />
<copy todir="${GUI}/history">
<fileset dir="${history}" includes="*.*" />
</copy>
<mkdir dir="${GUI}/com" />
<copy todir="${GUI}/com">
<fileset dir="${com}" includes="**" />
</copy>
<mkdir dir="${GUI}/pages" />
<copy todir="${GUI}/pages">
<fileset dir="${pages}" includes="**" />
</copy>
<mkdir dir="${GUI}/WEB-INF/flex" />
<copy todir="${GUI}/WEB-INF/flex">
<fileset dir="${WEB-INF}/flex" includes="*.*">
</fileset>
</copy>
<mkdir dir="${GUI}/WEB-INF/pages" />
<copy todir="${GUI}/WEB-INF/pages">
<fileset dir="${WEB-INF}/pages" includes="*.*">
</fileset>
</copy>
<mkdir dir="${dist}/conf" />
<copy todir="${dist}/conf">
<fileset dir="${BaseDir}/conf" includes="email.properties, Portal.properties" />
</copy>
<copy todir="${dist}">
<fileset dir="${BaseDir}/conf" includes="readme.txt" />
</copy>
<mkdir dir="${dist}/email/templates" />
<copy todir="${dist}/email/templates">
<fileset dir="${BaseDir}/email/templates" includes="*.*" />
</copy>
<mkdir dir="${dist}/jasper" />
<copy todir="${dist}/jasper">
<fileset dir="${BaseDir}/jasper" includes="*.*" />
</copy>
<mkdir dir="${dist}/conf" />
<copy todir="${dist}">
<fileset dir="${BaseDir}/db_scripts" includes="*.*" />
</copy>
<mkdir dir="${dist}/jars" />
<copy todir="${dist}/jars">
<fileset dir="${TPL}" includes="*.*" />
</copy>
<copy todir="${build}" file="src/MessageResources.properties">
</copy>
<!--
Put everything in ${build} into the MyProject-${DSTAMP}.war file
-->
<war destfile="${dist}/DikshaPortalv2.0.war" webxml="${WEB-INF}/web.xml" basedir="${GUI}">
<classes dir="${build}" />
<lib dir="${WEB-INF}/lib" />
<webinf dir="${WEB-INF}" includes="*.xml" excludes="web.xml" />
<fileset dir="${META-INF}" />
</war>
<copy todir="${build}">
<fileset dir="${dist}" includes="*.war" />
</copy>
<delete dir="${GUI}" />
<delete dir="${build}" />
</target>
Iam completely new to gradle, I was told to migrate the existing ant
script into gradle at my company. Somebody please help me on How to
convert the above given ant script into gradle.
Iam completely new to gradle, I was told to migrate the existing ant
script into gradle at my company. Somebody please help me on How to
convert the above given ant script into gradle.
I would start with a very basic build.gradle file in your root directory of the DikshaPortal project, run gradle build from the terminal or command line and see what happens. Do you understand your dependencies for this project? If so, then you can add that block into your gradle script.
apply plugin: 'war'
dependencies {
//enter your dependenices here such as
compile group: 'com.junit' name: 'junit' version: '4.12'
}
This is a start. Gradle docs are decent so I'd start to acquaint yourself with them. I just completed a decent size project converting Ant to Gradle in my first job as a developer and it took a while! Run a gradle build to check for errors. Even when it's successful check your war (or any generated artifact) against the Ant and keep on going. Hope that helps.
https://gradle.org/guides/
https://github.com/shekhargulati/gradle-tips
http://dougborg.org/what-makes-a-good-build-dot-gradle
https://docs.gradle.org/3.3/dsl/ You can change the version to whichever you are using.
Not an exact answer but a possible alternative solution.
I dont believe that there is a conversion tool for ant to gradle, but you can just import your ant file into gradle and run it from there.
Here is how to do it:
https://docs.gradle.org/current/userguide/ant.html?_ga=2.102231682.2042183466.1518506088-863573233.1518506088#sec:import_ant_build
Seems more viable than trying to rewrite the whole script to gradle.
build.gradle file
ant.importBuild 'build.xml'
I'm trying to create an application über jar, but running into an issue due to a dependency on the spring framework. In particular, the namespaces for the xml schemas are problematic. You get the infamous NamespaceHandler problem:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/c]
For creating (simple) uber jars, Creating a bundle jar with ant, but this doesn't work if you have spring dependencies due to the fact that the spring jars have files such as spring.handlers, spring.schemas and spring.tooling in the META-INF directories of many of their jar files. The namespace resolution is dependent, I believe, on these files.
The über jar seems to somehow contain all necessary files, but I'm guessing the runtime is seeing only one.
For example, a jar -tf of my uber jar shows (in part)
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.factories
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt
META-INF/notice.txt
META-INF/spring.handlers
META-INF/spring.schemas
META-INF/spring.tooling
META-INF/license.txt
META-INF/notice.txt
META-INF/license.txt
So: question.. is there a way to create an uber-jar that has the spring jars bundled inside? Do I need to merge the META-INF files? Anyone have experience doing file merger with ant builds?
Well.. this was a pain.
<target name="make-bundle" depends="jar">
<!-- retrieve the dependencies -->
<ivy:retrieve conf="deploy" pattern="${dist.dir}/dependencies/[artifact].[ext]"/>
<delete dir="${dist.dir}/dependencies/uber" failonerror="false" />
<mkdir dir="${dist.dir}/dependencies/uber"/>
<!-- iterate over the dependencies -->
<for param="file">
<path>
<fileset dir="${dist.dir}/dependencies">
<include name="**/*.jar"/>
</fileset>
</path>
<sequential>
<propertyregex override="yes"
property="jarname" input="#{file}"
regexp=".*/([^/]*)\.jar" replace="\1"/>
<!-- put the spring.* jars into special sub-directories -->
<mkdir dir="${dist.dir}/dependencies/${jarname}"/>
<unzip dest="${dist.dir}/dependencies/${jarname}" src="#{file}">
<patternset>
<include name="**/META-INF/spring.*"/>
</patternset>
</unzip>
<!-- put everything else in the 'uber' directory -->
<unzip dest="${dist.dir}/dependencies/uber" src="#{file}">
<patternset>
<exclude name="**/META-INF/spring.*"/>
</patternset>
</unzip>
</sequential>
</for>
<!-- build the concatenated spring.* files -->
<mkdir dir="${dist.dir}/dependencies/META-INF"/>
<concat destfile="${dist.dir}/dependencies/META-INF/spring.handlers" fixlastline="true">
<fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.handlers"/>
</concat>
<concat destfile="${dist.dir}/dependencies/META-INF/spring.schemas" fixlastline="true">
<fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.schemas"/>
</concat>
<concat destfile="${dist.dir}/dependencies/META-INF/spring.tooling" fixlastline="true">
<fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.tooling"/>
</concat>
<concat destfile="${dist.dir}/dependencies/META-INF/spring.factories" fixlastline="true">
<fileset dir="${dist.dir}/dependencies/" includes="*/*/spring.factories"/>
</concat>
<!-- build the uber jar! -->
<delete file="${dist.dir}/myproject-with-dependencies.jar" failonerror="false"/>
<jar destfile="${dist.dir}/myproject-with-dependencies.jar">
<!-- all dependency files except spring.* -->
<fileset dir="${dist.dir}/dependencies/uber"/>
<!-- the spring.* files -->
<fileset dir="${dist.dir}/dependencies/" includes="META-INF/*"/>
<!-- my project's classes & etc -->
<zipgroupfileset dir="${dist.dir}" includes="myproject.jar" />
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
It's easy to use org.apache.maven.plugins:maven-antrun-plugin to copy resources and rename them but is there a way to do this intelligently with wildcards or other mecanisms to conform personnal rules ?
For example if I have those files :
${project.artifactId}-${project.version}.swf
a.swf
b.swf
...
z.swf
I would like to copy all those files inside directory and rename only ${project.artifactId}-${project.version}.swf to foo.swf. I know I can use :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy-swf-files</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="copy swf files to web project">
<copy file="${project.build.directory}/${project.artifactId}-${project.version}.swf" tofile="${swf.output.location}/foo.swf" />
<copy file="${project.build.directory}/a.swf" tofile="${swf.output.location}/a.swf" />
<copy file="${project.build.directory}/z.swf" tofile="${swf.output.location}/z.swf" />
</target>
</configuration>
</execution>
</executions>
</plugin>
it's work but is there another convenient way to do that because if I have 1000 files to copy, it will be very boring...Thanks
Do you know Ant? All the Maven Ant plugin is doing is calling Ant with the tasks you list. You can do any Ant task including <taskdef>, etc.
What it looks like you're doing can be done with fileset:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="*.swf"/>
</fileset>
</copy>
This will copy all *.swf files located directly under in the ${project.build.directory} (and no subdirectories) to the ${swf.output.location} directory. If you want to copy the entire directory tree of *.swf files, just change the <include>:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="**/*.swf"/> <!--NOTE DIFFERENCE HERE-->
</fileset>
</copy>
If you need to munge the file names, you can use Mappers. The simplest mapper would be the flatten mapper:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="**/*.swf"/> <!--NOTE DIFFERENCE HERE-->
</fileset>
<mapper type="flatten"/>
</copy>
This will copy the entire directory tree and flatten all the files into a single directory. There are mappers that can match globs, regular expressions, and even scripting.
The <include> is a selector and not a mapper because it selects what files you want to act upon. These too can be quite complex, and you can match file based upon their names iva regular expressions, or even their contents.
I'm surprised there isn't a Maven plugin that allows you to do this.
Ok I finally used this plugin to do this :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy-swf-files</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="copy swf files to web project">
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}" includes="*.swf">
<filename regex="^sim-flex.*"/>
</fileset>
<mapper type="regexp" from=".*" to="sim.swf"/>
</copy>
<copy todir="${swf.output.location}" >
<fileset dir="${project.build.directory}" includes="*.swf">
<not>
<filename regex="^sim-flex.*"/>
</not>
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
Use maven-assembly-plugin with assembly descriptor of "dir" "formats/format", a "fileSets/fileSet" which will copy majority of swf's excluding the special swf, and a "files/file" which will copy that one swf to a file with different name.
I would like to add a custom key/value pair to the MANIFEST.MF of several existing jar files in my war project (those jars are not the project dependencies).
I already can pack/repack those jars using an ant task.
I read about "manifest" task, how can I apply that task to a fileset (if there is a way)? Thanks in advance.
This is my first answer at StackOverflow. Hope it suits you :)
I've done it like this:
<target name="xxx.modifyManifests">
<echo message="Modifying jar manifests to add trusted-library" />
<apply executable="jar">
<arg value="umf" />
<arg line="${xxx.resources}/manifest/custom_manifest.mf" />
<srcfile />
<fileset dir="${xxx.target}/applets" includes="*.jar" />
</apply>
</target>
The call is a simple one using maven-antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>xxx.modifyManifests</id>
<phase>compile</phase>
<configuration>
<target>
<property environment="windows" />
<property name="xxx.resources"
value="${project.build.directory}/../src/main/resources" />
<property name="xxx.target"
value="${project.build.directory}/${project.artifactId}-${project.version}" />
<ant antfile="${basedir}/build.xml">
<target name="xxx.modifyManifests" />
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
And my custom_manifest.mf is like this:
Trusted-Only: true
Trusted-Library: true
Im on CC.Net 1.6, where <sequential> is supposed to work.
When I try to run it with something like the sample shown below, I get ERROR level exceptions saying "Unused node detected" on the sequential node.
What am I missing?
Mark
<sequential>
<tasks>
<powershell>yada...</powershell>
<buildpublisher>yada...</buildpublisher>
<ftp>yada...</ftp>
</tasks>
</sequential>
Are you sure you have put the sequential node in the right place, i.e. inside another tasks node where it belongs? I tried constructing the project configuration below and it passed validation without errors.
<project>
<name>Test project</name>
<tasks>
<sequential>
<tasks>
<powershell>
<script>script.ps1</script>
</powershell>
<buildpublisher />
<ftp>
<ftpFolderName>upload</ftpFolderName>
<localFolderName>test</localFolderName>
<userName>user</userName>
<password>pwd</password>
<serverName>ftp.server.com</serverName>
</ftp>
</tasks>
</sequential>
</tasks>
</project>
It's also not clear from your post why exactly you need the sequential task. The task in CC.Net are executed sequentially by default so you would only need to use it inside a parallel task to specify a block of tasks to be executed sequentially:
<project>
<name>Test project</name>
<tasks>
<parallel>
<tasks>
<sequential>
<tasks>
<!-- other tasks here -->
</tasks>
</sequential>
<sequential>
<tasks>
<!-- other tasks here -->
</tasks>
</sequential>
</tasks>
</parallel>
</tasks>
</project>
Hope that helps.