How can we use Flex PMD for Flex Code Review - flex-pmd

How to use Flex PMD for Flex Code Review like the Eclips Jupiter Code Review?

I think you're asking for how you can run FlexPMD. Since you haven't specified, I'll post the Ant script that I've used on Flex projects in the past. It's just a snippet, so you might have to fill in some Ant variables, but it's a start.
<taskdef name="flexPmd"
classname="com.adobe.ac.pmd.ant.FlexPmdAntTask"
classpath="${flexpmd.lib.dir}/flex-pmd-ant-task-${flexpmd.version}.jar">
<classpath>
<pathelement location="${pmd.lib.dir}/pmd-4.2.5.jar"/>
<pathelement location="${flexpmd.lib.dir}/*.jar"/>
</classpath>
</taskdef>
<target name="flexPmdWithCustomRuleset">
<flexPmd
sourceDirectory="${src.dir}"
outputDirectory="${flexpmd.report.dir}"
ruleSet="${flexpmd.lib.dir}/pmd.xml"/>
</target>
<target name="flexPmdWithDefaultRuleset">
<flexPmd
sourceDirectory="${src.dir}"
outputDirectory="${flexpmd.report.dir}"/>
</target>

Related

ant: string manipulation on variable

I have a question based from this question
Replacing characters in Ant property
I want to build a variable (i can't use a property because i'm in a loop) that is pretty much StringA - StringB.
(maybe this is a misunderstanding of properties on my part but they can only be assigned once correct?)
I guess I could build a script function to calculate that, but my guess is that it must be possible to do it in an already existing function, probably something i'm missing.
this would be an example of the code
<for param="file">
<path>
<fileset dir="${mydir}" >
<include name="*.war"/>
</fileset>
</path>
<sequential>
<var name="undeploy_name" value="#{file} function_here ${mydir}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
in general I want to deploy several wars. this works fine when I run it once but if I want to make it re-runnable I need to undeploy them first.
I'm just a consumer of this interfaces, Ideally deployToLiferay would auto undeploy but it does not.
thanks for an feedback
edit: if I use something similar to what is define on the linked page i get:
<loadresource property="file-to-deploy">
<propertyresource name="#{file}"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="${mydir}" to=""/>
</tokenfilter>
</filterchain>
</loadresource>
10:52:49.541: * /data/contribution.xml:171: The following error occurred while executing this line:
10:52:49.541: * /data/contribution.xml:178: null doesn't exist
line 178 is my loadresource part
ANT is not a programming language. Personally I'd recommend embedding a scripting language like Groovy to process a group of files:
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
Example
├── build.xml
└── src
└── wars
├── app1.war
├── app2.war
└── app3.war
Example
process-files:
[echo] I want to do something with this /../src/wars/app1.war file
[echo] I want to do something with this /../src/wars/app2.war file
[echo] I want to do something with this /../src/wars/app3.war file
Update
The following working example shows how Apache ivy can be used to manage build dependencies. This is a capability that exists in other Java build tools like Maven.
<project name="demo" default="process-files" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==================
Normal ANT targets
==================
-->
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
<!--
=============================
Dependency management targets
=============================
-->
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>
</target>
<target name="install-ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>

Is SCP Ant task thread safe

We have multiple servers that we need to get files out to. We're using Ant based build system and to save up some time we're trying to deploy them to each of the boxes in a separate thread:
<for param="file" parallel="true" threadCount="10">
...
<sequential>
<sshexec host="${host}" trust="true" username="${username}" password="${password}" command="do some setup;"/>
<scp todir="${username}:${password}#${host}:~/" trust="true" >
<fileset dir="${releaseDir}/..">
<include name="releases/**" />
</fileset>
</scp>
...
</sequential>
</for>
This snippet fails intermittently for some boxes but works fine using a single thread - which leads me to believe that it doesn't handle multithreading well.
1.Has anyone come across similar issue?
2.Can you recommend any alternatives?

How to setup building steps for CruiseControl.net from repository of the building project?

I'd like to store ccnet.config file (or other cc.net configuration file for this project) in the repository (git) of my project and make CC.NET use it when I force building from dashboard. How can I do it?
Thank you!
Your "ccnet.config" should remain fairly static.
If you need different "logic" for your solution/project building, then I suggest:
1. Write your ccnet.config code to pull source code from repository. (aka, Task #1)
2. In your repository, include a MasterBuild.proj (msbuild definition).
3. Have cc.net call msbuild.exe on MasterBuild.proj (aka, Task #2).
4. Have the majority of your logic inside the MasterBuild.proj file. That is what you check in/out of source control.
If you think of CC.NET as a "super fancy msbuild.exe executor", you're world will make more sense IMHO.
Here is a very basic msbuild (definition) file.
You can call it
MySolutionMasterBuild.proj (or similar)
Put this in the same directory as your .sln file (in source control).
Use CC.NET to download the code.
Then wire up msbuild.exe to call the below file.
Then have any extra logic inside the .proj file.
You can do some of the other CC.NET stuff, like post build emailing and merging any results xml, but the majority of the logic (my preference anyways)..........would be in the file below.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<PropertyGroup>
<!-- Always declare some kind of "base directory" and then work off of that in the majority of cases -->
<WorkingCheckout>.</WorkingCheckout>
<ArtifactDestinationFolder>$(WorkingCheckout)\ZZZArtifacts</ArtifactDestinationFolder>
</PropertyGroup>
<Target Name="AllTargetsWrapped">
<CallTarget Targets="CleanArtifactFolder" />
<CallTarget Targets="BuildItUp" />
<CallTarget Targets="CopyFilesToArtifactFolder" />
</Target>
<Target Name="BuildItUp" >
<MSBuild Projects="$(WorkingCheckout)\MySolution.sln" Targets="Build" Properties="Configuration=$(Configuration)">
<Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"/>
</MSBuild>
<Message Text="BuildItUp completed" />
</Target>
<Target Name="CleanArtifactFolder">
<RemoveDir Directories="$(ArtifactDestinationFolder)" Condition="Exists($(ArtifactDestinationFolder))"/>
<MakeDir Directories="$(ArtifactDestinationFolder)" Condition="!Exists($(ArtifactDestinationFolder))"/>
<Message Text="Cleaning done" />
</Target>
<Target Name="CopyFilesToArtifactFolder">
<ItemGroup>
<MyExcludeFiles Include="$(WorkingCheckout)\**\*.doesnotexist" />
</ItemGroup>
<ItemGroup>
<MyIncludeFiles Include="$(WorkingCheckout)\bin\$(Configuration)\**\*.*" Exclude="#(MyExcludeFiles)"/>
</ItemGroup>
<Copy
SourceFiles="#(MyIncludeFiles)"
DestinationFiles="#(MyIncludeFiles->'$(ArtifactDestinationFolder)\%(Filename)%(Extension)')"
/>
</Target>
</Project>
Take a look at the scenario's at
http://www.cruisecontrolnet.org/projects/ccnet/wiki/Build_Server_Scenarios
Step 1 Setting up Source Control
Step 2 Build on Check-in
Step 3 Add unit tests
Step 4 Add Coverage
Step 5 Add source code analysis
There are build scripts foreseen in each step where you can base yourself on.

NAnt Property to lowercase

I want to protect against incorrect case being placed within a parameter in a nant script.
I want to take the value of x and convert it to lower case, I tried using
string::to-lower()
but that did not work hoping someone has come across this and has a simple solution.
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property name="x" value="default" unless="${property::exists('x')}"/>
<target name="test">
<echo message="${x}" />
</target>
</project>
UPDATE
I tried the suggestion put forward by Yan with the code below this still outputs capitals I will explain further
I have a nant script that has a parameter that can be passed into it, a property checks for the existence of the parameter and if it exists it uses it, if not there is a default value. I want to take the parameter in whatever form it is given and convert it to lower case while still checking for its existence.
<?xml version="1.0" encoding="utf-8"?>
<property overwrite="true" name="x" value="default" unless="${property::exists('x')}"/>
<property overwrite="true" name="x" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x}" />
</target>
</project>
I believe this to be the way you think I should do it Yan. I have tested this with the following command line arguments.
nant -buildfile:nant.build test -D:x=TEST
This produces the output
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
[property] Read-only property "x" cannot be overwritten.
test:
[echo] TEST
BUILD SUCCEEDED - 0 non-fatal error(s), 1 warning(s)
Total time: 0.1 seconds.
any solution would be much appreciated
When you say parameter, so you mean its name or its value? ie, do you want to ensure x is lowercase, or test (I assume the latter)? If I have the following nant script:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" Default="test" value="net-4.0" >
<property overwrite="false" name="x" value="default"/>
<property overwrite="false" name="x_internal" value="${string::to-lower(x)}" />
<target name="test">
<echo message="${x_internal}" />
</target>
</project>
And call it like this:
nant.exe -buildfile:nant.build test -D:x=TESTx
nant.exe -buildfile:nant.build test -D:X=TESTX
I receive the following response:
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] testx
BUILD SUCCEEDED
Total time: 0 seconds.
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: test
test:
[echo] default
BUILD SUCCEEDED
Total time: 0 seconds.
Is this what you are after?
UPDATE
I think this is what is tripping you up:
Note: properties set on the command-line are always read-only.
(From section 4 in the NAnt Properties documentation)
The function you mentioned should work. See if you spelled the syntax correctly:
<echo message="${string::to-lower(x)}" />

SVN checkout under Linux using Ant

When I run the build.xml in linux ubuntu, which should checkout the project from svn is giving the following error:-
svn:
BUILD FAILED
java.net.MalformedURLException: Invalid svn url: svn://xxx-xx-xx-xx-xx.compute-1.amazonaws.com/srv/svn
at org.tigris.subversion.svnclientadapter.SVNUrl.parseUrl(SVNUrl.java:117)
at org.tigris.subversion.svnclientadapter.SVNUrl.<init>(SVNUrl.java:63)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.tools.ant.IntrospectionHelper$11.set(IntrospectionHelper.java:1069)
at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:388)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:392)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:349)
at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:568)
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:346)
at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:198)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
Actually the path of svn is what I connect from my local box. So I don't know what path I shoul give here. The svn is in the same linux box.
My directory path where the build.xml is:-/home/ubuntu/antCheckout
And the path where svn is:-/srv/svn
I also tried this path:- ssh://srv/svn but exception was same.
This is my build.xml:-
<?xml version="1.0"?>
<project name="Test" default="Main" basedir=".">
<!-- Sets variables which can be used. -->
<property name="checkout" location="./svncheckout" />
<!-- Define the classpath which includes the jars
that are required for svnant.jar -->
<path id="/usr/local/ant/apache-ant-1.7.1/">
<pathelement location="lib/svnant.jar" />
<pathelement location="lib/svnClientAdapter.jar" />
<pathelement location="lib/svnjavahl.jar" />
<pathelement location="lib/svnkit.jar" />
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml"
classpathref="/usr/local/ant/apache-ant-1.7.1/" />
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${checkout}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${checkout}" />
</target>
<!-- Checkout the latest source code of svnant itself-->
<target name="svn">
<svn username="guest" password="">
<checkout url="svn://srv/svn" revision="HEAD" destPath="${checkout}" />
</svn>
</target>
<target name="Main" depends="clean, makedir, svn">
<description>Main target</description>
</target>
</project>
Thanks for help.
If you're on Linux, do you have the Subversion command line client?
Try this:
$ svn --version
If you have the Subversion command line client, try this command:
$ svn ls svn://svn/srv
And see what you get. I bet you'll get an error telling you that svn://srv/svn isn't found or isn't a valid URL.
This line:
<checkout url="svn://srv/svn" revision="HEAD" destPath="${checkout}" />
Is equivalent to the command line:
$ svn checkout -rHEAD svn://srv/svn .svncheckout
You will have to find the valid Subversion repository URL before this command will work. Then, change the url parameter in the <checkout> sub-task to match that URL. Subversion uses URLs to point to the repository address.
By the way, exactly what is this suppose to be doing? Why is this checking out the working directory to the .svncheckout directory? That's a hidden directory in Unix.
By the way: svn co svn://127.0.0.1 isn't going to work unless the program snvserve is running on the local system. The svnserve program

Resources