Skip to content

Commit

Permalink
Split the logic on plugin and core
Browse files Browse the repository at this point in the history
  • Loading branch information
SergKhram committed Dec 29, 2021
1 parent 6602574 commit b02bdf9
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 80 deletions.
1 change: 1 addition & 0 deletions ares-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
84 changes: 84 additions & 0 deletions ares-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.net.URI

group = "io.github.sergkhram"
version = "1.2.11-RELEASE"

plugins {
kotlin("jvm")
`maven-publish`
signing
}

dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.3")
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
implementation("com.malinskiy.adam:adam:0.4.3")
implementation("org.apache.ant:ant:1.8.2")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

signing {
sign(publishing.publications)
}

publishing {
val sonatypeUsername = System.getProperty("sonatypeUsername")
val sonatypePassword = System.getProperty("sonatypePassword")
val javaPlugin = project.the(JavaPluginConvention::class)

val sourcesJar by project.tasks.creating(org.gradle.api.tasks.bundling.Jar::class) {
classifier = "sources"
from(javaPlugin.sourceSets["main"].allSource)
}
val javadocJar by project.tasks.creating(org.gradle.api.tasks.bundling.Jar::class) {
classifier = "javadoc"
from(javaPlugin.docsDir)
dependsOn("javadoc")
}

publications {
create("default", MavenPublication::class.java) {
from(project.components["java"])
artifact(sourcesJar)
artifact(javadocJar)
pom {
name.set("ares-core")
url.set("https://github.com/SergKhram/ARES")
description.set("Android Core")

this.licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

this.developers {
developer {
id.set("serg-khram-team")
name.set("Sergei Khramkov")
email.set("[email protected]")
}
}

this.scm {
url.set("https://github.com/SergKhram/ARES")
}
}
}
}
repositories {
maven {
url = URI.create("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
50 changes: 50 additions & 0 deletions ares-core/src/main/java/io/github/sergkhram/AresCore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.sergkhram

import com.fasterxml.jackson.databind.ObjectMapper
import io.github.sergkhram.configuration.Configuration
import io.github.sergkhram.configuration.EnrichVariant
import io.github.sergkhram.enrich.CleanAllureEnrichService
import io.github.sergkhram.enrich.MarathonEnrichService
import java.io.File
import io.github.sergkhram.logger as customLogger

class AresCore(val outputDir: File, val log: File, val projectPath: String) {
private val allureDeviceResDirectory: (String) -> File = {
val marathonZeroSixOnePath = "${Configuration.getReportDirectory(it)}allure-device-results"
val marathonZeroSixTwoPath = "${Configuration.getReportDirectory(it)}device-files${Configuration.separator}allure-results"
if(File(marathonZeroSixOnePath).exists()) File(marathonZeroSixOnePath) else File(marathonZeroSixTwoPath)
}
private val marathonAllureResDirectory: (String) -> File = {
File("${Configuration.getReportDirectory(it)}allure-results")
}

fun execute() {
recursivelyDelete(outputDir)
Configuration.logFile = log
customLogger.info("Applying ares plugin")
val projectDirectory = projectPath
customLogger.info("Creating directory for allure-results if doesn't exist")
createAllureResultsDirectory(projectDirectory) // create directory for allure-results if not exists

val mapper = ObjectMapper()
val service = when (Configuration.enrichBy) {
EnrichVariant.MARATHON -> {
customLogger.info("Selected method for getting results is from Marathon")
MarathonEnrichService(
marathonAllureResDirectory(projectDirectory),
mapper,
projectDirectory,
allureDeviceResDirectory(projectDirectory)
)
}
EnrichVariant.CLEAN_ALLURE -> {
customLogger.info("Selected method for getting results is from device(clean allure)")
CleanAllureEnrichService(
mapper,
projectDirectory
)
}
}
service.iterableEnrich()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.sergkhram.helpers

import com.sun.org.slf4j.internal.LoggerFactory
import io.github.sergkhram.configuration.Configuration
import org.gradle.api.logging.Logging
import java.text.SimpleDateFormat
import java.util.*


class AresLogger<T>(clazz: Class<T>) {
private val logger = Logging.getLogger(clazz)
private val logger = LoggerFactory.getLogger(clazz)
val pattern: (String) -> String = {
val formatter = SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z")
val date = Date(System.currentTimeMillis())
Expand All @@ -17,7 +17,7 @@ class AresLogger<T>(clazz: Class<T>) {

fun info(string: String) {
val output = pattern(string)
logger.info(output)
logger.trace(output)
Configuration.logFile?.appendText("$output\n")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.sergkhram
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import io.github.sergkhram.configuration.Configuration
import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.configuration.ExecuteBy
import io.github.sergkhram.configuration.ScreenRecordAttachment
import io.github.sergkhram.helpers.AresLogger
Expand All @@ -19,7 +18,7 @@ import java.nio.file.Files.copy
import java.nio.file.Files.createDirectories
import java.nio.file.attribute.BasicFileAttributes

val logger = AresLogger(AresPlugin::class.java)
val logger = AresLogger(AresCore::class.java)

val marathonVideoDir: (String) -> File = {
File("${it}video")
Expand Down Expand Up @@ -106,7 +105,7 @@ internal fun createAllureResultsDirectory(projectDirectory: String) {
recursivelyDelete(directory)
}

internal fun recursivelyDelete(directory: File) {
fun recursivelyDelete(directory: File) {
if (!directory.exists()) {
directory.mkdir()
} else {
Expand Down Expand Up @@ -183,15 +182,6 @@ val androidHomeDir: File? =
}
}

fun getPropertyExecuteBy(aresExtension: ConfigurationExtension): ExecuteBy? {
return try {
System.getProperty("executeBy")?.let { ExecuteBy.valueOf(it) }
?: aresExtension.testExecutionBlock?.executeBy?.let { ExecuteBy.valueOf(it) }
} catch (e: IllegalArgumentException) {
throw CustomException("There is no chosen executeBy variant, only these values are supported : ${ExecuteBy.values().map {it.name}}")
}
}

internal fun prepareMarathonLogAttachments(mapper: ObjectMapper, logAtt: List<JsonNode>): JsonNode {
val path = logAtt.first()["source"].asText()
val separator = Paths.get(path).fileSystem.separator
Expand Down
5 changes: 3 additions & 2 deletions ares-exec-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import java.net.URI

group = "io.github.sergkhram"
version = "1.2.10-RELEASE"
version = "1.2.11-RELEASE"

plugins {
kotlin("jvm")
`kotlin-dsl`
id("org.gradle.kotlin.kotlin-dsl") version "1.4.9"
`maven-publish`
signing
}
Expand All @@ -19,6 +19,7 @@ dependencies {
implementation("io.qameta.allure.gradle.base:allure-base-plugin:2.9.6")
implementation("io.qameta.allure.gradle.adapter:allure-adapter-plugin:2.9.6")
implementation(project(":ares-plugin"))
implementation(project(":ares-core"))
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package io.github.sergkhram

import com.malinskiy.marathon.MarathonPlugin
import com.malinskiy.marathon.MarathonRunTask
import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.configuration.ExecuteBy
import io.github.sergkhram.tasks.ExecutionWReportGenTask
import io.github.sergkhram.tasks.ExecutionWReportTask
import io.github.sergkhram.tasks.enableAllureForMarathon
import io.github.sergkhram.tasks.setScreenRecordTypeFromMarathon
import io.github.sergkhram.tasks.*
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.sergkhram.tasks

import io.github.sergkhram.configuration.Configuration
import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.tasks.ConfigurationExtension
import io.github.sergkhram.configuration.ExecuteBy
import io.github.sergkhram.getPropertyExecuteBy
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.sergkhram.tasks

import io.github.sergkhram.configuration.Configuration
import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.tasks.ConfigurationExtension
import io.github.sergkhram.configuration.ExecuteBy
import io.github.sergkhram.getPropertyExecuteBy
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.malinskiy.marathon.android.configuration.AllureConfiguration
import com.malinskiy.marathon.device.DeviceFeature
import io.github.sergkhram.*
import io.github.sergkhram.configuration.Configuration
import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.configuration.ExecuteBy
import io.github.sergkhram.tasks.ConfigurationExtension
import io.github.sergkhram.configuration.MarathonBlock
import io.github.sergkhram.configuration.ScreenRecordAttachment
import io.github.sergkhram.helpers.CustomException
Expand Down Expand Up @@ -88,4 +89,13 @@ fun ConfigurationExtension.setScreenRecordTypeFromMarathon(marathonTask: Maratho
} else {
this.marathonBlock!!.screenRecordType = marathonVideoConfiguration
}
}

fun getPropertyExecuteBy(aresExtension: ConfigurationExtension): ExecuteBy? {
return try {
System.getProperty("executeBy")?.let { ExecuteBy.valueOf(it) }
?: aresExtension.testExecutionBlock?.executeBy?.let { ExecuteBy.valueOf(it) }
} catch (e: IllegalArgumentException) {
throw CustomException("There is no chosen executeBy variant, only these values are supported : ${ExecuteBy.values().map {it.name}}")
}
}
5 changes: 3 additions & 2 deletions ares-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import java.net.URI

group = "io.github.sergkhram"
version = "1.2.10-RELEASE"
version = "1.2.11-RELEASE"

plugins {
kotlin("jvm")
`kotlin-dsl`
id("org.gradle.kotlin.kotlin-dsl") version "1.4.9"
`maven-publish`
signing
}
Expand All @@ -20,6 +20,7 @@ dependencies {
implementation(gradleApi())
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
implementation("com.malinskiy.adam:adam:0.4.3")
implementation(project(":ares-core"))
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.sergkhram

import io.github.sergkhram.configuration.ConfigurationExtension
import io.github.sergkhram.tasks.ConfigurationExtension
import io.github.sergkhram.tasks.ReportGenTask
import io.github.sergkhram.tasks.ReportSyncTask
import io.qameta.allure.gradle.adapter.AllureAdapterPlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.github.sergkhram.configuration
package io.github.sergkhram.tasks

import groovy.lang.Closure
import io.github.sergkhram.androidHomeDir
import io.github.sergkhram.configuration.*
import io.github.sergkhram.helpers.CustomException
import org.gradle.api.Project
import java.io.File
Expand Down
Loading

0 comments on commit b02bdf9

Please sign in to comment.