diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..83f366f
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,16 @@
+# EditorConfig is awesome: https://EditorConfig.org
+
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+# noinspection EditorConfigKeyCorrectness
+[*.{kt,kts}]
+ktlint_code_style = intellij_idea
+ktlint_function_naming_ignore_when_annotated_with = Composable
+ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = unset
+ktlint_standard_no-wildcard-imports = disabled
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 15cf15f..6a0e7b4 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- - name: Set up JDK 17
+ - name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
- java-version: 17
+ java-version: 21
- name: Run Spotless
run: ./gradlew spotlessCheck
@@ -22,11 +22,11 @@ jobs:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- - name: Set up JDK 17
+ - name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
- java-version: 17
+ java-version: 21
- name: Setup Android problem matchers
uses: jonasb/android-problem-matchers-action@v1
- name: Build with Gradle
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 4d4e5be..7a15fb6 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,7 +11,7 @@
-
+
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 8491b65..69c42ca 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -4,6 +4,6 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 13ec721..77d2007 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ repositories {
}
dependencies {
- implementation("de.peilicke.sascha:android-customtabs:3.0.3")
+ implementation("de.peilicke.sascha:android-customtabs:3.1.0")
}
```
diff --git a/build.gradle.kts b/build.gradle.kts
index c5deb02..ee7818f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -14,42 +14,24 @@
* limitations under the License.
*/
-buildscript {
- repositories {
- google()
- }
- dependencies {
- classpath("com.android.tools.build:gradle:8.5.2")
- }
-}
-
plugins {
- id("com.diffplug.spotless") version "5.12.4"
- id("com.github.ben-manes.versions") version "0.38.0"
- kotlin("jvm") version "1.6.20"
-}
-
-repositories {
- mavenCentral()
+ id("com.android.application") version "8.5.2" apply false
+ id("com.diffplug.spotless") version "6.25.0"
+ id("com.github.ben-manes.versions") version "0.51.0"
+ kotlin("android") version "2.0.20" apply false
}
spotless {
- format("misc") {
- target("**/*.gradle", "**/*.md", "**/.gitignore")
- trimTrailingWhitespace()
- endWithNewline()
- }
freshmark {
target("**/*.md")
propertiesFile("gradle.properties")
}
kotlin {
- target("*/src/**/*.kt")
- ktlint().userData(mapOf("disabled_rules" to "no-wildcard-imports"))
+ target("**/*.kt")
+ ktlint().setEditorConfigPath("${project.rootDir}/.editorconfig")
}
kotlinGradle {
- target("**/*.gradle.kts")
- ktlint()
+ ktlint().setEditorConfigPath("${project.rootDir}/.editorconfig")
}
}
diff --git a/customtabs-example/build.gradle.kts b/customtabs-example/build.gradle.kts
index 8803015..3e5a42a 100644
--- a/customtabs-example/build.gradle.kts
+++ b/customtabs-example/build.gradle.kts
@@ -17,49 +17,45 @@
plugins {
id("com.android.application")
kotlin("android")
- kotlin("android.extensions")
}
-repositories {
- google()
- mavenCentral()
+dependencies {
+ implementation(project(":customtabs"))
+ implementation("androidx.constraintlayout:constraintlayout:2.1.4")
+ implementation("androidx.vectordrawable:vectordrawable-animated:1.2.0")
+ implementation("com.google.android.material:material:1.12.0")
}
+java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
+
android {
namespace = "com.example.saschpe.customtabs"
defaultConfig {
applicationId = "com.example.saschpe.customtabs"
- compileSdk = 33
- minSdk = 17
- targetSdk = 33
- versionCode = 170030003
- versionName = "3.0.3"
- base.archivesBaseName = "$applicationId-$versionName"
+ compileSdk = 34
+ minSdk = 21
+ targetSdk = 34
+ versionCode = 210030100
+ versionName = "3.1.0"
+ base.archivesName = "$applicationId-$versionName"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
+ buildFeatures {
+ viewBinding = true
+ }
+
buildTypes {
- named("release") {
+ debug {
+ applicationIdSuffix = ".debug"
+ }
+ release {
isMinifyEnabled = true
isShrinkResources = true
- proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
+ proguardFiles(getDefaultProguardFile("proguard-android.txt"))
signingConfig = signingConfigs.getByName("debug")
}
}
-
- compileOptions {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
- }
-
- kotlinOptions.jvmTarget = "1.8"
-}
-
-dependencies {
- implementation(project(":customtabs"))
- implementation("androidx.constraintlayout:constraintlayout:2.0.4")
- implementation("androidx.vectordrawable:vectordrawable-animated:1.1.0")
- implementation("com.google.android.material:material:1.3.0")
}
diff --git a/customtabs-example/src/main/kotlin/com/example/saschpe/customtabs/activity/MainActivity.kt b/customtabs-example/src/main/kotlin/com/example/saschpe/customtabs/activity/MainActivity.kt
index c9a8195..1271db3 100644
--- a/customtabs-example/src/main/kotlin/com/example/saschpe/customtabs/activity/MainActivity.kt
+++ b/customtabs-example/src/main/kotlin/com/example/saschpe/customtabs/activity/MainActivity.kt
@@ -19,21 +19,21 @@ package com.example.saschpe.customtabs.activity
import android.graphics.Bitmap
import android.graphics.Canvas
import android.net.Uri
-import android.os.Build
import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
+import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.res.ResourcesCompat
-import androidx.core.graphics.drawable.DrawableCompat
import com.example.saschpe.customtabs.R
-import kotlinx.android.synthetic.main.activity_main.fab
-import kotlinx.android.synthetic.main.activity_main.toolbar
+import com.example.saschpe.customtabs.databinding.ActivityMainBinding
import saschpe.android.customtabs.CustomTabsHelper
import saschpe.android.customtabs.WebViewFallback
class MainActivity : AppCompatActivity() {
+ private lateinit var binding: ActivityMainBinding
+
/**
* Apply some sensible defaults across a single app.
* Not strictly necessary but simplifies code when having many different
@@ -44,8 +44,12 @@ class MainActivity : AppCompatActivity() {
private val defaultCustomTabsIntentBuilder: CustomTabsIntent.Builder
get() {
val builder = CustomTabsIntent.Builder()
- .addDefaultShareMenuItem()
- .setToolbarColor(ResourcesCompat.getColor(resources, R.color.colorPrimary, null))
+ .setShareState(CustomTabsIntent.SHARE_STATE_ON)
+ .setDefaultColorSchemeParams(
+ CustomTabColorSchemeParams.Builder()
+ .setToolbarColor(ResourcesCompat.getColor(resources, R.color.colorPrimary, null))
+ .build(),
+ )
.setShowTitle(true)
getBitmapFromVectorDrawable(R.drawable.ic_arrow_back_white_24dp)?.let {
builder.setCloseButtonIcon(it)
@@ -55,10 +59,11 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- setSupportActionBar(toolbar)
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ setSupportActionBar(binding.toolbar)
- fab.setOnClickListener { startGitHubProjectCustomTab() }
+ binding.fab.setOnClickListener { startGitHubProjectCustomTab() }
}
/**
@@ -80,7 +85,7 @@ class MainActivity : AppCompatActivity() {
this,
customTabsIntent,
Uri.parse(GITHUB_PAGE),
- WebViewFallback()
+ WebViewFallback(),
)
}
@@ -90,16 +95,9 @@ class MainActivity : AppCompatActivity() {
* @param drawableId The drawable ID
* @return Bitmap equivalent
*/
- private fun getBitmapFromVectorDrawable(@DrawableRes drawableId: Int): Bitmap? {
- var drawable = AppCompatResources.getDrawable(this, drawableId) ?: return null
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- drawable = DrawableCompat.wrap(drawable).mutate()
- }
-
- val bitmap = Bitmap.createBitmap(
- drawable.intrinsicWidth,
- drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
- )
+ private fun getBitmapFromVectorDrawable(@Suppress("SameParameterValue") @DrawableRes drawableId: Int): Bitmap? {
+ val drawable = AppCompatResources.getDrawable(this, drawableId) ?: return null
+ val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
diff --git a/customtabs/build.gradle.kts b/customtabs/build.gradle.kts
index 20c00ad..2680d97 100644
--- a/customtabs/build.gradle.kts
+++ b/customtabs/build.gradle.kts
@@ -17,22 +17,29 @@
plugins {
id("com.android.library")
kotlin("android")
- id("org.jetbrains.dokka") version "1.4.32"
`maven-publish`
signing
}
-repositories {
- google()
- mavenCentral()
+dependencies {
+ api("androidx.browser:browser:1.8.0")
+
+ implementation("androidx.appcompat:appcompat:1.7.0")
+
+ testImplementation("androidx.test:core:1.6.1")
+ testImplementation("androidx.test.ext:junit:1.2.1")
+ testImplementation("org.robolectric:robolectric:4.13")
+ testImplementation("org.mockito:mockito-core:5.13.0")
}
+java.toolchain.languageVersion.set(JavaLanguageVersion.of(21))
+
android {
namespace = "saschpe.android.customtabs"
defaultConfig {
- compileSdk = 33
- minSdk = 16
+ compileSdk = 34
+ minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@@ -43,40 +50,13 @@ android {
}
}
- compileOptions {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
- }
-
- kotlinOptions.jvmTarget = "1.8"
-
testOptions.unitTests.isIncludeAndroidResources = true
-}
-
-dependencies {
- api("androidx.browser:browser:1.2.0")
-
- implementation("androidx.appcompat:appcompat:1.2.0")
- testImplementation("androidx.test:core:1.3.0")
- testImplementation("androidx.test.ext:junit:1.1.2")
- testImplementation("org.robolectric:robolectric:4.7.1")
- testImplementation("org.mockito:mockito-core:3.9.0")
-}
-
-group = "de.peilicke.sascha"
-version = android.defaultConfig.versionName.toString()
-
-tasks {
- register("javadocJar", Jar::class) {
- dependsOn(named("dokkaHtml"))
- archiveClassifier.set("javadoc")
- from("$buildDir/dokka/html")
- }
-
- register("sourcesJar", Jar::class) {
- archiveClassifier.set("sources")
- from(android.sourceSets.getByName("main").java.srcDirs)
+ publishing {
+ singleVariant("release") {
+ withSourcesJar()
+ withJavadocJar()
+ }
}
}
@@ -84,11 +64,12 @@ publishing {
publications {
register("mavenAndroid") {
artifactId = "android-customtabs"
- version = "3.0.3"
+ groupId = "de.peilicke.sascha"
+ version = "3.1.0"
- afterEvaluate { artifact(tasks.getByName("bundleReleaseAar")) }
- artifact(tasks.getByName("javadocJar"))
- artifact(tasks.getByName("sourcesJar"))
+ afterEvaluate {
+ from(components["release"])
+ }
pom {
name.set("Android CustomTabs")
@@ -113,28 +94,6 @@ publishing {
developerConnection.set("scm:git:ssh://github.com/saschpe/android-customtabs.git")
url.set("https://github.com/saschpe/android-customtabs")
}
-
- withXml {
- fun groovy.util.Node.addDependency(dependency: Dependency, scope: String) {
- appendNode("dependency").apply {
- appendNode("groupId", dependency.group)
- appendNode("artifactId", dependency.name)
- appendNode("version", dependency.version)
- appendNode("scope", scope)
- }
- }
-
- asNode().appendNode("dependencies").let { dependencies ->
- // List all "api" dependencies as "compile" dependencies
- configurations.api.get().allDependencies.forEach {
- dependencies.addDependency(it, "compile")
- }
- // List all "implementation" dependencies as "runtime" dependencies
- configurations.implementation.get().allDependencies.forEach {
- dependencies.addDependency(it, "runtime")
- }
- }
- }
}
}
}
diff --git a/customtabs/proguard-rules.pro b/customtabs/proguard-rules.pro
index e4dede5..9e6f1f5 100644
--- a/customtabs/proguard-rules.pro
+++ b/customtabs/proguard-rules.pro
@@ -21,4 +21,5 @@
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
-}
\ No newline at end of file
+}
+-dontwarn java.lang.invoke.StringConcatFactory
diff --git a/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsHelper.kt b/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsHelper.kt
index 854a765..ce024b7 100644
--- a/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsHelper.kt
+++ b/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsHelper.kt
@@ -84,7 +84,7 @@ class CustomTabsHelper {
val myConnection = object : CustomTabsServiceConnection() {
override fun onCustomTabsServiceConnected(
name: ComponentName,
- newClient: CustomTabsClient
+ newClient: CustomTabsClient,
) {
client = newClient
client?.warmup(0L)
@@ -156,7 +156,7 @@ class CustomTabsHelper {
context: Context,
customTabsIntent: CustomTabsIntent,
uri: Uri,
- fallback: CustomTabFallback?
+ fallback: CustomTabFallback?,
) {
val packageName = getPackageNameToUse(context)
// If we can't find a package name, it means there's no browser that supports Chrome Custom Tabs installed.
@@ -168,7 +168,7 @@ class CustomTabsHelper {
customTabsIntent.intent
.putExtra(
Intent.EXTRA_REFERRER,
- Uri.parse("${Intent.URI_ANDROID_APP_SCHEME}//${context.packageName}")
+ Uri.parse("${Intent.URI_ANDROID_APP_SCHEME}//${context.packageName}"),
)
}
customTabsIntent.intent.setPackage(packageName)
@@ -177,9 +177,12 @@ class CustomTabsHelper {
}
fun addKeepAliveExtra(context: Context, intent: Intent) {
- intent.putExtra(EXTRA_CUSTOM_TABS_KEEP_ALIVE, Intent().apply {
- setClassName(context.packageName, KeepAliveService::class.java.canonicalName as String)
- })
+ intent.putExtra(
+ EXTRA_CUSTOM_TABS_KEEP_ALIVE,
+ Intent().apply {
+ setClassName(context.packageName, KeepAliveService::class.java.canonicalName as String)
+ },
+ )
}
}
}
diff --git a/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsPackageHelper.kt b/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsPackageHelper.kt
index f8eef4f..dd06131 100644
--- a/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsPackageHelper.kt
+++ b/customtabs/src/main/java/saschpe/android/customtabs/CustomTabsPackageHelper.kt
@@ -76,8 +76,8 @@ internal object CustomTabsPackageHelper {
packagesSupportingCustomTabs.isEmpty() -> null
packagesSupportingCustomTabs.size == 1 -> packagesSupportingCustomTabs[0]
!TextUtils.isEmpty(defaultHandlerPackageName) &&
- !hasSpecializedHandlerIntents(context, activityIntent)
- && packagesSupportingCustomTabs.contains(defaultHandlerPackageName)
+ !hasSpecializedHandlerIntents(context, activityIntent) &&
+ packagesSupportingCustomTabs.contains(defaultHandlerPackageName)
-> defaultHandlerPackageName
packagesSupportingCustomTabs.contains(STABLE_PACKAGE) -> STABLE_PACKAGE
packagesSupportingCustomTabs.contains(BETA_PACKAGE) -> BETA_PACKAGE
diff --git a/customtabs/src/main/java/saschpe/android/customtabs/WebViewFallback.kt b/customtabs/src/main/java/saschpe/android/customtabs/WebViewFallback.kt
index 04dff89..b223807 100644
--- a/customtabs/src/main/java/saschpe/android/customtabs/WebViewFallback.kt
+++ b/customtabs/src/main/java/saschpe/android/customtabs/WebViewFallback.kt
@@ -33,8 +33,8 @@ class WebViewFallback : CustomTabFallback {
context?.startActivity(
Intent(context, WebViewActivity::class.java).putExtra(
WebViewActivity.EXTRA_URL,
- uri.toString()
- )
+ uri.toString(),
+ ),
)
}
}
diff --git a/customtabs/src/test/java/saschpe/android/customtabs/KeepAliveServiceTest.kt b/customtabs/src/test/java/saschpe/android/customtabs/KeepAliveServiceTest.kt
index fb4b56f..5bea3e5 100644
--- a/customtabs/src/test/java/saschpe/android/customtabs/KeepAliveServiceTest.kt
+++ b/customtabs/src/test/java/saschpe/android/customtabs/KeepAliveServiceTest.kt
@@ -39,7 +39,7 @@ class KeepAliveServiceTest {
// Act, assert
assertEquals(
KeepAliveService().onBind(mockIntent),
- KeepAliveService().onBind(Mockito.mock(Intent::class.java))
+ KeepAliveService().onBind(Mockito.mock(Intent::class.java)),
)
}
}
diff --git a/customtabs/src/test/java/saschpe/android/customtabs/WebViewFallbackTest.kt b/customtabs/src/test/java/saschpe/android/customtabs/WebViewFallbackTest.kt
index 238c0f3..a8c33cf 100644
--- a/customtabs/src/test/java/saschpe/android/customtabs/WebViewFallbackTest.kt
+++ b/customtabs/src/test/java/saschpe/android/customtabs/WebViewFallbackTest.kt
@@ -22,10 +22,10 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
-import org.mockito.Mockito.`when`
import org.mockito.Mockito.doNothing
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
+import org.mockito.Mockito.`when`
@RunWith(AndroidJUnit4::class)
class WebViewFallbackTest {
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c..a4b76b9 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 d951fac..1ed247e 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-all.zip
+networkTimeout=10000
+validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0..f5feea6 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
-# Copyright 2015 the original author or authors.
+# 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.
@@ -15,69 +15,104 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
-##
-## 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/platforms/jvm/plugins-application/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='"-Xmx64m" "-Xms64m"'
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || 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
@@ -87,9 +122,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
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
@@ -98,88 +133,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=SC2039,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=SC2039,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" = "true" -o "$msys" = "true" ] ; 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
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
# 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=`expr $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"
+# 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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+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 107acd3..9d21a21 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -13,8 +13,10 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
-@if "%DEBUG%" == "" @echo off
+@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +27,8 @@
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%
@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
+if %ERRORLEVEL% equ 0 goto execute
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
@@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
@@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
: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/scripts/inc.functions.sh b/scripts/inc.functions.sh
index 8867821..d6313d3 100644
--- a/scripts/inc.functions.sh
+++ b/scripts/inc.functions.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env sh
#
# Collection of shared functions
#
@@ -8,31 +8,33 @@ RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
-function approve {
- echo -e "${GREEN}$@${NC}"
+approve() {
+ printf "${GREEN}%s${NC}\n" "$*"
}
-function warn {
- echo -e "${YELLOW}$@${NC}"
+warn() {
+ printf "${YELLOW}%s${NC}\n" "$*"
}
-function die {
- echo -e "${RED}$@${NC}"
- exit 1
+die() {
+ printf "${RED}%s${NC}\n" "$*"
+ exit 1
}
-function safe {
- "$@"
- local status=$?
- if [[ ${status} -ne 0 ]]; then
- die "\nBUILD FAILED\nAfter invoking \"$@\"\n" >&2
- fi
- return ${status}
+safe() {
+ "$@"
+ _status=$?
+ if [ ${_status} -ne 0 ]; then
+ die "\nBUILD FAILED\nAfter invoking \"$*\"\n" >&2
+ fi
+ return ${_status}
}
-function sed2 {
- sed -i'.bak' "$1" ${@:2}
- for file in "${@:2}" ; do
- rm "${file}.bak"
- done
+sed2() {
+ cmd="${1}"
+ shift
+ sed -i'.bak' "${cmd}" "${@}"
+ for file in "${@}"; do
+ rm "${file}.bak"
+ done
}
diff --git a/scripts/release b/scripts/release
index a0ca0e0..ab7ad58 100755
--- a/scripts/release
+++ b/scripts/release
@@ -11,67 +11,66 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "${SCRIPT_DIR}/inc.functions.sh"
# Constants
-GRADLE_FILES=(
- customtabs/build.gradle.kts
- customtabs-example/build.gradle.kts
+FILES=(
+ customtabs-example/build.gradle.kts
+ customtabs/build.gradle.kts
)
-
# Functions
-function get_version_code {
- echo $(grep "versionCode = " $1 | xargs | cut -d"=" -f2)
+usage() {
+ echo -e "Usage: $0 [VERSION_NAME]\n\n Example: $0 0.0.1"
+ exit 1
}
-function get_version_name {
- echo $(grep "versionName = " $1 | xargs | cut -d"=" -f2)
+version_gt() {
+ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
-function usage {
- echo -e "Usage: $0 [VERSION_NAME]\n\n Example: $0 0.0.1"
- exit 1
+get_version_code() {
+ grep "versionCode = " "$1" | cut -d"=" -f2 | xargs
}
-function version_gt() {
- test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
+get_version_name() {
+ grep "versionName = " "$1" | cut -d"=" -f2 | xargs
}
# Checks
-if [[ $# -ne 1 ]] ; then
- usage
+if [[ $# -ne 1 ]]; then
+ usage
fi
-
# Increase version name
version_name_new=$1
# Split new version name into major, minor, patch and pad each number to two
# digits to ensure we can safely switch from 1.9.0 to 1.10.0. Padded, the
# latter would yield '011000' as the new version code. The result has a length
# of six digits.
-IFS='.' read -r -a version_name_new_array <<< "${version_name_new}"
-
-for gradle_file in ${GRADLE_FILES[@]} ; do
- version_name_old=$(get_version_name ${gradle_file})
- # To be able to compare with the previous version, do the same for the old
- # version name.
- IFS='.' read -r -a version_name_old_array <<< "${version_name_old}"
-
- if version_gt ${version_name_old} ${version_name_new}; then
- die "Already at version ${version_name_old}"
- fi
-
- # Since we're otherwise fine, start changing the version name..
- sed2 "s|versionName = \"${version_name_old}|versionName = \"${version_name_new}|" ${gradle_file}
-
- # Increment app version code for Google's Play Store (not applicable for libraries)
- version_code_old=$(get_version_code ${gradle_file})
- if [ -n "${version_code_old}" ] ; then
- padded_sem_ver=$(printf "%02d%02d%02d\n" ${version_name_new_array[0]} ${version_name_new_array[1]} ${version_name_new_array[2]})
- # Replace the last six digits with the new padded semantic version
- version_code_new=${version_code_old::${#version_code_old}-6}${padded_sem_ver}
- sed2 "s/versionCode = ${version_code_old}/versionCode = ${version_code_new}/" ${gradle_file}
- fi
-
- git_commit_files="${git_commit_files} ${gradle_file}"
+IFS='.' read -r -a version_name_new_array <<<"${version_name_new}"
+
+version_name_old=$(get_version_name "${FILES[0]}")
+
+for file in ${FILES[@]}; do
+ # To be able to compare with the previous version, do the same for the old
+ # version name.
+ IFS='.' read -r -a version_name_old_array <<<"${version_name_old}"
+
+ if version_gt "${version_name_old}" "${version_name_new}"; then
+ die "Already at version ${version_name_old}"
+ fi
+
+ # Since we're otherwise fine, start changing the version name
+ sed2 "s|${version_name_old}|${version_name_new}|g" "${file}"
+
+ # Increment app version code for Google's Play Store (not applicable for libraries)
+ version_code_old=$(get_version_code ${file})
+ if [ -n "${version_code_old}" ] ; then
+ padded_sem_ver=$(printf "%02d%02d%02d\n" ${version_name_new_array[0]} ${version_name_new_array[1]} ${version_name_new_array[2]})
+ # Replace the last six digits with the new padded semantic version
+ version_code_new=${version_code_old::${#version_code_old}-6}${padded_sem_ver}
+ sed2 "s/versionCode = ${version_code_old}/versionCode = ${version_code_new}/" ${file}
+ fi
+
+ git_commit_files="${git_commit_files} ${file}"
done
# Update README.md
@@ -81,4 +80,4 @@ git_commit_files="${git_commit_files} README.md"
# Create a commit with appropriate tag
git_commit_message="Release version ${version_name_new}"
safe git commit --signoff ${git_commit_files} -m "${git_commit_message}"
-safe git tag -f release/${version_name_new}
+safe git tag -f "release/${version_name_new}"
diff --git a/settings.gradle.kts b/settings.gradle.kts
index e6229d1..c230f5c 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -13,6 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+@file:Suppress("UnstableApiUsage")
+
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ mavenCentral()
+ google {
+ mavenContent {
+ includeGroupAndSubgroups("androidx")
+ includeGroupAndSubgroups("com.android")
+ includeGroupAndSubgroups("com.google")
+ }
+ }
+ }
+}
+
+dependencyResolutionManagement {
+ repositories {
+ mavenCentral()
+ google {
+ mavenContent {
+ includeGroupAndSubgroups("androidx")
+ includeGroupAndSubgroups("com.android")
+ includeGroupAndSubgroups("com.google")
+ }
+ }
+ }
+}
rootProject.name = "android-customtabs"