Skip to content

Commit

Permalink
Refactored to strategies for supporting AdoptOpenJDK in build.
Browse files Browse the repository at this point in the history
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
sampottinger committed Jan 15, 2019
1 parent 117d1a5 commit 79f6353
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 22 deletions.
57 changes: 48 additions & 9 deletions build/jre/build.xml
@@ -1,20 +1,58 @@
<project name="downloader" default="dist">

<target name="compile">
<path id="classpath.base">
<!-- kinda gross, but if not using the JDT, this just ignored anyway -->
<pathelement location="${jdt.jar};" />
<pathelement location="${java.mode}/jdtCompilerAdapter.jar" />
</path>

<path id="classpath.test">
<pathelement location="library-test/junit-4.8.1.jar" />
<pathelement location = "build" />
<path refid="classpath.base" />
</path>

<target name="test-compile">
<mkdir dir="build" />

<!-- Where can I expect to find Java Mode JARs? -->
<property name="java.mode" value="../../java/mode/" />

<javac source="1.8"
target="1.8"
srcdir="src; test"
destdir="build"
debug="true"
includeantruntime="true"
nowarn="true">
<classpath refid="classpath.test"/>
</javac>

</target>

<target name="test" depends="test-compile">
<junit haltonfailure="true">
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="AdoptOpenJdkDownloadUrlGeneratorTest" />
<test name="OracleDownloadUrlGeneratorTest" />
</junit>
</target>

<target name="compile" depends="test">
<mkdir dir="bin" />

<!-- Where can I expect to find Java Mode JARs? -->
<property name="java.mode" value="../../java/mode/" />

<javac source="1.8"
target="1.8"
srcdir="src"
destdir="bin"
debug="true"
includeantruntime="true"
nowarn="true">
<!-- kinda gross, but if not using the JDT, this just ignored anyway -->
<compilerclasspath path="${jdt.jar}; ${java.mode}/jdtCompilerAdapter.jar" />
target="1.8"
srcdir="src"
destdir="bin"
debug="true"
includeantruntime="true"
nowarn="true">
<classpath refid="classpath.test"/>
</javac>
</target>

Expand All @@ -32,6 +70,7 @@

<target name="clean">
<delete dir="bin" />
<delete dir="build" />
<delete file="downloader.jar" />
</target>

Expand Down
53 changes: 48 additions & 5 deletions build/jre/src/AdoptOpenJdkDownloadUrlGenerator.java
@@ -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";
}
}
38 changes: 33 additions & 5 deletions build/jre/src/DownloadUrlGenerator.java
@@ -1,13 +1,41 @@
/**
* Interface for strategy to generate download URLs.
* Abstract base class for strategy to generate download URLs.
*/
public abstract class DownloadUrlGenerator {

public abstract String buildUrl(String platform, boolean jdk, int train, int version, int update, int build,
String flavor, String hash);
/**
* Determine the URL at which the artifact can be downloaded.
*
* @param downloadPlatform The platform for which the download URL is being generated like
* "macos" or "linux64".
* @param jdk Flag indicating if the JDK or JRE is being downloaded. True indicates that the
* JDK is being downloaded and false indicates JRE.
* @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, boolean jdk, int train, int version,
int update, int build, String flavor, String hash);

public String getLocalFilename(String platform, boolean jdk, int train, int version, int update, int build,
String flavor, String hash) {
/**
* 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 jdk Flag indicating if the JDK or JRE is being downloaded. True indicates that the
* JDK is being downloaded and false indicates JRE.
* @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 String getLocalFilename(String downloadPlatform, boolean jdk, int train, int version,
int update, int build, String flavor, String hash) {

String baseFilename = (jdk ? "jdk" : "jre");

Expand Down
30 changes: 27 additions & 3 deletions build/jre/src/OracleDownloadUrlGenerator.java
@@ -1,11 +1,35 @@
/* -*- 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 the download URL from Oracle.
*/
public class OracleDownloadUrlGenerator extends DownloadUrlGenerator{

@Override
public String buildUrl(String platform, boolean jdk, int train, int version, int update, int build, String flavor,
String hash) {
public String buildUrl(String platform, boolean jdk, int train, int version, int update,
int build, String flavor, String hash) {

String filename = getLocalFilename(platform, jdk, train, version, update, build, flavor, hash);

Expand Down
84 changes: 84 additions & 0 deletions build/jre/test/AdoptOpenJdkDownloadUrlGeneratorTest.java
@@ -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
);
}

}
36 changes: 36 additions & 0 deletions build/jre/test/OracleDownloadUrlGeneratorTest.java
@@ -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
);
}

}

0 comments on commit 79f6353

Please sign in to comment.