phing get files in a directory and create a list of them for a xml file? - phing

I'm triyng to create a generic phing script that will build a joomla plugin.
Each joomla plugin must hava an .xml file that is used by joomla system to install the plugin. In this xml file we need to define what files and folders our zip archive has like this:
<files>
<folder>folder1</folder>
<filename plugin="nameofplugin">nameofplugin.php</filename>
<filename>index.html</filename>
</files>
Now, because I'm lazy and I don't want to do this thing always myself I want to have the phing script do this for me.
I have all the plugin files moved to a specific folder like this:
-pluginFolder
--folder1
--nameofplugin.php
--index.php
I see that I can use foreach like this:
<foreach param="dirname" absparam="absname" target="subtask">
<fileset dir="${destination.dir}">
<type type="file" />
<depth max="0" min="0" />
</fileset>
</foreach>
<target name="subtask">
<echo msg="<file>: ${dirname}" />
</target>
now here in the subtask I fail to figure out how to do merge all the files to a single variable so that I can then use replacetokens for example?
Any ideas about this? Should I build my own phing class that does this? Or is there an easy way to achieve this with what phing has to offer out of the box?

Ok, I managed to achieve what I wanted. I created a new phing task and made the replacement in there.
You can see how it works on the base of this joomla plugin:
https://github.com/compojoom/CUpdater
The build.xml file is here:
https://github.com/compojoom/CUpdater/blob/master/builds/plugin.xml
and the task is here:
https://github.com/compojoom/CUpdater/blob/master/builds/phingext/listjpackagefilestask.php

Related

Is it possible to create an ant-build file for a wikitext project automatically in eclipse?

I have a few hundred textile files in my eclipse project and I have written an ant-build xml file for creating the output html files. This works fine normally. However, every time I add some .textile files to the project, I also have to edit the projectBuilder.xml file manually if the the output has to be generated.
Is there a way in eclipse where I can generate the projectBuilder.xml file automatically? i.e. Lets say, I add a new folder with some 50 subfolders having .textile files inside them, I want eclipse to detect this and add those paths to the build file.
Following is part of the build file for illustration purpose:
<?xml version="1.0"?>
<project name="ALM" default="generate-html">
<property name="wikitext.standalone" value="jar" />
<path id="wikitext.classpath">
<fileset dir="${wikitext.standalone}">
<include name="org.eclipse.mylyn.wikitext.*core*.jar" />
</fileset>
</path>
<taskdef classpathref="wikitext.classpath" resource="org/eclipse/mylyn/wikitext/core/util/anttask/tasks.properties" />
<target name="generate-html" description="Generate HTML from textile source">
<wikitext-to-html markupLanguage="Textile">
<fileset dir="${basedir}/..">
<include name="Docu/*.textile" />
<include name="Add-Ons/*.textile" />
<include name="uC1/asv/ASD/doc/*.textile" />
I'm not sure, which of these 2 problems you have.
To automate the transformation process, select Project->Properties->Builder. Add an Ant builder and give it the Ant script that you already have. This leads to running your script on every change in the project (like the normal Java compiler). If you want to run the Ant script only when your textile files change, then have a look at the last tab "Build options" when configuring that builder, there you can restrict it to a "working set of relevant resources".
To dynamically get the list of directories, there are multiple ant tasks available and it might depend on your project layout what to use: Using fileset you could just find all textile files and then use the fileset contents for the generation: Find all directories in which a file exists, such that the file contains a search string Or if the directory structure very plain, then you can just iterate it with foreach: Ant: How do I interate over all subfolders and perform a task in ant.

How to edit XML parameter using Ant

I'm trying to write a timestamp as a context parameter into my context.xml at that time I execute my Ant script.
I was trying the following:
my context.xml
<Parameter name="deployingTimeStamp"
value="16.07.2012" <!-- shall be changed! -->
override="true" />
my build.xml
<tstamp>
<format property="time" pattern="dd.MM.yyyy"
unit="hour"/>
</tstamp>
<replace file="${conf.dir}/dev/context.xml" >
<replacefilter token="deployingTimeStamp" value="${time}" />
</replace>
Unfortunately it doesn't replace the value, it just replaces the name "deployingTimeStamp" itself and changes it to the current date.
How can I solve this problem?
The replacefilter token is going to replace the token you define. Why don't you add a placeholder value in the XML (i.e. [[buildTimeStamp]] ) and then use:
<replace file="${conf.dir}/dev/context.xml" >
<replacefilter token="[[buildTimeStamp]]" value="${time}" />
</replace>
So your original xml would be
<Parameter name="deployingTimeStamp"
value="[[buildTimeStamp]]" <!-- shall be changed! -->
override="true" />
Additional tips based on comment discussion:
What you might not be doing is copying your main source files into a build directory to perform your replaces first. This is pretty standard in build scripts which is why I mentioned you check your files out of source control first. If you are not using source control and have a folder on your computer then you need to copy the files from that folder to another folder first before performing your replace and other packaging of the app.
<copy todir="../dest/dir">
<fileset dir="src_dir" excludes="**/*.java"/>
</copy>
Something like above where you copy source to working directory. THEN you perform your actions on it, and afterwards remove it when you have a package (i.e. jar file or war file or something if java). You can view the delete functionality in Ant's documentation as well:
http://ant.apache.org/manual/Tasks/copy.html

MSBuild project deploy to local folder with config transformed

I'm having trouble trying to find the right way to use MSBuild to build a web project and output the project with only deployable files (i.e. no .cs, .csproj, .Debug.config etc.), but published to a local folder that I can then FTP, RoboCopy, (or whatever) to a secondary location.
The published output must have the Web.config file pre-transformed as per the specified configuration and the transformation config files (e.g. Web.Debug.config) not included in the output. I don't need any fancy publishing to IIS, database deployment or anything like that, I just want clean file system output that I can then test. Note that this cannot be done using visual tools as I want to run it as part of an automated build process.
I can generate a web deployment package, but I can't get WebDeploy to work because it doesn't seem to handle quoted command line options anymore (seems to be some kind of bug) and the directory structure has spaces, so I was hoping to accomplish the whole task using MSBuild, seeing as MSBuild seems to have native capacity to transform the config file (TransformXml), which is the only real bit of proper deployment functionality I'd be using.
Got it figured out eventually. The following build script does the trick:
<?xml version="1.0"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<PropertyGroup>
<OutputDir>obj\website-output</OutputDir>
</PropertyGroup>
<Target Name="PrepareDeploy">
<ItemGroup>
<DeployableFiles Include="App_Code/**/*.*;App_Data/**/*.*;Areas/**/Views/**/*.*;bin/**/*.*;Views/**/*.*;*.aspx;*.asax;*.html;*.htm;sitemap.xml;*.ico;*.png" Exclude="App_Data/**/*.log" />
</ItemGroup>
<RemoveDir ContinueOnError="true" Directories="$(OutputDir)" />
<MSBuild Projects="Website.csproj" />
<MakeDir ContinueOnError="true" Directories="$(OutputDir)" />
<Copy SourceFiles="#(DeployableFiles)" DestinationFiles="#(DeployableFiles->'$(OutputDir)\%(RelativeDir)%(Filename)%(Extension)')" />
<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="$(OutputDir)\web.config" />
</Target>
</Project>

Eclipse PDE Build: how to organize plugins and features with the "fetch" step skipped?

I'm building my Eclipse plugin by means of Eclipse PDE build, i e I've defined all the required targets in "custom.xml"
But I do not want to fetch my plugins from a repository, so I'm skipping this step. However, all plugins have to be located under plugins directory, and all the features have to be located under features folder accordingly. This is actually done with map files but I've skipped the step. So, I'm copying my elements as follows:
<target name="init">
<mkdir dir="${buildDirectory}" />
<mkdir dir="${buildDirectory}/plugins" />
<mkdir dir="${buildDirectory}/features" />
<copy todir="${buildDirectory}/${type}s">
<fileset dir="${buildDirectory}/../">
<include name="${id}/**" />
</fileset>
</copy>
</target>
<target name="preGenerate">
<antcall target="allElements">
<param name="genericTargets" value="${builder}/customTargets.xml"/>
<param name="target" value="init"/>
</antcall>
</target>
That works perfect! The only thing I do not like is that in "allElements" target I have to specify the set of all plugins and features I have. And I do this only for the goal of copying. Specifying in the elements only one 'main' feature is enough for the rest of the build process.
So, my question is: how to specify only one 'main' feature without need of specifying the rest set of plugins (which are already listed within this feature) to prepare the Eclipse build process? Or, it is possible to start the build without that copying? Probably, specify map files somehow?
Thanks in advance!
Why you have allElements.xml? PDE itself creates a dummy feature project to build the stuff you ask it to. Is it an RCP app that you wish to build? If yes, you can use a product configuration to invoke the build. If not, you can create a dummy root level feature project and add everything to it, generate its build.xml and headlessly build it.
You may want to have a look at this post series (apologies for shamelessly forwarding you to my blog) .

netbeans - scp after build

I'd like to copy a file to a remote server with scp after building, using Netbeans.
What I do now manually is:
Clean and Build Main Project
scp dist/project.jar login#dest/...../......
Is there some way to automate this task? I tried looking at the build.xml file, but it really looks like something I don't want to mess with.
Thanks
Nicola
I use WinSCP to perform something similar to this. I monitor a local directory for file changes and it automatically transfers the changes files.
This is possible, see the scp task on ant's site: http://ant.apache.org/manual/Tasks/scp.html
An example from the site:
Copy a set of files to a directory
<scp todir="user:password#somehost:/home/chuck">
<fileset dir="src_dir">
<include name="**/*.java"/>
</fileset>
</scp>
<scp todir="user:password#somehost:/home/chuck">
<fileset dir="src_dir" excludes="**/*.java"/>
</scp>
You can hardcore the password inside the build task, but that's not a great idea. Better to use public keys.