diff --git a/.circleci/config.yml b/.circleci/config.yml
index d21cbc7..ade5000 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -30,19 +30,19 @@ defaults_gradle: &defaults_gradle
path: build/reports/
jobs:
- build_gradle_jdk14:
+ build_gradle_jdk18:
<<: *defaults
docker:
- - image: openjdk:14-jdk
+ - image: cimg/openjdk:18.0
<<: *defaults_gradle
- build_gradle_jdk8:
+ build_gradle_jdk11:
<<: *defaults
docker:
- - image: circleci/openjdk:8-jdk
+ - image: cimg/openjdk:11.0
<<: *defaults_gradle
@@ -50,5 +50,5 @@ workflows:
version: 2
gradle:
jobs:
- - build_gradle_jdk8
- - build_gradle_jdk14
+ - build_gradle_jdk11
+ - build_gradle_jdk18
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index f1ac387..a0b7843 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -1,19 +1,61 @@
-name: Java CI with Gradle
+name: gradle-ci
on: [push, pull_request, workflow_dispatch]
jobs:
build:
-
runs-on: ubuntu-latest
+ env:
+ GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m"
+ SONAR_JDK: "11"
+
+ strategy:
+ matrix:
+ java-version: [ 11, 18 ]
+
steps:
- - uses: actions/checkout@v2
- - name: Set up JDK 1.8
- uses: actions/setup-java@v1
- with:
- java-version: 1.8
- - name: Grant execute permission for gradlew
- run: chmod +x gradlew
- - name: Test with Gradle
- run: ./gradlew check
+ - uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Set up JDK ${{ matrix.java-version }}
+ uses: actions/setup-java@v1
+ with:
+ java-version: ${{ matrix.java-version }}
+
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+
+ - name: Cache SonarCloud packages
+ if: matrix.java-version == env.SONAR_JDK
+ uses: actions/cache@v1
+ with:
+ path: ~/.sonar/cache
+ key: ${{ runner.os }}-sonar
+ restore-keys: ${{ runner.os }}-sonar
+
+ - name: Cache Gradle packages
+ uses: actions/cache@v2
+ with:
+ path: |
+ ~/.gradle/caches
+ ~/.gradle/wrapper
+ key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+ restore-keys: |
+ ${{ runner.os }}-gradle-${{ matrix.java-version }}-
+
+ - name: Test with Gradle
+ run: ./gradlew build check --stacktrace
+
+ - name: SonarCloud
+ if: success() && matrix.java-version == env.SONAR_JDK
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+ run: ./gradlew sonarqube
+
+ - name: Cleanup Gradle Cache
+ run: |
+ rm -f ~/.gradle/caches/modules-2/modules-2.lock
+ rm -f ~/.gradle/caches/modules-2/gc.properties
diff --git a/.gitignore b/.gitignore
index f007981..13a066e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,22 +1,7 @@
-.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json
-
-__pycache__
-.classpath
-.DS_Store
-.gradle
-.history
-.kobalt
-.mtj.tmp/
-.mvn/timing.properties
-.mvn/wrapper/maven-wrapper.jar
-.nb-gradle
-.project
-.scannerwork
-.settings
*.class
*.code-workspace
*.ctxt
@@ -27,7 +12,21 @@ __pycache__
*.sublime-*
*.tar.gz
*.zip
-/**/.idea_modules/
+.DS_Store
+.classpath
+.gradle
+.history
+.kobalt
+.mtj.tmp/
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+.nb-gradle
+.project
+.scannerwork
+.settings
+.vscode/*
+/**/.idea/$CACHE_FILE$
+/**/.idea/$PRODUCT_WORKSPACE_FILE$
/**/.idea/**/caches/build_file_checksums.ser
/**/.idea/**/contentModel.xml
/**/.idea/**/dataSources.ids
@@ -48,8 +47,10 @@ __pycache__
/**/.idea/**/uiDesigner.xml
/**/.idea/**/usage.statistics.xml
/**/.idea/**/workspace.xml
-/**/.idea/$CACHE_FILE$
-/**/.idea/$PRODUCT_WORKSPACE_FILE$
+/**/.idea/sonarlint*
+/**/.idea_modules/
+Thumbs.db
+__pycache__
atlassian-ide-plugin.xml
bin/
build/
@@ -71,6 +72,7 @@ lib/kotlin*
libs/
local.properties
out/
+pom.xml.asc
pom.xml.next
pom.xml.releaseBackup
pom.xml.tag
@@ -80,5 +82,4 @@ project.properties
release.properties
target/
test-output
-Thumbs.db
venv
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 26820aa..f30e74b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,4 @@
-image: gradle:alpine
+image: gradle:7-jdk11
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
@@ -12,7 +12,7 @@ stages:
build:
stage: build
- script: ./gradlew --build-cache assemble
+ script: gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
@@ -22,7 +22,7 @@ build:
test:
stage: test
- script: ./gradlew check
+ script: gradle check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 61a9130..fb7f4a8 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml
index 08660a1..1c363f3 100644
--- a/.idea/copyright/Erik_s_Copyright_Notice.xml
+++ b/.idea/copyright/Erik_s_Copyright_Notice.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/isgd-shorten.iml b/.idea/isgd-shorten.iml
deleted file mode 100644
index 78b2cc5..0000000
--- a/.idea/isgd-shorten.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index ac476f9..4290988 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..2b8a50f
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index f126aa3..b674354 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -4,7 +4,10 @@
-
+
+
+
+
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 48c5805..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-language: java
-dist: trusty
-
-env:
- global:
- - CI=true
-
-#install:
-# - git fetch --unshallow --tags
-
-addons:
- sonarcloud:
- organization: "ethauvin-github"
-
-jdk:
- - oraclejdk8
- - openjdk14
-
-before_install:
- - chmod +x gradlew
-
-after_success:
- - |
- if [ "${TRAVIS_TEST_RESULT}" == 0 ] && [ "$TRAVIS_JDK_VERSION" == "openjdk14" ]; then
- ./gradlew sonarqube
- fi
diff --git a/LICENSE.txt b/LICENSE.txt
index 2fadd27..77cf63c 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,5 +1,4 @@
-Copyright (c) 2020, Erik C. Thauvin (erik@thauvin.net)
-All rights reserved.
+Copyright 2020-2023 Erik C. Thauvin (erik@thauvin.net)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/README.md b/README.md
index 011990f..e3ba552 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,16 @@
-[](http://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/isgd-shorten/releases/latest) [](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/isgd-shorten) [](https://bintray.com/ethauvin/maven/isgd-shorten/_latestVersion)
+[](https://opensource.org/licenses/BSD-3-Clause)
+[](https://kotlinlang.org/)
+[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/isgd-shorten/)
+[](https://github.com/ethauvin/isgd-shorten/releases/latest)
+[](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/isgd-shorten)
-[](https://snyk.io/test/github/ethauvin/isgd-shorten?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_isgd-shorten) [](https://travis-ci.com/ethauvin/isgd-shorten) [](https://circleci.com/gh/ethauvin/isgd-shorten/tree/master)
+[](https://sonarcloud.io/dashboard?id=ethauvin_isgd-shorten)
+[](https://github.com/ethauvin/isgd-shorten/actions/workflows/gradle.yml)
+[](https://circleci.com/gh/ethauvin/isgd-shorten/tree/master)
-# [is.gd](https://is.gd/developers.php) Shortener for Kotlin/Java/Android
+# [is.gd](https://is.gd/developers.php) Shortener for Kotlin, Java & Android
-A simple implementation of the [is.gd API](https://is.gd/developers.php).
+A simple implementation of the [is.gd](https://is.gd/) URL shortening and lookup [APIs](https://is.gd/developers.php).
## Examples (TL;DR)
@@ -44,7 +50,7 @@ Isgd.shorten(url = url, shorturl="foobar", callback = "test", logstats = true, f
```
returns:
-```json
+```js
test({ "shorturl": "https://is.gd/foobar" });
```
### Gradle
@@ -53,14 +59,33 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
```gradle
repositories {
- jcenter()
+ mavenCentral()
+ maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
}
dependencies {
- implementation("net.thauvin.erik:isgd-shorten:0.9.1")
+ implementation("net.thauvin.erik:isgd-shorten:0.9.2")
}
```
-Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/artifact/net.thauvin.erik/isgd-shorten/0.9.1/jar).
+Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/isgd-shorten).
+
+### Errors
+
+An `IsgdException` is thrown when an API error occurs. The error message (text, XML or JSON) and HTTP status code can be retrieved as follows:
+
+```kotlin
+try {
+ Isgd.shorten("https://is.gd/Pt2sET") // already shorten
+} catch (e: IsgdException)
+ println("Status Code: ${e.statusCode}")
+ println("${e.message})
+}
+```
+
+```
+Status Code: 400
+Error: Sorry, the URL you entered is on our internal blacklist. It may have been used abusively in the past, or it may link to another URL redirection service.
+```
### v.gd
diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml
index 7d98402..a9514a0 100644
--- a/bitbucket-pipelines.yml
+++ b/bitbucket-pipelines.yml
@@ -1,4 +1,4 @@
-image: openjdk:8
+image: maven:3-openjdk-18
pipelines:
default:
diff --git a/build.gradle.kts b/build.gradle.kts
index b4f8402..d2e302c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,24 +1,24 @@
-import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-import java.io.FileInputStream
-import java.util.*
+import org.gradle.api.tasks.testing.logging.TestExceptionFormat
+import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
- jacoco
- `java-library`
- `maven-publish`
- id("com.github.ben-manes.versions") version "0.29.0"
- id("com.jfrog.bintray") version "1.8.5"
- id("io.gitlab.arturbosch.detekt") version "1.11.0"
+ id("com.github.ben-manes.versions") version "0.44.0"
+ id("io.gitlab.arturbosch.detekt") version "1.22.0"
+ id("java")
+ id("java-library")
+ id("maven-publish")
id("net.thauvin.erik.gradle.semver") version "1.0.4"
- id("org.jetbrains.dokka") version "1.4.0-rc"
- id("org.jetbrains.kotlin.jvm") version "1.4.0"
- id("org.jetbrains.kotlin.kapt") version "1.4.0"
- id("org.sonarqube") version "3.0"
+ id("org.jetbrains.dokka") version "1.7.20"
+ id("org.jetbrains.kotlinx.kover") version "0.6.1"
+ id("org.sonarqube") version "3.5.0.2730"
+ id("signing")
+ kotlin("jvm") version "1.8.0"
+ kotlin("kapt") version "1.8.0"
}
group = "net.thauvin.erik"
-description = "is.gd Shortener for Kotlin/Java"
+description = "A simple implementation of the is.gd URL shortening and lookup APIs"
val gitHub = "ethauvin/$name"
val mavenUrl = "https://github.com/$gitHub"
@@ -27,62 +27,41 @@ var isRelease = "release" in gradle.startParameter.taskNames
val publicationName = "mavenJava"
-var semverProcessor = "net.thauvin.erik:semver:1.2.0"
-
-// Load local.properties
-File("local.properties").apply {
- if (exists()) {
- FileInputStream(this).use { fis ->
- Properties().apply {
- load(fis)
- forEach { (k, v) ->
- extra[k as String] = v
- }
- }
- }
- }
-}
-
repositories {
- jcenter()
+ mavenCentral()
+ maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}
dependencies {
- testImplementation("org.jetbrains.kotlin:kotlin-test")
- testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
-}
+ implementation(platform(kotlin("bom")))
+ implementation("net.thauvin.erik:urlencoder:1.3.0")
-kapt {
- arguments {
- arg("semver.project.dir", projectDir)
- }
+ testImplementation(kotlin("test"))
+ testImplementation(kotlin("test-junit"))
+ testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
}
java {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
+ withSourcesJar()
}
detekt {
+ //toolVersion = "main-SNAPSHOT"
baseline = project.rootDir.resolve("config/detekt/baseline.xml")
}
-jacoco {
- toolVersion = "0.8.5"
-}
-
sonarqube {
properties {
property("sonar.projectKey", "ethauvin_$name")
+ property("sonar.organization", "ethauvin-github")
+ property("sonar.host.url", "https://sonarcloud.io")
property("sonar.sourceEncoding", "UTF-8")
+ property("sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/kover/xml/report.xml")
}
}
-val sourcesJar by tasks.creating(Jar::class) {
- archiveClassifier.set("sources")
- from(sourceSets.getByName("main").allSource)
-}
-
val javadocJar by tasks.creating(Jar::class) {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc)
@@ -92,15 +71,15 @@ val javadocJar by tasks.creating(Jar::class) {
}
tasks {
- withType {
- reports {
- xml.isEnabled = true
- html.isEnabled = true
- }
+ withType().configureEach {
+ kotlinOptions.jvmTarget = java.targetCompatibility.toString()
}
- withType().configureEach {
- kotlinOptions.jvmTarget = "1.8"
+ withType {
+ testLogging {
+ exceptionFormat = TestExceptionFormat.FULL
+ events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
+ }
}
withType {
@@ -108,7 +87,7 @@ tasks {
}
assemble {
- dependsOn(sourcesJar, javadocJar)
+ dependsOn(javadocJar)
}
clean {
@@ -140,75 +119,23 @@ tasks {
}
}
- val bintrayUpload by existing(BintrayUploadTask::class) {
- dependsOn(publishToMavenLocal, gitTag)
- doFirst {
- versionName = "${project.version}"
- versionDesc = "${project.name} ${project.version}"
- versionVcsTag = "${project.version}"
- versionReleased = Date().toString()
- }
- }
-
register("deploy") {
description = "Copies all needed files to the $deployDir directory."
group = PublishingPlugin.PUBLISH_TASK_GROUP
- dependsOn("build", "jar")
+ dependsOn(clean, wrapper, build, jar)
outputs.dir(deployDir)
inputs.files(copyToDeploy)
- mustRunAfter("clean")
+ mustRunAfter(clean)
}
register("release") {
- description = "Publishes version ${project.version} to Bintray."
+ description = "Publishes version ${project.version} to local repository."
group = PublishingPlugin.PUBLISH_TASK_GROUP
- dependsOn("wrapper", bintrayUpload)
+ dependsOn(wrapper, "deploy", gitTag, publishToMavenLocal)
}
"sonarqube" {
- dependsOn("jacocoTestReport")
- }
-}
-
-fun findProperty(s: String) = project.findProperty(s) as String?
-bintray {
- user = findProperty("bintray.user")
- key = findProperty("bintray.apikey")
- publish = isRelease
- setPublications(publicationName)
- pkg.apply {
- repo = "maven"
- name = project.name
- desc = description
- websiteUrl = mavenUrl
- issueTrackerUrl = "$mavenUrl/issues"
- githubRepo = gitHub
- githubReleaseNotesFile = "README.md"
- vcsUrl = "$mavenUrl.git"
- setLabels(
- "android",
- "is.gd",
- "v.gd",
- "java",
- "kotlin",
- "shorten",
- "shorten-urls",
- "shortener",
- "shortener-service",
- "shortens-links",
- "shorturl",
- "url-shortener"
- )
- setLicenses("BSD 3-Clause")
- publicDownloadNumbers = true
- version.apply {
- name = project.version as String
- desc = description
- vcsTag = project.version as String
- gpg.apply {
- sign = true
- }
- }
+ dependsOn(koverReport)
}
}
@@ -216,37 +143,51 @@ publishing {
publications {
create(publicationName) {
from(components["java"])
- artifact(sourcesJar)
artifact(javadocJar)
- pom.withXml {
- asNode().apply {
- appendNode("name", project.name)
- appendNode("description", project.description)
- appendNode("url", mavenUrl)
-
- appendNode("licenses").appendNode("license").apply {
- appendNode("name", "BSD 3-Clause")
- appendNode("url", "https://opensource.org/licenses/BSD-3-Clause")
+ pom {
+ name.set(project.name)
+ description.set(project.description)
+ url.set(mavenUrl)
+ licenses {
+ license {
+ name.set("BSD 3-Clause")
+ url.set("https://opensource.org/licenses/BSD-3-Clause")
}
-
- appendNode("developers").appendNode("developer").apply {
- appendNode("id", "ethauvin")
- appendNode("name", "Erik C. Thauvin")
- appendNode("email", "erik@thauvin.net")
- }
-
- appendNode("scm").apply {
- appendNode("connection", "scm:git:$mavenUrl.git")
- appendNode("developerConnection", "scm:git:git@github.com:$gitHub.git")
- appendNode("url", mavenUrl)
- }
-
- appendNode("issueManagement").apply {
- appendNode("system", "GitHub")
- appendNode("url", "$mavenUrl/issues")
+ }
+ developers {
+ developer {
+ id.set("ethauvin")
+ name.set("Erik C. Thauvin")
+ email.set("erik@thauvin.net")
+ url.set("https://erik.thauvin.net/")
}
}
+ scm {
+ connection.set("scm:git://github.com/$gitHub.git")
+ developerConnection.set("scm:git@github.com:$gitHub.git")
+ url.set(mavenUrl)
+ }
+ issueManagement {
+ system.set("GitHub")
+ url.set("$mavenUrl/issues")
+ }
}
}
}
+ repositories {
+ maven {
+ name = "ossrh"
+ project.afterEvaluate {
+ url = if (project.version.toString().contains("SNAPSHOT"))
+ uri("https://oss.sonatype.org/content/repositories/snapshots/") else
+ uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
+ }
+ credentials(PasswordCredentials::class)
+ }
+ }
+}
+
+signing {
+ useGpgCmd()
+ sign(publishing.publications[publicationName])
}
diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index 7a2ff7e..f7b49af 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -1,7 +1,9 @@
-
+
-
-
+
+
LongParameterList:Isgd.kt$Isgd.Companion$( url: String, shorturl: String = "", callback: String = "", logstats: Boolean = false, format: Format = Format.SIMPLE, isVgd: Boolean = false )
-
+ MagicNumber:Isgd.kt$Isgd.Companion$200
+ MagicNumber:Isgd.kt$Isgd.Companion$399
+
diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts
index cf09f15..ef12539 100644
--- a/examples/build.gradle.kts
+++ b/examples/build.gradle.kts
@@ -1,29 +1,41 @@
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
plugins {
- id("org.jetbrains.kotlin.jvm") version "1.4.0"
- id("com.github.ben-manes.versions") version "0.29.0"
- application
+ id("application")
+ id("com.github.ben-manes.versions") version "0.44.0"
+ kotlin("jvm") version "1.8.0"
}
-// ./gradlew run --args='https://wwwcom.example. https://is.gd/Pt2sET'
+// ./gradlew run --args='https://www.example.com https://is.gd/Pt2sET'
// ./gradlew runJava --args='https://www.example.com https://is.gd/Pt2sET'
repositories {
mavenLocal()
- jcenter()
+ mavenCentral()
+ maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
}
dependencies {
- implementation("net.thauvin.erik:isgd-shorten:0.9.1")
+ implementation("net.thauvin.erik:isgd-shorten:0.9.2-SNAPSHOT")
+}
+
+java {
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
}
application {
- mainClassName = "com.example.IsgdExampleKt"
+ mainClass.set("com.example.IsgdExampleKt")
}
tasks {
+ withType().configureEach {
+ kotlinOptions.jvmTarget = java.targetCompatibility.toString()
+ }
+
register("runJava", JavaExec::class) {
group = "application"
- main = "com.example.IsgdSample"
- classpath = sourceSets["main"].runtimeClasspath
+ mainClass.set("com.example.IsgdSample")
+ classpath = sourceSets.main.get().runtimeClasspath
}
}
diff --git a/examples/gradle/wrapper/gradle-wrapper.jar b/examples/gradle/wrapper/gradle-wrapper.jar
index e708b1c..7454180 100644
Binary files a/examples/gradle/wrapper/gradle-wrapper.jar and b/examples/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties
index 6c9a224..070cb70 100644
--- a/examples/gradle/wrapper/gradle-wrapper.properties
+++ b/examples/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/examples/gradlew b/examples/gradlew
old mode 100644
new mode 100755
index 4f906e0..1b6c787
--- a/examples/gradlew
+++ b/examples/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.
@@ -17,67 +17,101 @@
#
##############################################################################
-##
-## 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/master/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_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
+APP_BASE_NAME=${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"'
# 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 +121,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,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
- JAVACMD="java"
+ 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.
Please set the JAVA_HOME variable in your environment to match the
@@ -106,80 +140,95 @@ location of your Java installation."
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
-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
-
-# 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
- # 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\""
- fi
- i=`expr $i + 1`
- 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" ;;
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
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, 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.
-# 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"
+# 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" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ 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
+ # 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
+fi
+
+# 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 \
+ "$@"
+
+# 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/examples/src/main/java/com/example/IsgdSample.java b/examples/src/main/java/com/example/IsgdSample.java
index 2328776..2f431cb 100644
--- a/examples/src/main/java/com/example/IsgdSample.java
+++ b/examples/src/main/java/com/example/IsgdSample.java
@@ -1,15 +1,20 @@
package com.example;
import net.thauvin.erik.isgd.Isgd;
+import net.thauvin.erik.isgd.IsgdException;
public final class IsgdSample {
public static void main(final String[] args) {
if (args.length > 0) {
for (final String arg : args) {
- if (arg.contains("is.gd")) {
- System.out.println(arg + " <-- " + Isgd.lookup(arg));
- } else {
- System.out.println(arg + " --> " + Isgd.shorten(arg));
+ try {
+ if (arg.contains("is.gd")) {
+ System.out.println(arg + " <-- " + Isgd.lookup(arg));
+ } else {
+ System.out.println(arg + " --> " + Isgd.shorten(arg));
+ }
+ } catch (IsgdException e) {
+ System.out.println(e.getMessage());
}
}
} else {
diff --git a/examples/src/main/kotlin/com/example/IsgdExample.kt b/examples/src/main/kotlin/com/example/IsgdExample.kt
index 5acaad5..fe721a0 100644
--- a/examples/src/main/kotlin/com/example/IsgdExample.kt
+++ b/examples/src/main/kotlin/com/example/IsgdExample.kt
@@ -1,15 +1,20 @@
package com.example
import net.thauvin.erik.isgd.Isgd
+import net.thauvin.erik.isgd.IsgdException
import kotlin.system.exitProcess
fun main(args: Array) {
if (args.isNotEmpty()) {
args.forEach {
- if (it.contains("is.gd"))
- println(it + " <-- " + Isgd.lookup(it))
- else
- println(it + " --> " + Isgd.shorten(it))
+ try {
+ if (it.contains("is.gd"))
+ println(it + " <-- " + Isgd.lookup(it))
+ else
+ println(it + " --> " + Isgd.shorten(it))
+ } catch (e: IsgdException) {
+ println(e.message)
+ }
}
} else {
println("Try specifying one or more URLs as arguments.")
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c..7454180 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 6c9a224..070cb70 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0..1b6c787 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.
@@ -17,67 +17,101 @@
#
##############################################################################
-##
-## 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/master/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_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
+APP_BASE_NAME=${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"'
# 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 +121,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,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
- JAVACMD="java"
+ 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.
Please set the JAVA_HOME variable in your environment to match the
@@ -106,80 +140,95 @@ location of your Java installation."
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
-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
-
-# 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
- # 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\""
- fi
- i=`expr $i + 1`
- 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" ;;
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
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, 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.
-# 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"
+# 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" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ 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
+ # 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
+fi
+
+# 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 \
+ "$@"
+
+# 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/pom.xml b/pom.xml
index a56815b..a3b26de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,5 @@
-
+
@@ -8,28 +8,9 @@
4.0.0
net.thauvin.erik
isgd-shorten
- 0.9.1
-
-
-
- org.jetbrains.kotlin
- kotlin-bom
- 1.3.72
- pom
- import
-
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- 1.3.72
- runtime
-
-
+ 0.9.2-SNAPSHOT
isgd-shorten
- is.gd Shortener for Kotlin/Java
+ A simple implementation of the is.gd URL shortening and lookup APIs
https://github.com/ethauvin/isgd-shorten
@@ -42,15 +23,41 @@
ethauvin
Erik C. Thauvin
erik@thauvin.net
+ https://erik.thauvin.net/
- scm:git:https://github.com/ethauvin/isgd-shorten.git
- scm:git:git@github.com:ethauvin/isgd-shorten.git
+ scm:git://github.com/ethauvin/isgd-shorten.git
+ scm:git@github.com:ethauvin/isgd-shorten.git
https://github.com/ethauvin/isgd-shorten
GitHub
https://github.com/ethauvin/isgd-shorten/issues
+
+
+
+ org.jetbrains.kotlin
+ kotlin-bom
+ 1.8.0
+ pom
+ import
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ 1.8.0
+ compile
+
+
+ net.thauvin.erik
+ urlencoder
+ 1.3.0
+ runtime
+
+
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 4383f65..e93f35f 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -1 +1,18 @@
+plugins {
+ id("com.gradle.enterprise").version("3.6.3")
+}
+
+gradleEnterprise {
+ buildScan {
+ link("GitHub", "https://github.com/ethauvin/isgd-shorten/tree/master")
+ if (!System.getenv("CI").isNullOrEmpty()) {
+ isUploadInBackground = false
+ publishOnFailure()
+ tag("CI")
+ }
+ termsOfServiceUrl = "https://gradle.com/terms-of-service"
+ termsOfServiceAgree = "yes"
+ }
+}
+
rootProject.name = "isgd-shorten"
diff --git a/src/main/kotlin/net/thauvin/erik/isgd/Isgd.kt b/src/main/kotlin/net/thauvin/erik/isgd/Isgd.kt
index c9a9afe..22ec7eb 100644
--- a/src/main/kotlin/net/thauvin/erik/isgd/Isgd.kt
+++ b/src/main/kotlin/net/thauvin/erik/isgd/Isgd.kt
@@ -1,8 +1,7 @@
/*
* Isgd.kt
*
- * Copyright (c) 2020, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,34 +31,38 @@
package net.thauvin.erik.isgd
+import net.thauvin.erik.urlencoder.UrlEncoder
import java.net.HttpURLConnection
import java.net.URL
-import java.net.URLEncoder
-import java.nio.charset.StandardCharsets
/**
- * See the [is.gd API](https://is.gd/apishorteningreference.php)
+ * See the [is.gd API](https://is.gd/apishorteningreference.php).
*/
enum class Format(val type: String) {
WEB("web"), SIMPLE("simple"), XML("xml"), JSON("json")
}
-fun String.encode(): String {
- return URLEncoder.encode(this, StandardCharsets.UTF_8.name())
-}
+fun String.encode(): String = UrlEncoder.encode(this)
+/**
+ * Implements the [is.gd API](https://is.gd/developers.php).
+ */
class Isgd private constructor() {
companion object {
private fun callApi(url: String): String {
val connection = URL(url).openConnection() as HttpURLConnection
connection.setRequestProperty(
"User-Agent",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0"
+ "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0"
)
- return connection.inputStream.bufferedReader().readText()
+ if (connection.responseCode in 200..399) {
+ return connection.inputStream.bufferedReader().readText()
+ } else {
+ throw IsgdException(connection.responseCode, connection.errorStream.bufferedReader().readText())
+ }
}
- private fun host(isVgd: Boolean = false): String {
+ private fun getHost(isVgd: Boolean = false): String {
return if (isVgd) "v.gd" else "is.gd"
}
@@ -68,17 +71,16 @@ class Isgd private constructor() {
*/
@JvmStatic
@JvmOverloads
+ @Throws(IsgdException::class)
fun lookup(
shorturl: String,
callback: String = "",
format: Format = Format.SIMPLE,
isVgd: Boolean = false
): String {
- if (shorturl.isEmpty()) {
- throw IllegalArgumentException("Please specify a valid short URL to lookup.")
- }
+ require(shorturl.isNotEmpty()) { "Please specify a valid short URL to lookup." }
- val sb = StringBuilder("https://${host(isVgd)}/forward.php?shorturl=${shorturl.encode()}")
+ val sb = StringBuilder("https://${getHost(isVgd)}/forward.php?shorturl=${shorturl.encode()}")
if (callback.isNotEmpty()) {
sb.append("&callback=${callback.encode()}")
@@ -94,6 +96,7 @@ class Isgd private constructor() {
*/
@JvmStatic
@JvmOverloads
+ @Throws(IsgdException::class)
fun shorten(
url: String,
shorturl: String = "",
@@ -102,11 +105,9 @@ class Isgd private constructor() {
format: Format = Format.SIMPLE,
isVgd: Boolean = false
): String {
- if (url.isEmpty()) {
- throw IllegalArgumentException("Please enter a valid URL to shorten.")
- }
+ require(url.isNotEmpty()) { "Please enter a valid URL to shorten." }
- val sb = StringBuilder("https://${host(isVgd)}/create.php?url=${url.encode()}")
+ val sb = StringBuilder("https://${getHost(isVgd)}/create.php?url=${url.encode()}")
if (shorturl.isNotEmpty()) {
sb.append("&shorturl=${shorturl.encode()}")
diff --git a/src/main/kotlin/net/thauvin/erik/isgd/IsgdException.kt b/src/main/kotlin/net/thauvin/erik/isgd/IsgdException.kt
new file mode 100644
index 0000000..ebafb24
--- /dev/null
+++ b/src/main/kotlin/net/thauvin/erik/isgd/IsgdException.kt
@@ -0,0 +1,44 @@
+/*
+ * IsgdException.kt
+ *
+ * Copyright 2023 Erik C. Thauvin (erik@thauvin.net)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.isgd
+
+/**
+ * Thrown when an exceptional condition has occurred.
+ *
+ * @property statusCode The HTTP status code.
+ * @property message The error message.
+ */
+class IsgdException(val statusCode: Int, message: String) : Exception(message) {
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+}
diff --git a/src/test/kotlin/net/thauvin/erik/isgd/IsgdTest.kt b/src/test/kotlin/net/thauvin/erik/isgd/IsgdTest.kt
index 399030b..59ca783 100644
--- a/src/test/kotlin/net/thauvin/erik/isgd/IsgdTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/isgd/IsgdTest.kt
@@ -1,8 +1,7 @@
/*
* IsgdTest.kt
*
- * Copyright (c) 2020, Erik C. Thauvin (erik@thauvin.net)
- * All rights reserved.
+ * Copyright 2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,19 +31,54 @@
package net.thauvin.erik.isgd
+import assertk.all
+import assertk.assertThat
+import assertk.assertions.contains
+import assertk.assertions.isEqualTo
+import assertk.assertions.isNotNull
+import assertk.assertions.matches
+import assertk.assertions.prop
+import assertk.assertions.startsWith
import kotlin.test.Test
import kotlin.test.assertEquals
-import kotlin.test.assertTrue
+import kotlin.test.assertFailsWith
class IsgdTest {
private val url = "https://www.example.com"
private val shortUrl = "https://is.gd/Pt2sET"
private val shortVgdUrl = "https://v.gd/2z2ncj"
+ @Test
+ fun testException() {
+ assertFailsWith(
+ message = "shorten(duplicate)",
+ exceptionClass = IsgdException::class,
+ block = { Isgd.shorten(shortUrl) }
+ )
+
+ try {
+ Isgd.shorten(shortUrl)
+ } catch (e: IsgdException) {
+ assertThat(e, "shorten(duplicate)").all {
+ prop(IsgdException::statusCode).isEqualTo(400)
+ prop(IsgdException::message).isNotNull().startsWith("Error: ")
+ }
+ }
+ }
+
+ @Test
+ fun testLookup() {
+ assertFailsWith(
+ message = "lookup(empty)",
+ exceptionClass = IllegalArgumentException::class,
+ block = { Isgd.lookup("") }
+ )
+ }
+
@Test
fun testLookupDefault() {
assertEquals(url, Isgd.lookup(shortUrl))
- assertEquals(url, Isgd.lookup(shortVgdUrl, isVgd = true), "v.gd")
+ assertEquals(url, Isgd.lookup(shortVgdUrl, isVgd = true), "lookup(isVgd)")
}
@Test
@@ -53,7 +87,7 @@ class IsgdTest {
assertEquals(
"test({ \"url\": \"$url\" });",
Isgd.lookup(shortUrl, callback = "test", format = Format.JSON),
- "with callback"
+ "lookup(callback)"
)
}
@@ -65,10 +99,28 @@ class IsgdTest {
)
}
+ @Test
+ fun testShorten() {
+ assertFailsWith(
+ message = "shorten(empty)",
+ exceptionClass = IllegalArgumentException::class,
+ block = { Isgd.shorten("") }
+ )
+
+ assertFailsWith(
+ message = "shorten(shorturl)",
+ exceptionClass = IsgdException::class,
+ block = { Isgd.shorten(url, shorturl = "test") }
+ )
+ }
+
@Test
fun testShortenDefault() {
- assertEquals(shortUrl, Isgd.shorten(url))
- assertEquals(shortVgdUrl, Isgd.shorten(url, isVgd = true), "v.gd")
+ assertEquals(shortUrl, Isgd.shorten(url), "shorten(url)")
+ assertEquals(shortVgdUrl, Isgd.shorten(url, isVgd = true), "shorten(isVgd)")
+ assertThat(Isgd.shorten(url, logstats = true), "shorten(callback)").matches("https://is.gd/\\w{6}".toRegex())
+
+
}
@Test
@@ -77,20 +129,21 @@ class IsgdTest {
assertEquals(
"test({ \"shorturl\": \"$shortUrl\" });",
Isgd.shorten(url, callback = "test", format = Format.JSON),
- "with callback"
+ "shorten(callback,json)"
)
}
@Test
fun testShortenXml() {
assertEquals(
- "",
+ "" +
+ "",
Isgd.shorten(url, format = Format.XML)
)
}
@Test
fun testShortenWeb() {
- assertTrue(Isgd.shorten(url, format = Format.WEB).contains(shortUrl))
+ assertThat(Isgd.shorten(url, format = Format.WEB)).contains(shortUrl)
}
}
diff --git a/version.properties b/version.properties
index 7d7030f..5040329 100644
--- a/version.properties
+++ b/version.properties
@@ -1,8 +1,8 @@
#Generated by the Semver Plugin for Gradle
-#Sat Mar 21 16:36:23 PDT 2020
+#Sun May 02 21:57:08 PDT 2021
version.buildmeta=
version.major=0
version.minor=9
-version.patch=1
-version.prerelease=
-version.semver=0.9.1
+version.patch=2
+version.prerelease=SNAPSHOT
+version.semver=0.9.2-SNAPSHOT