PHP Mess Detector integration with Teamcity - teamcity

I have Teamcity 7.0.3 installed with different projects. I want to use PHP Mess Detector. I want to have limited set of rules from PHP Mess Detector. And different set of rules for every project. So my questions are
1: How can I modify default rules of PHP Mess Detector?
2: How can I have different set of rules defined against each project in Teamcity?
My current build file content is :
<?xml version="1.0" encoding="UTF-8"?>
<project name="bnnpoa" default="analyse" basedir=".">
<property name="project-name" value="${ant.project.name}" />
<property name="work-dir" value="%system.teamcity.build.workingDir%" />
<property name="folder-to-check" value="${work-dir}\sites" />
<target name="analyse">
<exec executable="C:\php\PEAR\scripts\phpmd.bat">
<arg value="${folder-to-check}"/>
<arg value="html"/>
<arg value="C:\php\PEAR\resources\rulesets\naming.xml,C:\php\PEAR\resources\rulesets\codesize.xml,C:\php\PEAR\resources\rulesets\controversial.xml"/>
<arg value=">"/>
<arg value="${project-name}_analysis.htm"/>
</exec>
</target>
</project>

Add a build step and use same code for every project.
To define your own rules you can modify XML files or copy them , modify rules as per needs, place files in same path and other option is to create new XML and import required rules from files.

Related

Google Closure Compiler Ant Build without concatenating the output

1) I finally managed to get something compiled through Google Closure Compiler using Ant to automate the process. The problem im facing, is that all the examples provided concatenate the output into one main file (main example I followed), say foo.min.js. What I need is to minify/compile ALL the .js files in one and/or more directories into their respective .min.js files, without concatenating the output, so, lets say, I have 3 .js files, I need 3 minified .min.js outputs.
Here's my (first) current build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" basedir="." default="compile">
<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
<condition>
<not>
<equals arg1="${env.CLASSPATH}" arg2=""/>
</not>
</condition>
</fail>
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="${env.CLOSURE_COMPILER}/compiler.jar" />
<target name="compile">
<jscomp compilationLevel="simple" warning="quiet" debug="false" output="${basedir}/admin/js/foo.min.js">
<sources dir="${basedir}/admin/js">
<file name="home.js" />
<file name="mailing.js" />
<file name="table_modal_events.js" />
</sources>
</jscomp>
</target>
</project>
2) Following Ant's installation manual, I've added this
<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
<condition>
<not>
<equals arg1="${env.CLASSPATH}" arg2=""/>
</not>
</condition>
</fail>
to the top of my project, and after building successfully multiple times this way, I noticed that if I remove <property environment="env."/> I get a taskdef class com.google.javascript.jscomp.ant.CompileTask cannot be found
using the classloader AntClassLoader[] error. May I ask why? (being %CLOSURE_COMPILER% an environment variable which I also added to PATH) This answer may be related to this? But I still don't understand.
3) This is the closest related question/answer I could find. But it makes use of a bash script, so my question is: is it possible to achieve what I want using Ant?
I would appreciate if somebody could tell me what I'm doing wrong.
You just need something like into your target
<apply executable="java" parallel="false">
<fileset dir="webapp/js" includes="**/*.js"
excludes="any to exclude" />
<arg line="-jar"/>
<arg path="PATH/closure-compiler-XXX.jar"/>
<arg line="--js "/>
<srcfile/>
<arg line="--warning_level=QUIET" />
<arg line="--js_output_file"/>
<mapper type="glob" from="*.js" to="build/webapp/js/*.js"/>
<targetfile/>
</apply>

Publishing ClickOnce application with NANT script

My WPF application is deployed with ClickOnce.
In Visual Studio I open "Project properties / Publish".
There I have:
Publish location
Publish URL
Version
Signature
The problem is, that I have to publish every version for test and production.
The difference between them are properties publish location and publish URL. Currently I have to execute the process twice, while changing the values before publishing for production.
So the result of pressing publish is a folder containing folder "ApplicationFiles", the application manifest file and a setup.exe.
Then i decided to automate this process using NANT.
I build/publish the application first for testing (here i set the .csproj file location, publish folder and application varsion)
<target name="BuildTestApplication" depends="Clean" description="Build">
<echo message="Building..." />
<exec program="${msbuildExe}" workingdir="." verbose="true">
<arg value="${projectFile}" />
<arg value="/target:Clean;Publish" />
<arg value="/p:PublishDir=${testPublishFolder}" />
<arg value="/p:ApplicationVersion=${version}" />
<arg value="/p:Publisher="${publisherName}"" />
</exec>
<echo message="Built" />
</target>
With this I found out that build does not set the publisher. Plus I need to change the provider URL, since the application is also installed via internet (different URLs for test and production). So i did:
<target name="UpdateTestApplication" depends="BuildTestApplication" description="Update">
<echo message="Updating..." />
<exec program="${mageExe}" workingdir="." verbose="true">
<arg value="-Update" />
<arg value="${testPublishFolder}/EdpClient.application" />
<arg value="-ProviderUrl" />
<arg value=""${testPublishUrl}"" />
<arg value="-Publisher" />
<arg value=""${publisherName}"" />
</exec>
<echo message="Updated" />
</target>
With this I have updated the application manifest file with correct values (Publisher and ProviderUrl)...
I do the same for production build, meaning i build the application to another folder and update it with different ProviderUrl and add Publisher, since it has to be included in every mage update...
Now the problem is with setup.exe file.
Setup.exe is generated at build and it takes the values from the .csproj file.
Considering all of the above I have three issues:
1.
Is there a way of building the application with the correct parameters, so the setup.exe would contain the correct values?
2.
Also how would I update Assembly information (parameter version) before build? When publishing from VS i need to update it on "Probject properties / Application / Assembly Information"
3.
I noticed that when Publishing from VS the application manifest file is also generated in the "Application Files" folder, while publishing with MSBUILD it is not. Why is that?
Thank you in advance and best regards, no9
EDIT:
I fixed the problem #2 like so:
<!--UPDATE ASSEMBLY INFORMATION BEFORE BUILD-->
<target name="UpdateAssemblyInfo">
<asminfo output="${assemblyInfoFile}" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Resources" />
<import namespace="System.Runtime.CompilerServices" />
<import namespace="System.Runtime.InteropServices" />
<import namespace="System.Windows" />
</imports>
<attributes>
<attribute type="AssemblyTitleAttribute" value="some value" />
<attribute type="AssemblyDescriptionAttribute" value="some value" />
<attribute type="AssemblyConfigurationAttribute" value="some value" />
<attribute type="AssemblyCompanyAttribute" value="some value" />
<attribute type="AssemblyProductAttribute" value="some value" />
<attribute type="AssemblyVersionAttribute" value="some value" />
<attribute type="AssemblyFileVersionAttribute" value="some value" />
<attribute type="AssemblyCopyrightAttribute" value="some value" />
<attribute type="AssemblyTrademarkAttribute" value="some value" />
<attribute type="AssemblyCultureAttribute" value="some value" />
<attribute type="CLSCompliantAttribute" value="boolean value" />
<attribute type="ComVisibleAttribute" value="boolean value" />
</attributes>
</asminfo>
<echo file="${assemblyInfoFile}" append="true">
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
</echo>
<echo message="Updated" />
</target>
Meaning I override Assembly.info file before build and add relevant values.
And the problem #3 like so:
<!--COPY APPLICATION MANIFEST TO APPLICATIONFILES FOLDER-->
<target name="CopyTestApplicationManifestToApplicationFilesFolder" depends="Dependency target name" description="Update">
<echo message="Copying..." />
<copy
file="source file"
tofile="target file" />
<echo message="Copied" />
</target>
I was able to create tasks that properly generated the assets you mentioned in your question (setup.exe,application folder, etc.) without having to explicitly sign manifest.
the "clean_and_publish_application" task does the following
Clean the project
Rebuild the project
Publish the project **Here i provide several parameters specifying my publish url, BootstrapperSDKPath,Application Version, and Application Revision
<target name="clean_and_publish_application" description="Build the application.">
<echo message="Clean the build directory"/>
<msbuild project ="${src.dir}\${target.assembly.name}.csproj">
<arg value="/property:Configuration=Debug;outdir=bin\Debug" />
<arg value="/t:clean" />
</msbuild>
<echo message="Rebuild the application"/>
<msbuild project ="${src.dir}\${target.assembly.name}.csproj">
<arg value="/property:Configuration=Debug;outdir=bin\Debug" />
<arg value="/t:rebuild" />
</msbuild>
<echo message="Publish the application"/>
<msbuild project ="${src.dir}\${target.assembly.name}.csproj">
<arg value="/p:publishurl=${publish.url};
GenerateBootstrapperSdkPath=
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\;
ApplicationVersion=${app.version};
ApplicationRevision=${app.revision}" />
<arg value="/t:publish" />
</msbuild>
</target>
The BootstrapperSdkPath property is required for the creation of the setup.exe file. I hard coded the location because it doesn't change. MSBuild is looking for a setup.bin file within that directory.
The ApplicationVersion property is formatted as for example 2.0.0.%2a
The ApplicationRevision property is formatted as a number for example 24 (these values are the Publish Version we see in visual studio. I never actually update the AssemplyInfo.cs file at all.)
Any property you see listed in the .csproj file can be passed as an argument for msbuild. I found this documentation very helpful MSBuild Command-Line Reference
The above task does everything you need EXCEPT actually copy the files to your publish url (Still looking for the answer for this). So I just manually copy all the files from the app.config directory the publish creates
<target name="copy_src">
<echo message="Copying app.config folder"/>
<copy todir="${publish.url}" overwrite="true" failonerror="true">
<fileset basedir="${src.dir}\${app.config.location}">
<include name="**" />
</fileset>
</copy>
</target>
I'm running these scripts in Team City. Because I used the publish target, I didn't have to worry about signing any manifests. Also, I use the msbuild task from the NAnt.Contrib.Tasks.dll which you can download here NAntContrib

Running Ruby tests (Rspec and Cucumber) through Ant

I'm currently looking at TeamCity and how to get our Ruby tests running. I can run the tests just fine when using the Command line or Rake builders. The question I'm trying to solve right now is two fold:
In one of my previous jobs, we also relied on TeamCity to run our .NET tests. We used Nant for this and we had means of tracking the amount of queries that were ran during tests as well as the average execution time for these queries.
I'm trying to do the same right now with my Ruby project. So the first logical step I want to tackle is, How do I run for example RSpec or Cucumber tests using Ant?
I tried looking at Ant itself and grasp it a little bit, but all the examples I find are for jRuby, which we don't use. We rely on RVM and a normal Ruby installation.
The second part of the question is, How can I track the amount of queries ran and their execution time? I'm guessing there is probably a gem for it or some sort of global variable to track. Would love to output this information back to TeamCity somehow.
EDIT
Ok, so I managed to get things running with Ant for my TeamCity server.
This is the XML i'm using atm:
<?xml version="1.0"?>
<project name="rubycas" default="init">
<description>
This buildfile is used to build the RubyCAS project under TeamCity and run the required tasks to validated
whether the project is stable and fully functional.
</description>
<property name="test_type" value="cucumber" />
<target name="init">
<echo message="##teamcity[testStarted name='Rubycas']" />
<condition property="cucumberBool">
<equals arg1="${test_type}" arg2="cucumber" />
</condition>
<condition property="rspecBool">
<equals arg1="${test_type}" arg2="rspec" />
</condition>
</target>
<target name="rspec" if="rspecBool" depends="init">
<exec executable="rspec" outputproperty="result">
<arg value="--require teamcity/spec/runner/formatter/teamcity/formatter" /> <arg value="--format Spec::Runner::Formatter::TeamcityFormatter" />
</exec>
<echo message="${result}" />
</target>
<target name="cucumber" if="cucumberBool" depends="init">
<exec executable="cucumber" outputproperty="result">
<arg value="--format junit" />
<arg value="--out results" />
<arg value="features" />
</exec>
<echo message="${result}" />
</target>
</project>
Problem now is, I cannot get the output from RSpec into TeamCity to recognize the tests.
You can use ant's exec task to run arbitrary system calls, which in your case might be rspec:
https://ant.apache.org/manual/Tasks/exec.html
Something along the lines of
<target name="rspec">
<exec executable="rake">
<arg value="spec"/>
</exec>
</target>
I don't know if your tracking stuff will work with this though, because it's really executing the commands outside of ant.

MSBuild 2010 - how to publish web app to a specific location (nant)?

I'm trying to get MSBuild 2010 to publish a web app to a specific location.
I can get it to publish the deployment package to a particular path, but the deployment package then adds its own path that changes.
For example: if I tell it to publish to C:\dev\build\Output\Debug then the actual web files end up at C:\dev\build\Output\Debug\Archive\Content\C_C\code\app\Source\ControllersViews\obj\Debug\Package\PackageTmp
And the C_C part of the path changes (not sure how it chooses this part of the path).
This means I can't just script a copy from the publish location.
I'm using this nant/msbuild command at the moment:
<target name="compile" description="Compiles">
<msbuild project="${name}.sln">
<property name="Platform" value="Any CPU"/>
<property name="Configuration" value="Debug"/>
<property name="DeployOnBuild" value="true"/>
<property name="DeployTarget" value="Package"/>
<property name="PackageLocation" value="C:\dev\build\Output\Debug\"/>
<property name="AutoParameterizationWebConfigConnectionStrings" value="false"/>
<property name="PackageAsSingleFile" value="false"/>
</msbuild>
Any ideas on how to get it to send the web files directly to a specific location?
msbuild /t:Build;PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation;AutoParameterizationWebConfigConnectionStrings=false MyProject.csproj
Corresponding NAnt script:
<msbuild project="MyProject.csproj" target="PipelinePreDeployCopyAllFilesToOneFolder">
<property name="Configuration" value="Release" />
<property name="_PackageTempDir" value="C:\temp\somelocation" />
<property name="AutoParameterizationWebConfigConnectionStrings" value="false" />
</msbuild>
References
Simulating "Publish to folder" Functionality in Visual Studio 2010
Team Build + Web Deployment + Web Deploy + VS 2010 = Goodness
See also Team Build: Publish locally using MSDeploy
If you are using a VS2010 web application (as opposed to a web site project), consider setting up the Package/Publish Web settings in your project and building the 'Project' target in your nant script.
Lots of juicy msdeploy goodness and background here: http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx
In my nant scripts, I run the following msbuild commands:
<if test="${property::exists('basename')}">
<exec program="${msbuild.location}" workingdir="${project::get-base-directory()}">
<arg value="/p:Configuration=${configuration}" />
<arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
<arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
<arg value="${basename}.sln"/>
</exec>
</if>
...
<if test="${property::exists('basename')}">
<exec program="${msbuild.location}" workingdir="${project::get-base-directory()}\${basename}">
<arg value="/p:Configuration=${configuration}" />
<arg value="/t:Package" />
<arg value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger,${msbuild.logger.dll}" if="${nunit.formatter.type == 'Xml'}"/>
<arg value="/noconsolelogger" if="${nunit.formatter.type == 'Xml'}"/>
<arg value="${basename}.csproj"/>
</exec>
</if>
My basename nant variable gives the name of both the VS solution file (.sln) and the project file (.csproj) for the web application. I happen to prefer the zip-file deployment as shown in my project settings:
There is one additional quirk. If you install MSDeploy version 2.0 on the target machine, the .deploy.cmd file must be edited to change the MSDeploy version number as follows:
Change
for /F "usebackq tokens=2*" %%i in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1" /v InstallPath`) do (
To
for /F "usebackq tokens=2*" %%i in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2" /v InstallPath`) do (
I think you're using the wrong property. Try the OutDir property instead.
<arg value="/property:OutDir=C:\dev\build\Output\Debug\" />
Personally, I call MsBuild.exe directly instead of using the msbuild tag:
<exec program="${MSBuildPath}">
<arg line='"${ProjectFile}"' />
<arg value="/target:_CopyWebApplication" />
<arg value="/property:OutDir=${LocalDeployPath}\" />
<arg value="/property:WebProjectOutputDir=${LocalDeployPath}" />
<arg value="/property:Configuration=${SolutionConfiguration}" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
</exec>
MSBuildPath - The path to MsBuild.exe (allows you to target any framework version you want)
ProjectFile - The relative path to your project file
LocalDeployPath - The local folder where everthing will be outputed. Your copy script will use also use this as the source directory.
SolutionConfiguration - Release, Debug

How do I create a ZIP file of my Cruise Control builds?

I use CruiseControl.NET to automatically build my .NET 3.5 web applications, which works a treat. However, is there any way to automatically create a ZIP file of these builds, and put the ZIP's into a separate directory?
I have seen this is possible using NAnt but cannot find an example of how to get this working.
Can anyone offer help/examples?
I've just added such a Nant task to our CC machine.
See http://nant.sourceforge.net/release/latest/help/tasks/zip.html
Note when initially viewing the zip archive, it may appear as if all the files are at the same level, i.e no folders, but actually they folders are preserved.
Notice how you can exclude file types or folders.
You could take the approach of only including the file types you want and excluding the rest.
First define properties for where the source files are allcode.dir and the name and location of the zip file sourcebackup.zip
Now here is the nant task
<zip zipfile="${sourcebackup.zip}" includeemptydirs="true" verbose="true">
<fileset basedir="${allcode.dir}">
<include name="**/*" />
<exclude name="**/_resharper*/**" />
<exclude name="**/build/**" />
<exclude name="**/obj/**" />
<exclude name="**/bin/**" />
<exclude name="**/*.dll" />
<exclude name="**/*.scc" />
<exclude name="**/*.log" />
<exclude name="**/*.vssscc" />
<exclude name="**/*.suo" />
<exclude name="**/*.user" />
<exclude name="**/*.pdb" />
<exclude name="**/*.cache" />
<exclude name="**/*.vspscc" />
<exclude name="**/*.msi" />
<exclude name="**/*.irs" />
<exclude name="**/*.exe" />
</fileset>
<echo message="########## Zipped##########" />
Call this from your cc build like any other nant task.
We find it best if each CC project calls a single task if possible, then you only have to change the nant script, and you can run the nant script on your local machine.
Eg in the project block, we have the single target "build", which as part of its work calls ZipSource
<targetList>
<target>Build</target>
</targetList>
We use the above for a BizTalk project.
Enjoy.
If you're using Nant, then doesn't the Zip task work for you?
We are zipping the sources of a CruiseControl.NET project
but we are using ant
<target name="zipProject">
<mkdir dir="output"/>
<zip destfile="output\sources.zip" basedir="C:\project\src" />
</target>
i don't know about nant but i would expect it to be similar
#David: The NAnt Zip task is what I'm after, yes, but I'm asking how to integrate it as part of an automatic CruiseControl.NET build. If you take a look at the NAnt documentation for the cruise control config it doesn't make it clear if I can run an NAnt task from inside the <tasks> XML node in my CruiseControl config - it only says that it can be part of a <schedule>.
I have found a few examples of setting up your CruiseControl config and a few examples of NAnt tasks but nothing that integrates the two: specifically, zipping up a CruiseControl build.
If anyone has some sample XML of their CruiseControl config, hooking up to an NAnt zip task, post samples here.
Cheers.

Resources