Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple vgo-plugin from AGP versions #91

Merged
merged 12 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: vgo
path: vgo/build/libs/vgo
path: vgo-cli/build/libs/vgo

# Prepare a draft release for GitHub Releases page for the manual verification
# If accepted and published, release workflow would be triggered
Expand All @@ -81,6 +81,12 @@ jobs:
- name: Fetch Sources
uses: actions/checkout@v4

- name: archive vgo
uses: actions/download-artifact@v4
with:
name: vgo
path: ${{ github.workspace }}/vgo

# Remove old release drafts by using the curl request for the available releases with draft flag
- name: Remove Old Release Drafts
env:
Expand All @@ -101,4 +107,5 @@ jobs:
--notes "$(cat << 'EOM'
${{ needs.build.outputs.changelog }}
EOM
)"
) \
${{ github.workspace }}/vgo"
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ changelog.path.set("changelog.md")
subprojects {
apply<KtlintPlugin>()
configure<KtlintExtension> {
version.set("1.2.1")
version.set("1.3.1")
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

### Changed

- `vgo-plugin` (`com.jzbrooks.vgo.plugin`) no longer requires a particular version of Android Gradle Plugin.
Note: `:vgo` is now an abstract implementation of the tool which does not assume either a cli or plugin context. CLI related logic has been relocated into `:vgo-cli`.

### Deprecated

### Removed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-XX:+UseParallelGC

GROUP=com.jzbrooks
VERSION_NAME=2.4.0
VERSION_NAME=3.0.0

POM_URL=https://github.com/jzbrooks/vgo/

Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vgo is a tool for optimizing and converting between vector artwork representatio

vgo is built on vgo-core, a library and intermediate representation for vector graphics.

[![Build Status](https://github.com/jzbrooks/vgo/workflows/build/badge.svg)](https://github.com/jzbrooks/vgo/actions?workflow=build)
[![Build Status](https://github.com/jzbrooks/vgo/workflows/build/badge.svg?branch=master)](https://github.com/jzbrooks/vgo/actions?workflow=build)
[![Maven Central: vgo](https://img.shields.io/maven-central/v/com.jzbrooks/vgo?label=vgo)](https://ossindex.sonatype.org/component/pkg:maven/com.jzbrooks/vgo)
[![Maven Central: vgo-core](https://img.shields.io/maven-central/v/com.jzbrooks/vgo-core?label=vgo-core)](https://ossindex.sonatype.org/component/pkg:maven/com.jzbrooks/vgo-core)
[![Maven Central: vgo-plugin](https://img.shields.io/maven-central/v/com.jzbrooks/vgo-plugin?label=vgo-plugin)](https://ossindex.sonatype.org/component/pkg:maven/com.jzbrooks/vgo-plugin)
Expand Down Expand Up @@ -50,6 +50,11 @@ vgo {
}
```

> [!NOTE]
> You must have the android tools sdk on your build classpath if you are converting SVGs to vector drawables.
> This is typically done by applying the Android Gradle Plugin.

> [!TIP]
> For Android projects a non-zero indent is better for readability and provides no apk size impact after AAPT processing.

## Command Line Interface
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencyResolutionManagement {
}
}

include("vgo-core", "vgo", "vgo-plugin")
include("vgo-core", "vgo", "vgo-plugin", "vgo-cli")
112 changes: 112 additions & 0 deletions vgo-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
plugins {
id("org.jetbrains.kotlin.jvm")
}

tasks {
jar {
dependsOn(configurations.runtimeClasspath)
manifest {
attributes["Main-Class"] = "com.jzbrooks.vgo.cli.CommandLineInterface"
attributes["Bundle-Version"] = project.properties["VERSION_NAME"]
}

val sourceClasses =
sourceSets.main
.get()
.output.classesDirs
inputs.files(sourceClasses)
destinationDirectory.set(layout.buildDirectory.dir("libs/debug"))

doFirst {
from(files(sourceClasses))
from(
configurations.runtimeClasspath
.get()
.asFileTree.files
.map(::zipTree),
)

exclude(
"**/*.kotlin_metadata",
"**/*.kotlin_module",
"**/*.kotlin_builtins",
"**/module-info.class",
"META-INF/maven/**",
"META-INF/*.version",
"META-INF/LICENSE*",
"META-INF/LGPL2.1",
"META-INF/DEPENDENCIES",
"META-INF/AL2.0",
"META-INF/BCKEY.DSA",
"META-INF/BC2048KE.DSA",
"META-INF/BCKEY.SF",
"META-INF/BC2048KE.SF",
"**/NOTICE*",
"javax/activation/**",
"xsd/catalog.xml",
)
}
}

val optimize by registering(JavaExec::class) {
description = "Runs r8 on the jar application."
group = "build"

inputs.file("build/libs/debug/vgo-cli.jar")
outputs.file("build/libs/vgo.jar")

val javaHome = System.getProperty("java.home")

classpath(r8)
mainClass = "com.android.tools.r8.R8"

args(
"--release",
"--classfile",
"--lib",
javaHome,
"--output",
"build/libs/vgo.jar",
"--pg-conf",
"optimize.pro",
"build/libs/debug/vgo-cli.jar",
)

dependsOn(getByName("jar"))
}

val binaryFileProp = layout.buildDirectory.file("libs/vgo")
val binary by registering {
description = "Prepends shell script in the jar to improve CLI"
group = "build"

dependsOn(optimize)

inputs.file("build/libs/vgo.jar")
outputs.file(binaryFileProp)

doLast {
val binaryFile = binaryFileProp.get().asFile
binaryFile.parentFile.mkdirs()
binaryFile.delete()
binaryFile.appendText("#!/bin/sh\n\nexec java \$JAVA_OPTS -jar \$0 \"\$@\"\n\n")
file("build/libs/vgo.jar").inputStream().use { binaryFile.appendBytes(it.readBytes()) }
binaryFile.setExecutable(true, false)
}
}
}

val r8: Configuration by configurations.creating

dependencies {
implementation(project(":vgo"))

implementation("com.android.tools:sdk-common:31.7.0")

r8("com.android.tools:r8:8.5.35")

testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.28.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
2 changes: 1 addition & 1 deletion optimize.pro → vgo-cli/optimize.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
-mergeinterfacesaggressively
-verbose

-keep class com.jzbrooks.vgo.Application {
-keep class com.jzbrooks.vgo.cli.CommandLineInterface {
public static void main(java.lang.String[]);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package com.jzbrooks.vgo

class ArgReader(private val args: MutableList<String>) {
package com.jzbrooks.vgo.cli

import kotlin.collections.any
import kotlin.collections.first
import kotlin.collections.firstOrNull
import kotlin.collections.getOrElse
import kotlin.collections.indexOfFirst
import kotlin.collections.isNotEmpty
import kotlin.collections.map
import kotlin.text.isNotBlank
import kotlin.text.split

class ArgReader(
private val args: MutableList<String>,
) {
private val hasArguments
get() = args.isNotEmpty()

Expand Down Expand Up @@ -41,7 +53,7 @@ class ArgReader(private val args: MutableList<String>) {
}

fun readArguments(): List<String> {
val arguments = mutableListOf<String>()
val arguments = kotlin.collections.mutableListOf<String>()
while (hasArguments) {
arguments.add(readArgument())
}
Expand All @@ -63,12 +75,11 @@ class ArgReader(private val args: MutableList<String>) {
private fun isOptionArgument(
name: String,
argument: String,
): Boolean {
return if (name.length == 1) {
): Boolean =
if (name.length == 1) {
"-$name" == argument
} else {
"--$name" == argument
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.jzbrooks.vgo.cli

import com.jzbrooks.vgo.Vgo
import kotlin.system.exitProcess

class CommandLineInterface {
fun run(args: Array<String>): Int {
val argReader = ArgReader(args.toMutableList())

val printHelp = argReader.readFlag("help|h")
if (printHelp) {
println(HELP_MESSAGE)
return 0
}

val printVersion = argReader.readFlag("version|v")
val printStats = argReader.readFlag("stats|s")
val indent = argReader.readOption("indent")?.toIntOrNull()

val outputs =
run {
val outputPaths = mutableListOf<String>()
var output = argReader.readOption("output|o")
while (output != null) {
outputPaths.add(output)
output = argReader.readOption("output|o")
}
outputPaths.toList()
}

var format = argReader.readOption("format")

var inputs = argReader.readArguments()

val options =
Vgo.Options(
printVersion = printVersion,
printStats = printStats,
indent = indent,
output = outputs,
format = format,
input = inputs,
)

return Vgo(options).run()
}

companion object {
private val HELP_MESSAGE =
"""
> vgo [options] [file/directory]
Options:
-h --help print this message
-o --output file or directory, if not provided the input will be overwritten
-s --stats print statistics on processed files to standard out
-v --version print the version number
--indent value write files with value columns of indentation
--format value output format (svg, vd, etc)
""".trimIndent()

@JvmStatic
fun main(args: Array<String>): Unit = exitProcess(CommandLineInterface().run(args))
}
}
Loading