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>
Related
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>
I was reading a tutorial with the following ant script in build.xml
<project name="calculator4" default="generate" basedir=".">
<property name="src" location="src" />
<property name="gen" location="gen" />
<property name="src" location="src" />
<property name="package" value="calculator4" />
<target name="generate">
<mkdir dir="${gen}/${package}" />
<java classname="org.antlr.v4.Tool" classpathref="classpath" fork="true">
<arg value="-o" />
<arg path="${gen}/${package}" />
<arg value="-lib" />
<arg path="${src}/${package}" />
<arg value="-listener" />
<arg value="${src}/${package}/Calculator.g4" />
</java>
</target>
As I don't know much about ant and don't want to use it, I try to translate the command to bash like so
java org.antlr.v4.Tool -o gen/calculator4 -lib src/calculator4 -listener src/calculator4/Calculator.g4
But this is wrong as it generates files in gen/calculator4/src/calculator4 as supposed to the correct behavior of generating files in gen/calculator4
Is there something special going on with ${} other than direct substitution?
The relative path for generated files matches the relative path for input files. Since you specified src/calculator4/Calculator.g4 as the input file, the output files will be src/calculator4/*.java.
Change directories so the working directory is the same folder where Calculator.g4 is.
Remove the -lib src/calculator4 argument.
Change the -o argument to -o ../../gen/calculator4.
Pass just Calculator.g4 as the final argument to the command.
Is it possible to configure Selenium to use Firefox driver and run the browser headlessly within Windows?
I am aware of other drivers working so within Windows or under Linux but not in the particular case mentioned above. Any reference information (ad-hoc ways to achieve it, limitations, etc.) to read upon is highly appreaciated.
Regards,
It is possible to run browsers (Firefox, IE, ...) via dedicated virtual desktop which supported by OS Windows. One such known helper utility for that task is Headless Selenium for Windows.
Here is the way we are running selenium using firefox driver in headless mode on windows.
Create a windows task schedule, you can either do this using the UI
http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7
or with a command like this :
schtasks /Create /TN Automation /TR C:\automation\automated_regression.bat /SC ONSTART /RU Administrator /RP password /F /V1
in our case, the automation is ant driven, so the automated_regression.bat has something like this
:myLoop
cd c:\automation
call ant_env.bat
call ant -f regression.xml
GOTO myLoop
where the regression.xml has a the typical junit targets of a selenium java project
<property name="main.dir" location="./selweb" />
<property name="src.dir" location="${main.dir}/src" />
<property name="lib.dir" location="${main.dir}/lib" />
<property name="build.dir" location="${main.dir}/build" />
<property name="test.report" location="${main.dir}/testreport">
</property>
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${test.report}" />
</target>
<target name="make dir" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${test.report}" />
</target>
<target name="compile" depends="clean, make dir">
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="true">
<classpath refid="build.classpath" />
</javac>
</target>
<target name="junit" depends="clean, make dir,compile">
<loadfile property="LATEST" srcFile="LATEST" />
<junit printsummary="no" fork="true" haltonfailure="false" dir="${main.dir}">
<classpath>
<pathelement path="${build.dir}" />
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
<formatter type="xml" />
<batchtest todir="${test.report}">
<fileset dir="${build.dir}">
<include name="**/tests/**/*.class" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${test.report}">
<fileset dir="${test.report}">
<include name="**/*.xml"/>
</fileset>
<report format="noframes" todir="${test.report}/html" styledir="${main.dir}/style">
<param name="TITLE" expression="Selenium Test Results for build ${LATEST}"/>
</report>
<report format="frames" todir="${test.report}/html" styledir="${main.dir}/style"/>
</junitreport>
</target>
you can use a logger to record your ant runtime eg.
<record name="log\automation_${timestamp}.log" loglevel="verbose" append="false" />
using this you can follow what is going on in your headless automation.
The ' characters around the executable and arguments are
not part of the command.
[junit] Test com.yourtests ... FAILED
[junit] Implicitly adding C:\automation\dep\apache-ant-1.8.4\lib\ant-launcher.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant-junit.jar;C:\automation\dep\apache-ant-1.8.4\lib\ant-junit4.jar to CLASSPATH
.....
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'com.yourtests'
'filtertrace=true'
'haltOnError=false'
'haltOnFailure=false'
'showoutput=false'
'outputtoformatters=true'
'logfailedtests=true'
'logtestlistenerevents=false'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,c:\automation\selweb\testreport\TEST-com.yourtests'
'crashfile=c:\automation\junitvmwatcher2114698975676150832.properties'
'propsfile=c:\automation\junit4190343520192991051.properties'
We have followed this approach and it's working, even screen shots are being taken and inserted in the ant-junit html report.
So the essence is that you need to run your selenium through windows Tasks Scheduler and it will run in headless mode. I think something similar can be done under linux using the cron, but i haven't tried it out to see if it works.
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>
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