11package datadog.smoketest
22
3+
34import com.fasterxml.jackson.databind.ObjectMapper
45import datadog.trace.agent.test.server.http.TestHttpServer
56import datadog.trace.api.Config
67import datadog.trace.api.config.CiVisibilityConfig
78import datadog.trace.api.config.GeneralConfig
89import datadog.trace.test.util.MultipartRequestParser
910import datadog.trace.util.Strings
11+ import okhttp3.OkHttpClient
12+ import okhttp3.Request
13+ import okhttp3.Response
1014import org.apache.maven.wrapper.MavenWrapperMain
1115import org.msgpack.jackson.dataformat.MessagePackFactory
16+ import org.slf4j.Logger
17+ import org.slf4j.LoggerFactory
18+ import org.w3c.dom.Document
19+ import org.w3c.dom.NodeList
1220import spock.lang.AutoCleanup
1321import spock.lang.Shared
1422import spock.lang.Specification
1523import spock.lang.TempDir
1624import spock.util.concurrent.PollingConditions
1725
26+ import javax.xml.parsers.DocumentBuilder
27+ import javax.xml.parsers.DocumentBuilderFactory
1828import java.nio.file.FileVisitResult
1929import java.nio.file.Files
2030import java.nio.file.Path
@@ -31,6 +41,35 @@ import static org.hamcrest.Matchers.not
3141
3242class MavenSmokeTest extends Specification {
3343
44+ private static final Logger LOGGER = LoggerFactory . getLogger(MavenSmokeTest . class)
45+
46+ private static final String LATEST_MAVEN_VERSION = getLatestMavenVersion()
47+
48+ private static String getLatestMavenVersion () {
49+ OkHttpClient client = new OkHttpClient ()
50+ Request request = new Request.Builder (). url(" https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/maven-metadata.xml" ). build()
51+ try (Response response = client. newCall(request). execute()) {
52+ if (response. successful) {
53+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory . newInstance()
54+ DocumentBuilder dBuilder = dbFactory. newDocumentBuilder()
55+ Document doc = dBuilder. parse(response. body(). byteStream())
56+ doc. getDocumentElement(). normalize()
57+
58+ NodeList versionList = doc. getElementsByTagName(" latest" )
59+ if (versionList. getLength() > 0 ) {
60+ return versionList. item(0 ). getTextContent()
61+ }
62+ } else {
63+ LOGGER . warn(" Could not get latest maven version, response from repo.maven.apache.org is ${ response.code()} : ${ response.body().string()} " )
64+ }
65+ } catch (Exception e) {
66+ LOGGER . warn(" Could not get latest maven version" , e)
67+ }
68+ def hardcodedLatestVersion = " 4.0.0-alpha-8"
69+ LOGGER . warn(" Will run the 'latest' tests with hard-coded version ${ hardcodedLatestVersion} " )
70+ return hardcodedLatestVersion
71+ }
72+
3473 private static final String TEST_SERVICE_NAME = " test-maven-service"
3574 private static final String TEST_ENVIRONMENT_NAME = " integration-test"
3675 private static final String JAVAC_PLUGIN_VERSION = Config . get(). ciVisibilityCompilerPluginVersion
@@ -80,14 +119,14 @@ class MavenSmokeTest extends Specification {
80119
81120 prefix(" /api/v2/ci/tests/skippable" ) {
82121 response. status(200 ). send(' { "data": [{' +
83- ' "id": "d230520a0561ee2f",' +
84- ' "type": "test",' +
85- ' "attributes": {' +
86- ' "configurations": {},' +
87- ' "name": "test_to_skip_with_itr",' +
88- ' "suite": "datadog.smoke.TestSucceed"' +
89- ' }' +
90- ' }] }' )
122+ ' "id": "d230520a0561ee2f",' +
123+ ' "type": "test",' +
124+ ' "attributes": {' +
125+ ' "configurations": {},' +
126+ ' "name": "test_to_skip_with_itr",' +
127+ ' "suite": "datadog.smoke.TestSucceed"' +
128+ ' }' +
129+ ' }] }' )
91130 }
92131 }
93132 }
@@ -112,7 +151,7 @@ class MavenSmokeTest extends Specification {
112151 verifyEventsAndCoverages(mavenVersion)
113152
114153 where :
115- mavenVersion << [" 3.2.1" , " 3.2.5" , " 3.3.9" , " 3.5.4" , " 3.6.3" , " 3.8.8" , " 3.9.4 " , " 4.0.0-alpha-7 " ]
154+ mavenVersion << [" 3.2.1" , " 3.2.5" , " 3.3.9" , " 3.5.4" , " 3.6.3" , " 3.8.8" , " 3.9.5 " , LATEST_MAVEN_VERSION ]
116155 }
117156
118157 def " test maven run with jacoco and argLine, v#mavenVersion" () {
@@ -130,7 +169,7 @@ class MavenSmokeTest extends Specification {
130169 verifyEventsAndCoverages(mavenVersion)
131170
132171 where :
133- mavenVersion << [" 3.9.4 " ]
172+ mavenVersion << [" 3.9.5 " ]
134173 }
135174
136175 private verifyEventsAndCoverages (String mavenVersion ) {
@@ -302,20 +341,20 @@ class MavenSmokeTest extends Specification {
302341
303342 private void copyFolder (Path src , Path dest ) throws IOException {
304343 Files . walkFileTree(src, new SimpleFileVisitor<Path > () {
305- @Override
306- FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs )
307- throws IOException {
308- Files . createDirectories(dest. resolve(src. relativize(dir)))
309- return FileVisitResult . CONTINUE
310- }
344+ @Override
345+ FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs )
346+ throws IOException {
347+ Files . createDirectories(dest. resolve(src. relativize(dir)))
348+ return FileVisitResult . CONTINUE
349+ }
311350
312- @Override
313- FileVisitResult visitFile (Path file , BasicFileAttributes attrs )
314- throws IOException {
315- Files . copy(file, dest. resolve(src. relativize(file)))
316- return FileVisitResult . CONTINUE
317- }
318- })
351+ @Override
352+ FileVisitResult visitFile (Path file , BasicFileAttributes attrs )
353+ throws IOException {
354+ Files . copy(file, dest. resolve(src. relativize(file)))
355+ return FileVisitResult . CONTINUE
356+ }
357+ })
319358
320359 // creating empty .git directory so that the tracer could detect projectFolder as repo root
321360 Files . createDirectory(projectHome. resolve(" .git" ))
@@ -401,16 +440,16 @@ class MavenSmokeTest extends Specification {
401440 if (runWithAgent) {
402441 def agentShadowJar = System . getProperty(" datadog.smoketest.agent.shadowJar.path" )
403442 def agentArgument = " -javaagent:${ agentShadowJar} =" +
404- " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)} =${ TEST_ENVIRONMENT_NAME} ," +
405- " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)} =${ TEST_SERVICE_NAME} ," +
406- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)} =true," +
407- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)} =true," +
408- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)} =false," +
409- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)} =false," +
410- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)} =false," +
411- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)} =true," +
412- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)} =${ JAVAC_PLUGIN_VERSION} ," +
413- " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)} =${ intakeServer.address.toString()} "
443+ " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)} =${ TEST_ENVIRONMENT_NAME} ," +
444+ " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)} =${ TEST_SERVICE_NAME} ," +
445+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)} =true," +
446+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)} =true," +
447+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)} =false," +
448+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)} =false," +
449+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)} =false," +
450+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)} =true," +
451+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)} =${ JAVAC_PLUGIN_VERSION} ," +
452+ " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)} =${ intakeServer.address.toString()} "
414453 arguments + = agentArgument. toString()
415454 }
416455 return arguments
0 commit comments