395 lines
12 KiB
Groovy
395 lines
12 KiB
Groovy
/*
|
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
|
*
|
|
* This module is responsible for handling an instance of the Firefox web browser during runtime. This will install the
|
|
* appropriate version of Firefox Developer edition to the application installation directory, downloading it directly
|
|
* from Mozilla (administrator privileges are needed on Windows). It will also compile addon dependencies and add them
|
|
* to the install.
|
|
*
|
|
* This is all done prior to compiling the Java component of this module. The Java component is a single library that
|
|
* contains the appropriate methods to launch the browser and relay messages to and from the running instance.
|
|
*/
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import java.util.stream.Stream
|
|
|
|
plugins {
|
|
id 'java'
|
|
id "de.undercouch.download" version "4.1.2"
|
|
}
|
|
|
|
configurations {
|
|
/**
|
|
* Addons are dependencies that will be added to the Firefox installation as an extension.
|
|
*/
|
|
addon {
|
|
canBeConsumed = false
|
|
canBeResolved = true
|
|
}
|
|
/**
|
|
* This will be how the browser policy and addon configuration will be exported.
|
|
*/
|
|
install {
|
|
canBeConsumed = true
|
|
canBeResolved = false
|
|
}
|
|
}
|
|
|
|
// In this section you declare where to find the dependencies of your project
|
|
repositories {
|
|
mavenCentral()
|
|
def mozilla = ivy {
|
|
url 'https://download-installer.cdn.mozilla.net/'
|
|
|
|
patternLayout {
|
|
artifact '/pub/[module]/releases/[revision]/[classifier]/en-US/firefox-[revision].[ext]'
|
|
artifact '/pub/[module]/releases/[revision]/[classifier]/en-US/Firefox [revision].[ext]'
|
|
artifact '/pub/[module]/releases/[revision]/[classifier]/en-US/Firefox Setup [revision].[ext]'
|
|
}
|
|
|
|
metadataSources {
|
|
artifact()
|
|
}
|
|
}
|
|
flatDir {
|
|
dirs new File(rootDir, 'libs')
|
|
}
|
|
exclusiveContent {
|
|
forRepositories(mozilla)
|
|
filter {
|
|
includeGroup("firefox")
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
implementation 'org.slf4j:slf4j-api:1.7.30'
|
|
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
|
|
implementation 'org.apache.logging.log4j:log4j-core:2.13.3'
|
|
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.3'
|
|
implementation project(":browserCommands")
|
|
testImplementation 'junit:junit:4.12'
|
|
addon project(path: ":add-on", configuration: 'addonBuild')
|
|
}
|
|
|
|
/**
|
|
* Downloads the 64-bit Linux Firefox installer.
|
|
*
|
|
* @return The msi file that installs firefox.
|
|
*/
|
|
task downloadWindows_x86_64(type: Download) {
|
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win64/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
|
dest layout.buildDirectory.file("installer.msi")
|
|
overwrite false
|
|
onlyIfModified true
|
|
}
|
|
|
|
/**
|
|
* Downloads the 32-bit Linux Firefox installer.
|
|
*
|
|
* @return The msi file that installs firefox.
|
|
*/
|
|
task downloadWindows_x86(type: Download) {
|
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win32/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
|
dest layout.buildDirectory.file("installer.msi")
|
|
overwrite false
|
|
onlyIfModified true
|
|
}
|
|
|
|
/**
|
|
* Downloads the 64-bit Linux Firefox installation.
|
|
*
|
|
* @return The tar file that contains the Firefox download.
|
|
*/
|
|
task downloadLinux_x86_64(type: Download) {
|
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-x86_64/en-US/firefox-${firefox_revision}.tar.bz2"
|
|
dest layout.buildDirectory.file("installer.tar.bz2")
|
|
overwrite false
|
|
onlyIfModified true
|
|
}
|
|
|
|
/**
|
|
* Downloads the 32-bit Linux Firefox installation.
|
|
*
|
|
* @return The tar file that contains the Firefox download.
|
|
*/
|
|
task downloadLinux_i686(type: Download) {
|
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-i686/en-US/firefox-${firefox_revision}.tar.bz2"
|
|
dest layout.buildDirectory.file("installer.tar.bz2")
|
|
overwrite false
|
|
onlyIfModified true
|
|
}
|
|
|
|
/**
|
|
* Installs the 64-bit Windows Firefox to the firefox directory within the project root ($rootDir/firefox). Note that
|
|
* administrator privileges will be needed to properly install.
|
|
*
|
|
* This depends on the output of downloadWindows_x86_64.
|
|
*
|
|
* @return The directory Firefox was installed to.
|
|
*/
|
|
task installWindows_x86_64(dependsOn: downloadWindows_x86_64, type: Exec) {
|
|
workingDir layout.buildDirectory
|
|
commandLine 'msiexec', '/i', '"' + downloadWindows_x86_64.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir\\firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
|
it.outputs.dir("$rootDir\\firefox")
|
|
}
|
|
//installWindows_x86_64.onlyIf { !layout.buildDirectory.file("browser/firefox.exe").get().asFile.exists() }
|
|
installWindows_x86_64.doFirst {
|
|
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
|
}
|
|
|
|
/**
|
|
* Installs the 32-bit Windows Firefox to the firefox directory within the project root ($rootDir/firefox). Note that
|
|
* administrator privileges will be needed to properly install.
|
|
*
|
|
* This depends on the output of downloadWindows_x86.
|
|
*
|
|
* @return The directory Firefox was installed to.
|
|
*/
|
|
task installWindows_x86(dependsOn: downloadWindows_x86, type: Exec) {
|
|
workingDir layout.buildDirectory
|
|
commandLine 'msiexec', '/i', '"' + downloadWindows_x86.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir/firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
|
it.outputs.dir("$rootDir\\firefox")
|
|
}
|
|
//installWindows_x86.onlyIf { !layout.buildDirectory.file("browser/firefox.exe").get().asFile.exists() }
|
|
installWindows_x86.doFirst {
|
|
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
|
}
|
|
|
|
/**
|
|
* Removes the Firefox installation directory, $rootDir/firefox.
|
|
*/
|
|
task deleteFirefoxWindows(type: Delete) {
|
|
delete "$rootDir/firefox"
|
|
}
|
|
|
|
/**
|
|
* Invoke's the Firefox's Windows uninstaller.
|
|
*
|
|
* This task will call deleteFirefoxWindows.
|
|
*
|
|
* @return The directory Firefox was installed to.
|
|
*/
|
|
task uninstallFirefoxWindows(type: Exec) {
|
|
workingDir layout.buildDirectory
|
|
commandLine 'cmd', '/c', "$rootDir\\firefox\\uninstall\\helper.exe", '/S'
|
|
}
|
|
uninstallFirefoxWindows.onlyIf { new File("$rootDir/firefox/firefox.exe").exists() }
|
|
uninstallFirefoxWindows.doFirst {
|
|
println "Administrator privileges needed for uninstalling Firefox. Please confirm on the popup."
|
|
}
|
|
uninstallFirefoxWindows.finalizedBy deleteFirefoxWindows
|
|
|
|
/**
|
|
* Installs the 64-bit Linux Firefox to the firefox directory within the project root ($rootDir/firefox).
|
|
*
|
|
* This depends on the output of downloadLinux_x86_64.
|
|
*
|
|
* @return The directory Firefox was installed to.
|
|
*/
|
|
task installLinux_x86_64(dependsOn: downloadLinux_x86_64, type: Copy) {
|
|
from(tarTree(downloadLinux_x86_64.dest)) {
|
|
include "firefox/**"
|
|
eachFile { fcd ->
|
|
fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1))
|
|
}
|
|
}
|
|
into "$rootDir/firefox"
|
|
// outputs.dir(new File(rootDir, "firefox"))
|
|
}
|
|
|
|
/**
|
|
* Installs the 32-bit Linux Firefox to the firefox directory within the project root ($rootDir/firefox).
|
|
*
|
|
* This depends on the output of downloadLinux_i686.
|
|
*
|
|
* @return The directory Firefox was installed to.
|
|
*/
|
|
task installLinux_i686(dependsOn: downloadLinux_i686, type: Copy) {
|
|
from(tarTree(downloadLinux_i686.dest)) {
|
|
include "firefox/**"
|
|
eachFile { fcd ->
|
|
fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1))
|
|
}
|
|
}
|
|
into "$rootDir/firefox"
|
|
outputs.dir("$rootDir/firefox")
|
|
}
|
|
|
|
/**
|
|
* Installs the version of Firefox appropriate for the current system.
|
|
*
|
|
* This depends on the output of installWindows_x86_64, installWindows_x86, installLinux_x86_64, or installLinux_i686,
|
|
* depending on the architecture.
|
|
*
|
|
* @return The directory Firefox was installed in.
|
|
*/
|
|
task installFirefox() {
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS))
|
|
{
|
|
if (Os.isArch("x86_64") || Os.isArch("amd64"))
|
|
{
|
|
print("Windows x86_64")
|
|
dependsOn installWindows_x86_64
|
|
outputs.dir(installWindows_x86_64.getOutputs())
|
|
}
|
|
else if (Os.isArch("x86") || Os.isArch("i386") || Os.isArch("i686"))
|
|
{
|
|
print("Windows x86")
|
|
dependsOn installWindows_x86
|
|
outputs.dir(installWindows_x86.getOutputs())
|
|
}
|
|
else
|
|
{
|
|
printf("Unknown windows architecture %s!\n", System.getProperty("os.arch"))
|
|
}
|
|
}
|
|
else if (Os.isFamily(Os.FAMILY_MAC))
|
|
{
|
|
print("Mac")
|
|
processResources.finalizedBy {
|
|
api "firefox:devedition:92.0b7:mac@dmg"
|
|
}
|
|
}
|
|
else if (Os.isFamily(Os.FAMILY_UNIX))
|
|
{
|
|
if (Os.isArch("x86_64") || Os.isArch("amd64"))
|
|
{
|
|
dependsOn installLinux_x86_64
|
|
outputs.dir(installLinux_x86_64.getOutputs().getFiles().getSingleFile())
|
|
}
|
|
else if (Os.isArch("x86") || Os.isArch("i386") || Os.isArch("i686"))
|
|
{
|
|
dependsOn installLinux_i686
|
|
outputs.dir(installLinux_i686.getOutputs())
|
|
}
|
|
else
|
|
{
|
|
printf("Unknown Linux architecture %s!\n", System.getProperty("os.arch"))
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf("Unknown operating system %s!\n", System.getProperty("os.name"))
|
|
}
|
|
onlyIf {
|
|
return !new File(rootDir, 'firefox').isDirectory()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets up the folders that addons will be stored in, the /distribution/extensions folder.
|
|
*
|
|
* This task depends on installFirefox.
|
|
*/
|
|
task setupProfile {
|
|
dependsOn installFirefox
|
|
doFirst {
|
|
for (File file : installFirefox.getOutputs().getFiles().getFiles()) {
|
|
println file
|
|
}
|
|
mkdir "${installFirefox.getOutputs().getFiles().getSingleFile()}/distribution"
|
|
mkdir "${installFirefox.getOutputs().getFiles().getSingleFile()}/distribution/extensions"
|
|
}
|
|
doLast {
|
|
println "Setting up profile!"
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This task sets up the policies that Firefox will use when creating new profiles. These are copied from the
|
|
* browserConf directory.
|
|
*
|
|
* This task depends on setupProfile.
|
|
*/
|
|
task movePolicies(type: Copy) {
|
|
dependsOn setupProfile
|
|
from files("browserConf")
|
|
into "$rootDir/firefox/"
|
|
/*
|
|
* Registers any required addons as needed.
|
|
*/
|
|
filesMatching('**/policies.json'){
|
|
def pre = ""
|
|
for (File addon: configurations.addon.resolve())
|
|
{
|
|
if (pre.length() > 0)
|
|
{
|
|
pre += ",\n"
|
|
}
|
|
pre += "\"" + addon.name.substring(0, addon.name.lastIndexOf('.')) + "\": {\n"
|
|
pre += "\"installation_mode\": \"forced_install\","
|
|
pre += "\"install_url\": \"" + addon.toURI().toString() + "\""
|
|
pre += "}"
|
|
}
|
|
println "Expanding ${pre}"
|
|
expand(preinstalled: pre)
|
|
}
|
|
doLast {
|
|
println "Making policies firefox!"
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Builds all addon dependencies and copies them to the Firefox installation's distribution/extensions folder.
|
|
*
|
|
* Depends on installFirefox, setupProfile, and addon dependencies.
|
|
*/
|
|
task installAddons(type: Copy) {
|
|
dependsOn setupProfile
|
|
dependsOn configurations.addon
|
|
from configurations.addon.resolve()
|
|
into "${installFirefox.getOutputs().getFiles().getSingleFile()}/distribution/extensions"
|
|
doFirst {
|
|
println "Installing addons!"
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zips all addons and browser policies into a conf.tar file.
|
|
*
|
|
* I don't actually remember what this is supposed to do.
|
|
*/
|
|
task zipPolicies(type: Tar) {
|
|
archiveFileName = "conf.tar"
|
|
destinationDirectory = file("$buildDir")
|
|
from(configurations.addon.files) {
|
|
into "distribution/extensions"
|
|
}
|
|
from files("browserConf")
|
|
filesMatching('**/policies.json'){
|
|
def pre = ""
|
|
for (File addon: configurations.addon.resolve())
|
|
{
|
|
if (pre.length() > 0)
|
|
{
|
|
pre += ",\n"
|
|
}
|
|
pre += "\"" + addon.name.substring(0, addon.name.lastIndexOf('.')) + "\": {\n"
|
|
pre += "\"installation_mode\": \"forced_install\","
|
|
pre += "\"install_url\": \"" + addon.toURI().toString() + "\""
|
|
pre += "}"
|
|
}
|
|
println "Expanding ${pre}"
|
|
expand(preinstalled: pre)
|
|
}
|
|
}
|
|
|
|
tasks.named('clean') {
|
|
dependsOn uninstallFirefoxWindows
|
|
}
|
|
println configurations.getNames()
|
|
|
|
/*
|
|
* The java runtime requires the browser to be set up beforehand.
|
|
*/
|
|
compileJava.dependsOn installAddons
|
|
compileJava.dependsOn movePolicies
|
|
|
|
/*
|
|
* Exports the addons and policy configuration.
|
|
*/
|
|
artifacts {
|
|
install(zipPolicies)
|
|
} |