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

feat/dsl #6

Merged
merged 19 commits into from
Jun 17, 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
25 changes: 15 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
version: ${{ steps.nyx-infer.outputs.version }}
newRelease: ${{ steps.nyx-infer.outputs.newRelease }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run nyx Infer
Expand Down Expand Up @@ -46,17 +46,22 @@ jobs:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Strip the 'v' character from the version number
id: strip
run: |
stripped=$(echo "${{ needs.infer-version.outputs.version }}" | cut -c 2-)
echo "stripped=$stripped" >> "$GITHUB_OUTPUT"
- name: Change wrapper permissions
run: chmod +x gradlew
# - name: Run gradle publish
# run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache
# env:
# ORG_GRADLE_PROJECT_projectVersion: ${{ needs.infer-version.outputs.version }}
# ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
# ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
# ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
# ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
- name: Nyx publish
- name: Run gradle publish (MavenCentral)
run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache
env:
ORG_GRADLE_PROJECT_projectVersion: ${{ steps.strip.outputs.stripped }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
- name: Nyx publish (Github Release)
uses: mooltiverse/nyx-github-action@main
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .nyx.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"collapsedVersionQualifier": "beta",
"description": "{{#replace from=\"# Changelog\" to=\"\"}}{{#fileContent}}CHANGELOG.md{{/fileContent}}{{/replace}}",
"gitCommit": "false",
"gitPush": "false",
"gitPush": "true",
"publishPreRelease": "true",
"releaseName": "{{version}} ({{#timeFormat format=\"2006-01-02\"}}{{timestamp}}{{/timeFormat}})",
"gitTag": "false",
"gitTag": "true",
"publish": "true",
"identifiers": [
{
Expand Down
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ dependencies {
implementation("io.github.moonlightsuite:moonlight-engine:0.3.0")

// Selenium
implementation("org.seleniumhq.selenium:selenium-java:4.20.0")
implementation("org.seleniumhq.selenium:selenium-http-jdk-client:4.13.0")
implementation("org.seleniumhq.selenium:selenium-java:4.21.0")
// implementation("org.seleniumhq.selenium:selenium-http-jdk-client:4.13.0")
testImplementation("org.seleniumhq.selenium:selenium-java:4.21.0")

implementation("io.github.bonigarcia:webdrivermanager:5.8.0")
// implementation("io.github.bonigarcia:webdrivermanager:5.8.0")

// TestFX (headless GUI)
implementation("org.testfx:testfx-core:4.0.18")
Expand All @@ -135,7 +136,7 @@ dependencies {
implementation("eu.hansolo.fx:charts:21.0.7")

// Logging
implementation("io.github.oshai:kotlin-logging-jvm:6.0.9")
implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
runtimeOnly("org.slf4j:slf4j-api:2.0.7")
implementation("ch.qos.logback:logback-classic:1.5.6")

Expand All @@ -146,7 +147,7 @@ dependencies {
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testImplementation("io.mockk:mockk:1.13.10")
testImplementation("io.mockk:mockk:1.13.11")
testImplementation("com.github.stefanbirkner:system-lambda:1.2.1")
testImplementation(kotlin("reflect"))
}
Expand Down
13 changes: 13 additions & 0 deletions kotlinx-html.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env kotlin

@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0")

import kotlinx.html.*; import kotlinx.html.stream.* // ; import kotlinx.html.attributes.*

val addressee = args.firstOrNull() ?: "World"

print(createHTML().html {
body {
h1 { +"Hello, $addressee!" }
}
})
30 changes: 30 additions & 0 deletions script-definition/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id("java")
kotlin("jvm")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("scripting-common"))
implementation(kotlin("scripting-jvm"))
implementation(kotlin("scripting-dependencies"))
implementation(kotlin("scripting-dependencies-maven"))
implementation(kotlin("stdlib-jdk8"))

// coroutines dependency is required for this particular definition
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")

testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(21)
}
52 changes: 52 additions & 0 deletions script-definition/src/main/kotlin/ScriptDef.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import kotlin.script.experimental.api.*
import kotlin.script.experimental.dependencies.*
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
import kotlin.script.experimental.jvm.JvmDependency
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
import kotlin.script.experimental.jvm.jvm
import kotlin.script.experimental.annotations.KotlinScript
import kotlinx.coroutines.runBlocking


// @KotlinScript annotation marks a script definition class
@KotlinScript(
// File extension for the script type
fileExtension = "webmonitor.kts",
// Compilation configuration for the script type
compilationConfiguration = ScriptWithMavenDepsConfiguration::class
)
abstract class ScriptWithMavenDeps

object ScriptWithMavenDepsConfiguration : ScriptCompilationConfiguration(
{
// Implicit imports for all scripts of this type
defaultImports(DependsOn::class, Repository::class)
jvm {
// Extract the whole classpath from context classloader and use it as dependencies
dependenciesFromCurrentContext(wholeClasspath = true)
}
// Callbacks
refineConfiguration {
// Process specified annotations with the provided handler
onAnnotations(DependsOn::class, Repository::class, handler = ::configureMavenDepsOnAnnotations)
}
}
)

private val resolver = CompoundDependenciesResolver(FileSystemDependenciesResolver(), MavenDependenciesResolver())

// The handler that is called during script compilation in order to reconfigure compilation on the fly
fun configureMavenDepsOnAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
val annotations = context.collectedData?.get(ScriptCollectedData.collectedAnnotations)?.takeIf { it.isNotEmpty() }
?: return context.compilationConfiguration.asSuccess() // If no action is performed, the original configuration should be returned
return runBlocking {
// resolving maven artifacts using annotation arguments
resolver.resolveFromScriptSourceAnnotations(annotations)
}.onSuccess {
context.compilationConfiguration.with {
// updating the original configurations with the newly resolved artifacts as compilation dependencies
dependencies.append(JvmDependency(it))
}.asSuccess()
}
}
34 changes: 34 additions & 0 deletions script-host/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id("java")
kotlin("jvm")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("scripting-common"))
implementation(kotlin("scripting-jvm"))
implementation(kotlin("scripting-jvm-host"))
runtimeOnly(kotlin("scripting-jsr223"))

// Logging
implementation("io.github.oshai:kotlin-logging-jvm:6.0.9")
runtimeOnly("org.slf4j:slf4j-api:2.0.7")
implementation("ch.qos.logback:logback-classic:1.5.6")


implementation(project(":script-definition")) // the script definition module

testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
28 changes: 28 additions & 0 deletions script-host/src/main/kotlin/host.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import java.io.File
import kotlin.script.experimental.api.EvaluationResult
import kotlin.script.experimental.api.ResultWithDiagnostics
import kotlin.script.experimental.api.ScriptDiagnostic
import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate

fun main(vararg args: String) {
if (args.size != 1) {
println("usage: <app> <script file>")
} else {
val scriptFile = File(args[0])
println("Executing script $scriptFile")
val res = evalFile(scriptFile)
res.reports.forEach {
if (it.severity > ScriptDiagnostic.Severity.DEBUG) {
println(" : ${it.message}" + if (it.exception == null) "" else ": ${it.exception}")
}
}
}
}

fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<ScriptWithMavenDeps>()
return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, null)
}
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
rootProject.name = providers.gradleProperty("project.name").get()
include("script-definition")
include("script-host")
5 changes: 3 additions & 2 deletions src/main/kotlin/com/enniovisco/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import java.net.*
private typealias ResultData = List<Map<String, String>>
private typealias Metadata = Map<String, String>

fun main(args: Array<String>) {
Cli(args, toFile = true) {
fun main(args: Array<String>, preloaded: Boolean = false, toFile : Boolean = true, toConsole: Boolean = false) {
println("Running....")
Cli(args, toFile = toFile, toConsole = toConsole, preloaded = preloaded) {
it.title("Tracking")
val snapshots = tracking(it)

Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/com/enniovisco/Shared.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.enniovisco

import com.enniovisco.dsl.*
import com.enniovisco.tracking.Browser
import io.github.moonlightsuite.moonlight.core.formula.*
import io.github.moonlightsuite.moonlight.formula.*
import io.github.moonlightsuite.moonlight.formula.classic.*
import io.github.moonlightsuite.moonlight.offline.signal.*

internal typealias GridSignal = SpatialTemporalSignal<Boolean>

/**
* Enum of the supported browsers.
*/
typealias Browser = com.enniovisco.tracking.Browser

/**
* Singleton object used to define the general settings of the browser session.
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/enniovisco/cli/Cli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ class Cli(
args: Array<String>,
toConsole: Boolean = false,
toFile: Boolean = false,
preloaded: Boolean = false,
exec: Cli.(Reporter) -> Unit
) {
val report = Reporter(toConsole, toFile)
private val report = Reporter(toConsole, toFile)
private val log = io.github.oshai.kotlinlogging.KotlinLogging.logger {}

init {
report.use {
validateArgs(args)
if(!preloaded) {
validateArgs(args)
}
exec(it)
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/com/enniovisco/dsl/Dsl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.enniovisco.dsl

import com.enniovisco.Spec
import com.enniovisco.WebSource
import com.enniovisco.main


/**
* Enum of the supported browsers.
*/
typealias Browser = com.enniovisco.tracking.Browser

class WebMonitor {
var toFile = true
var toConsole = false

fun webSource(init: WebSource.() -> Unit): WebSource {
WebSource.init()
return WebSource
}

fun spec(init: Spec.() -> Unit): Spec {
Spec.init()
return Spec
}
}

fun monitor(init: WebMonitor.()-> Unit) {
val webmonitor = WebMonitor()
webmonitor.init()
println("Starting WebMonitor...")
main(emptyArray(), preloaded = true, toFile = webmonitor.toFile, toConsole = webmonitor.toConsole)
}
4 changes: 0 additions & 4 deletions src/main/kotlin/com/enniovisco/tracking/SessionBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.enniovisco.tracking

import io.github.bonigarcia.wdm.*
import org.openqa.selenium.*
import org.openqa.selenium.chrome.*
import org.openqa.selenium.devtools.*
Expand Down Expand Up @@ -40,7 +39,6 @@ class SessionBuilder(
}

private fun initFirefoxSettings(): FirefoxDriver {
WebDriverManager.firefoxdriver().setup()
return FirefoxDriver()
}

Expand All @@ -49,7 +47,6 @@ class SessionBuilder(
headless: Boolean
): ChromeDriver {
reduceDriverVerbosity()
WebDriverManager.chromedriver().setup()
val options = ChromeOptions()
options.addArguments("--force-device-scale-factor=2.75")

Expand All @@ -67,7 +64,6 @@ class SessionBuilder(
options.addArguments("--no-sandbox")
options.addArguments("--disable-dev-shm-usage")
}
options.addArguments("--remote-allow-origins=*")

return ChromeDriver(options)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/enniovisco/tracking/SnapshotBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.enniovisco.tracking

import com.enniovisco.tracking.commands.*
import io.github.oshai.kotlinlogging.*
import org.apache.commons.io.*
import org.openqa.selenium.*
import org.openqa.selenium.devtools.*
import org.openqa.selenium.remote.*
Expand Down Expand Up @@ -73,6 +72,7 @@ class SnapshotBuilder(
private fun takeScreenshot(id: Int) {
val screenshotFile = driver.getScreenshotAs(OutputType.FILE)
val outputFile = File("./output/snap_${id}.png")
FileUtils.copyFile(screenshotFile, outputFile)
screenshotFile.copyTo(outputFile, overwrite = true)
// FileUtils.copyFile(screenshotFile, outputFile)
}
}
Loading