From 2d5683d4f9ca4526e5a2835578ed58731e9ad3d5 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Fri, 17 Jan 2020 16:41:40 -0500 Subject: [PATCH 01/15] prevent Rename from allowing Java identifiers (5828, 5906) --- java/src/processing/mode/java/pdex/Rename.java | 4 ++-- todo.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/src/processing/mode/java/pdex/Rename.java b/java/src/processing/mode/java/pdex/Rename.java index 7c5c6bca2..1941f4135 100644 --- a/java/src/processing/mode/java/pdex/Rename.java +++ b/java/src/processing/mode/java/pdex/Rename.java @@ -129,8 +129,8 @@ class Rename { final String newName = textField.getText().trim(); if (!newName.isEmpty()) { if (newName.length() >= 1 && - newName.chars().limit(1).allMatch(Character::isUnicodeIdentifierStart) && - newName.chars().skip(1).allMatch(Character::isUnicodeIdentifierPart)) { + newName.chars().limit(1).allMatch(Character::isJavaIdentifierStart) && + newName.chars().skip(1).allMatch(Character::isJavaIdentifierPart)) { rename(ps, binding, newName); window.setVisible(false); } else { diff --git a/todo.txt b/todo.txt index 804bb9944..2dc67893c 100755 --- a/todo.txt +++ b/todo.txt @@ -74,6 +74,9 @@ X https://github.com/processing/processing/issues/5805 X https://github.com/processing/processing/pull/5909 X updtes to Ukrainian translation X https://github.com/processing/processing/pull/5944 +X rename-variable menu allows Java identifiers +X https://github.com/processing/processing/issues/5828 +X https://github.com/processing/processing/pull/5906 sampottinger X Fix JDK naming and cleanup in ant build @@ -129,9 +132,6 @@ _ windows anti-malware leaves browser stuck at 100% _ https://github.com/processing/processing/issues/5893 -quick fixes -_ rename-variable menu allows Java identifiers -_ https://github.com/processing/processing/pull/5906 from Casey _ Math for BLEND incorrect in the reference? From 96b4e841b9893a81187188ad2530c24473b971cf Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 13:54:33 -0500 Subject: [PATCH 02/15] further simplifying the jdk downloader --- .../src/AdoptOpenJdkDownloadUrlGenerator.java | 20 ++----- .../jre/src/GluonHqDownloadUrlGenerator.java | 14 ++--- .../test/OracleDownloadUrlGeneratorTest.java | 59 ------------------- core/todo.txt | 8 ++- todo.txt | 2 + 5 files changed, 18 insertions(+), 85 deletions(-) delete mode 100644 build/jre/test/OracleDownloadUrlGeneratorTest.java diff --git a/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java b/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java index 92b40e1b6..5ffb6b449 100644 --- a/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java +++ b/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java @@ -23,7 +23,7 @@ * Utility to generate download URLs from AdoptOpenJDK. */ public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { - static private final String BASE_URL = + static private final String URL_FORMAT = "https://github.com/AdoptOpenJDK/openjdk%d-binaries/releases/download/jdk-%d.%d.%d%%2B%d/OpenJDK%dU-%s_%d.%d.%d_%d.%s"; @@ -37,9 +37,9 @@ public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { } String filename = buildDownloadRemoteFilename(platform); - String fileExtension = buildFileExtension(platform); + String fileExtension = platform.startsWith("windows") ? "zip" : "tar.gz"; return String.format( - BASE_URL, + URL_FORMAT, train, train, version, @@ -63,7 +63,7 @@ public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { * "macos" or "linux64". * @return The artifact name without extension like "jdk_x64_mac_hotspot". */ - private String buildDownloadRemoteFilename(String downloadPlatform) { + static private String buildDownloadRemoteFilename(String downloadPlatform) { switch (downloadPlatform.toLowerCase()) { case "windows32": return "jdk_x86-32_windows_hotspot"; case "windows64": return "jdk_x64_windows_hotspot"; @@ -74,16 +74,4 @@ public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { 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"; - } } diff --git a/build/jre/src/GluonHqDownloadUrlGenerator.java b/build/jre/src/GluonHqDownloadUrlGenerator.java index 77ef62677..94ff7c634 100644 --- a/build/jre/src/GluonHqDownloadUrlGenerator.java +++ b/build/jre/src/GluonHqDownloadUrlGenerator.java @@ -24,13 +24,13 @@ * URL generator for downloading JFX directly from OpenJFX's sponsor Gluon. */ public class GluonHqDownloadUrlGenerator extends DownloadUrlGenerator { - - private static final String TEMPLATE_URL = "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; + static private final String URL_FORMAT = + "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; @Override - public String buildUrl(String platform, String component, int train, int version, int update, - int build, String flavor) { - + public String buildUrl(String platform, String component, + int train, int version, int update, + int build, String flavor) { String platformLower = platform.toLowerCase(); String platformShort; @@ -43,8 +43,6 @@ public class GluonHqDownloadUrlGenerator extends DownloadUrlGenerator { } else { throw new RuntimeException("Unsupported platform for JFX: " + platform); } - - return String.format(TEMPLATE_URL, train, version, update, platformShort); + return String.format(URL_FORMAT, train, version, update, platformShort); } - } diff --git a/build/jre/test/OracleDownloadUrlGeneratorTest.java b/build/jre/test/OracleDownloadUrlGeneratorTest.java deleted file mode 100644 index 2124c210f..000000000 --- a/build/jre/test/OracleDownloadUrlGeneratorTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- 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 -*/ - -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", - "jdk", - 1, - 8, - 131, - 11, - "macosx-x64.dmg", - "d54c1d3a095b4ff2b6607d096fa80163" - ); - - assertEquals( - EXPECTED_URL, - url - ); - } - -} diff --git a/core/todo.txt b/core/todo.txt index c60cd6721..ca2932a9c 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -22,8 +22,6 @@ _ removing AWT from core _ https://github.com/codeanticode/processing-lwjgl/wiki#making-awt-optional-in-papplet _ move loadImage() into surface -_ size() issues on Mojave? (3.4 works, 3.5.3 does not) -_ https://github.com/processing/processing/issues/5791 _ use exit event to set mouseY to 0 on macOS _ https://github.com/processing/processing/pull/5796/files @@ -31,6 +29,12 @@ _ possible fix for precision issues with PDF _ https://github.com/processing/processing/issues/5801#issuecomment-466632459 +high +_ size() issues on Mojave? (3.4 works, 3.5.3 does not) +_ https://github.com/processing/processing/issues/5791 +_ closed for now; unable to confirm anything in the thread + + high-ish _ Update isAccessible() in Table to use JDK 11 reflection methods _ https://github.com/processing/processing4/issues/3 diff --git a/todo.txt b/todo.txt index 2dc67893c..4f2a6a23f 100755 --- a/todo.txt +++ b/todo.txt @@ -120,6 +120,8 @@ _ change help menu links to go to newer FAQ and the rest open issues +_ update the docs repo +_ check with Casey re: shallow clone or approach _ reliable getLibraryFolder() and getDocumentsFolder() methods in MacPlatform _ https://github.com/processing/processing4/issues/9 _ further streamline the downloader From 36bb9ab958ebfcbc428eb249caebbb2d2a9ae58c Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 13:57:05 -0500 Subject: [PATCH 03/15] remove hash entry from the test --- .../test/AdoptOpenJdkDownloadUrlGeneratorTest.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java b/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java index 4a07fa990..c8c1824d9 100644 --- a/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java +++ b/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java @@ -40,7 +40,6 @@ public class AdoptOpenJdkDownloadUrlGeneratorTest { 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; @@ -58,8 +57,7 @@ public class AdoptOpenJdkDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "windows" + FLAVOR_SUFFIX, - HASH + "windows" + FLAVOR_SUFFIX ); assertEquals( @@ -77,8 +75,7 @@ public class AdoptOpenJdkDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "mac" + FLAVOR_SUFFIX, - HASH + "mac" + FLAVOR_SUFFIX ); assertEquals( @@ -96,8 +93,7 @@ public class AdoptOpenJdkDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "linux64" + FLAVOR_SUFFIX, - HASH + "linux64" + FLAVOR_SUFFIX ); assertEquals( @@ -115,8 +111,7 @@ public class AdoptOpenJdkDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "linuxArm" + FLAVOR_SUFFIX, - HASH + "linuxArm" + FLAVOR_SUFFIX ); assertEquals( From 48c3a0ba599b68b7218c46bb7dfc696d71989c69 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 14:00:00 -0500 Subject: [PATCH 04/15] remove Oracle test --- build/jre/build.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/build/jre/build.xml b/build/jre/build.xml index f39ed41a1..f1eb42f6b 100644 --- a/build/jre/build.xml +++ b/build/jre/build.xml @@ -43,7 +43,6 @@ - From 47dec86327a0432801432e7751f57047e2adabad Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 14:00:10 -0500 Subject: [PATCH 05/15] remove HASH variable since unused --- build/jre/test/GluonHqDownloadUrlGeneratorTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/build/jre/test/GluonHqDownloadUrlGeneratorTest.java b/build/jre/test/GluonHqDownloadUrlGeneratorTest.java index 0f1ca2faa..163d3d23d 100644 --- a/build/jre/test/GluonHqDownloadUrlGeneratorTest.java +++ b/build/jre/test/GluonHqDownloadUrlGeneratorTest.java @@ -39,7 +39,6 @@ public class GluonHqDownloadUrlGeneratorTest { private static final int UPDATE = 2; private static final int BUILD = 0; private static final String FLAVOR_SUFFIX = ".zip"; - private static final String HASH = ""; private AdoptOpenJdkDownloadUrlGenerator urlGenerator; @@ -57,8 +56,7 @@ public class GluonHqDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "windows" + FLAVOR_SUFFIX, - HASH + "windows" + FLAVOR_SUFFIX ); assertEquals( @@ -76,8 +74,7 @@ public class GluonHqDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "mac" + FLAVOR_SUFFIX, - HASH + "mac" + FLAVOR_SUFFIX ); assertEquals( @@ -95,8 +92,7 @@ public class GluonHqDownloadUrlGeneratorTest { VERSION, UPDATE, BUILD, - "linux64" + FLAVOR_SUFFIX, - HASH + "linux64" + FLAVOR_SUFFIX ); assertEquals( From 2e97a52f2d15b2abe14fcced6a33f1fcb4f51d7c Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 14:11:35 -0500 Subject: [PATCH 06/15] remove jre alias, support jdk or jfx, always lowercase --- build/build.xml | 10 ++++------ build/jre/src/Downloader.java | 21 +++++++-------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/build/build.xml b/build/build.xml index c0ff1817f..c1a2aabc5 100644 --- a/build/build.xml +++ b/build/build.xml @@ -366,13 +366,12 @@ - @@ -380,14 +379,13 @@ - diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index 575faa824..ef216a032 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -39,7 +39,7 @@ public class Downloader extends Task { private int update; // Update 131 private int build; // Build 11 - private String component; // "jre", "jdk", or "jfx" + private String component; // "jdk" or "jfx" private String flavor; // Like "zip" private String path; // target path @@ -103,10 +103,10 @@ public class Downloader extends Task { /** * Indicate what component or release type of Java is being downloaded. * - * @param component The component to download like "JDK", "JRE", or "OpenJFX". + * @param component The component to download like "jdk" or "jfx" */ public void setComponent(String component) { - this.component = component; + this.component = component.toLowerCase(); } @@ -131,7 +131,7 @@ public class Downloader extends Task { /** - * Download the JDK or JRE. + * Entry point called by Ant */ public void execute() throws BuildException { if (train == 0) { @@ -139,8 +139,7 @@ public class Downloader extends Task { throw new BuildException("Train (i.e. 1 or 11) must be set"); } - boolean isJava11 = train == 11; - if (!isJava11 && version == 0) { + if (train != 11 && version == 0) { throw new BuildException("Version (i.e. 7 or 8) must be set"); } @@ -281,18 +280,12 @@ public class Downloader extends Task { * @return The to be downloaded or empty if there is no download required. */ private Optional getDownloadItem() { - // Determine download type - boolean isJavaDownload = component.equalsIgnoreCase("jdk"); - isJavaDownload = isJavaDownload || component.equalsIgnoreCase("jre"); - - boolean isJfxDownload = component.equalsIgnoreCase("jfx"); - DownloadUrlGenerator downloadUrlGenerator; // Determine url generator - if (isJavaDownload) { + if (component.equals("jdk")) { downloadUrlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); - } else if (isJfxDownload) { + } else if (component.equals("jfx")) { downloadUrlGenerator = new GluonHqDownloadUrlGenerator(); } else { throw new RuntimeException("Do not know how to download: " + component); From 4fa07698f88065a85fc96267d5d9f03cb0405018 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 14:47:46 -0500 Subject: [PATCH 07/15] simplifying the downloader further --- build/jre/src/DownloadItem.java | 77 --------- build/jre/src/DownloadUrlGenerator.java | 31 ++-- build/jre/src/Downloader.java | 146 ++++++------------ .../jre/src/GluonHqDownloadUrlGenerator.java | 2 +- 4 files changed, 62 insertions(+), 194 deletions(-) delete mode 100644 build/jre/src/DownloadItem.java diff --git a/build/jre/src/DownloadItem.java b/build/jre/src/DownloadItem.java deleted file mode 100644 index 30e716f43..000000000 --- a/build/jre/src/DownloadItem.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2014-19 The Processing Foundation - - 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 -*/ - -import java.util.Optional; - - -/** - * Data structure describing an item to be downloaded as part the Processing build. - */ -public class DownloadItem { - - private String url; - private String localPath; - private Optional cookie; - - /** - * Create a new download item. - * - * @param newUrl The remote URL at which the download can be found (via GET). - * @param newLocalPath The local path to which the file should be written. - * @param newCookie Optional cookie that, if present, should be given to the server along with the - * GET request for the download contents. - */ - public DownloadItem(String newUrl, String newLocalPath, Optional newCookie) { - url = newUrl; - localPath = newLocalPath; - cookie = newCookie; - } - - /** - * Determine where the download can be requested. - * - * @return The remote URL at which the download can be found (via GET). - */ - public String getUrl() { - return url; - } - - /** - * Determine to where the download should be saved. - * - * @return The local path to which the file should be written. - */ - public String getLocalPath() { - return localPath; - } - - /** - * Determine if and what cookie should be given as part of the download request. - * - * @return Optional cookie that, if present, should be given to the server along with the - * GET request for the download contents. Should be ignored otherwise. - */ - public Optional getCookie() { - return cookie; - } - - -} diff --git a/build/jre/src/DownloadUrlGenerator.java b/build/jre/src/DownloadUrlGenerator.java index 08e3541d1..cce2c9f44 100644 --- a/build/jre/src/DownloadUrlGenerator.java +++ b/build/jre/src/DownloadUrlGenerator.java @@ -19,8 +19,25 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2019-20 The Processing Foundation + + 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 +*/ -import java.util.Optional; /** * Abstract base class for strategy to generate download URLs. @@ -44,16 +61,6 @@ public abstract class DownloadUrlGenerator { int train, int version, int update, int build, String flavor); - /** - * Get the cookie that should be used in downloading the target component. - * - * @return Optional that is empty if no cookie should be used or optional with the string cookie - * value if one should be used. - */ - public Optional getCookie() { - return Optional.empty(); - } - /** * Determine the name of the file to which the remote file should be saved. * @@ -78,8 +85,6 @@ public abstract class DownloadUrlGenerator { } else { versionStr = String.format("-%du%d-%s", version, update, flavor); } - return baseFilename + versionStr; } - } diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index ef216a032..9921c1712 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2014-19 The Processing Foundation + Copyright (c) 2014-20 The Processing Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -31,8 +31,6 @@ import org.apache.tools.ant.Task; * Ant Task for downloading the latest JRE, JDK, or OpenJFX release. */ public class Downloader extends Task { - private static final boolean PRINT_LOGGING = true; - private String platform; // macos private int train; // Java 11 (was 1 through Java 8) private int version; // 0 (was 8 prior to Java 9) @@ -44,9 +42,6 @@ public class Downloader extends Task { private String path; // target path - /** - * Create a new downloader without tag attributes filled in. - **/ public Downloader() { } @@ -163,46 +158,63 @@ public class Downloader extends Task { * Download the package from AdoptOpenJDK or Oracle. */ void download() throws IOException { - DownloadItem downloadItem; + DownloadUrlGenerator downloadUrlGenerator; - // Determine url generator for task - Optional downloadItemMaybe = getDownloadItem(); - if (downloadItemMaybe.isEmpty()) { - return; // There is nothing to do. + // Determine url generator + if (component.equals("jdk")) { + downloadUrlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); + } else if (component.equals("jfx")) { + downloadUrlGenerator = new GluonHqDownloadUrlGenerator(); } else { - downloadItem = downloadItemMaybe.get(); + throw new RuntimeException("Do not know how to download: " + component); } - // Build URL and path if (path == null) { - path = downloadItem.getLocalPath(); + path = downloadUrlGenerator.getLocalFilename( + platform, + component, + train, + version, + update, + build, + flavor + ); } - String url = downloadItem.getUrl(); + String url = downloadUrlGenerator.buildUrl( + platform, + component, + train, + version, + update, + build, + flavor + ); - // Downlaod - println("Attempting download at " + url); + System.out.println("Attempting download at " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + /* Optional cookieMaybe = downloadItem.getCookie(); if (cookieMaybe.isPresent()) { conn.setRequestProperty("Cookie", cookieMaybe.get()); } + */ - //printHeaders(conn); - //conn.connect(); while (conn.getResponseCode() == 302 || conn.getResponseCode() == 301) { Map> headers = conn.getHeaderFields(); List location = headers.get("Location"); if (location.size() == 1) { url = location.get(0); - println("Redirecting to " + url); + System.out.println("Redirecting to " + url); } else { - throw new BuildException("Got " + location.size() + " locations."); + // TODO should + throw new BuildException("Received multiple redirect locations"); } + /* List cookies = headers.get("Set-Cookie"); conn = (HttpURLConnection) new URL(url).openConnection(); if (cookies != null) { @@ -214,7 +226,7 @@ public class Downloader extends Task { if (cookieMaybe.isPresent()) { conn.setRequestProperty("Cookie", cookieMaybe.get()); } - + */ conn.connect(); } @@ -223,8 +235,8 @@ public class Downloader extends Task { BufferedInputStream bis = new BufferedInputStream(input); File outputFile = new File(path); //folder, filename); - String msg = String.format("Downloading %s from %s%n", outputFile.getAbsolutePath(), url); - println(msg); + System.out.format("Downloading %s from %s%n", + outputFile.getAbsolutePath(), url); // Write to a temp file so that we don't have an incomplete download // masquerading as a good archive. @@ -242,7 +254,8 @@ public class Downloader extends Task { if (outputFile.exists()) { if (!outputFile.delete()) { - throw new BuildException("Could not delete old download: " + outputFile.getAbsolutePath()); + throw new BuildException("Could not delete old download: " + + outputFile.getAbsolutePath()); } } if (!tempFile.renameTo(outputFile)) { @@ -256,91 +269,18 @@ public class Downloader extends Task { } } - /** - * Print the headers used for {URLConnection}. - */ - static void printHeaders(URLConnection conn) { + + static private void printHeaders(URLConnection conn) { Map> headers = conn.getHeaderFields(); Set>> entrySet = headers.entrySet(); for (Map.Entry> entry : entrySet) { String headerName = entry.getKey(); - println("Header Name:" + headerName); + System.err.println("Header Name:" + headerName); List headerValues = entry.getValue(); for (String value : headerValues) { - print("Header value:" + value); + System.err.println("Header Value:" + value); } - printEmptyLine(); - printEmptyLine(); + System.err.println(); } } - - /** - * Get the item to be downloaded for this task. - * - * @return The to be downloaded or empty if there is no download required. - */ - private Optional getDownloadItem() { - DownloadUrlGenerator downloadUrlGenerator; - - // Determine url generator - if (component.equals("jdk")) { - downloadUrlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); - } else if (component.equals("jfx")) { - downloadUrlGenerator = new GluonHqDownloadUrlGenerator(); - } else { - throw new RuntimeException("Do not know how to download: " + component); - } - - // Build download item - String path = downloadUrlGenerator.getLocalFilename( - platform, - component, - train, - version, - update, - build, - flavor - ); - - String url = downloadUrlGenerator.buildUrl( - platform, - component, - train, - version, - update, - build, - flavor - ); - - return Optional.of(new DownloadItem(url, path, downloadUrlGenerator.getCookie())); - } - - /** - * Print a line out to console if logging is enabled. - * - * @param message The message to be printed. - */ - private static void println(String message) { - if (PRINT_LOGGING) { - System.out.println(message); - } - } - - /** - * Print a line out to console if logging is enabled without a newline. - * - * @param message The message to be printed. - */ - private static void print(String message) { - if (PRINT_LOGGING) { - System.out.print(message); - } - } - - /** - * Print an empty line to the system.out. - */ - private static void printEmptyLine() { - println(""); - } } diff --git a/build/jre/src/GluonHqDownloadUrlGenerator.java b/build/jre/src/GluonHqDownloadUrlGenerator.java index 94ff7c634..e5023a562 100644 --- a/build/jre/src/GluonHqDownloadUrlGenerator.java +++ b/build/jre/src/GluonHqDownloadUrlGenerator.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2014-20 The Processing Foundation + Copyright (c) 2019-20 The Processing Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License From 22a8e14904f430dcdb0f51be9c3405051379043e Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 14:50:27 -0500 Subject: [PATCH 08/15] local filename is never overridden, move into main class --- build/jre/src/DownloadUrlGenerator.java | 27 ------------------------- build/jre/src/Downloader.java | 27 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/build/jre/src/DownloadUrlGenerator.java b/build/jre/src/DownloadUrlGenerator.java index cce2c9f44..0435cec40 100644 --- a/build/jre/src/DownloadUrlGenerator.java +++ b/build/jre/src/DownloadUrlGenerator.java @@ -60,31 +60,4 @@ public abstract class DownloadUrlGenerator { public abstract String buildUrl(String platform, String component, int train, int version, int update, int build, String flavor); - - /** - * Determine the name of the file to which the remote file should be saved. - * - * @param downloadPlatform The platform for which the download URL is being generated like - * "macos" or "linux64". - * @param component The component to download like "JDK", "JRE", or "JFX". - * @param train The JDK train (like 1 or 11). - * @param version The JDK version (like 8 or 1). - * @param update The update (like 13). - * @param build The build number (like 133). - * @param flavor The flavor like "macosx-x64.dmg". - */ - public String getLocalFilename(String downloadPlatform, String component, - int train, int version, int update, - int build, String flavor) { - - String baseFilename = component.toLowerCase(); - - String versionStr; - if (update == 0) { - versionStr = String.format("-%d-%s", version, flavor); - } else { - versionStr = String.format("-%du%d-%s", version, update, flavor); - } - return baseFilename + versionStr; - } } diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index 9921c1712..c05afe442 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -170,7 +170,7 @@ public class Downloader extends Task { } if (path == null) { - path = downloadUrlGenerator.getLocalFilename( + path = getLocalFilename( platform, component, train, @@ -270,6 +270,31 @@ public class Downloader extends Task { } + /** + * Determine the name of the file to which the remote file should be saved. + * + * @param downloadPlatform The platform for which the download URL is being generated like + * "macos" or "linux64". + * @param component The component to download like "JDK", "JRE", or "JFX". + * @param train The JDK train (like 1 or 11). + * @param version The JDK version (like 8 or 1). + * @param update The update (like 13). + * @param build The build number (like 133). + * @param flavor The flavor like "macosx-x64.dmg". + */ + public String getLocalFilename(String downloadPlatform, String component, + int train, int version, int update, + int build, String flavor) { + String versionStr; + if (update == 0) { + versionStr = String.format("-%d-%s", version, flavor); + } else { + versionStr = String.format("-%du%d-%s", version, update, flavor); + } + return component + versionStr; + } + + static private void printHeaders(URLConnection conn) { Map> headers = conn.getHeaderFields(); Set>> entrySet = headers.entrySet(); From 9d79ff63fc2cba6e8eee61d2b61b84960a5884ff Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 15:05:20 -0500 Subject: [PATCH 09/15] simplify further; trade three distinct classes for two url creation methods --- build/jre/build.xml | 2 +- .../src/AdoptOpenJdkDownloadUrlGenerator.java | 77 ----------- build/jre/src/DownloadUrlGenerator.java | 63 --------- build/jre/src/Downloader.java | 97 +++++++++----- .../jre/src/GluonHqDownloadUrlGenerator.java | 48 ------- .../AdoptOpenJdkDownloadUrlGeneratorTest.java | 123 ------------------ .../test/GluonHqDownloadUrlGeneratorTest.java | 104 --------------- 7 files changed, 66 insertions(+), 448 deletions(-) delete mode 100644 build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java delete mode 100644 build/jre/src/DownloadUrlGenerator.java delete mode 100644 build/jre/src/GluonHqDownloadUrlGenerator.java delete mode 100644 build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java delete mode 100644 build/jre/test/GluonHqDownloadUrlGeneratorTest.java diff --git a/build/jre/build.xml b/build/jre/build.xml index f1eb42f6b..b3e2a6800 100644 --- a/build/jre/build.xml +++ b/build/jre/build.xml @@ -42,7 +42,7 @@ - + diff --git a/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java b/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java deleted file mode 100644 index 5ffb6b449..000000000 --- a/build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2019-20 The Processing Foundation - - 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 download URLs from AdoptOpenJDK. - */ -public class AdoptOpenJdkDownloadUrlGenerator extends DownloadUrlGenerator { - static private final String URL_FORMAT = - "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, String component, - int train, int version, int update, - int build, String flavor) { - - if (!component.equalsIgnoreCase("jdk")) { - throw new RuntimeException("Can only generate JDK download URLs for AdoptOpenJDK."); - } - - String filename = buildDownloadRemoteFilename(platform); - String fileExtension = platform.startsWith("windows") ? "zip" : "tar.gz"; - return String.format( - URL_FORMAT, - train, - train, - version, - update, - build, - train, - filename, - train, - version, - update, - 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". - */ - static private String buildDownloadRemoteFilename(String downloadPlatform) { - switch (downloadPlatform.toLowerCase()) { - case "windows32": return "jdk_x86-32_windows_hotspot"; - case "windows64": return "jdk_x64_windows_hotspot"; - case "macosx64": return "jdk_x64_mac_hotspot"; - 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); - } - } -} diff --git a/build/jre/src/DownloadUrlGenerator.java b/build/jre/src/DownloadUrlGenerator.java deleted file mode 100644 index 0435cec40..000000000 --- a/build/jre/src/DownloadUrlGenerator.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2014-19 The Processing Foundation - - 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 -*/ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2019-20 The Processing Foundation - - 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 -*/ - - -/** - * Abstract base class for strategy to generate download URLs. - */ -public abstract class DownloadUrlGenerator { - - /** - * Determine the URL at which the artifact can be downloaded. - * - * @param platform The platform for which the download URL is being generated like "macos" or - * "linux64". - * @param component The component to download like "JDK", "JRE", or "JFX". - * @param train The JDK train (like 1 or 11). - * @param version The JDK version (like 8 or 1). - * @param update The update (like 13). - * @param build The build number (like 133). - * @param flavor The flavor like "macosx-x64.dmg". - * @param hash The hash like "d54c1d3a095b4ff2b6607d096fa80163". - */ - public abstract String buildUrl(String platform, String component, - int train, int version, int update, - int build, String flavor); -} diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index c05afe442..381bd768c 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -51,7 +51,7 @@ public class Downloader extends Task { * @param platform The platfom for which files are being downloaded like macosx. */ public void setPlatform(String platform) { - this.platform = platform; + this.platform = platform.toLowerCase(); } @@ -158,40 +158,19 @@ public class Downloader extends Task { * Download the package from AdoptOpenJDK or Oracle. */ void download() throws IOException { - DownloadUrlGenerator downloadUrlGenerator; + if (path == null) { + path = getLocalFilename(component, version, update, flavor); + } - // Determine url generator + String url = null; if (component.equals("jdk")) { - downloadUrlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); + url = adoptOpenJdkUrl(platform, component, train, version, update, build, flavor); } else if (component.equals("jfx")) { - downloadUrlGenerator = new GluonHqDownloadUrlGenerator(); + url = gluonHqUrl(platform, component, train, version, update); } else { throw new RuntimeException("Do not know how to download: " + component); } - - if (path == null) { - path = getLocalFilename( - platform, - component, - train, - version, - update, - build, - flavor - ); - } - - String url = downloadUrlGenerator.buildUrl( - platform, - component, - train, - version, - update, - build, - flavor - ); - - System.out.println("Attempting download at " + url); + System.out.println("Downloading from " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); @@ -270,6 +249,61 @@ public class Downloader extends Task { } + static private String adoptOpenJdkUrl(String platform, String component, + int train, int version, int update, + int build, String flavor) { + final String URL_FORMAT = "https://github.com/AdoptOpenJDK/openjdk%d-binaries/releases/download/jdk-%d.%d.%d%%2B%d/OpenJDK%dU-%s_%d.%d.%d_%d.%s"; + + String filename = null; + switch (platform) { + case "windows32": filename = "jdk_x86-32_windows_hotspot"; break; + case "windows64": filename = "jdk_x64_windows_hotspot"; break; + case "macosx64": filename = "jdk_x64_mac_hotspot"; break; + case "linux32": throw new RuntimeException("32-bit Linux not supported by AdoptOpenJDK."); + case "linux64": filename = "jdk_x64_linux_hotspot"; break; + case "linuxarm": filename = "jdk_aarch64_linux_hotspot"; break; + default: throw new RuntimeException("Unknown platform: " + platform); + } + + String fileExtension = platform.startsWith("windows") ? "zip" : "tar.gz"; + + return String.format( + URL_FORMAT, + train, + train, + version, + update, + build, + train, + filename, + train, + version, + update, + build, + fileExtension + ); + } + + + static private String gluonHqUrl(String platform, String component, + int train, int version, int update) { + final String URL_FORMAT = + "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; + + String platformShort; + if (platform.contains("linux")) { + platformShort = "linux"; + } else if (platform.contains("mac")) { + platformShort = "mac"; + } else if (platform.contains("windows")) { + platformShort = "windows"; + } else { + throw new RuntimeException("Unsupported platform for JFX: " + platform); + } + return String.format(URL_FORMAT, train, version, update, platformShort); + } + + /** * Determine the name of the file to which the remote file should be saved. * @@ -282,9 +316,8 @@ public class Downloader extends Task { * @param build The build number (like 133). * @param flavor The flavor like "macosx-x64.dmg". */ - public String getLocalFilename(String downloadPlatform, String component, - int train, int version, int update, - int build, String flavor) { + static private String getLocalFilename(String component, int version, + int update, String flavor) { String versionStr; if (update == 0) { versionStr = String.format("-%d-%s", version, flavor); diff --git a/build/jre/src/GluonHqDownloadUrlGenerator.java b/build/jre/src/GluonHqDownloadUrlGenerator.java deleted file mode 100644 index e5023a562..000000000 --- a/build/jre/src/GluonHqDownloadUrlGenerator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2019-20 The Processing Foundation - - 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 -*/ - - -/** - * URL generator for downloading JFX directly from OpenJFX's sponsor Gluon. - */ -public class GluonHqDownloadUrlGenerator extends DownloadUrlGenerator { - static private final String URL_FORMAT = - "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; - - @Override - public String buildUrl(String platform, String component, - int train, int version, int update, - int build, String flavor) { - String platformLower = platform.toLowerCase(); - - String platformShort; - if (platformLower.contains("linux")) { - platformShort = "linux"; - } else if (platformLower.contains("mac")) { - platformShort = "mac"; - } else if (platformLower.contains("windows")) { - platformShort = "windows"; - } else { - throw new RuntimeException("Unsupported platform for JFX: " + platform); - } - return String.format(URL_FORMAT, train, version, update, platformShort); - } -} diff --git a/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java b/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java deleted file mode 100644 index c8c1824d9..000000000 --- a/build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- 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 -*/ - - -import org.junit.Before; -import org.junit.Test; - -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 String EXPECTED_LINUX_URL_ARM = "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 COMPONENT = "jdk"; - 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 AdoptOpenJdkDownloadUrlGenerator urlGenerator; - - @Before - public void setUp() throws Exception { - urlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); - } - - @Test - public void testBuildUrlWindows() { - String url = urlGenerator.buildUrl( - "windows64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "windows" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_WIN64_URL, - url - ); - } - - @Test - public void testBuildUrlMac() { - String url = urlGenerator.buildUrl( - "macosx64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "mac" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_MAC_URL, - url - ); - } - - @Test - public void testBuildUrlLinux64() { - String url = urlGenerator.buildUrl( - "linux64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "linux64" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_LINUX_URL, - url - ); - } - - @Test - public void testBuildUrlLinuxArm() { - String url = urlGenerator.buildUrl( - "linuxArm", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "linuxArm" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_LINUX_URL_ARM, - url - ); - } - -} diff --git a/build/jre/test/GluonHqDownloadUrlGeneratorTest.java b/build/jre/test/GluonHqDownloadUrlGeneratorTest.java deleted file mode 100644 index 163d3d23d..000000000 --- a/build/jre/test/GluonHqDownloadUrlGeneratorTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- 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 -*/ - - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class GluonHqDownloadUrlGeneratorTest { - - private static final String EXPECTED_WIN64_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-windows/"; - private static final String EXPECTED_MAC_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-mac"; - private static final String EXPECTED_LINUX_URL = "http://gluonhq.com/download/javafx-11-0-2-sdk-linux/"; - - private static final String COMPONENT = "jfx"; - private static final int TRAIN = 11; - private static final int VERSION = 0; - private static final int UPDATE = 2; - private static final int BUILD = 0; - private static final String FLAVOR_SUFFIX = ".zip"; - - private AdoptOpenJdkDownloadUrlGenerator urlGenerator; - - @Before - public void setUp() throws Exception { - urlGenerator = new AdoptOpenJdkDownloadUrlGenerator(); - } - - @Test - public void testBuildUrlWindows() { - String url = urlGenerator.buildUrl( - "windows64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "windows" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_WIN64_URL, - url - ); - } - - @Test - public void testBuildUrlMac() { - String url = urlGenerator.buildUrl( - "macosx64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "mac" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_MAC_URL, - url - ); - } - - @Test - public void testBuildUrlLinux() { - String url = urlGenerator.buildUrl( - "linux64", - COMPONENT, - TRAIN, - VERSION, - UPDATE, - BUILD, - "linux64" + FLAVOR_SUFFIX - ); - - assertEquals( - EXPECTED_LINUX_URL, - url - ); - } - -} From 0ca766cb954c3ad85b4064525d51d27e49136931 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 15:13:41 -0500 Subject: [PATCH 10/15] couple notes about downloader --- build/jre/src/Downloader.java | 2 +- todo.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index 381bd768c..41e6ce57a 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -48,7 +48,7 @@ public class Downloader extends Task { /** * Set the platform being used. * - * @param platform The platfom for which files are being downloaded like macosx. + * @param platform The platform for which files are being downloaded like macosx. */ public void setPlatform(String platform) { this.platform = platform.toLowerCase(); diff --git a/todo.txt b/todo.txt index 4f2a6a23f..c9bef4630 100755 --- a/todo.txt +++ b/todo.txt @@ -12,6 +12,8 @@ X link to a wiki page for 4.x X create wiki page for changes in 4.x X selecting a sketch in the Sketch menu no longer opens its window X https://github.com/processing/processing/issues/5882 +X streamlining the jdk downloader +X https://github.com/processing/processing4/issues/47 cross-ported from 3.5.4 X don't remove entries from Recent menu on Save As From cae266744b9f94edc9f4c81a6928ecd7e802b812 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 16:56:44 -0500 Subject: [PATCH 11/15] remove the hash stuff and pre-11 versions of jdk.dir --- build/build.xml | 53 +++---------------------------------------------- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/build/build.xml b/build/build.xml index c1a2aabc5..e8893b1a2 100644 --- a/build/build.xml +++ b/build/build.xml @@ -354,9 +354,6 @@ - - - @@ -385,10 +382,8 @@ platform="${target-platform}${jdk.data.model}" update="${jfx.update}" build="1" - hash="${jfx.hash}" flavor="${target-platform}${jdk.data.model}.zip" path="${jfx.path.zip}" /> - @@ -692,16 +687,7 @@ - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1483,16 +1445,7 @@ src="${jdk.tgz.path}" overwrite="false" /> - - - - - - - - - - + From 272457bb6bcc5518423371558c0ed585b0aee69c Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 17:00:52 -0500 Subject: [PATCH 12/15] turn cookies back on --- build/jre/src/Downloader.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index 41e6ce57a..347bce9a2 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -186,22 +186,22 @@ public class Downloader extends Task { while (conn.getResponseCode() == 302 || conn.getResponseCode() == 301) { Map> headers = conn.getHeaderFields(); List location = headers.get("Location"); - if (location.size() == 1) { + if (location.size() > 0) { url = location.get(0); System.out.println("Redirecting to " + url); } else { - // TODO should - throw new BuildException("Received multiple redirect locations"); + // TODO should this just do one of the + throw new BuildException("No redirect location provided"); } - /* List cookies = headers.get("Set-Cookie"); conn = (HttpURLConnection) new URL(url).openConnection(); if (cookies != null) { for (String cookie : cookies) { + System.out.println("Setting cookie " + cookie); conn.setRequestProperty("Cookie", cookie); } } - + /* if (cookieMaybe.isPresent()) { conn.setRequestProperty("Cookie", cookieMaybe.get()); } @@ -288,7 +288,7 @@ public class Downloader extends Task { static private String gluonHqUrl(String platform, String component, int train, int version, int update) { final String URL_FORMAT = - "http://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; + "https://gluonhq.com/download/javafx-%d-%d-%d-sdk-%s/"; String platformShort; if (platform.contains("linux")) { From 880e5c71b60855c057a0d7b72a7bcd83a887ba0e Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 17:03:04 -0500 Subject: [PATCH 13/15] maybe it wasn't cookies --- build/jre/src/Downloader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/jre/src/Downloader.java b/build/jre/src/Downloader.java index 347bce9a2..546229b78 100644 --- a/build/jre/src/Downloader.java +++ b/build/jre/src/Downloader.java @@ -193,15 +193,15 @@ public class Downloader extends Task { // TODO should this just do one of the throw new BuildException("No redirect location provided"); } - List cookies = headers.get("Set-Cookie"); conn = (HttpURLConnection) new URL(url).openConnection(); + /* + List cookies = headers.get("Set-Cookie"); if (cookies != null) { for (String cookie : cookies) { System.out.println("Setting cookie " + cookie); conn.setRequestProperty("Cookie", cookie); } } - /* if (cookieMaybe.isPresent()) { conn.setRequestProperty("Cookie", cookieMaybe.get()); } From 2f0da33ffc4973d2d6fd788ac854bbeebd108975 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 17:16:56 -0500 Subject: [PATCH 14/15] disable tests --- build/jre/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jre/build.xml b/build/jre/build.xml index b3e2a6800..3cf363e3a 100644 --- a/build/jre/build.xml +++ b/build/jre/build.xml @@ -35,7 +35,7 @@ - + From dcf0d386a15a974bb5a192070e8673d8c1ba3cdd Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 18 Jan 2020 17:18:38 -0500 Subject: [PATCH 15/15] tweak welcome screen text --- build/shared/lib/welcome/generic.html | 2 +- build/shared/lib/welcome/sketchbook.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/shared/lib/welcome/generic.html b/build/shared/lib/welcome/generic.html index 50a4e8216..0946269b3 100644 --- a/build/shared/lib/welcome/generic.html +++ b/build/shared/lib/welcome/generic.html @@ -13,7 +13,7 @@ -

Welcome to Processing 4 (alpha)

+

Processing 4 (alpha)

diff --git a/build/shared/lib/welcome/sketchbook.html b/build/shared/lib/welcome/sketchbook.html index a45c02bdd..6d4cc8cfa 100644 --- a/build/shared/lib/welcome/sketchbook.html +++ b/build/shared/lib/welcome/sketchbook.html @@ -13,7 +13,7 @@ -

Welcome to Processing 4 (alpha) +

Processing 4 (alpha)