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
Related
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.
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>
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
I want to deploy my ASP.NET MVC site and have the following script.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\MyProjName\MyProjName.csproj"/>
<PropertyGroup>
<NewInstallDir>C:\DeployFolder\</NewInstallDir>
<BinDir>$(NewInstallDir)bin\</BinDir>
</PropertyGroup>
<Target Name="Build">
<MSBuild Projects="..\MySlnName.sln"
Properties="Configuration=Release;Platform=Any CPU;OutputPath=$(BinDir)" />
<Copy SourceFiles="#(Content->'..\MyProjName\%(RelativeDir)%(FileName)%(Extension)')"
DestinationFiles="#(Content->'$(NewInstallDir)%(RelativeDir)%(FileName)%(Extension)')" />
<Copy SourceFiles="#(None->'..\MyProjName\%(RelativeDir)%(FileName)%(Extension)')"
DestinationFiles="#(None->'$(NewInstallDir)%(RelativeDir)%(FileName)%(Extension)')" />
<MakeDir Directories="#(Folder->'$(NewInstallDir)%(RelativeDir)')" />
</Target>
</Project>
Main idea.
I copied binary to C:\DeployFolder (take structure of folder from sources). I build my dll to C:\DeployFolder\Bin (I don't have this folder in sources folder so I need separately copy this).
I run my script - all works instead of copy DLLs to OutputPath. Same scripts works for other asp.net mvc project. I have no idea what is wrong in this case.
I complete this issue with workaround but I would like to know what is wrong with this script.
The first thing I'd try is to replace your use of the deprecated $(OutputPath) with $(OutDir). From when I've seen this error, 9 times out of 10 it is due to a mismatch between the Platform/Configuration requested and how a particular project is actually defined. Take care to keep track of the discrepency between "Any CPU" (with a space) preferred by solution files and "AnyCPU" actually used inside project files for $(Platform). Some project wizards only set up an "x86" Platform or otherwise omit "AnyCPU" which can cause the OutputPath to be empty.
Beyond that, the approach of importing a project file and then building a solution (presumbably that includes the very same project" is a bit off center. Consider making the deployment changes you desire within the project file itself, through an import. You can either wire into the existing build targets at the right place, or perhaps add an additional target.
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) .