diff --git a/.ci b/.ci index cfe8a1c..e8a4c8f 160000 --- a/.ci +++ b/.ci @@ -1 +1 @@ -Subproject commit cfe8a1c333d2c769450c45a3bb9830f439ed638c +Subproject commit e8a4c8f43974112581c2da0519074e8abae7d5fa diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7d34348 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +[*.kt] +indent_size=2 +insert_final_newline=true +ktlint_standard_argument-list-wrapping = disabled +ktlint_standard_class-naming = disabled +ktlint_standard_enum-entry-name-case = disabled +ktlint_standard_import-ordering = disabled +ktlint_standard_package-name = disabled +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = disabled +ktlint_standard_wrapping = disabled + +[*.kts] +indent_size=4 + +[*.gradle] +indent_size=2 +insert_final_newline=true + +[*.java] +indent_size=2 +insert_final_newline=true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..63b021c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "gitsubmodule" + directory: "/" + schedule: + interval: "daily" + diff --git a/README-CHANGES.xml b/README-CHANGES.xml index 63b6c44..604b51e 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -12,11 +12,12 @@ - + - + + diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9de3ec9..0000000 --- a/build.gradle +++ /dev/null @@ -1,239 +0,0 @@ -buildscript { - if ("$gradle.gradleVersion" != "7.4") { - throw new GradleException("Gradle version 7.4 is required (received $gradle.gradleVersion)") - } - - // https://github.com/gradle/gradle/issues/11308#issuecomment-554317655 - if (System.properties['org.gradle.internal.publish.checksums.insecure'] != 'true') { - throw new GradleException("org.gradle.internal.publish.checksums.insecure must be 'true'") - } - - repositories { - mavenCentral() - google() - } - - ext.kotlin_version = "1.5.30" - - dependencies { - classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:5.3.0" - classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.16.0" - classpath "digital.wup:android-maven-publish:3.6.3" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.android.tools.build:gradle:7.3.1" - classpath "de.undercouch:gradle-download-task:4.1.2" - classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.0.0" - } -} - -plugins { - id "com.github.ben-manes.versions" version "0.33.0" - id "com.vanniktech.android.junit.jacoco" version "0.16.0" - id "ru.vyarus.animalsniffer" version "1.5.1" - id "ca.cutterslade.analyze" version "1.4.3" - id "maven-publish" -} - -ext { - androidBuildToolsVersion = "33.0.0" - androidCompileSDKVersion = 33 - androidMinimumSDKVersion = 21 - androidTargetSDKVersion = 33 - - if (!project.hasProperty("mavenCentralUsername")) { - logger.warn("No mavenCentralUsername property specified: Using an empty value") - mavenCentralUsername = "" - } - if (!project.hasProperty("mavenCentralPassword")) { - logger.warn("No mavenCentralPassword property specified: Using an empty value") - mavenCentralPassword = "" - } - - if (project.hasProperty("org.librarysimplified.directory.publish")) { - useDirectoryPublishPath = project.property("org.librarysimplified.directory.publish") - useDirectoryPublish = true - logger.warn("org.librarysimplified.directory.publish is set: We will publish artifacts to ${useDirectoryPublishPath}") - } else { - logger.warn("org.librarysimplified.directory.publish is not set: We will not publish artifacts to a custom directory") - useDirectoryPublish = false - useDirectoryPublishPath = null - } - - if (project.hasProperty("org.librarysimplified.no_signing")) { - disableSigning = true - logger.warn("org.librarysimplified.no_signing is set: We will not sign artifacts") - } else { - disableSigning = false - logger.warn("org.librarysimplified.no_signing is not set: We will attempt to sign artifacts") - } -} - -apply plugin: "com.vanniktech.android.junit.jacoco" -apply plugin: "de.undercouch.download" - -allprojects { project -> - group = project.ext["GROUP"] - version = project.ext["VERSION_NAME"] - - apply plugin: 'ca.cutterslade.analyze' -} - -// Configure all projects -subprojects { project -> - - switch (POM_PACKAGING) { - case "jar": - logger.info("Configuring ${project} ${version} (${POM_PACKAGING}) as jar project") - - apply plugin: "java" - apply plugin: "java-library" - apply plugin: "kotlin" - - /* - * Apply the Animal Sniffer plugin to check that code is Android compatible. - */ - - apply plugin: "ru.vyarus.animalsniffer" - - dependencies { - signature "org.codehaus.mojo.signature:java16:1.1@signature" - signature "net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature" - } - - /* - * Build an OSGi bundle. - */ - - apply plugin: "biz.aQute.bnd.builder" - - jar { - bnd """ -Automatic-Module-Name: ${POM_AUTOMATIC_MODULE_NAME} - --removeheaders: Bnd-LastModified, Tool, Private-Package -""" - } - break - - case "apk": - logger.info("Configuring ${project} ${version} (${POM_PACKAGING}) as Android application project") - - apply plugin: "com.android.application" - apply plugin: "kotlin-android" - - android { - compileSdkVersion androidCompileSDKVersion - buildToolsVersion androidBuildToolsVersion - - defaultConfig { - minSdkVersion androidMinimumSDKVersion - targetSdkVersion androidTargetSDKVersion - } - compileOptions { - encoding 'UTF-8' - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } - } - break - - case "aar": - logger.info("Configuring ${project} ${version} (${POM_PACKAGING}) as Android library project") - - apply plugin: "com.android.library" - apply plugin: "kotlin-android" - apply plugin: "de.mannodermaus.android-junit5" - - android { - compileSdkVersion androidCompileSDKVersion - buildToolsVersion androidBuildToolsVersion - - defaultConfig { - minSdkVersion androidMinimumSDKVersion - targetSdkVersion androidTargetSDKVersion - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - useLibrary 'org.apache.http.legacy' - } - compileOptions { - encoding 'UTF-8' - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } - testOptions { - junitPlatform { - releaseFilters { - excludePattern "**/**" - } - } - unitTests.includeAndroidResources = true - unitTests.all { - reports { - junitXml.enabled = true - html.enabled = true - } - } - } - } - break - - default: - throw new IllegalStateException( - "Unrecognized packaging type ${POM_PACKAGING} for ${project}") - } - - /* - * Configure publishing for the various project types. - */ - - switch (POM_PACKAGING) { - case "jar": - apply from: file("$rootDir/build_publishing.gradle") - break - - case "apk": - break - - case "aar": - apply from: file("$rootDir/build_publishing.gradle") - break - - default: - throw new IllegalStateException( - "Unrecognized packaging type ${POM_PACKAGING} for ${project}") - } - - repositories { - mavenLocal() - mavenCentral() - google() - - // Sonatype snapshots - maven { - url "https://s01.oss.sonatype.org/content/repositories/snapshots/" - } - - maven { url "https://jitpack.io" } - } -} - -/** - * An empty task called by CI. We don't do semantic versioning analysis here yet. - */ - -task verifySemanticVersioning {} - -/* - * Add ktlint tasks. - */ - -apply from: file("$rootDir/build_ktlint.gradle") - -subprojects { - assemble.dependsOn ktlint -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..b44be02 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,848 @@ +import com.android.build.api.dsl.ApplicationExtension +import com.android.build.gradle.LibraryExtension +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download +import org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Verify +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension + +val gradleVersionRequired = "8.2.1" +val gradleVersionReceived = gradle.gradleVersion + +if (gradleVersionRequired != gradleVersionReceived) { + throw GradleException( + "Gradle version $gradleVersionRequired is required to run this build. You are using Gradle $gradleVersionReceived", + ) +} + +plugins { + signing + + id("org.jetbrains.kotlin.jvm") + .version("1.9.0") + .apply(false) + + id("org.jetbrains.kotlin.android") + .version("1.9.0") + .apply(false) + + /* + * The AndroidX plugin for navigation (including view binding generation). + * + * https://developer.android.com/jetpack/androidx/releases/navigation + */ + + id("androidx.navigation.safeargs.kotlin") + .version("2.7.1") + .apply(false) + + id("com.android.library") + .version("8.1.0") + .apply(false) + + id("com.android.application") + .version("8.1.0") + .apply(false) + + /* + * Android Junit5 plugin. Required to run JUnit 5 tests on Android projects. + * + * https://github.com/mannodermaus/android-junit5 + */ + + id("de.mannodermaus.android-junit5") + .version("1.9.3.0") + .apply(false) + + /* + * Download plugin. Used to fetch artifacts such as Scando during the build. + * + * https://plugins.gradle.org/plugin/de.undercouch.download + */ + + id("de.undercouch.download") + .version("5.4.0") + .apply(false) + + /* + * https://developers.google.com/android/guides/google-services-plugin + */ + + id("com.google.gms.google-services") + .version("4.3.15") + .apply(false) + + /* + * https://firebase.google.com/docs/crashlytics/get-started?platform=android + */ + + id("com.google.firebase.crashlytics") + .version("2.9.9") + .apply(false) + + id("maven-publish") +} + +/* + * The various paths used during the build. + */ + +val palaceRootBuildDirectory = + "$rootDir/build" +val palaceDeployDirectory = + "$palaceRootBuildDirectory/maven" +val palaceScandoJarFile = + "$rootDir/scando.jar" +val palaceKtlintJarFile = + "$rootDir/ktlint.jar" + +/** + * Convenience functions to read strongly-typed values from property files. + */ + +fun property( + project: Project, + name: String, +): String { + return project.extra[name] as String +} + +fun propertyOptional(project: Project, name: String): String? { + val map = project.extra + if (map.has(name)) { + return map[name] as String? + } + return null +} + +fun propertyInt( + project: Project, + name: String, +): Int { + val text = property(project, name) + return text.toInt() +} + +fun propertyBoolean( + project: Project, + name: String, +): Boolean { + val text = property(project, name) + return text.toBooleanStrict() +} + +fun propertyBooleanOptional( + project: Project, + name: String, + defaultValue: Boolean, +): Boolean { + val value = propertyOptional(project, name) ?: return defaultValue + return value.toBooleanStrict() +} + +/** + * Configure Maven publishing. Artifacts are published to a local directory + * so that they can be pushed to Maven Central in one step using brooklime. + */ + +fun configurePublishingFor(project: Project) { + val mavenCentralUsername = + (project.findProperty("mavenCentralUsername") ?: "") as String + val mavenCentralPassword = + (project.findProperty("mavenCentralPassword") ?: "") as String + + val versionName = + property(project, "VERSION_NAME") + val packaging = + property(project, "POM_PACKAGING") + + val publishSources = + propertyBoolean(project, "org.thepalaceproject.build.publishSources") + val enableSigning = + propertyBooleanOptional(project, "org.thepalaceproject.build.enableSigning", true) + + /* + * Create an empty JavaDoc jar. Required for Maven Central deployments. + */ + + val taskJavadocEmpty = + project.task("JavadocEmptyJar", org.gradle.jvm.tasks.Jar::class) { + this.archiveClassifier = "javadoc" + } + + /* + * Create a publication. Note that the name of the publication must be unique across all + * modules, because the broken Gradle signing plugin will create a signing task for each + * one that, in the case of a name conflict, will silently overwrite the previous signing + * task. + */ + + project.publishing { + publications { + create("_${project.name}_MavenPublication") { + groupId = property(project, "GROUP") + artifactId = property(project, "POM_ARTIFACT_ID") + version = versionName + + /* + * https://central.sonatype.org/publish/requirements/#sufficient-metadata + */ + + pom { + name.set(property(project, "POM_NAME")) + description.set(property(project, "POM_DESCRIPTION")) + url.set(property(project, "POM_URL")) + + scm { + connection.set(property(project, "POM_SCM_CONNECTION")) + developerConnection.set(property(project, "POM_SCM_DEV_CONNECTION")) + url.set(property(project, "POM_SCM_URL")) + } + + licenses { + license { + name.set(property(project, "POM_LICENCE_NAME")) + url.set(property(project, "POM_LICENCE_URL")) + } + } + + developers { + developer { + name.set("The Palace Project") + email.set("info@thepalaceproject.org") + organization.set("The Palace Project") + organizationUrl.set("https://thepalaceproject.org/") + } + } + } + + artifact(taskJavadocEmpty) + + from( + when (packaging) { + "jar" -> { + project.components["java"] + } + + "aar" -> { + project.components["release"] + } + + "apk" -> { + project.components["release"] + } + + else -> { + throw java.lang.IllegalArgumentException( + "Cannot set up publishing for packaging type $packaging", + ) + } + }, + ) + } + } + + repositories { + maven { + name = "Directory" + url = uri(palaceDeployDirectory) + } + + /* + * Only deploy to the Sonatype snapshots repository if the current version is a + * snapshot version. + */ + + if (versionName.endsWith("-SNAPSHOT")) { + maven { + name = "SonatypeCentralSnapshots" + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + + credentials { + username = mavenCentralUsername + password = mavenCentralPassword + } + } + } + } + } + + /* + * If source publications are disabled in the project properties, it seems that the only + * way to stop the Android plugins from publishing sources is to manually "disable" the + * publication tasks by deleting all of the actions within the tasks, and then specifying + * a dependency on our own task that produces an empty jar file. + */ + + if (!publishSources) { + logger.info("org.thepalaceproject.build.publishSources is false, so source jars are disabled.") + + val taskSourcesEmpty = + project.task("SourcesEmptyJar", org.gradle.jvm.tasks.Jar::class) { + this.archiveClassifier = "sources" + } + + project.tasks.matching { task -> task.name.endsWith("SourcesJar") } + .forEach { task -> + task.actions.clear() + task.dependsOn.add(taskSourcesEmpty) + } + } + + /* + * Configure signing. + */ + + if (enableSigning) { + signing { + useGpgCmd() + sign(project.publishing.publications) + } + } +} + +/* + * A task that cleans up the Maven deployment directory. The "clean" tasks of + * each project are configured to depend upon this task. This prevents any + * deployment of stale artifacts to remote repositories. + */ + +val cleanTask = task("CleanMavenDeployDirectory", Delete::class) { + this.delete.add(palaceDeployDirectory) +} + +/** + * A function to download and verify the Scando jar file. + * + * @return The verification task + */ + +fun createScandoDownloadTask(project: Project): Task { + val scandoVersion = + "1.0.0" + val scandoSHA256 = + "08fba5fc4bc3b5a49d205a4c38356dc8c7e01f4963adb661b67f9d2ed23751ae" + val scandoSource = + "https://repo1.maven.org/maven2/com/io7m/scando/com.io7m.scando.cmdline/$scandoVersion/com.io7m.scando.cmdline-$scandoVersion-main.jar" + + val scandoMakeDirectory = + project.task("ScandoMakeDirectory") { + mkdir(palaceRootBuildDirectory) + } + + val scandoDownload = + project.task("ScandoDownload", Download::class) { + src(scandoSource) + dest(file(palaceScandoJarFile)) + overwrite(true) + this.dependsOn.add(scandoMakeDirectory) + } + + return project.task("ScandoDownloadVerify", Verify::class) { + src(file(palaceScandoJarFile)) + checksum(scandoSHA256) + algorithm("SHA-256") + this.dependsOn(scandoDownload) + } +} + +/** + * A task to execute Scando to analyze semantic versioning. + */ + +fun createScandoAnalyzeTask(project: Project): Task { + val group = + property(project, "GROUP") + val artifactId = + property(project, "POM_ARTIFACT_ID") + val versionCurrent = + property(project, "VERSION_NAME") + val versionPrevious = + property(project, "VERSION_PREVIOUS") + + val oldGroup = + group.replace('.', '/') + val oldPath = + "$oldGroup/$artifactId/$versionPrevious/$artifactId-$versionPrevious.aar" + val oldUrl = + "https://repo1.maven.org/maven2/$oldPath" + + val commandLineArguments: List = arrayListOf( + "java", + "-jar", + palaceScandoJarFile, + "--excludeList", + "${project.rootDir}/VERSIONING.txt", + "--oldJarUri", + oldUrl, + "--oldJarVersion", + versionPrevious, + "--ignoreMissingOld", + "--newJar", + "${project.buildDir}/outputs/aar/$artifactId-debug.aar", + "--newJarVersion", + versionCurrent, + "--textReport", + "${project.buildDir}/scando-report.txt", + "--htmlReport", + "${project.buildDir}/scando-report.html", + ) + + return project.task("ScandoAnalyze", Exec::class) { + commandLine = commandLineArguments + } +} + +/* + * Create a task in the root project that downloads Scando. + */ + +lateinit var scandoDownloadTask: Task + +rootProject.afterEvaluate { + apply(plugin = "de.undercouch.download") + scandoDownloadTask = createScandoDownloadTask(this) +} + +/** + * A function to download and verify the ktlint jar file. + * + * @return The verification task + */ + +fun createKtlintDownloadTask(project: Project): Task { + val ktlintVersion = + "0.50.0" + val ktlintSHA256 = + "c704fbc28305bb472511a1e98a7e0b014aa13378a571b716bbcf9d99d59a5092" + val ktlintSource = + "https://repo1.maven.org/maven2/com/pinterest/ktlint/$ktlintVersion/ktlint-$ktlintVersion-all.jar" + + val ktlintMakeDirectory = + project.task("KtlintMakeDirectory") { + mkdir(palaceRootBuildDirectory) + } + + val ktlintDownload = + project.task("KtlintDownload", Download::class) { + src(ktlintSource) + dest(file(palaceKtlintJarFile)) + overwrite(true) + onlyIfModified(true) + this.dependsOn.add(ktlintMakeDirectory) + } + + return project.task("KtlintDownloadVerify", Verify::class) { + src(file(palaceKtlintJarFile)) + checksum(ktlintSHA256) + algorithm("SHA-256") + this.dependsOn(ktlintDownload) + } +} + +/** + * A task to execute ktlint to check sources. + */ + +val ktlintPatterns: List = arrayListOf( + "*/src/**/*.kt", + "*/build.gradle.kts", + "build.gradle.kts", + "!*/src/test/**", +) + +fun createKtlintCheckTask(project: Project): Task { + val commandLineArguments: ArrayList = arrayListOf( + "java", + "-jar", + palaceKtlintJarFile, + ) + commandLineArguments.addAll(ktlintPatterns) + + return project.task("KtlintCheck", Exec::class) { + commandLine = commandLineArguments + } +} + +/** + * A task to execute ktlint to reformat sources. + */ + +fun createKtlintFormatTask(project: Project): Task { + val commandLineArguments: ArrayList = arrayListOf( + "java", + "-jar", + palaceKtlintJarFile, + "-F", + ) + commandLineArguments.addAll(ktlintPatterns) + + return project.task("KtlintFormat", Exec::class) { + commandLine = commandLineArguments + } +} + +/* + * Create a task in the root project that downloads ktlint. + */ + +lateinit var ktlintDownloadTask: Task + +rootProject.afterEvaluate { + apply(plugin = "de.undercouch.download") + ktlintDownloadTask = createKtlintDownloadTask(this) + + val enableKtlintChecks = + propertyBoolean(this, "org.thepalaceproject.build.enableKtLint") + + if (enableKtlintChecks) { + val checkActual = createKtlintCheckTask(this) + checkActual.dependsOn.add(ktlintDownloadTask) + cleanTask.dependsOn.add(checkActual) + } + + /* + * Create a task that can be used to reformat sources. This is purely for manual execution + * from the command-line, and is not executed otherwise. + */ + + val formatTask = createKtlintFormatTask(this) + formatTask.dependsOn.add(ktlintDownloadTask) +} + +allprojects { + + /* + * Configure the project metadata. + */ + + this.group = + property(this, "GROUP") + this.version = + property(this, "VERSION_NAME") + + val jdkBuild = + propertyInt(this, "org.thepalaceproject.build.jdkBuild") + val jdkBytecodeTarget = + propertyInt(this, "org.thepalaceproject.build.jdkBytecodeTarget") + + /* + * Configure builds and tests for various project types. + */ + + when (extra["POM_PACKAGING"]) { + "pom" -> { + logger.info("Configuring ${this.project} $version as a pom project") + } + + "apk" -> { + logger.info("Configuring ${this.project} $version as an apk project") + + apply(plugin = "com.android.application") + apply(plugin = "org.jetbrains.kotlin.android") + + /* + * Configure the JVM toolchain version that we want to use for Kotlin. + */ + + val kotlin: KotlinAndroidProjectExtension = + this.extensions["kotlin"] as KotlinAndroidProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Configure the various required Android properties. + */ + + val android: ApplicationExtension = + this.extensions["android"] as ApplicationExtension + + android.namespace = + property(this, "POM_ARTIFACT_ID") + android.compileSdk = + propertyInt(this, "org.thepalaceproject.build.androidSDKCompile") + + android.defaultConfig { + multiDexEnabled = true + targetSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKTarget") + minSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKMinimum") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + android.compileOptions { + encoding = "UTF-8" + sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + } + } + + "aar" -> { + logger.info("Configuring ${this.project} $version as an aar project") + + apply(plugin = "com.android.library") + apply(plugin = "org.jetbrains.kotlin.android") + apply(plugin = "de.mannodermaus.android-junit5") + + /* + * Configure the JVM toolchain version that we want to use for Kotlin. + */ + + val kotlin: KotlinAndroidProjectExtension = + this.extensions["kotlin"] as KotlinAndroidProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Configure the various required Android properties. + */ + + val android: LibraryExtension = + this.extensions["android"] as LibraryExtension + + android.namespace = + property(this, "POM_ARTIFACT_ID") + android.compileSdk = + propertyInt(this, "org.thepalaceproject.build.androidSDKCompile") + + android.defaultConfig { + multiDexEnabled = true + minSdk = + propertyInt(this@allprojects, "org.thepalaceproject.build.androidSDKMinimum") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + android.compileOptions { + encoding = "UTF-8" + sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + } + + android.testOptions { + execution = "ANDROIDX_TEST_ORCHESTRATOR" + animationsDisabled = true + + /* + * Enable the production of reports for all unit tests. + */ + + unitTests { + isIncludeAndroidResources = true + + all { test -> + // Required for the Mockito ByteBuddy agent on modern VMs. + test.systemProperty("jdk.attach.allowAttachSelf", "true") + test.reports.html.required = true + test.reports.junitXml.required = true + } + } + } + + /* + * Configure semantic versioning analysis. + */ + + afterEvaluate { + val enableSemanticVersionChecks = + propertyBoolean(this, "org.thepalaceproject.build.checkSemanticVersioning") + + if (enableSemanticVersionChecks) { + val verifyActual = createScandoAnalyzeTask(this) + verifyActual.dependsOn.add(scandoDownloadTask) + verifyActual.dependsOn.add("assembleDebug") + + val verifyTask = project.task("verifySemanticVersioning") + verifyTask.dependsOn.add(verifyActual) + } else { + // Create a do-nothing task to keep interface compatibility. + project.task("verifySemanticVersioning") + } + } + } + + "jar" -> { + logger.info("Configuring ${this.project} $version as a jar project") + + apply(plugin = "java-library") + apply(plugin = "org.jetbrains.kotlin.jvm") + + /* + * Configure the JVM toolchain versions that we want to use for Kotlin and Java. + */ + + val kotlin: KotlinProjectExtension = + this.extensions["kotlin"] as KotlinProjectExtension + val java: JavaPluginExtension = + this.extensions["java"] as JavaPluginExtension + + kotlin.jvmToolchain(jdkBuild) + java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkBuild)) + + /* + * Produce JDK bytecode of the correct version. + */ + + tasks.withType { + kotlinOptions.jvmTarget = jdkBytecodeTarget.toString() + } + java.sourceCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + java.targetCompatibility = JavaVersion.toVersion(jdkBytecodeTarget) + + /* + * Configure JUnit tests. + */ + + tasks.named("test") { + useJUnitPlatform() + + // Required for the Mockito ByteBuddy agent on modern VMs. + systemProperty("jdk.attach.allowAttachSelf", "true") + + testLogging { + events("passed") + } + + this.reports.html.required = true + this.reports.junitXml.required = true + } + } + } + + /* + * Configure publishing. + */ + + when (extra["POM_PACKAGING"]) { + "jar", "aar" -> { + apply(plugin = "maven-publish") + + afterEvaluate { + configurePublishingFor(this.project) + } + } + } + + /* + * Configure some aggressive version resolution behaviour. The listed configurations have + * transitive dependency resolution enabled; all other configurations do not. This forces + * projects to be extremely explicit about what is imported. + */ + + val transitiveConfigurations = setOf( + "androidTestDebugImplementation", + "androidTestDebugImplementationDependenciesMetadata", + "androidTestImplementation", + "androidTestImplementationDependenciesMetadata", + "androidTestReleaseImplementation", + "androidTestReleaseImplementationDependenciesMetadata", + "annotationProcessor", + "debugAndroidTestCompilationImplementation", + "debugAndroidTestImplementation", + "debugAndroidTestImplementationDependenciesMetadata", + "debugAnnotationProcessor", + "debugAnnotationProcessorClasspath", + "debugUnitTestCompilationImplementation", + "debugUnitTestImplementation", + "debugUnitTestImplementationDependenciesMetadata", + "kotlinBuildToolsApiClasspath", + "kotlinCompilerClasspath", + "kotlinCompilerPluginClasspath", + "kotlinCompilerPluginClasspathDebug", + "kotlinCompilerPluginClasspathDebugAndroidTest", + "kotlinCompilerPluginClasspathDebugUnitTest", + "kotlinCompilerPluginClasspathMain", + "kotlinCompilerPluginClasspathRelease", + "kotlinCompilerPluginClasspathReleaseUnitTest", + "kotlinCompilerPluginClasspathTest", + "kotlinKlibCommonizerClasspath", + "kotlinNativeCompilerPluginClasspath", + "kotlinScriptDef", + "kotlinScriptDefExtensions", + "mainSourceElements", + "releaseAnnotationProcessor", + "releaseAnnotationProcessorClasspath", + "releaseUnitTestCompilationImplementation", + "releaseUnitTestImplementation", + "releaseUnitTestImplementationDependenciesMetadata", + "testDebugImplementation", + "testDebugImplementationDependenciesMetadata", + "testFixturesDebugImplementation", + "testFixturesDebugImplementationDependenciesMetadata", + "testFixturesImplementation", + "testFixturesImplementationDependenciesMetadata", + "testFixturesReleaseImplementation", + "testFixturesReleaseImplementationDependenciesMetadata", + "testImplementation", + "testImplementationDependenciesMetadata", + "testReleaseImplementation", + "testReleaseImplementationDependenciesMetadata", + ) + + /* + * Write the set of available configurations to files, for debugging purposes. Plugins can + * add new configurations at any time, and so it's nice to have a list of the available + * configurations visible. + */ + + val configurationsActual = mutableSetOf() + afterEvaluate { + configurations.all { + configurationsActual.add(this.name) + } + File("configurations.txt").writeText(configurationsActual.joinToString("\n")) + } + + afterEvaluate { + configurations.all { + isTransitive = transitiveConfigurations.contains(name) + // resolutionStrategy.failOnVersionConflict() + } + } + + /* + * Configure all "clean" tasks to depend upon the global Maven deployment directory cleaning + * task. + */ + + afterEvaluate { + tasks.matching { task -> task.name == "clean" } + .forEach { task -> task.dependsOn(cleanTask) } + } + + /* + * Configure all "test" tasks to be disabled. The tests are enabled only in those modules + * that specifically ask for them. Why do this? Because the Android plugins do lots of + * expensive per-module configuration for tests that don't exist. + */ + + afterEvaluate { + tasks.matching { task -> task.name.contains("UnitTest") } + .forEach { task -> task.enabled = false } + } +} diff --git a/build_ktlint.gradle b/build_ktlint.gradle deleted file mode 100644 index dc5c686..0000000 --- a/build_ktlint.gradle +++ /dev/null @@ -1,26 +0,0 @@ -repositories { - jcenter() -} -configurations { - ktlint -} -dependencies { - ktlint "com.pinterest:ktlint:0.39.0" -} -task ktlint(type: JavaExec, group: "quality") { - description = "Check Kotlin code style." - classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" - args "src/**/*.kt" -} -task ktlintFormat(type: JavaExec, group: "quality") { - description = "Fix Kotlin code style deviations." - classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" - args "-F", "src/**/*.kt" -} -afterEvaluate { - tasks.withType(Test) { - dependsOn 'ktlint' - } -} diff --git a/build_publishing.gradle b/build_publishing.gradle deleted file mode 100644 index 296e9e2..0000000 --- a/build_publishing.gradle +++ /dev/null @@ -1,143 +0,0 @@ -apply plugin: "maven-publish" -apply plugin: "signing" - -def mavenCentralUsername = - project.findProperty('mavenCentralUsername') ?: '' -def mavenCentralPassword = - project.findProperty('mavenCentralPassword') ?: '' - -def publishDirectory = - project.findProperty('org.librarysimplified.directory.publish') ?: '' -def noSigning = - project.hasProperty('org.librarysimplified.no_signing') - -task javadocsJar(type: Jar) { - classifier = "javadoc" -} - -task sourcesJar(type: Jar) { - classifier = "sources" - from "src/main/java", "src/main/resources" -} - -afterEvaluate { - publishing { - publications { - binaryAndSources(MavenPublication) { - artifactId = POM_ARTIFACT_ID - - switch (POM_PACKAGING) { - case "aar": - from components.release - break - case "apk": - from components.release_apk - break - case "jar": - from components.java - break - } - artifact sourcesJar - artifact javadocsJar - - pom { - name = POM_NAME - packaging = POM_PACKAGING - description = POM_DESCRIPTION - url = POM_URL - - scm { - connection = POM_SCM_CONNECTION - developerConnection = POM_SCM_DEV_CONNECTION - url = POM_SCM_URL - } - - licenses { - license { - name = POM_LICENCE_NAME - url = POM_LICENCE_URL - } - } - - developers { - developer { - id = "io7m" - name = "Mark Raynsford" - email = "code@io7m.com" - url = "https://www.io7m.com" - } - developer { - id = "winniequinn" - name = "Winnie Quinn" - url = "https://www.winniequinn.com/" - } - developer { - id = "gioneill" - name = "Greg O'Neill" - url = "https://github.com/gioneill" - } - developer { - id = "mattniehoff" - name = "Matt Niehoff" - url = "https://github.com/mattniehoff" - } - developer { - id = "MalcolmMcFly" - name = "Malcolm Woods" - url = "https://github.com/MalcolmMcFly" - } - developer { - id = "twaddington" - name = "Tristan Waddington" - url = "https://github.com/twaddington" - } - } - } - } - } - - repositories { - maven { - name = "directory" - url = "file://${publishDirectory}" - } - maven { - name = "centralSnapshots" - url = "https://s01.oss.sonatype.org/content/repositories/snapshots/" - credentials(PasswordCredentials) { - username mavenCentralUsername - password mavenCentralPassword - } - } - } - } - - if (!noSigning) { - apply plugin: "signing" - signing { - useGpgCmd() - sign publishing.publications.binaryAndSources - } - } - - // This block controls what repositories will be pushed to - // when the base 'publish' task is executed. - // - tasks.withType(PublishToMavenRepository) { - def isSnapshot = version.endsWith('-SNAPSHOT') - def isRelease = !isSnapshot - - onlyIf { - if (publishDirectory) { - repository == publishing.repositories.directory - } else { - switch (repository) { - case publishing.repositories.centralSnapshots: - isSnapshot && (mavenCentralUsername && mavenCentralPassword) - break - default: false - } - } - } - } -} diff --git a/gradle.properties b/gradle.properties index fdf991e..d3390d8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=org.thepalaceproject.drm -POM_ARTIFACT_ID=org.librarysimplified.drm +POM_ARTIFACT_ID=org.thepalaceproject.drm POM_DESCRIPTION=NYPL DRM POM_DEVELOPER_ID=io7m POM_DEVELOPER_NAME=Mark Raynsford @@ -9,13 +9,23 @@ POM_INCEPTION_YEAR=2015 POM_LICENCE_DIST=repo POM_LICENCE_NAME=Apache 2.0 License POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt -POM_NAME=org.librarysimplified.drm +POM_NAME=org.thepalaceproject.drm POM_PACKAGING=pom POM_SCM_CONNECTION=scm:git:git://github.com/ThePalaceProject/android-drm-core POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/ThePalaceProject/android-drm-core POM_SCM_URL=http://github.com/ThePalaceProject/android-drm-core/ POM_URL=http://github.com/ThePalaceProject/android-drm-core/ -VERSION_NAME=1.2.8-SNAPSHOT +VERSION_NAME=2.0.0-SNAPSHOT +VERSION_PREVIOUS=2.0.0-SNAPSHOT android.useAndroidX=true android.enableJetifier=true + +org.thepalaceproject.build.androidSDKCompile=34 +org.thepalaceproject.build.androidSDKTarget=34 +org.thepalaceproject.build.androidSDKMinimum=24 +org.thepalaceproject.build.checkSemanticVersioning=true +org.thepalaceproject.build.enableKtLint=true +org.thepalaceproject.build.jdkBytecodeTarget=11 +org.thepalaceproject.build.jdkBuild=17 +org.thepalaceproject.build.publishSources=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f6b961f..033e24c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eddfccc..9f4197d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Sat Apr 20 18:49:58 UTC 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/gradlew b/gradlew index cccdd3d..fcb6fca 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,126 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +129,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,19 +25,23 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/org.librarysimplified.drm.core.tests/build.gradle b/org.librarysimplified.drm.core.tests/build.gradle deleted file mode 100644 index 05c640f..0000000 --- a/org.librarysimplified.drm.core.tests/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - implementation project(":org.librarysimplified.drm.core") - - implementation libs.junit -} diff --git a/org.librarysimplified.drm.core.tests/gradle.properties b/org.librarysimplified.drm.core.tests/gradle.properties deleted file mode 100644 index d16c659..0000000 --- a/org.librarysimplified.drm.core.tests/gradle.properties +++ /dev/null @@ -1,5 +0,0 @@ -POM_ARTIFACT_ID=org.librarysimplified.drm.core.tests -POM_DESCRIPTION=NYPL DRM (Test suite) -POM_NAME=org.librarysimplified.drm.core.tests -POM_PACKAGING=aar -POM_AUTOMATIC_MODULE_NAME=org.librarysimplified.drm.core.tests diff --git a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptJoinAccountDispatcherTest.java b/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptJoinAccountDispatcherTest.java deleted file mode 100644 index 3eb389c..0000000 --- a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptJoinAccountDispatcherTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.nypl.drm.tests.core; - -import android.net.Uri; - -import com.io7m.junreachable.UnreachableCodeException; - -import junit.framework.Assert; - -import org.nypl.drm.core.AdobeAdeptJoinAccountDispatcher; -import org.nypl.drm.core.AdobeAdeptJoinAccountDispatcherListenerType; -import org.nypl.drm.core.AdobeAdeptJoinAccountDispatcherType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - -/** - * Tests for the default join account dispatcher. - */ - -public final class AdobeAdeptJoinAccountDispatcherTest { - private static final Logger LOG; - - static { - LOG = LoggerFactory.getLogger(AdobeAdeptJoinAccountDispatcherTest.class); - } - - /** - * Construct the test suite. - */ - - public AdobeAdeptJoinAccountDispatcherTest() { - - } - - /** - * URI parsing works. - * - * @throws Exception On errors - */ - - public void testURIParsing() - throws Exception { - final String uri = - "adobe:join-form-submit/%7B%22url%22%3A%22https%3A%2F%2Fadeactivate" - + ".adobe.com%2Fadept%2FJoinAccountsFormSubmit%22%2C%22username%22%3A" - + "%22LABS00000013%22%2C%22password%22%3A%226534%22%2C%22sessionId%22" - + "%3A%227310fdd40cdf3741bff0355a7aaa7c11d29cd176%22%2C%22currentNonce" - + "%22%3A%22b91d53984262bf0234b45a3b7b2addee5e7c6bf1%22%2C%22locale%22" - + "%3A%22en%22%7D"; - - final ExecutorService exec = Executors.newFixedThreadPool(1); - final AdobeAdeptJoinAccountDispatcherType dispatcher = - AdobeAdeptJoinAccountDispatcher.newDispatcher(exec); - - final AtomicReference query = new AtomicReference(); - final CountDownLatch latch = new CountDownLatch(1); - - dispatcher.onFormSubmit( - uri, new AdobeAdeptJoinAccountDispatcherListenerType() { - @Override - public void onJoinAccountsException(final Throwable e) { - AdobeAdeptJoinAccountDispatcherTest.LOG.debug( - "exception raised: ", - e); - latch.countDown(); - throw new UnreachableCodeException(); - } - - @Override - public boolean onPreparedQuery(final Uri.Builder builder) { - final Uri u = builder.build(); - AdobeAdeptJoinAccountDispatcherTest.LOG.debug("uri: {}", u); - - query.set(u.getEncodedQuery()); - latch.countDown(); - return false; - } - - @Override - public void onReceivedHTMLPage(final String text) { - latch.countDown(); - throw new UnreachableCodeException(); - } - - @Override - public void onReceivedACSM(final String text) { - latch.countDown(); - throw new UnreachableCodeException(); - } - }); - - latch.await(); - - Assert.assertEquals( - "username=LABS00000013&password=6534&sessionId" - + "=7310fdd40cdf3741bff0355a7aaa7c11d29cd176¤tNonce" - + "=b91d53984262bf0234b45a3b7b2addee5e7c6bf1&locale=en&responseType=acsm", - query.get()); - } -} diff --git a/org.librarysimplified.drm.core/build.gradle b/org.librarysimplified.drm.core/build.gradle deleted file mode 100644 index b84ac87..0000000 --- a/org.librarysimplified.drm.core/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -dependencies { - api libs.slf4j - api libs.io7m.junreachable - - implementation libs.androidx.core.ktx - implementation libs.kotlin.stdlib - implementation libs.r2.shared - implementation libs.palace.http.api -} - diff --git a/org.librarysimplified.drm.core/gradle.properties b/org.librarysimplified.drm.core/gradle.properties deleted file mode 100644 index ea70a34..0000000 --- a/org.librarysimplified.drm.core/gradle.properties +++ /dev/null @@ -1,5 +0,0 @@ -POM_ARTIFACT_ID=org.librarysimplified.drm.core -POM_DESCRIPTION=NYPL DRM (Core API) -POM_NAME=org.librarysimplified.drm.core -POM_PACKAGING=aar -POM_AUTOMATIC_MODULE_NAME=org.librarysimplified.drm.core diff --git a/org.librarysimplified.drm.core/src/main/AndroidManifest.xml b/org.librarysimplified.drm.core/src/main/AndroidManifest.xml deleted file mode 100644 index 0509214..0000000 --- a/org.librarysimplified.drm.core/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFileAsset.kt b/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFileAsset.kt deleted file mode 100644 index 2569bca..0000000 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFileAsset.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.nypl.drm.core - -import org.readium.r2.shared.publication.asset.FileAsset -import org.readium.r2.shared.publication.asset.PublicationAsset -import java.io.File - -/** - * A Readium2 Adept-protected asset. - */ - -class AdobeAdeptFileAsset( - - /** - * The actual EPUB file. - */ - - val fileAsset: FileAsset, - - /** - * The Adobe rights file, assuming there is one. - */ - - val adobeRightsFile: File?, - -) : PublicationAsset by fileAsset diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFileAsset.kt b/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFileAsset.kt deleted file mode 100644 index 306e005..0000000 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFileAsset.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.nypl.drm.core - -import org.readium.r2.shared.publication.asset.FileAsset -import org.readium.r2.shared.publication.asset.PublicationAsset -import java.io.File - -/** - * A Readium2 AxisNow-protected asset. - */ - -class AxisNowFileAsset( - - /** - * The actual EPUB file. - */ - - val fileAsset: FileAsset, - - /** - * The Axis license file, assuming there is one. - */ - - val axisLicense: File?, - - /** - * The Axis user key file, assuming there is one. - */ - - val axisUserKey: File?, - -) : PublicationAsset by fileAsset diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt b/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt deleted file mode 100644 index 9083abc..0000000 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.nypl.drm.core - -import android.content.Context -import org.readium.r2.shared.publication.ContentProtection - -interface ContentProtectionProvider { - - fun create(context: Context): ContentProtection? -} diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/package-info.java b/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/package-info.java deleted file mode 100644 index 4b172f2..0000000 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Core DRM types and interfaces. - */ - -@com.io7m.jnull.NonNullByDefault package org.nypl.drm.core; - diff --git a/org.thepalaceproject.android.platform b/org.thepalaceproject.android.platform index 62f5aa2..d641e14 160000 --- a/org.thepalaceproject.android.platform +++ b/org.thepalaceproject.android.platform @@ -1 +1 @@ -Subproject commit 62f5aa2e3c1bb60392cb5b8bd7f0a155870ec8ce +Subproject commit d641e148ddab2ee623dc38cf7a4debd2fbba6c59 diff --git a/org.thepalaceproject.drm.core.tests/build.gradle.kts b/org.thepalaceproject.drm.core.tests/build.gradle.kts new file mode 100644 index 0000000..5eb10cb --- /dev/null +++ b/org.thepalaceproject.drm.core.tests/build.gradle.kts @@ -0,0 +1,5 @@ +dependencies { + implementation(project(":org.thepalaceproject.drm.core")) + implementation(libs.slf4j) + implementation(libs.junit) +} diff --git a/org.thepalaceproject.drm.core.tests/gradle.properties b/org.thepalaceproject.drm.core.tests/gradle.properties new file mode 100644 index 0000000..1a5963f --- /dev/null +++ b/org.thepalaceproject.drm.core.tests/gradle.properties @@ -0,0 +1,5 @@ +POM_ARTIFACT_ID=org.thepalaceproject.drm.core.tests +POM_DESCRIPTION=NYPL DRM (Test suite) +POM_NAME=org.thepalaceproject.drm.core.tests +POM_PACKAGING=aar +POM_AUTOMATIC_MODULE_NAME=org.thepalaceproject.drm.core.tests diff --git a/org.librarysimplified.drm.core.tests/src/main/AndroidManifest.xml b/org.thepalaceproject.drm.core.tests/src/main/AndroidManifest.xml similarity index 75% rename from org.librarysimplified.drm.core.tests/src/main/AndroidManifest.xml rename to org.thepalaceproject.drm.core.tests/src/main/AndroidManifest.xml index d26ad70..ed9c2cc 100644 --- a/org.librarysimplified.drm.core.tests/src/main/AndroidManifest.xml +++ b/org.thepalaceproject.drm.core.tests/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ - + + diff --git a/org.librarysimplified.drm.core.tests/src/main/assets/logback.xml b/org.thepalaceproject.drm.core.tests/src/main/assets/logback.xml similarity index 100% rename from org.librarysimplified.drm.core.tests/src/main/assets/logback.xml rename to org.thepalaceproject.drm.core.tests/src/main/assets/logback.xml diff --git a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptACSMUtilitiesTest.java b/org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptACSMUtilitiesTest.java similarity index 100% rename from org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptACSMUtilitiesTest.java rename to org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptACSMUtilitiesTest.java diff --git a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptFulfillmentTokenTest.java b/org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptFulfillmentTokenTest.java similarity index 100% rename from org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptFulfillmentTokenTest.java rename to org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/AdobeAdeptFulfillmentTokenTest.java diff --git a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java b/org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java similarity index 67% rename from org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java rename to org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java index e121c76..3a2bc78 100644 --- a/org.librarysimplified.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java +++ b/org.thepalaceproject.drm.core.tests/src/main/java/org/nypl/drm/tests/core/package-info.java @@ -2,6 +2,5 @@ * Unit tests for core. */ -@com.io7m.jnull.NonNullByDefault package org.nypl.drm.tests.core; diff --git a/org.librarysimplified.drm.core.tests/src/main/resources/org/nypl/drm/tests/core/valid0.acsm b/org.thepalaceproject.drm.core.tests/src/main/resources/org/nypl/drm/tests/core/valid0.acsm similarity index 100% rename from org.librarysimplified.drm.core.tests/src/main/resources/org/nypl/drm/tests/core/valid0.acsm rename to org.thepalaceproject.drm.core.tests/src/main/resources/org/nypl/drm/tests/core/valid0.acsm diff --git a/org.thepalaceproject.drm.core/build.gradle.kts b/org.thepalaceproject.drm.core/build.gradle.kts new file mode 100644 index 0000000..c5bcf63 --- /dev/null +++ b/org.thepalaceproject.drm.core/build.gradle.kts @@ -0,0 +1,8 @@ +dependencies { + implementation(libs.androidx.core.ktx) + implementation(libs.io7m.junreachable) + implementation(libs.kotlin.stdlib) + implementation(libs.palace.http.api) + implementation(libs.r2.shared) + implementation(libs.slf4j) +} diff --git a/org.thepalaceproject.drm.core/gradle.properties b/org.thepalaceproject.drm.core/gradle.properties new file mode 100644 index 0000000..2285cf6 --- /dev/null +++ b/org.thepalaceproject.drm.core/gradle.properties @@ -0,0 +1,5 @@ +POM_ARTIFACT_ID=org.thepalaceproject.drm.core +POM_DESCRIPTION=NYPL DRM (Core API) +POM_NAME=org.thepalaceproject.drm.core +POM_PACKAGING=aar +POM_AUTOMATIC_MODULE_NAME=org.thepalaceproject.drm.core diff --git a/org.thepalaceproject.drm.core/src/main/AndroidManifest.xml b/org.thepalaceproject.drm.core/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9336d92 --- /dev/null +++ b/org.thepalaceproject.drm.core/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMException.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMException.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMException.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMException.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMUtilities.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMUtilities.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMUtilities.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptACSMUtilities.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAbstractDRMClient.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAbstractDRMClient.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAbstractDRMClient.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAbstractDRMClient.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java similarity index 88% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java index a441ff6..39a2fb9 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptActivationReceiverType.java @@ -1,7 +1,5 @@ package org.nypl.drm.core; -import com.io7m.jnull.Nullable; - /** *

The type of activation receivers.

* @@ -9,8 +7,8 @@ * (AdobeAdeptActivationReceiverType) */ -public interface AdobeAdeptActivationReceiverType -{ +public interface AdobeAdeptActivationReceiverType { + /** * Receive the number of activations, if any. * @@ -36,7 +34,7 @@ void onActivation( final AdobeDeviceID device_id, final String user_name, final AdobeUserID user_id, - final @Nullable String expires); + final String expires); /** * Receive activation errors, if any. diff --git a/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAssets.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAssets.kt new file mode 100644 index 0000000..d40f8b5 --- /dev/null +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptAssets.kt @@ -0,0 +1,81 @@ +package org.nypl.drm.core + +import org.readium.r2.shared.util.Url +import org.readium.r2.shared.util.asset.ContainerAsset +import org.readium.r2.shared.util.data.CompositeContainer +import org.readium.r2.shared.util.file.FileResource +import org.readium.r2.shared.util.format.AdeptSpecification +import org.readium.r2.shared.util.format.Format +import org.readium.r2.shared.util.format.FormatSpecification +import org.readium.r2.shared.util.format.Specification +import org.readium.r2.shared.util.resource.SingleResourceContainer +import java.io.File + +/** + * Functions to open Adobe-encrypted EPUB files in a form the Readium2 DRM can handle. + */ + +object AdobeAdeptAssets { + + /** + * The path at which the rights file is "mounted" within the container. + */ + + const val RIGHTS_PATH = "META-INF/rights.xml" + + /** + * The path at which the encryption descriptor can be found. + */ + + const val ENCRYPTION_PATH = "META-INF/encryption.xml" + + /** + * Open an encrypted EPUB as an asset. + */ + + @JvmStatic + fun openAsset( + epubAsset: ContainerAsset, + rightsFile: File + ): ContainerAsset { + /* + * We need to make the separate rights file appear as if it were an entry in the EPUB file. + * We can do this by creating a "composite container" that conceptually merges the rights + * file and the original EPUB file. + */ + + val rightsResource = + FileResource(rightsFile) + val rightsContainer = + SingleResourceContainer( + entryUrl = Url(RIGHTS_PATH)!!, + resource = rightsResource + ) + + val mainContainer = + CompositeContainer(epubAsset.container, rightsContainer) + + /* + * We need to add Adobe Adept as a specification to the existing format. + */ + + val specifications = mutableSetOf() + specifications.addAll(epubAsset.format.specification.specifications) + specifications.add(AdeptSpecification) + + val formatSpecification = + FormatSpecification(epubAsset.format.specification.specifications) + + val encryptedFormat = + Format( + specification = formatSpecification, + mediaType = epubAsset.format.mediaType, + fileExtension = epubAsset.format.fileExtension + ) + + return ContainerAsset( + format = encryptedFormat, + container = mainContainer + ) + } +} diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java similarity index 87% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java index 6948050..5522088 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactory.java @@ -1,7 +1,7 @@ package org.nypl.drm.core; import java.util.Objects; -import com.io7m.jnull.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,21 +65,17 @@ //@formatter:on public final class AdobeAdeptConnectorFactory - implements AdobeAdeptConnectorFactoryType -{ - private static final String CLASS_NAME; - private static final Logger LOG; - private static @Nullable AdobeAdeptConnectorType INSTANCE; + implements AdobeAdeptConnectorFactoryType { + private static final String CLASS_NAME; + private static final Logger LOG; + private static AdobeAdeptConnectorType INSTANCE; static { - LOG = Objects.requireNonNull(LoggerFactory.getLogger( - AdobeAdeptConnectorFactory.class)); - + LOG = Objects.requireNonNull(LoggerFactory.getLogger(AdobeAdeptConnectorFactory.class)); CLASS_NAME = "org.nypl.drm.adobe.AdobeAdeptConnector"; } - private AdobeAdeptConnectorFactory() - { + private AdobeAdeptConnectorFactory() { // Nothing } @@ -87,15 +83,14 @@ private AdobeAdeptConnectorFactory() * @return A new factory */ - public static AdobeAdeptConnectorFactoryType get() - { + public static AdobeAdeptConnectorFactoryType get() { return new AdobeAdeptConnectorFactory(); } - @Override public AdobeAdeptConnectorType get( + @Override + public AdobeAdeptConnectorType get( final AdobeAdeptConnectorParameters p) - throws DRMException - { + throws DRMException { Objects.requireNonNull(p); try { @@ -107,8 +102,7 @@ public static AdobeAdeptConnectorFactoryType get() AdobeAdeptConnectorFactory.LOG.debug( "looking up class {}", AdobeAdeptConnectorFactory.CLASS_NAME); - @SuppressWarnings("unchecked") - final Class c = + @SuppressWarnings("unchecked") final Class c = (Class) Class.forName( AdobeAdeptConnectorFactory.CLASS_NAME); diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactoryType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactoryType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactoryType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorFactoryType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorParameters.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorParameters.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorParameters.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorParameters.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptConnectorType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java similarity index 80% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java index 4ff6340..27fe018 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactory.java @@ -1,7 +1,7 @@ package org.nypl.drm.core; import java.util.Objects; -import com.io7m.jnull.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,20 +21,17 @@ //@formatter:on public final class AdobeAdeptContentFilterFactory - implements AdobeAdeptContentFilterFactoryType -{ - private static final String CLASS_NAME; - private static final Logger LOG; - private static @Nullable AdobeAdeptContentFilterType INSTANCE; + implements AdobeAdeptContentFilterFactoryType { + private static final String CLASS_NAME; + private static final Logger LOG; + private static AdobeAdeptContentFilterType INSTANCE; static { LOG = Objects.requireNonNull(LoggerFactory.getLogger(AdobeAdeptContentFilterFactory.class)); - CLASS_NAME = "org.nypl.drm.adobe.AdobeAdeptContentFilter"; } - private AdobeAdeptContentFilterFactory() - { + private AdobeAdeptContentFilterFactory() { // Nothing } @@ -42,12 +39,12 @@ private AdobeAdeptContentFilterFactory() * @return A new factory */ - public static AdobeAdeptContentFilterFactoryType get() - { + public static AdobeAdeptContentFilterFactoryType get() { return new AdobeAdeptContentFilterFactory(); } - @Override public AdobeAdeptContentFilterType get( + @Override + public AdobeAdeptContentFilterType get( final String package_name, final String package_version, final AdobeAdeptResourceProviderType res, @@ -58,8 +55,7 @@ public static AdobeAdeptContentFilterFactoryType get() final File xml_storage, final File book_path, final File temporary_dir) - throws DRMException - { + throws DRMException { Objects.requireNonNull(package_name); Objects.requireNonNull(package_version); Objects.requireNonNull(res); @@ -81,8 +77,7 @@ public static AdobeAdeptContentFilterFactoryType get() AdobeAdeptContentFilterFactory.LOG.debug( "looking up class {}", AdobeAdeptContentFilterFactory.CLASS_NAME); - @SuppressWarnings("unchecked") - final Class c = + @SuppressWarnings("unchecked") final Class c = (Class) Class.forName( AdobeAdeptContentFilterFactory.CLASS_NAME); @@ -104,17 +99,17 @@ public static AdobeAdeptContentFilterFactoryType get() AdobeAdeptContentFilterFactory.LOG.debug( "invoking 'get' method on {}", c); final AdobeAdeptContentFilterType instance = Objects.requireNonNull((AdobeAdeptContentFilterType) gm.invoke( - null, - package_name, - package_version, - res, - net, - device_serial, - device_name, - app_storage, - xml_storage, - book_path, - temporary_dir)); + null, + package_name, + package_version, + res, + net, + device_serial, + device_name, + app_storage, + xml_storage, + book_path, + temporary_dir)); AdobeAdeptContentFilterFactory.INSTANCE = instance; AdobeAdeptContentFilterFactory.LOG.debug("returning fresh instance"); diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactoryType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactoryType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactoryType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterFactoryType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentFilterType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentRightsClientType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentRightsClientType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentRightsClientType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptContentRightsClientType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDRMClientType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDRMClientType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDRMClientType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDRMClientType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationAdapter.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationAdapter.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationAdapter.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationAdapter.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationReceiverType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationReceiverType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationReceiverType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptDeactivationReceiverType.java diff --git a/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptErrors.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptErrors.kt new file mode 100644 index 0000000..7f22958 --- /dev/null +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptErrors.kt @@ -0,0 +1,34 @@ +package org.nypl.drm.core + +import org.readium.r2.shared.util.Error +import org.readium.r2.shared.util.format.AdeptSpecification +import org.nypl.drm.core.AdobeAdeptAssets.ENCRYPTION_PATH +import org.nypl.drm.core.AdobeAdeptAssets.RIGHTS_PATH + +data object AdobeErrorNoSpecification : Error { + override val cause: Error? = + null + override val message: String = + "The given asset does not have $AdeptSpecification in its format" +} + +data object AdobeErrorNotContainer : Error { + override val cause: Error? = + null + override val message: String = + "The given asset is not a ContainerAsset" +} + +data object AdobeErrorRightsFileMissing : Error { + override val cause: Error? = + null + override val message: String = + "No $RIGHTS_PATH was included as part of the provided asset" +} + +data object AdobeErrorEncryptionFileMissing : Error { + override val cause: Error? = + null + override val message: String = + "No $ENCRYPTION_PATH was included as part of the provided asset" +} diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutor.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutor.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutor.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutor.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutorType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutorType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutorType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptExecutorType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java similarity index 99% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java index d1fb5b6..c88e44a 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentAdapter.java @@ -4,7 +4,6 @@ import org.slf4j.Logger; import java.io.File; -import java.nio.ByteBuffer; /** * An adapter to convert the results of fulfillment as delivered by the Adobe diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentListenerType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentListenerType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentListenerType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentListenerType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentToken.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentToken.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentToken.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptFulfillmentToken.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountAdapter.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountAdapter.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountAdapter.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountAdapter.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcher.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcher.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcher.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcher.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherListenerType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherListenerType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherListenerType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherListenerType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountDispatcherType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountInjection.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountInjection.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountInjection.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountInjection.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountListenerType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountListenerType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountListenerType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptJoinAccountListenerType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoan.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoan.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoan.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoan.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnAdapter.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnAdapter.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnAdapter.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnAdapter.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnListenerType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnListenerType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnListenerType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptLoanReturnListenerType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java similarity index 86% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java index 86f7c9a..21c89b0 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProvider.java @@ -1,7 +1,7 @@ package org.nypl.drm.core; import java.util.Objects; -import com.io7m.jnull.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,9 +23,9 @@ * interface. */ -@SuppressWarnings("boxing") public final class AdobeAdeptNetProvider - implements AdobeAdeptNetProviderType -{ +@SuppressWarnings("boxing") +public final class AdobeAdeptNetProvider + implements AdobeAdeptNetProviderType { private static final Logger LOG; static { @@ -33,13 +33,12 @@ Objects.requireNonNull(LoggerFactory.getLogger(AdobeAdeptNetProvider.class)); } - private final String user_agent; + private final String user_agent; private final AtomicInteger recursion; private final AtomicBoolean want_cancel; private AdobeAdeptNetProvider( - final String in_user_agent) - { + final String in_user_agent) { this.user_agent = Objects.requireNonNull(in_user_agent); this.recursion = new AtomicInteger(0); this.want_cancel = new AtomicBoolean(false); @@ -49,23 +48,21 @@ private AdobeAdeptNetProvider( * Retrieve a new instance of the net provider. * * @param in_user_agent The user agent that will be used to make requests. - * * @return A new net provider */ public static AdobeAdeptNetProviderType get( - final String in_user_agent) - { + final String in_user_agent) { return new AdobeAdeptNetProvider(in_user_agent); } - @Override public @Nullable AdobeAdeptStreamType newStream( + @Override + public AdobeAdeptStreamType newStream( final String method, final String url_text, - final @Nullable AdobeAdeptStreamClientType client, - final @Nullable String post_data_content_type, - final @Nullable byte[] post_data) - { + final AdobeAdeptStreamClientType client, + final String post_data_content_type, + final byte[] post_data) { Objects.requireNonNull(method); Objects.requireNonNull(url_text); @@ -118,58 +115,52 @@ public static AdobeAdeptNetProviderType get( return null; } - @Override public void cancel() - { + @Override + public void cancel() { AdobeAdeptNetProvider.LOG.debug("requesting download cancellation"); this.want_cancel.compareAndSet(false, true); } - private static final class PostData - { + private static final class PostData { private final String content_type; private final byte[] data; public PostData( final String in_content_type, - final byte[] in_data) - { + final byte[] in_data) { this.content_type = Objects.requireNonNull(in_content_type); this.data = Objects.requireNonNull(in_data); } - public String getContentType() - { + public String getContentType() { return this.content_type; } - public byte[] getData() - { + public byte[] getData() { return this.data; } } - private static final class Stream implements AdobeAdeptStreamType - { + private static final class Stream implements AdobeAdeptStreamType { private static final Logger LOG_STREAM; static { LOG_STREAM = Objects.requireNonNull(LoggerFactory.getLogger(Stream.class)); } - private final HttpURLConnection conn; - private final AtomicInteger recursion; - private final @Nullable PostData post_data; - private final AtomicBoolean want_cancel; - private @Nullable AdobeAdeptStreamClientType client; - private int content_length; + private final HttpURLConnection conn; + private final AtomicInteger recursion; + private final PostData post_data; + private final AtomicBoolean want_cancel; + private AdobeAdeptStreamClientType client; + private int content_length; public Stream( final HttpURLConnection in_conn, - final @Nullable AdobeAdeptStreamClientType in_client, + final AdobeAdeptStreamClientType in_client, final AtomicInteger in_recursion, - final @Nullable PostData in_post_data, - final AtomicBoolean in_want_cancel) - { + final PostData in_post_data, + final AtomicBoolean in_want_cancel) { this.conn = Objects.requireNonNull(in_conn); this.client = in_client; this.recursion = Objects.requireNonNull(in_recursion); @@ -179,17 +170,17 @@ public Stream( Stream.LOG_STREAM.debug("constructed stream with client {}", in_client); } - @Override public void onError( - final String message) - { + @Override + public void onError( + final String message) { final AdobeAdeptStreamClientType c = Objects.requireNonNull(this.client); c.onError("E_STREAM_ERROR: " + message); } - @Override public void onRequestBytes( + @Override + public void onRequestBytes( final long offset, - final long size) - { + final long size) { Stream.LOG_STREAM.debug("onRequestBytes: {} {}", offset, size); try { @@ -211,7 +202,7 @@ public Stream( final int r = is.read(buffer); if (r == -1) { eof = true; - data = new byte[] {}; + data = new byte[]{}; } else { if (r == buffer.length) { data = buffer; @@ -265,8 +256,8 @@ public Stream( } } - @Override public void onRequestInfo() - { + @Override + public void onRequestInfo() { final int r = this.recursion.incrementAndGet(); Stream.LOG_STREAM.debug( @@ -337,8 +328,7 @@ public Stream( } private void sendPostData(final PostData post) - throws IOException - { + throws IOException { final byte[] post_bytes = post.getData(); this.conn.setDoOutput(true); @@ -353,8 +343,7 @@ private void sendPostData(final PostData post) out.close(); } - private void reportHeaders(final Map> headers) - { + private void reportHeaders(final Map> headers) { for (final String k : headers.keySet()) { if (k == null) { // A null key indicates that this header is the HTTP status line @@ -385,24 +374,22 @@ private void reportHeaders(final Map> headers) } } - @Override public void onRelease() - { + @Override + public void onRelease() { Stream.LOG_STREAM.debug("onRelease: {}", this.conn.getURL()); this.conn.disconnect(); } - @Override public void onSetStreamClient( - final @Nullable AdobeAdeptStreamClientType c) - { + @Override + public void onSetStreamClient( + final AdobeAdeptStreamClientType c) { Stream.LOG_STREAM.debug("setStreamClient: {}", c); this.client = c; } } - private static final class CancelledDownloadException extends Exception - { - CancelledDownloadException() - { + private static final class CancelledDownloadException extends Exception { + CancelledDownloadException() { super(); } } diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java similarity index 82% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java index e07fcee..eb379a6 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptNetProviderType.java @@ -1,13 +1,10 @@ package org.nypl.drm.core; -import com.io7m.jnull.Nullable; - /** *

The type of net providers.

*/ -public interface AdobeAdeptNetProviderType -{ +public interface AdobeAdeptNetProviderType { /** *

Open a new stream to url, using method, delivering * data to client. Optional data to be sent to the destination may be @@ -24,18 +21,17 @@ public interface AdobeAdeptNetProviderType * @param client The stream client * @param post_data_content_type The post data type, if any * @param post_data The post data, if any - * * @return A new stream, or null if the stream cannot be opened for * any reason. Implementations are encouraged to notify the stream client of * specific errors. */ - @Nullable AdobeAdeptStreamType newStream( + AdobeAdeptStreamType newStream( String method, String url, - @Nullable AdobeAdeptStreamClientType client, - @Nullable String post_data_content_type, - @Nullable byte[] post_data); + AdobeAdeptStreamClientType client, + String post_data_content_type, + byte[] post_data); /** * Cancel the currently running download. diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptProcedureType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptProcedureType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptProcedureType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptProcedureType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java similarity index 93% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java index c21836c..6bbdc65 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProvider.java @@ -1,7 +1,6 @@ package org.nypl.drm.core; import java.util.Objects; -import com.io7m.jnull.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +38,7 @@ public static AdobeAdeptResourceProviderType get(final byte[] in_certificate) return new AdobeAdeptResourceProvider(in_certificate); } - @Override public @Nullable byte[] getResourceAsBytes( + @Override public byte[] getResourceAsBytes( final String name) { AdobeAdeptResourceProvider.LOG.debug("getResource: {}", name); diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java similarity index 82% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java index 158cad2..1e47b88 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptResourceProviderType.java @@ -1,7 +1,5 @@ package org.nypl.drm.core; -import com.io7m.jnull.Nullable; - /** * The type of functions that map resources to byte arrays. */ @@ -15,6 +13,6 @@ public interface AdobeAdeptResourceProviderType * null if the resource does not exist. */ - @Nullable byte[] getResourceAsBytes( + byte[] getResourceAsBytes( String name); } diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamClientType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamClientType.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamClientType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamClientType.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java similarity index 88% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java index cad3f9f..db6005a 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeAdeptStreamType.java @@ -1,15 +1,12 @@ package org.nypl.drm.core; -import com.io7m.jnull.Nullable; - /** *

The type of streams.

When used as part of the Adobe Adept * Connector, the streams are almost always HTTP(s) connections, used to * authorize devices and download books.

*/ -public interface AdobeAdeptStreamType -{ +public interface AdobeAdeptStreamType { /** * Called when information about the stream should be requested. For example, * a stream that represents an HTTP connection would open the connection here @@ -51,5 +48,5 @@ void onError( * @param c A new stream client */ - void onSetStreamClient(@Nullable AdobeAdeptStreamClientType c); + void onSetStreamClient(AdobeAdeptStreamClientType c); } diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeDeviceID.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeDeviceID.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeDeviceID.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeDeviceID.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeLoanID.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeLoanID.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeLoanID.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeLoanID.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeUserID.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeUserID.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeUserID.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeUserID.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeVendorID.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeVendorID.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AdobeVendorID.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AdobeVendorID.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/Assertions.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/Assertions.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/Assertions.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/Assertions.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt similarity index 54% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt index ecd6445..f5c9f6e 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillment.kt @@ -3,7 +3,7 @@ package org.nypl.drm.core import java.io.File data class AxisNowFulfillment( - val book: File, - val license: File, - val userKey: File -) \ No newline at end of file + val book: File, + val license: File, + val userKey: File, +) diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt similarity index 63% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt index a33f6d2..2d5aace 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowFulfillmentException.kt @@ -1,4 +1,4 @@ package org.nypl.drm.core -class AxisNowFulfillmentException(message: String? = null, cause: Throwable? = null) - : Exception(message, cause) \ No newline at end of file +class AxisNowFulfillmentException(message: String? = null, cause: Throwable? = null) : + Exception(message, cause) diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt similarity index 64% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt index 8ac3252..771b929 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceFactoryType.kt @@ -4,5 +4,5 @@ import org.librarysimplified.http.api.LSHTTPClientType interface AxisNowServiceFactoryType { - fun create(httpClient: LSHTTPClientType): AxisNowServiceType -} \ No newline at end of file + fun create(httpClient: LSHTTPClientType): AxisNowServiceType +} diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt similarity index 50% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt index fc22f7d..5bf3cf2 100644 --- a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/AxisNowServiceType.kt @@ -4,5 +4,5 @@ import java.io.File interface AxisNowServiceType { - fun fulfill(token: ByteArray, tempFactory: () -> File): AxisNowFulfillment -} \ No newline at end of file + fun fulfill(token: ByteArray, tempFactory: () -> File): AxisNowFulfillment +} diff --git a/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt new file mode 100644 index 0000000..955bc90 --- /dev/null +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/ContentProtectionProvider.kt @@ -0,0 +1,9 @@ +package org.nypl.drm.core + +import android.app.Application +import org.readium.r2.shared.publication.protection.ContentProtection + +interface ContentProtectionProvider { + + fun create(context: Application): ContentProtection? +} diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMDecryptionException.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMDecryptionException.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMDecryptionException.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMDecryptionException.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMException.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMException.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMException.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMException.java diff --git a/org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMUnsupportedException.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMUnsupportedException.java similarity index 100% rename from org.librarysimplified.drm.core/src/main/java/org/nypl/drm/core/DRMUnsupportedException.java rename to org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/DRMUnsupportedException.java diff --git a/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/package-info.java b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/package-info.java new file mode 100644 index 0000000..a2890e7 --- /dev/null +++ b/org.thepalaceproject.drm.core/src/main/java/org/nypl/drm/core/package-info.java @@ -0,0 +1,6 @@ +/** + * Core DRM types and interfaces. + */ + +package org.nypl.drm.core; + diff --git a/org.librarysimplified.drm.core/src/main/resources/org/nypl/drm/core/AdobeAdeptJoinAccountsInjected.js b/org.thepalaceproject.drm.core/src/main/resources/org/nypl/drm/core/AdobeAdeptJoinAccountsInjected.js similarity index 100% rename from org.librarysimplified.drm.core/src/main/resources/org/nypl/drm/core/AdobeAdeptJoinAccountsInjected.js rename to org.thepalaceproject.drm.core/src/main/resources/org/nypl/drm/core/AdobeAdeptJoinAccountsInjected.js diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index f4583d6..0000000 --- a/settings.gradle +++ /dev/null @@ -1,12 +0,0 @@ -enableFeaturePreview('VERSION_CATALOGS') - -dependencyResolutionManagement { - versionCatalogs { - libs { - from(files("org.thepalaceproject.android.platform/build_libraries.toml")) - } - } -} - -include ":org.librarysimplified.drm.core" -include ":org.librarysimplified.drm.core.tests" diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..9d0d3d3 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,44 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + google() + } +} + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("$rootDir/org.thepalaceproject.android.platform/build_libraries.toml")) + } + } + + /* + * The set of repositories used to resolve library dependencies. The order is significant! + */ + + repositories { + mavenLocal() + mavenCentral() + google() + + /* + * Allow access to the Sonatype snapshots repository. + */ + + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + } + + /* + * Allow access to Jitpack. This is used by, for example, Readium. + */ + + maven { + url = uri("https://jitpack.io") + } + } +} + +include(":org.thepalaceproject.drm.core") +include(":org.thepalaceproject.drm.core.tests")