|
41 | 41 |
|
42 | 42 | public class JdkDownloadPluginIT extends GradleIntegrationTestCase {
|
43 | 43 |
|
44 |
| - private static final String FAKE_JDK_VERSION = "1.0.2+99"; |
| 44 | + private static final String OLD_JDK_VERSION = "1+99"; |
| 45 | + private static final String JDK_VERSION = "12.0.1+99@123456789123456789123456789abcde"; |
45 | 46 | private static final Pattern JDK_HOME_LOGLINE = Pattern.compile("JDK HOME: (.*)");
|
46 | 47 | private static final Pattern NUM_CONFIGS_LOGLINE = Pattern.compile("NUM CONFIGS: (.*)");
|
47 | 48 |
|
48 | 49 | public void testLinuxExtraction() throws IOException {
|
49 |
| - assertExtraction("getLinuxJdk", "linux", "bin/java"); |
| 50 | + assertExtraction("getLinuxJdk", "linux", "bin/java", JDK_VERSION); |
50 | 51 | }
|
51 | 52 |
|
52 | 53 | public void testDarwinExtraction() throws IOException {
|
53 |
| - assertExtraction("getDarwinJdk", "osx", "Contents/Home/bin/java"); |
| 54 | + assertExtraction("getDarwinJdk", "osx", "Contents/Home/bin/java", JDK_VERSION); |
54 | 55 | }
|
55 | 56 |
|
56 | 57 | public void testWindowsExtraction() throws IOException {
|
57 |
| - assertExtraction("getWindowsJdk", "windows", "bin/java"); |
| 58 | + assertExtraction("getWindowsJdk", "windows", "bin/java", JDK_VERSION); |
| 59 | + } |
| 60 | + |
| 61 | + public void testLinuxExtractionOldVersion() throws IOException { |
| 62 | + assertExtraction("getLinuxJdk", "linux", "bin/java", OLD_JDK_VERSION); |
| 63 | + } |
| 64 | + |
| 65 | + public void testDarwinExtractionOldVersion() throws IOException { |
| 66 | + assertExtraction("getDarwinJdk", "osx", "Contents/Home/bin/java", OLD_JDK_VERSION); |
| 67 | + } |
| 68 | + |
| 69 | + public void testWindowsExtractionOldVersion() throws IOException { |
| 70 | + assertExtraction("getWindowsJdk", "windows", "bin/java", OLD_JDK_VERSION); |
58 | 71 | }
|
59 | 72 |
|
60 | 73 | public void testCrossProjectReuse() throws IOException {
|
61 | 74 | runBuild("numConfigurations", "linux", result -> {
|
62 | 75 | Matcher matcher = NUM_CONFIGS_LOGLINE.matcher(result.getOutput());
|
63 | 76 | assertTrue("could not find num configs in output: " + result.getOutput(), matcher.find());
|
64 | 77 | assertThat(Integer.parseInt(matcher.group(1)), equalTo(6)); // 3 import configs, 3 export configs
|
65 |
| - }); |
| 78 | + }, JDK_VERSION); |
66 | 79 | }
|
67 | 80 |
|
68 |
| - public void assertExtraction(String taskname, String platform, String javaBin) throws IOException { |
| 81 | + public void assertExtraction(String taskname, String platform, String javaBin, String version) throws IOException { |
69 | 82 | runBuild(taskname, platform, result -> {
|
70 | 83 | Matcher matcher = JDK_HOME_LOGLINE.matcher(result.getOutput());
|
71 | 84 | assertTrue("could not find jdk home in output: " + result.getOutput(), matcher.find());
|
72 | 85 | String jdkHome = matcher.group(1);
|
73 | 86 | Path javaPath = Paths.get(jdkHome, javaBin);
|
74 | 87 | assertTrue(javaPath.toString(), Files.exists(javaPath));
|
75 |
| - }); |
| 88 | + }, version); |
76 | 89 | }
|
77 | 90 |
|
78 |
| - private void runBuild(String taskname, String platform, Consumer<BuildResult> assertions) throws IOException { |
| 91 | + private void runBuild(String taskname, String platform, Consumer<BuildResult> assertions, String version) throws IOException { |
79 | 92 | WireMockServer wireMock = new WireMockServer(0);
|
80 | 93 | try {
|
81 | 94 | String extension = platform.equals("windows") ? "zip" : "tar.gz";
|
82 |
| - String filename = "openjdk-1.0.2_" + platform + "-x64_bin." + extension; |
83 |
| - wireMock.stubFor(head(urlEqualTo("/java/GA/jdk1/99/GPL/" + filename)) |
84 |
| - .willReturn(aResponse().withStatus(200))); |
| 95 | + boolean isOld = version.equals(OLD_JDK_VERSION); |
| 96 | + String filename = "openjdk-" + (isOld ? "1" : "12.0.1") + "_" + platform + "-x64_bin." + extension; |
85 | 97 | final byte[] filebytes;
|
86 |
| - try (InputStream stream = JdkDownloadPluginIT.class.getResourceAsStream(filename)) { |
| 98 | + try (InputStream stream = JdkDownloadPluginIT.class.getResourceAsStream("fake_openjdk_" + platform + "." + extension)) { |
87 | 99 | filebytes = stream.readAllBytes();
|
88 | 100 | }
|
89 |
| - wireMock.stubFor(get(urlEqualTo("/java/GA/jdk1/99/GPL/" + filename)) |
90 |
| - .willReturn(aResponse().withStatus(200).withBody(filebytes))); |
| 101 | + String versionPath = isOld ? "jdk1/99" : "jdk12.0.1/123456789123456789123456789abcde/99"; |
| 102 | + String urlPath = "/java/GA/" + versionPath + "/GPL/" + filename; |
| 103 | + wireMock.stubFor(head(urlEqualTo(urlPath)).willReturn(aResponse().withStatus(200))); |
| 104 | + wireMock.stubFor(get(urlEqualTo(urlPath)).willReturn(aResponse().withStatus(200).withBody(filebytes))); |
91 | 105 | wireMock.start();
|
92 | 106 |
|
93 | 107 | GradleRunner runner = GradleRunner.create().withProjectDir(getProjectDir("jdk-download"))
|
94 | 108 | .withArguments(taskname,
|
95 | 109 | "-Dlocal.repo.path=" + getLocalTestRepoPath(),
|
96 |
| - "-Dtests.jdk_version=" + FAKE_JDK_VERSION, |
97 |
| - "-Dtests.jdk_repo=" + wireMock.baseUrl()) |
| 110 | + "-Dtests.jdk_version=" + version, |
| 111 | + "-Dtests.jdk_repo=" + wireMock.baseUrl(), |
| 112 | + "-i") |
98 | 113 | .withPluginClasspath();
|
99 | 114 |
|
100 | 115 | BuildResult result = runner.build();
|
|
0 commit comments