From f74ebf3d0c21d6b18a1679d932614630c2c64e18 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 17:47:56 -0800 Subject: [PATCH 001/197] Added license. --- LICENSE.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..15db583 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,32 @@ +Software License Agreement (BSD License) +---------------------------------------- + +Copyright (c) 2017, Erik C. Thauvin (erik@thauvin.net)\ +All rights reserved. + + +Redistribution and use of this software 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 owner 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._ \ No newline at end of file From 169bab65f9c5b80331ff578ed07c81df747aae93 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 17:52:36 -0800 Subject: [PATCH 002/197] Renamed. --- LICENCE.txt | 27 +++++++++++++++++++++++++++ LICENSE.md | 32 -------------------------------- 2 files changed, 27 insertions(+), 32 deletions(-) create mode 100644 LICENCE.txt delete mode 100644 LICENSE.md diff --git a/LICENCE.txt b/LICENCE.txt new file mode 100644 index 0000000..861c1ef --- /dev/null +++ b/LICENCE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2017, Erik C. Thauvin (erik@thauvin.net) +All rights reserved. + +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. \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 15db583..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,32 +0,0 @@ -Software License Agreement (BSD License) ----------------------------------------- - -Copyright (c) 2017, Erik C. Thauvin (erik@thauvin.net)\ -All rights reserved. - - -Redistribution and use of this software 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 owner 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._ \ No newline at end of file From 7c7c33b716724d3f674b2b9a76e2e4725fbaa852 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 20:04:02 -0800 Subject: [PATCH 003/197] Fixed local property syntax. --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec04161..0974365 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,11 @@ PINBOARD_API_TOKEN=user\:TOKEN ``` ```kotlin -val poster = PinboardPoster(Paths.get("local.properties")) +val properties = Properties().apply { + Files.newInputStream(Paths.get("local.properties")).use { fis -> load(fis) } +} + +val poster = PinboardPoster(properties) ``` To specify your own key: @@ -141,7 +145,8 @@ my.api.key=user\:TOKEN ``` ```kotlin -val poster = PinboardPoster(Paths.get("my.properties"), "my.api.key") +val properties = Properties().apply { FileInputStream("my.properties").use { fis -> load(fis) } } +val poster = PinboardPoster(properties, "my.api.key") ``` ### Environment Variable From 95428c22f8656d106387e5c88942a88c114d33c5 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 20:10:48 -0800 Subject: [PATCH 004/197] Fixed example. --- src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt index 191c796..44b6fd3 100644 --- a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt +++ b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt @@ -228,7 +228,7 @@ fun main(args: Array) { PinboardPoster( Properties().apply { Files.newInputStream(properties).use { fis -> load(fis) } - }.getProperty(ENV_API_TOKEN, "") + } ) else -> // API Token is an environment variable (PINBOARD_API_TOKEN) or empty; From b4d411726f62896f37494923cd92b12d75d678e9 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 22:09:20 -0800 Subject: [PATCH 005/197] Added constructor to specify a property file path directly. --- .../thauvin/erik/pinboard/JavaExample.java | 21 ++-------- .../thauvin/erik/pinboard/PinboardPoster.kt | 38 +++++++++++-------- .../erik/pinboard/PinboardPosterTest.kt | 14 +------ 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/main/java/net/thauvin/erik/pinboard/JavaExample.java b/src/main/java/net/thauvin/erik/pinboard/JavaExample.java index d5b4ff4..d252652 100644 --- a/src/main/java/net/thauvin/erik/pinboard/JavaExample.java +++ b/src/main/java/net/thauvin/erik/pinboard/JavaExample.java @@ -31,12 +31,8 @@ */ package net.thauvin.erik.pinboard; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; @@ -44,24 +40,15 @@ import java.util.logging.Logger; public class JavaExample { public static void main(String[] args) { final String url = "http://www.example.com/pinboard"; - final Path properties = Paths.get("local.properties"); + final Path localProps = Paths.get("local.properties"); final PinboardPoster poster; if (args.length == 1) { // API Token is an argument poster = new PinboardPoster(args[0]); - } else if (Files.exists(properties)) { - // API Token is in local.properties (PINBOARD_API_TOKEN) - final Properties p = new Properties(); - try (final InputStream stream = Files.newInputStream(properties)) { - p.load(stream); - } catch (IOException ignore) { - ; - } - poster = new PinboardPoster(p); } else { - // API Token is an environment variable (PINBOARD_API_TOKEN) or empty - poster = new PinboardPoster(); + // API Token is in local.properties or PINBOARD_API_TOKEN environment variable + poster = new PinboardPoster(localProps); } // Set logging levels @@ -72,7 +59,7 @@ public class JavaExample { logger.setLevel(Level.FINE); // Add Pin - if (poster.addPin(url, "Testing", "Extended test", "test kotlin")) { + if (poster.addPin(url, "Testing", "Extended test", "test java")) { System.out.println("Added: " + url); } diff --git a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt index 44b6fd3..495a11d 100644 --- a/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt +++ b/src/main/kotlin/net/thauvin/erik/pinboard/PinboardPoster.kt @@ -39,6 +39,7 @@ import org.xml.sax.InputSource import java.io.StringReader import java.net.URL import java.nio.file.Files +import java.nio.file.Path import java.nio.file.Paths import java.util.* import java.util.logging.ConsoleHandler @@ -58,9 +59,21 @@ open class PinboardPoster() { this.apiToken = apiToken } + @Suppress("unused") @JvmOverloads constructor(properties: Properties, key: String = ENV_API_TOKEN) : this() { - this.apiToken = properties.getProperty(key, "") + apiToken = properties.getProperty(key, apiToken) + } + + @JvmOverloads + constructor(propertiesFilePath: Path, key: String = ENV_API_TOKEN) : this() { + if (Files.exists(propertiesFilePath)) { + apiToken = Properties().apply { + Files.newInputStream(propertiesFilePath).use { nis -> + load(nis) + } + }.getProperty(key, apiToken) + } } var apiToken: String = if (System.getenv(ENV_API_TOKEN).isNullOrBlank()) "" else System.getenv(ENV_API_TOKEN) @@ -218,21 +231,14 @@ open class PinboardPoster() { fun main(args: Array) { val url = "http://www.example.com/pinboard" - val properties = Paths.get("local.properties") - val poster = when { - args.size == 1 -> - // API Token is an argument - PinboardPoster(args[0]) - Files.exists(properties) -> - // API Token is in a local.properties (PINBOARD_API_TOKEN) - PinboardPoster( - Properties().apply { - Files.newInputStream(properties).use { fis -> load(fis) } - } - ) - else -> - // API Token is an environment variable (PINBOARD_API_TOKEN) or empty; - PinboardPoster() + val localProp = Paths.get("local.properties") + + val poster = if (args.size == 1) { + // API Token is an argument + PinboardPoster(args[0]) + } else { + // API Token is in local.properties or PINBOARD_API_TOKEN environment variable + PinboardPoster(localProp) } // Set logging levels diff --git a/src/test/kotlin/net/thauvin/erik/pinboard/PinboardPosterTest.kt b/src/test/kotlin/net/thauvin/erik/pinboard/PinboardPosterTest.kt index bfd72e8..06cf351 100644 --- a/src/test/kotlin/net/thauvin/erik/pinboard/PinboardPosterTest.kt +++ b/src/test/kotlin/net/thauvin/erik/pinboard/PinboardPosterTest.kt @@ -33,9 +33,7 @@ package net.thauvin.erik.pinboard import org.testng.Assert import org.testng.annotations.Test -import java.nio.file.Files import java.nio.file.Paths -import java.util.* class PinboardPosterTest { private val url = "http://www.foo.com/" @@ -54,13 +52,13 @@ class PinboardPosterTest { //poster.apiToken = "foo:TESTING" //Assert.assertFalse(poster.addPin(url, desc), "apiToken: ${poster.apiToken}") - poster = pinboardPosterInstance() + poster = PinboardPoster(localProps) Assert.assertTrue(poster.addPin(url, desc), "apiToken: ${Constants.ENV_API_TOKEN}") } @Test fun testDeletePin() { - val poster = pinboardPosterInstance() + val poster = PinboardPoster(localProps) poster.apiEndPoint = "" Assert.assertFalse(poster.deletePin(url), "apiEndPoint: ") @@ -70,12 +68,4 @@ class PinboardPosterTest { Assert.assertFalse(poster.deletePin("foo.com"), "url: foo.com") } - - private fun pinboardPosterInstance(): PinboardPoster { - return if (Files.exists(localProps)) { - PinboardPoster(Properties().apply { Files.newInputStream(localProps).use { fis -> load(fis) } }) - } else { - PinboardPoster() - } - } } From 7cc91b52f1a2a07f109862437e299108ba0ce55f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 8 Nov 2017 22:10:06 -0800 Subject: [PATCH 006/197] Kobalt wrapper update. --- .idea/kobalt.xml | 2 +- kobalt/Build.kt.iml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml index 7f1760d..3e8b0d0 100644 --- a/.idea/kobalt.xml +++ b/.idea/kobalt.xml @@ -6,7 +6,7 @@