Issue with replacing multiple lines in xml during maven build - maven

I need to replace mutliple lines in .wsdd file in war generated after my maven build.
I am using antrun-maven-plugin and ant's replace task for this purpose.
Below is the snippet from pom.xml:
<plugin>
<groupId>com.github.odavid.maven.plugins</groupId>
<artifactId>antrun-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<ant antfile="replace.xml">
<target name="replace-config"/>
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions></plugin>
Here the replace.xml contains ant target to actually replace the multiline token and updating final war with replaced .wsdd file, below is part where we replace the multiline token in .wsdd file.
<target name ="replace-config">
<echo>********** Replacing tokens in server-config.wsdd file *************</echo>
<replace dir="${basedir}/target/as_gen/WEB-INF/" >
<include name="server-config.wsdd"/>
<replacetoken><![CDATA[<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session"/>
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request"/>
<parameter name="extension" value=".jwr"/>
</handler>
</requestFlow>]]></replacetoken>
<replacevalue><![CDATA[<requestFlow>
<handler type="java:com.as.webservices.TS9TicketTokenSender">
<parameter name="scope" value="session"/>
</handler>
<handler name="_wss4j_as_receiver_handler" type="java:com.as.security.asWSSReceiverHandler">
<parameter name="action" value="NoSecurity"/>
</handler>
<handler type="java:com.cm.ChangeHandler"/>
<handler type="java:com.cm.WSLoggingHandler"/>
</requestFlow>
<responseFlow>
<handler type="java:com.as.webservices.TS9TicketTokenSender"/>
<handler name="_wss4j_as_sender_handler" type="java:com.as.security.asWSSSenderHandler">
<parameter name="signatureKeyIdentifier" value="IssuerSerial"/>
<parameter name="encryptionKeyIdentifier" value="IssuerSerial"/>
<parameter name="action" value="NoSecurity"/>
</handler>
<handler type="java:com.cm.WSLoggingHandler"/>
</responseFlow>
]]></replacevalue>
</replace>
Now this gives correct results when run on unix machine, and token is successfully replaced by replace value but somehow the replacement does not take place on my windows machine.
Kindly help with issue identification and alternate method to do so. Thanks.

I was able to do this using ant's replaceregexp task.
identified the first content between <requestFlow>....</requestFlow> in match attribute and added the replaced value in replace attribute of replaceregexp task

Related

Maven antrun move not deleting source file

Developing on Windows 10 I have a Java project in Maven that has a Linux "launcher" shell script for the FooBar utility stored in the repository at src/bin/foobar.sh. It uses resource filtering to substitute in the correct executable JAR path so that what gets built is a foobar.sh script that launches the executable JAR in the same directory.
The POM uses org.apache.maven.plugins:maven-antrun-plugin:1.8 to enable the executable flag on the foobar.sh script in the target/bin directory (which has been already been copied using Maven resource filtering, with that directory path stored in the ${binOutputDirectory} property):
<chmod dir="${binOutputDirectory}" includes="**/*.sh" perm="+x" />
Then it renames the foobar.sh file to simply foobar (i.e. it removes the extension) to follow best practices for shell scripts:
<move todir="${binOutputDirectory}">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>
You can see e.g. globalmentor-root pom.xml at c31ae410143f86ebf2bf10467214214d87b2eb61 for the full POM source code. Actual child POMs will simply enable the AntRun operations by providing their executions an appropriate phase like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>set-shell-scripts-executable</id>
<phase>process-resources</phase>
</execution>
<execution>
<id>remove-shell-script-extensions</id>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
The essential part of that is working fine, and I wind up with a foobar file in my distributable ZIP file, with its executable flag enabled as desired. Unfortunately I also wind up with the original foobar.sh file as well, and I can see in target/bin (where the .sh extension gets removed) that both files are there as well. So it would appear that AntRun <move> is behaving as <copy>.
To see this in action, build the Guise Mummy 0.1.0 project and look in the cli/target/bin directory; you'll see that guise.sh has not been deleted.
To work around the problem, I can add an extraneous <delete> command; this will successfully remove foobar.sh. (The difference in <fileset> syntax is irrelevant; I switched only because it was more concise.)
<move todir="${binOutputDirectory}">
<fileset dir="${binOutputDirectory}" includes="**/*.sh"/>
<mapper type="glob" from="*.sh" to="*" />
</move>
<delete>
<fileset dir="${binOutputDirectory}" includes="**/*.sh"/>
</delete>
Why is AntRun <move> by itself not removing the original target/bin/foobar.sh file after it copies it to target/bin/foobar as part of the move operation?
Upgrading to org.apache.maven.plugins:maven-antrun-plugin:3.1.0 seems to have fixed the problem. When I created this question I had been using v1.8. I can only suppose that org.apache.maven.plugins:maven-antrun-plugin:1.8 is buggy.
Noticed in the pom, within the antrun goals, you are modifying permissions of the .sh script. This does not confirm if the shell script is writeable, it may be read-only:
<execution>
<id>set-shell-scripts-executable</id>
<!--
Enable execute permission for the shell scripts in `${binOutputDirectory}`.
Enable by specifying a phase (e.g. `process-resources`) in child POM.
-->
<phase>none</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<chmod dir="${binOutputDirectory}" includes="**/*.sh" perm="+x" />
</target>
</configuration>
</execution>
Try the following, apply the overwrite attribute, like so:
(overwrite overwrite existing files even if the destination files are newer)
<move todir="${binOutputDirectory}" overwrite="true">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>
If that does not work, also add the force attribute, like so:
(force Overwrite read-only destination files)
<move todir="${binOutputDirectory}" overwrite="true" force="true">
<fileset dir="${binOutputDirectory}">
<include name="**/*.sh" />
</fileset>
<mapper type="glob" from="*.sh" to="*" />
</move>

Pass package parameters to Execute Package Task

I'm using BIML to generate a coordination package that will execute multiple SSIS packages (some parallel and some linear). (I'm using VS2012 and the SSIS project deployment model)
With the code below I can generate two dummy Execute Package Tasks:
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package ConstraintMode="Linear" AutoCreateConfigurationsType="None" ProtectionLevel="DontSaveSensitive" Name="Coordination">
<Parameters>
<Parameter Name="param1" DataType="Int64" IsRequired="true" IsSensitive="false">1</Parameter>
</Parameters>
<Tasks>
<Container Name="SEQ container" ConstraintMode="Parallel">
<Tasks>
<ExecutePackage Name="Run Package1">
<ExternalProjectPackage Package="Package1.dtsx" />
</ExecutePackage>
<ExecutePackage Name="Run Package2">
<ExternalProjectPackage Package="Package2.dtsx" />
</ExecutePackage>
</Tasks>
</Container>
</Tasks>
</Package>
</Packages>
</Biml>
BIDS Helper with generate the coordination package without any errors.
The next step in completing the coordination package is using a package parameter to control the executed packages. I don't see any way to pass the parameter "param1".
Is there any way to pass the parameter in BIML? (in the Execute SQL task I see this option, but not here)
UPDATE: There is a new version of BIDSHelper with the right support for project parameters...-> http://bidshelper.codeplex.com/releases/view/112755
Those options have been added to the latest builds of BIDSHelper, which will be shipping in the next two weeks. If you email support#varigence.com, we can send you a pre-release, if you'd like. The syntax is:
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package ConstraintMode="Linear" AutoCreateConfigurationsType="None" ProtectionLevel="DontSaveSensitive" Name="Coordination">
<Parameters>
<Parameter Name="param1" DataType="Int64" IsRequired="true" IsSensitive="false">1</Parameter>
</Parameters>
<Tasks>
<Container Name="SEQ container" ConstraintMode="Parallel">
<Tasks>
<ExecutePackage Name="Run Package1">
<ExternalProjectPackage Package="Package1.dtsx" />
<ParameterBindings>
<ParameterBinding Name="Param1" VariableName="System.PackageID" />
</ParameterBindings>
</ExecutePackage>
<ExecutePackage Name="Run Package2">
<ExternalProjectPackage Package="Package2.dtsx" />
<ParameterBindings>
<ParameterBinding Name="Param1" VariableName="System.PackageID" />
</ParameterBindings>
</ExecutePackage>
</Tasks>
</Container>
</Tasks>
</Package>
</Packages>
</Biml>

Maven and Ant Can't run Java - CreateProcess error=206, The filename or extension is too long

When maven via antrun executes this java code I get the dreaded error=206, The filename or extension is too long
<java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out">
<arg value="${className}" />
<arg value="${name}" />
<arg value="${wsdlFile}" />
<classpath>
<path refid="maven.test.classpath" />
</classpath>
Maven creates lengthy classpaths due to the structure and location of the local maven repo. We need to use a pathing jar.
Convert Classpath into string
Escape windows drive letter (C: = bad \C: = good)
Create manifest only jar with class path attribute
Use the pathing jar instead of the maven compile classpath
<mkdir dir="${classpath-compile.dir}"/>
<!-- Convert into usable string . -->
<pathconvert property="compile_classpath_raw" pathsep=" ">
<path refid="maven.compile.classpath"/>
</pathconvert>
<!-- escape windows drive letters (remove C: from paths -- need to wrap with a condition os.family="windows")-->
<propertyregex property="compile_classpath_prep"
input="${compile_classpath_raw}"
regexp="([A-Z]:)"
replace="\\\\\1"
casesensitive="false"
global="true"/>
<!-- Create pathing Jars -->
<jar destfile="${classpath-compile.jar}">
<manifest>
<attribute name="Class-Path" value="${compile_classpath_prep}"/>
</manifest>
</jar>
<java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out">
<arg value="${className}" />
<arg value="${name}" />
<arg value="${wsdlFile}" />
<classpath>
<pathelement location="${classpath-compile.jar}" />
</classpath>
Extending the answer provided by #user4386022: You can define (starting with Ant 1.8) this macro which can help you if you have the same problem in different places in your build process (and you cannot just copy-paste the same snippet everywhere because Ant does not allow re-defining properties, so you will get an error saying that "manifest.classpath" is already defined.)
<macrodef name="create-classpath-jar" description="Create classpath Jar, to avoid getting the error about CreateProcess error=206, The filename or extension is too long">
<attribute name="classpathjar"/>
<attribute name="classpathref"/>
<sequential>
<!-- Turn the classpath into a property formatted for inclusion in a MANIFEST.MF file -->
<local name="manifest.classpath.property"/>
<manifestclasspath property="manifest.classpath.property" jarfile="#{classpathjar}">
<classpath refid="#{classpathref}" />
</manifestclasspath>
<!-- Create the Jar -->
<jar destfile="#{classpathjar}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath.property}"/>
</manifest>
</jar>
</sequential>
</macrodef>
To use the macro in your targets or tasks, then simply use it like this:
<path id="myclasspath">
.........
</path>
<create-classpath-jar classpathjar="classpath-compile.jar" classpathref="myclasspath" />
If using Ant 1.7 or newer you can utilize the manifestclasspath task to generate a manifest file then include it in a jar for use on the javac classpath
<!-- turn the classpath into a property formatted for inclusion in a MANIFEST.MF file -->
<manifestclasspath property="manifest.classpath"
jarfile="${classpath-compile.jar}">
<classpath refid="maven.compile.classpath" />
</manifestclasspath>
<!-- Create pathing Jars -->
<jar destfile="${classpath-compile.jar}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
<java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out">
<arg value="${className}" />
<arg value="${name}" />
<arg value="${wsdlFile}" />
<classpath>
<pathelement location="${classpath-compile.jar}" />
</classpath>
Fixed problem by removing fork="true" from javac target in build.xml file. Please refer to solutions above if forking is mandatory for your build process.

Selenium running headless Firefox browser in Windows

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.

Visual Studio Config Transforms

Suppose I have a Web.config like such:
<configuration>
<elmah>
...
</elmah>
</configuration>
Is it possible to remove the <elmah> node with config transforms? So far I've tried something like:
<configuration>
<elmah xdt:Transfrom="RemoveAll"/>
</configuration>
Which doesn't work (according to Preview Transform). Althought this type of thing does seem to work on other nodes. Does anyone know how this can be removed?
Thanks
You need to have a xdt:Locator to get the match.
Try using the following:
Debug:
<configuration>
<elmah name="debug" />
</configuration>
Release:
<configuration>
<elmah name="debug" xdt:Locator="Match(name)" xdt:Transform="RemoveAll" />
</configuration>
Or without the need for name matching:
<configuration>
<elmah name="debug" xdt:Locator="XPath(//elmah)" xdt:Transform="RemoveAll" />
</configuration>
or
<configuration>
<elmah name="debug" xdt:Locator="XPath(configuration/elmah)" xdt:Transform="RemoveAll" />
</configuration>
As a note:
Currently the Web.config transforms are only applied during the Web Publish Pipleline (WPP) that is on Publish, not during debug, to enable them during debug check the following link: http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx .
Hope it helps.
You have a typo in your xdt syntax – it should be xdt:Transform, not xdt:Transfrom.

Resources