|
15 | 15 | import java.io.File; |
16 | 16 | import java.io.FileWriter; |
17 | 17 | import java.io.IOException; |
| 18 | +import java.io.InputStream; |
18 | 19 | import java.net.URISyntaxException; |
19 | 20 | import java.nio.file.Path; |
20 | 21 | import java.util.Collection; |
21 | 22 | import java.util.Collections; |
22 | 23 | import java.util.List; |
23 | 24 | import java.util.Map; |
| 25 | +import java.util.Properties; |
24 | 26 | import java.util.stream.Stream; |
25 | | -import javax.xml.parsers.DocumentBuilder; |
26 | | -import javax.xml.parsers.DocumentBuilderFactory; |
27 | | -import okhttp3.OkHttpClient; |
28 | | -import okhttp3.Request; |
29 | | -import okhttp3.Response; |
30 | 27 | import org.apache.maven.artifact.versioning.ComparableVersion; |
31 | 28 | import org.apache.maven.execution.ExecutionEvent; |
32 | 29 | import org.apache.maven.execution.MavenSession; |
|
38 | 35 | import org.junit.jupiter.params.provider.MethodSource; |
39 | 36 | import org.slf4j.Logger; |
40 | 37 | import org.slf4j.LoggerFactory; |
41 | | -import org.w3c.dom.Document; |
42 | | -import org.w3c.dom.NodeList; |
43 | 38 |
|
44 | 39 | public class MavenUtilsTest extends AbstractMavenTest { |
45 | 40 |
|
@@ -481,38 +476,27 @@ private boolean assertGetContainer(ExecutionEvent executionEvent) { |
481 | 476 | } |
482 | 477 |
|
483 | 478 | private static String getLatestMavenSurefireVersion() { |
484 | | - OkHttpClient client = new OkHttpClient(); |
485 | | - Request request = |
486 | | - new Request.Builder() |
487 | | - .url( |
488 | | - "https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/maven-metadata.xml") |
489 | | - .build(); |
490 | | - try (Response response = client.newCall(request).execute()) { |
491 | | - if (response.isSuccessful()) { |
492 | | - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); |
493 | | - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); |
494 | | - Document doc = dBuilder.parse(response.body().byteStream()); |
495 | | - doc.getDocumentElement().normalize(); |
496 | | - |
497 | | - NodeList versionList = doc.getElementsByTagName("latest"); |
498 | | - if (versionList.getLength() > 0) { |
499 | | - String version = versionList.item(0).getTextContent(); |
500 | | - if (!version.contains("alpha") && !version.contains("beta")) { |
501 | | - LOGGER.info("Will run the 'latest' tests with version {}", version); |
502 | | - return version; |
503 | | - } |
504 | | - } |
505 | | - } else { |
506 | | - LOGGER.warn( |
507 | | - "Could not get latest Maven Surefire version, response from repo.maven.apache.org is {}:{}", |
508 | | - response.code(), |
509 | | - response.body().string()); |
| 479 | + // The pinned value is bumped on a schedule by the update-smoke-test-latest-versions workflow. |
| 480 | + // See latest-tool-versions.properties. |
| 481 | + String version = loadLatestToolVersions().getProperty("maven-surefire.latest"); |
| 482 | + LOGGER.info("Will run the 'latest' tests with Maven Surefire version {}", version); |
| 483 | + return version; |
| 484 | + } |
| 485 | + |
| 486 | + private static Properties loadLatestToolVersions() { |
| 487 | + Properties properties = new Properties(); |
| 488 | + try (InputStream stream = |
| 489 | + MavenUtilsTest.class |
| 490 | + .getClassLoader() |
| 491 | + .getResourceAsStream("latest-tool-versions.properties")) { |
| 492 | + if (stream == null) { |
| 493 | + throw new IllegalStateException( |
| 494 | + "Could not find latest-tool-versions.properties on classpath"); |
510 | 495 | } |
511 | | - } catch (Exception e) { |
512 | | - LOGGER.warn("Could not get latest Maven Surefire version", e); |
| 496 | + properties.load(stream); |
| 497 | + } catch (IOException e) { |
| 498 | + throw new RuntimeException(e); |
513 | 499 | } |
514 | | - String hardcodedLatestVersion = "3.5.0"; // latest version that is known to work |
515 | | - LOGGER.info("Will run the 'latest' tests with hard-coded version {}", hardcodedLatestVersion); |
516 | | - return hardcodedLatestVersion; |
| 500 | + return properties; |
517 | 501 | } |
518 | 502 | } |
0 commit comments