Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Creating a Session ID

Before running the build scan and tests, you need to create a session ID. The session ID is provided to each step in order to link them together as one complete cycle.
Generating a session ID in Java is done using the Java Build scanner with the -config flag. In the following sample, we have used a timestamp for the build name but any environment variable can be used according to your organization’s naming convention.

Code Block
languagexml
<tstamp>
     <format property="time.stamp" pattern="yyyyMMdd-HHmm"/>
</tstamp>

<target name="sealights_config">
	<java jar="${sealights.dir}/sl-build-scanner.jar" fork="true">
		<arg value="-config"/>
		<arg value="-tokenfile"/>
		<arg value="/path/to/sltoken.txt"/>
		<arg value="-appname"/>
		<arg value="myApp"/>
		<arg value="-branchname"/>
		<arg value="master"/>
		<arg value="buildname"/>
		<arg value="${time.stamp}"/>
		<arg value="-pi"/>
		<arg value="*.com.company.*"/>
	</java>
</target>
Info

See 'Java Command Reference - Creating a session ID' for full parameter details

Scanning a build

In order to collect coverage information SeaLights agents need to first scan the binary files for the build information: it can be the *.class, *.jar or even the *.war files.

...

Code Block
languagexml
<target name="sealights_scan" depends="compile,sealights_config">
    <java jar="${sealights.dir}/sl-build-scanner.jar" fork="true">
		<arg value="-scan"/>
		<arg value="-tokenfile"/>
		<arg value="/path/to/sltoken.txt"/>
		<arg value="-buildsessionidfile"/>
		<arg value="buildSessionId.txt"/>
		<arg value="-workspacepath"/>
		<arg value="${build}"/>
		<arg value="-r"/>
		<arg value="-fi"/>
		<arg value="*.class"/>
		<arg value="-moduleName"/>
		<arg value="${package}"/>
	</java>
</target>

In order to add logs flags, you need to add the <jvmarg> values like below

<jvmarg value="-Dsl.log.toConsole=true"/>
<jvmarg value="-Dsl.log.level=info"/>

...

Code Block
languagexml
<junit fork="yes">
  <jvmarg value="-javaagent:${sealights.dir}/sl-test-listener.jar"/>
  <jvmarg value="-Dsl.tokenFile=/path/to/sltoken.txt"/>
  <jvmarg value="-Dsl.buildSessionIdFile=buildSessionId.txt"/>
  <jvmarg value='-Dsl.testStage="Unit Tests"'/>
</junit>
Info

See 'Java Command Reference - Installing test listener as Java Agent' for full parameter details

Sample integration into an existing ANT project

In order to keep backward compatibility, you can use the ant:if condition to execute Sealights commands according to a boolean.
In the sample below, you’ll be required to add -Dsealights=true to your ANT command in order to enable the agents.

The sample below does not contain the command themselves for clarity. Please replace the <echo> lines with commands explained in previous sections.

Code Block
languagexml
<project name="sl-ant-sample" xmlns:if="ant:if">

    <target name="compile">
		<echo>Compiling the JAR</echo>
		<antcall if:true="${sealights}" target="sealights_scan" />
    </target>

	<target name="sealights_config">
		<echo>Sealights -- Create BSID</echo>
	</target>

	<target name="sealights_scan" depends="sealights_config">
		<echo>Sealights -- Scan artefacts</echo>
	</target>

	<target name="junit">
		<echo if:true="${sealights}">Sealights</echo>
		<echo>Regular</echo>
  	</target>

</project>

...