forked from processing/processing
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to strategies for supporting AdoptOpenJDK in build.
As part of processing#5750, added support for AdoptOpenJDK (also required for - OracleDownloadUrlGenerator - AdoptOpenJdkDownloadUrlGenerator which support Downloader. Tests and documentation included (required refactor of build.xml).
- Loading branch information
1 parent
117d1a5
commit 79f6353
Showing
6 changed files
with
276 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,81 @@ | ||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
|
||
/* | ||
Part of the Processing project - http://processing.org | ||
Copyright (c) 2012-19 The Processing Foundation | ||
Copyright (c) 2004-12 Ben Fry and Casey Reas | ||
Copyright (c) 2001-04 Massachusetts Institute of Technology | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
version 2, as published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
/** | ||
* Utility to generate | ||
* Utility to generate download URLs from AdoptOpenJDK. | ||
*/ | ||
public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { | ||
|
||
// "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.1_13.tar.gz"; | ||
private static final String BASE_URL = "https://github.com/AdoptOpenJDK/openjdk%d-binaries/releases/download/jdk-%d.%d.%d%2B%d/OpenJDK%dU-%s_%d.%d.%d_%d.tar.gz"; | ||
private static final String BASE_URL = "https://github.com/AdoptOpenJDK/openjdk%d-binaries/releases/download/jdk-%d.%d.%d%%2B%d/OpenJDK%dU-%s_%d.%d.%d_%d.%s"; | ||
|
||
@Override | ||
public String buildUrl(String platform, boolean jdk, int train, int version, int update, int build, String flavor, String hash) { | ||
String filename = buildDownloadRemoteFilename(platform); | ||
String fileExtension = buildFileExtension(platform); | ||
return String.format( | ||
BASE_URL, | ||
train, | ||
train, | ||
version, | ||
update, | ||
build, | ||
train, | ||
filename, | ||
train, | ||
version, | ||
update, | ||
build | ||
build, | ||
fileExtension | ||
); | ||
} | ||
|
||
/** | ||
* Build a the filename (the "flavor") that is expected on AdoptOpenJDK. | ||
* | ||
* @param downloadPlatform The platform for which the download URL is being generated like | ||
* "macos" or "linux64". | ||
* @return The artifact name without extension like "jdk_x64_mac_hotspot". | ||
*/ | ||
private String buildDownloadRemoteFilename(String downloadPlatform) { | ||
switch (downloadPlatform.toLowerCase()) { | ||
case "windows32": return "jdk_x86-32_windows_hotspot"; | ||
case "windows64": return "jdk_x64_windows_hotspot"; | ||
case "macos": return "jdk_x64_mac_hotspot"; | ||
case "linux32": throw new RuntimeException("Linux 32bit no longer supported by AdoptOpenJDK."); | ||
case "linux32": throw new RuntimeException("Linux32 not supported by AdoptOpenJDK."); | ||
case "linux64": return "jdk_x64_linux_hotspot"; | ||
case "linuxArm": return "jdk_aarch64_linux_hotspot"; | ||
default: throw new RuntimeException("Unknown platform: " + downloadPlatform); | ||
} | ||
} | ||
|
||
/** | ||
* Determine the download file extension. | ||
* | ||
* @param downloadPlatform The platform for which the download URL is being generated like | ||
* "macos" or "linux64". | ||
* @return The file extension without leading period like "zip" or "tar.gz". | ||
*/ | ||
private String buildFileExtension(String downloadPlatform) { | ||
return downloadPlatform.startsWith("windows") ? "zip" : "tar.gz"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.Ignore; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AdoptOpenJdkDownloadUrlGeneratorTest { | ||
|
||
private static final String EXPECTED_WIN64_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_windows_hotspot_11.0.1_13.zip"; | ||
private static final String EXPECTED_MAC_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_mac_hotspot_11.0.1_13.tar.gz"; | ||
private static final String EXPECTED_LINUX_URL = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_x64_linux_hotspot_11.0.1_13.tar.gz"; | ||
|
||
private static final boolean JDK = true; | ||
private static final int TRAIN = 11; | ||
private static final int VERSION = 0; | ||
private static final int UPDATE = 1; | ||
private static final int BUILD = 13; | ||
private static final String FLAVOR_SUFFIX = "-x64.tar.gz"; | ||
private static final String HASH = ""; | ||
|
||
private AdoptOpenJdkDownloadUrlGenerator urlGenerator; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
urlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); | ||
} | ||
|
||
@Test | ||
public void testBuildUrlWindows() { | ||
String url = urlGenerator.buildUrl( | ||
"windows64", | ||
JDK, | ||
TRAIN, | ||
VERSION, | ||
UPDATE, | ||
BUILD, | ||
"windows" + FLAVOR_SUFFIX, | ||
HASH | ||
); | ||
|
||
assertEquals( | ||
EXPECTED_WIN64_URL, | ||
url | ||
); | ||
} | ||
|
||
@Test | ||
public void testBuildUrlMac() { | ||
String url = urlGenerator.buildUrl( | ||
"macos", | ||
JDK, | ||
TRAIN, | ||
VERSION, | ||
UPDATE, | ||
BUILD, | ||
"mac" + FLAVOR_SUFFIX, | ||
HASH | ||
); | ||
|
||
assertEquals( | ||
EXPECTED_MAC_URL, | ||
url | ||
); | ||
} | ||
|
||
@Test | ||
public void testBuildUrlLinux() { | ||
String url = urlGenerator.buildUrl( | ||
"linux64", | ||
JDK, | ||
TRAIN, | ||
VERSION, | ||
UPDATE, | ||
BUILD, | ||
"linux64" + FLAVOR_SUFFIX, | ||
HASH | ||
); | ||
|
||
assertEquals( | ||
EXPECTED_LINUX_URL, | ||
url | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.Ignore; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class OracleDownloadUrlGeneratorTest { | ||
|
||
private static final String EXPECTED_URL = "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-macosx-x64.dmg"; | ||
|
||
private OracleDownloadUrlGenerator urlGenerator; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
urlGenerator = new OracleDownloadUrlGenerator(); | ||
} | ||
|
||
@Test | ||
public void testBuildUrl() { | ||
String url = urlGenerator.buildUrl( | ||
"macos", | ||
true, | ||
1, | ||
8, | ||
131, | ||
11, | ||
"macosx-x64.dmg", | ||
"d54c1d3a095b4ff2b6607d096fa80163" | ||
); | ||
|
||
assertEquals( | ||
EXPECTED_URL, | ||
url | ||
); | ||
} | ||
|
||
} |