I'm finding that this code is being used multiple times, so inheritance seems to be warranted.
115 lines
4.3 KiB
Groovy
115 lines
4.3 KiB
Groovy
/*
|
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
|
*/
|
|
|
|
|
|
import java.nio.file.CopyOption
|
|
import java.nio.file.Files
|
|
import java.nio.file.Path
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import java.nio.file.Paths
|
|
import java.nio.file.StandardCopyOption
|
|
import java.util.stream.Stream
|
|
|
|
plugins {
|
|
id 'java'
|
|
id 'application'
|
|
}
|
|
|
|
// In this section you declare where to find the dependencies of your project
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
// In this section you declare the dependencies for your production and test code
|
|
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 'com.google.code.gson:gson:2.8.7'
|
|
|
|
implementation project(":browserCommands")
|
|
|
|
// Declare the dependency for your favourite test framework you want to use in your tests.
|
|
// TestNG is also supported by the Gradle Test task. Just change the
|
|
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
|
|
// 'test.useTestNG()' to your build script.
|
|
testImplementation 'junit:junit:4.12'
|
|
}
|
|
|
|
abstract class BuildManifest extends DefaultTask {
|
|
@InputDirectory
|
|
final abstract DirectoryProperty inputFile = project.objects.directoryProperty()
|
|
@OutputFile
|
|
final abstract RegularFileProperty outputFile = project.objects.fileProperty().convention(project.layout.buildDirectory.file("universalmusic.json"))
|
|
|
|
@TaskAction
|
|
void join() {
|
|
File startupScript
|
|
File binFiles = new File(inputFile.get().asFile, "bin")
|
|
print binFiles
|
|
Stream<File> files = Arrays.stream(binFiles.listFiles())
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
startupScript = files.filter(file -> file.getName().endsWith(".bat")).findFirst().get()
|
|
}
|
|
else if (Os.isFamily(Os.FAMILY_UNIX)) {
|
|
startupScript = files.filter(file -> !file.getName().endsWith(".bat")).findFirst().get()
|
|
}
|
|
else {
|
|
throw new RuntimeException("Unknown OS family")
|
|
}
|
|
outputFile.get().asFile.text = "{\n" +
|
|
" \"name\": \"universalmusic\",\n" +
|
|
" \"description\": \"A link between the Universal Music Player and the web browser.\",\n" +
|
|
" \"path\": \"" + startupScript.getAbsolutePath().replace("\\", "\\\\") + "\",\n" +
|
|
" \"type\": \"stdio\",\n" +
|
|
" \"allowed_extensions\": [\"universalmusic@regis.edu\"]\n" +
|
|
"}"
|
|
}
|
|
}
|
|
|
|
TaskProvider<BuildManifest> buildManifestP = tasks.register("buildManifest", BuildManifest) {
|
|
inputFile = tasks.named("installDist", Sync).get().destinationDir
|
|
}
|
|
|
|
buildManifest.dependsOn(installDist)
|
|
|
|
abstract class InstallAddon extends DefaultTask {
|
|
@InputFile
|
|
final abstract RegularFileProperty inputFile = project.objects.fileProperty()
|
|
|
|
@TaskAction
|
|
void join() {
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
Process p = Runtime.getRuntime()
|
|
.exec("REG DELETE HKEY_CURRENT_USER\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\universalmusic /f ")
|
|
p.waitFor()
|
|
p = Runtime.getRuntime()
|
|
.exec("REG ADD HKEY_CURRENT_USER\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\universalmusic /ve /d \""
|
|
+ inputFile.get().asFile.getAbsolutePath() + "\" /f ")
|
|
p.waitFor()
|
|
}
|
|
else if (Os.isFamily(Os.FAMILY_MAC)) {
|
|
Files.copy(inputFile.get().asFile.toPath(), Paths.get(System.getProperty("user.home"), "Library/Application Support/Mozilla/NativeMessagingHosts", inputFile.get().asFile.getName()))
|
|
}
|
|
else if (Os.isFamily(Os.FAMILY_UNIX)) {
|
|
Files.copy(inputFile.get().asFile.toPath(), Paths.get(System.getProperty("user.home"), ".mozilla/native-messaging-hosts", inputFile.get().asFile.getName()))
|
|
}
|
|
}
|
|
}
|
|
|
|
TaskProvider<InstallAddon> installAddonP = tasks.register("installAddon", InstallAddon) {
|
|
inputFile = buildManifestP.get().outputFile
|
|
}
|
|
|
|
installAddon.dependsOn(buildManifest)
|
|
|
|
run.dependsOn(installAddon)
|
|
|
|
// Define the main class for the application
|
|
mainClassName = defaultPackage + '.addon.Main'
|
|
|
|
compileJava.dependsOn rootProject.bundleAddOn |