I have some code in different folders like folder a, folder b,folder c....and all these three folders are in folder name "sonar". if I want to scan all these folders at a time using sonarqube how can I do it. will it be fine if I keep sonar-project.properties file in folder sonar? or do I need to keep sonar-project.properties in all the folders like in folder a, folder b, and folder c individiually
Usually properties should be there for every folder for making analysis on every folder.
You can also try the following approach if it suits your needs and if it is not a big learning curve:
Prerequisites:
ANT Knowledge
Sonar API
Advantages:
1. Single/Central approach for every code analysis
2. Can avoid sonar.properties for every project/source folder
In this approach, write an ANT script that accepts dynamic parameters
Sample:
<target name="setsonarproperties" description="Setting the sonar properties">
<property name="sonar.projectVersion" value="${projectVersion}" />
<property name="sonar.projectKey" value="${targetProduct}_${projectVersion}" />
<property name="sonar.projectName" value="${targetProduct}" />
<property name="sonar.host.url" value="${hostUrl}" />
<property name="sonar.login" value="${hostUserName}" />
<property name="sonar.password" value="${hostPassword}" />
<loadfile property="textFile" srcfile="${buildOrder}" />
<for param="line" list="${textFile}" delimiter="${line.separator}">
<sequential>
<echo message="#{line}" />
<copy todir="${sourcePath}/sonarsources/#{line}">
<fileset dir="${sourcePath}/#{line}">
</fileset>
</copy>
</sequential>
</for>
</target>
Next also set the sonar user name and password details:
Run analyser:
<target name="sonar" depends="setsonarproperties" description="executing sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file
in your "$HOME/.ant/lib" folder -->
</taskdef>
<sonar:sonar />
</target>
Related
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>
Im using eclipse and maven for my day to day development, which works fine. However I need a specialized war created when its time to export to send over to production, which includes things like minifying and combining js/css etc, separating out static resources for apache rather than tomcat etc.
I tried the maven plugin route but it was a hassle, I'd rather write a simply ant script to export when necessary. I'm using the ant war task, but the exported war contains everything except my WEB-INF/libs folder, which is blank. Does anyone know a way to make the script work with all the libs that maven looks up? This is what I have:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="war" basedir=".">
<property name="builder" value="Me" />
<property name="project-name" value="${ant.project.name}" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src/main/java" />
<property name="classes-directory" value="target/classes" />
<property name="web-directory" value="src/main/webapp" />
<property name="web-xml-file" value="src/main/webapp/WEB-INF/web.xml" />
<property name="build-directory" value="/" />
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<target name="war" depends="">
<mkdir dir="${build-directory}" />
<delete file="${build-directory}/${war-file-name}" />
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${classes-directory}" />
<fileset dir="${web-directory}">
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
</project>
You can use maven ant tasks for this. I have not tried this, but from the examples, something like this should work...
<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
<pom file="pom.xml"/>
</artifact:dependencies>
<copy todir="${webapp.output}/WEB-INF/lib">
<fileset refid="dependency.fileset" />
<!-- This mapper strips off all leading directory information -->
<mapper type="flatten" />
</copy>
I'm just about to setup teamcity for the first time on my own. Very nice and simple in most ways I have to say. However, I have one issue that I haven't manage to solve and find any information about.
When I wanna publish my artifacts I want to exclude some file types.
example:
%system.agent.work.dir%\trunk\Source\Projects\Webproject.Web/Controllers => Webproject.Web/Controllers
However, I don't want to copy all the .cs files in the folder. I just need the folder.
Is it possible to copy just the folder and not the content, and then copy what ever content I need? Or can I exclude files if I copy a directory?
You can add a MSBUILD target which prepares the "deployment" package for you. I have the following (may need some changes for your project):
<Target Name="Publish" DependsOnTargets="Build" Condition="'$(WebProjectOutputDir)'!=''">
<RemoveDir Directories="$(WebProjectOutputDir)" ContinueOnError="true" />
<!-- Log tasks -->
<Message Text="Publishing web application for $(MSBuildProjectName)" />
<Message Text="WebProjectOutputDir: $(WebProjectOutputDir)" />
<!-- Create the _PublishedWebsites\app\bin folder -->
<MakeDir Directories="$(WebProjectOutputDir)\bin" />
<!-- Copy build outputs to _PublishedWebsites\app\bin folder -->
<Copy SourceFiles="#(IntermediateAssembly)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(AddModules)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(IntermediateOutputPath)$(_SGenDllName)" DestinationFolder="$(WebProjectOutputDir)\%(Content.SubFolder)%(Content.RecursiveDir)" SkipUnchangedFiles="true" Condition="'$(_SGenDllCreated)'=='true'" />
<Copy SourceFiles="$(IntermediateOutputPath)$(TargetName).pdb" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DebugSymbolsProduced)'=='true'" />
<Copy SourceFiles="#(DocFileItem)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" Condition="'$(_DocumentationFileProduced)'=='true'" />
<Copy SourceFiles="#(IntermediateSatelliteAssembliesWithTargetPath)" DestinationFiles="#(IntermediateSatelliteAssembliesWithTargetPath->'$(WebProjectOutputDir)\bin\%(Culture)\$(TargetName).resources.dll')" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(ReferenceComWrappersToCopyLocal); #(ResolvedIsolatedComModules); #(_DeploymentLooseManifestFile); #(NativeReferenceFile)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<!-- copy any referenced assemblies to _PublishedWebsites\app\bin folder -->
<Copy SourceFiles="#(ReferenceCopyLocalPaths)" DestinationFiles="#(ReferenceCopyLocalPaths->'$(WebProjectOutputDir)\bin\%(DestinationSubDirectory)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<!-- Copy content files recursively to _PublishedWebsites\app\ folder -->
<Copy SourceFiles="#(Content)" DestinationFolder="$(WebProjectOutputDir)\%(Content.RelativeDir)" />
<!-- Copy items that have been marked to be copied to the bin folder -->
<Copy SourceFiles="#(_SourceItemsToCopyToOutputDirectory)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="true" />
<Copy SourceFiles="#(_SourceItemsToCopyToOutputDirectoryAlways)" DestinationFolder="$(WebProjectOutputDir)\bin" SkipUnchangedFiles="false" />
</Target>
So, in the TC build, I use the MSBUILD builder like this:
Targets: Rebuild;Publish
Command line parameters: /p:WebProjectOutputDir="%system.teamcity.build.workingDir%\Website"
You can then use the Website directory as your artifact.
Hi All,
I am trying to run wsInstallApp task to deploy my war file into
websphere.
I am getting the error "Unable to parse setupCmdLine:
null\bin\setupCmdLine.bat (The system cannot find the path specified.)"
<property name="ear.file" value="../archive/DocProcessing.war" />
There is no attribute for war
Here is the code SNIPPET:
<target name="init">
<path id="lib.ref">
<fileset dir="${env.classpath.WAS_HOME}\lib">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\bin">
<include name="*.*bat" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\plugins">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\java\lib">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}\deploytool\itp\plugins">
<include name="*.*jar" />
</fileset>
<fileset dir="${env.classpath.WAS_HOME}">
<include name="*.*jar" />
</fileset>
</path>
<taskdef name="wsStartServer" classpathref="lib.ref"
classname="com.ibm.websphere.ant.tasks.StartServer" />
<taskdef name="wsInstallApp" classpathref="lib.ref"
classname="com.ibm.websphere.ant.tasks.InstallApplication" />
</target>
<target name="StartServer" depends="init">
<exec dir="${env.classpath.WAS_HOME}\bin" executable="cmd">
<arg line="/c startServer.bat server1 -profileName AppSrv01" />
</exec>
</target>
<target name="installEar" depends="StartServer">
<echo message="EAR File located: ${ear.file}" />
<wsInstallApp ear="${ear.file}" wasHome="${env.classpath.WAS_HOME}"
conntype="${remoteConnType}" host="${remoteHostName}" user="${remoteUserId}"
password="${remotePassword}" />
</target>
properties set are:
<property name="remoteHostName" value="localhost" />
<property name="remoteConnType" value="SOAP" />
<property name="remotePort" value="8880" />
<property name="remoteUserId" value="wasadmin" />
<property name="remotePassword" value="wasadmin" />
path set for wasHome ="C:\Program Files\IBM\WebSphere\AppServer"
I could
not findout what is wrong in this .Though i am new to websphere i am
trying to find out the solution to install application and start
application using ant script .Please kindly provide me the solution to
get it set right .
Thanx in advance
You have to set 'user.install.root' property, here is an example:
<property name="user.install.root" value="${env.classpath.WAS_HOME}/profiles/was60profile1" />
Yes, we needed to add the following:
<property name="user.install.root" value="${was.path}/profiles/AppSrv01" />
where was.path would be the location where your was application is installed.
I had this error today. And found the answer!!!
Add profileName="[name of the profile]", in my case profileName="wp_profile", And it works!
This process most probably runs ws_ant.bat which in turn calls setupcmdline to initialise all the variables. In my installation the line is like this:
#echo off
#setlocal
call "%~dp0setupCmdLine.bat" %*
Could it be something to do with your server/RAD configuration being invalid, or the project not having a default server assigned to it?
What happens when you run it outside of RAD through the command line, does it still fail in the same way?
More information from IBM Support here:
http://www-01.ibm.com/support/docview.wss?rs=180&uid=swg1PK23265
is it possible to make nant run a publish on mvc project or a good old web application project
and after the publish make nant FTP the files to the web server
UPDATE: found the solution to the ftp problem
Nant ftp task thanks Paco
what i mean by publich
is there a command line application or nant task that can public like visual studio publish...
The visual studio publish command rebuilds your solution and then copies the files in the solution directory to a new directory. I use the following target to do almost the same:
<target name="copyToPublish">
<delete dir="${dir.publish}" />
<mkdir dir="${dir.publish}" />
<mkdir dir="${dir.publish}\wwwroot"/>
<copy todir="${dir.publish}\wwwroot" includeemptydirs="false">
<fileset basedir="${website.dir}">
<exclude name="**/*.cs"/>
<exclude name="**/*.pdb"/>
<exclude name="**/*.csproj*"/>
<exclude name="**/obj/**"/>
<include name="**/*.*"/>
</fileset>
</copy>
<mkdir dir="${dir.publish}\database"/>
<copy todir="${dir.publish}\database" includeemptydirs="false">
<fileset basedir="${dir.databasescripts}">
<include name="**/*.sql" />
</fileset>
</copy>
<xmlpoke
file="${dir.publish}\wwwroot\Web.config"
xpath="/configuration/system.web/compilation/#debug"
value="false" />
<xmlpoke
file="${dir.publish}\wwwroot\Web.config"
xpath="/configuration/system.web/trace/#enabled"
value="false" />
<move file="${dir.publish}\wwwroot\Web.config" tofile="${dir.publish}\wwwroot\Release.config" overwrite="true" />
<delete file="${dir.publish}\wwwroot\Web.config" />
</target>
Before this target you have to run the normal build procedure of course.
There is a Ftp Task for nant.
Beside that, you have to create a script that copies the files and directories you need and the config files. I don't do it automatically, because I want to have control over database update scripts and changes in web.config.