diff --git a/README.md b/README.md index c2d2e12..3c7a7cb 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,23 @@ Optional parameters: * `-f` to force overwrite target `_nonstop.svg` file, * `-v` to have verbose output. +## Using as a Java/Kotlin dependency + +From version 1.1.2, SVG non-stop is available via [JitPack](https://jitpack.io/#14v/svg-non-stop) as a library: + +```groovy +repositories { + // ... + maven { url 'https://jitpack.io' } +} +dependencies { + implementation "com.github.14v:svg-non-stop:$version" +} +``` + +Use `NonStop.process(rootNodes)` with the root [NodeList](https://docs.oracle.com/javase/8/docs/api/org/w3c/dom/NodeList.html) +of the SVG file. See the source of the `main()` function for an example. + ## Technical notes Utility copies stops definitions into target gradients in SVG file. Then IDE can process file correctly. Utility is _not_ for use in android code. diff --git a/build.gradle.kts b/build.gradle.kts index 545b5e8..81b9160 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,15 @@ plugins { - kotlin("jvm") version "1.3.61" + kotlin("jvm") version "1.6.10" application + `java-library` + `maven-publish` } -group = "" -version = "1.1.1" +group = "com.github.14v" +version = "1.1.2" application { - mainClassName = "NonStopKt" + mainClass.set("NonStopKt") } repositories { @@ -25,4 +27,30 @@ tasks { compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } -} \ No newline at end of file +} + +java { + withJavadocJar() + withSourcesJar() + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +publishing { + publications { + create("maven") { + from(components["java"]) + + pom { + name.set("svg-non-stop") + url.set("https://github.com/14v/svg-non-stop") + licenses { + license { + name.set("MIT License") + url.set("https://github.com/14v/svg-non-stop/blob/master/LICENSE") + } + } + } + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..00e33ed 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-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/NonStop.kt b/src/main/kotlin/NonStop.kt index f45cd95..7811ba9 100644 --- a/src/main/kotlin/NonStop.kt +++ b/src/main/kotlin/NonStop.kt @@ -8,10 +8,22 @@ import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult +/** + * Utility for repairing SVG for compatibility with Android build tools vector drawable + * conversion. + */ object NonStop { + /** + * Whether to log verbosely when processing. + */ var optionVerbose = false + /** + * Modifies the given XML [rootNodes] to repair missing stop info so the SVG can be + * converted to an Android vector asset by the Android build tools. + * @return whether any changes were made. + */ fun processSvg(rootNodes: NodeList): Boolean { val defsNode = rootNodes.findNode("defs") if (defsNode == null) {