8000 Change GraalVM build process to allow multiple Clikt commands + some oauth starting by hrothwell · Pull Request #15 · hrothwell/mal-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Change GraalVM build process to allow multiple Clikt commands + some oauth starting #15

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

Merged
merged 4 commits into from
Oct 4, 2022
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ out/
.project
.settings
.classpath
.factorypath
native-image-result/
.factorypath
13 changes: 9 additions & 4 deletions build-native-image-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ set root=%~dp0
call %root%gradlew.bat clean build
echo making config directory
mkdir %root%build\libs\META-INF\native-image
set configPath=%root%build\libs\META-INF\native-image
set configPath=%root%native-image-items\config
echo running agentlib
call java -agentlib:native-image-agent=config-output-dir=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar
@REM no args for base command, then add all subcommands also. potentially will need to run with any arguments also?
call java -agentlib:native-image-agent=config-merge-dir=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar
call java -agentlib:native-image-agent=config-merge-dir=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar login
call java -agentlib:native-image-agent=config-merge-dir=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar random
call java -agentlib:native-image-agent=config-merge-dir=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar random -u hone_the_rat -l completed
Comment on lines +9 to +12
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see documentation on agentlib

It can be necessary to run the target application more than once with different inputs to trigger separate execution paths for a better coverage of dynamic accesses. The agent supports this with the config-merge-dir option which adds the intercepted accesses to an existing set of configuration files

I read it and literally didn't even think about that until hours in 🤦

echo config files located here "%configPath%"
set exeBuildResultPath=%root%native-image-result
set exeBuildResultPath=%root%native-image-items\build-results
mkdir %exeBuildResultPath%
cd %exeBuildResultPath%
echo building native image
call native-image --no-fallback --report-unsupported-elements-at-runtime -H:ConfigurationFileDirectories=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar anime --enable-url-protocols=https --no-server
@REM "-J--add-modules -JALL-SYSTEM" is part of a work around which should be fixed in later graalvm version: https://github.com/oracle/graal/issues/4671
call native-image --no-fallback -J--add-modules -JALL-SYSTEM --report-unsupported-elements-at-runtime -H:ConfigurationFileDirectories=%configPath% -jar %root%build\libs\anime-cli-1.0-SNAPSHOT-all.jar anime --enable-url-protocols=https,http
echo running exe to test! anime.exe is found at "%exeBuildResultPath%"
call %exeBuildResultPath%\anime
cd %root%
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ application {
mainClass.set("com.hrothwell.anime.Main")
}

run{
standardInput = System.in
}

jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
Expand Down
6 changes: 6 additions & 0 deletions native-image-items/build-results/anime.build_artifacts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[EXECUTABLE]
anime.exe

[JDK_LIB]
sunmscapi.dll

Binary file added native-image-items/build-results/anime.exe
Binary file not shown.
Binary file added native-image-items/build-results/sunmscapi.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions native-image-items/config/jni-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
}
]
8 changes: 8 additions & 0 deletions native-image-items/config/predefined-classes-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

2 changes: 2 additions & 0 deletions native-image-items/config/proxy-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
218 changes: 218 additions & 0 deletions native-image-items/config/reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
[
{
"name":"[B"
},
{
"name":"[Ljava.lang.String;"
},
{
"name":"[Lsun.security.pkcs.SignerInfo;"
},
{
"name":"com.hrothwell.anime.domain.MALUserListResponse",
"fields":[{"name":"Companion"}]
},
{
"name":"com.hrothwell.anime.domain.MALUserListResponse$Companion",
"methods":[{"name":"serializer","parameterTypes":[] }]
},
{
"name":"com.hrothwell.anime.domain.UserSecrets",
"fields":[{"name":"Companion"}]
},
{
"name":"com.hrothwell.anime.domain.UserSecrets$Companion",
"methods":[{"name":"serializer","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.AESCipher$General",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.DHParameters",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.HmacCore$HmacSHA256",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.TlsMasterSecretGenerator",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"java.lang.String"
},
{
"name":"java.security.AlgorithmParametersSpi"
},
{
"name":"java.security.KeyStoreSpi"
},
{
"name":"java.security.MessageDigestSpi"
},
{
"name":"java.security.SecureRandomParameters"
},
{
"name":"java.security.interfaces.RSAPrivateKey"
},
{
"name":"java.security.interfaces.RSAPublicKey"
},
{
"name":"java.util.Date"
},
{
"name":"javax.security.auth.x500.X500Principal",
"fields":[{"name":"thisX500Name"}],
"methods":[{"name":"<init>","parameterTypes":["sun.security.x509.X500Name"] }]
},
{
"name":"kotlin.internal.jdk8.JDK8PlatformImplementations",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore$DualFormatPKCS12",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.DRBG",
"methods":[{"name":"<init>","parameterTypes":["java.security.SecureRandomParameters"] }]
},
{
"name":"sun.security.provider.DSA$SHA224withDSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.DSA$SHA256withDSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.JavaKeyStore$DualFormatJKS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.JavaKeyStore$JKS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA2$SHA224",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA2$SHA256",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA5$SHA384",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA5$SHA512",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.X509Factory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.certpath.PKIXCertPathValidator",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.PSSParameters",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSAKeyFactory$Legacy",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSAPSSSignature",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA224withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA256withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.KeyManagerFactoryImpl$SunX509",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.SSLContextImpl$DefaultSSLContext",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.util.ObjectIdentifier"
},
{
"name":"sun.security.x509.AuthorityInfoAccessExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.AuthorityKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.BasicConstraintsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CRLDistributionPointsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CertificateExtensions"
},
{
"name":"sun.security.x509.CertificatePoliciesExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.ExtendedKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.IssuerAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.KeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.NetscapeCertTypeExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.PrivateKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
}
]
5 changes: 5 additions & 0 deletions native-image-items/config/resource-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"resources":{
"includes":[]},
"bundles":[]
}
6 changes: 6 additions & 0 deletions native-image-items/config/serialization-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"types":[
],
"lambdaCapturingTypes":[
]
}
7 changes: 4 additions & 3 deletions src/main/kotlin/com/hrothwell/anime/Main.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.hrothwell.anime

import com.github.ajalt.clikt.core.subcommands
import com.hrothwell.anime.commands.Anime
import com.hrothwell.anime.commands.Login
import com.hrothwell.anime.commands.Random

object Main {
@JvmStatic
fun main(args: Array<String>) {
Anime().main(args)
// TODO adding subcommands seemed to break native image as it no longer created reflection-config.json. Tried several things with no luck.
// see if there is some other way to set subcommands, or just use flags to dictate logic?
Anime().subcommands(Login(), Random()).main(args)
}
}
52 changes: 3 additions & 49 deletions src/main/kotlin/com/hrothwell/anime/commands/Anime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,12 @@ import com.hrothwell.anime.util.AnimeUtil.Companion.RED
import kotlinx.serialization.decodeFromString

class Anime : CliktCommand(
help = "pick a random anime from your MAL lists",
help = "CLI for interacting with MAL",
epilog = """
extended user guide, source code, etc - https://github.com/hrothwell/anime-cli
""".trimIndent()
) {
// entry point
override fun run() = Unit

private val possibleListStatusValues = ListStatus.values().map { it.malValue }.toTypedArray()
private val user by option("-u", "--user-name", help = """
user name. if not provided this will default to "user_name" value in "${AnimeUtil.home}/anime-cli/mal-secret.json"
""".trimIndent())

private val list by option(
"-l",
"--list-status",
help = "list to select from"
).choice(choices = possibleListStatusValues)
.default("plan_to_watch")

override fun run() {
getRandomAnime(user, list)
}

fun getRandomAnime(user: String?, list: String) {

val clientSecrets = AnimeUtil.getUserSecrets()

val headers = "X-MAL-CLIENT-ID" to clientSecrets.client_id
val listStatus = "status" to list
val limit = "limit" to 1000
val userPathParam = user ?: clientSecrets.user_name

val request =
Fuel.get(path = "https://api.myanimelist.net/v2/users/$userPathParam/animelist", parameters = listOf(listStatus, limit))
.appendHeader(headers)

// TODO check for errors before getting result here
// (also why does Fuel do this this way it feels weird to call .third)
val response = request.response()
AnimeUtil.handlePotentialHttpErrors(response.second)

try {
val json = String(response.third.get())
val result = AnimeUtil.jsonReader.decodeFromString<MALUserListResponse>(json)
echo("Anime selected: ${result.data.random().node.title}")
} catch (t: Throwable) {
echoError("couldn't read the response from MAL: $t")
echoError("Stack trace of error: \n")
t.printStackTrace(System.err)
}
}

private fun echoError(msg: String) {
echo("$RED $msg", err = true)
}
}
Loading
0