native2ascii only for files which contain a specific text - unicode

I have a big load of .properties files in multi-languages, some contain unicode escaped formatting (\u304B\u3089). I'm interested in decoding all all of the files to non-escaped utf-8 chars ( から). I was thinking about using the native2ascii task reverse option in ANT, and I used this code for the build.xml:
<project>
<target name= "test">
<native2ascii reverse="true" encoding="utf-8" src="build/test" dest="build/test/1"/>
</target>
</project>
Problem is that the files are mixed, some have escaped-unicode and some show the proper chars. As a result of running this build with ANT, the ones that were proper are now distorted. How can I modify the code so it will only run on the files which have unicode-escaped? (I was thinking about a condition which modifies only files which contain "\u", but I was not able to achieve this)

Try using the copy task, setting the source encoding and destination encoding to UTF-8:
<copy file="input.properties" tofile="output.properties" overwrite="true"
encoding="UTF-8" outputencoding="UTF-8" />

Related

Converting files to UTF-8 without BOM in ANT

I have some js files that are in UTF-8 BOM encoding. I want to convert these files to UTF-8 encoding using ant. I used copy task of ant for this
<copy todir="./custom_plugins" overwrite="true" outputencoding="UTF-8">
<fileset dir="../plugins" />
</copy>
Now when I open a file that was in UTF-8 BOM in notepad++ it shows its encoding in ANSI format but this also appends the  character at the beginning of the file.
Even i tried this, but not working.
How can I solve this?
After encoding these files to UTF-8 I used replaceregexp ant task to remove/replace BOM character \xEF\xBB\xBF with empty string.
<replaceregexp match="\xEF\xBB\xBF" replace="" byline="true" encoding="UTF-8">
<fileset dir="./custom_plugins">
<include name="**/*.js"/>
</fileset>
</replaceregexp>

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>

MSBuild: OutputPath directory is empty

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.