Skip to content

Commit

Permalink
Merge pull request #12 from SergKhram/bugfix/fixed-rerun-video-attach…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
SergKhram authored Apr 20, 2021
2 parents bc60bb7 + 6ba1c81 commit 43b35aa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.net.URI

group = "io.github.sergkhram"
version = "1.0.1-RELEASE"
version = "1.0.2-RELEASE"

dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.8.9")
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/io/github/sergkhram/helpers/conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal val isAppropriateMarathonResultFile: (File, ObjectMapper, JsonNode) ->
(
currentMarathonFile.getStartTime() in currentDeviceFile.getStartTime()..currentDeviceFile.getStopTime() ||
currentMarathonFile.getStopTime() in currentDeviceFile.getStartTime()..currentDeviceFile.getStopTime() ||
(currentMarathonFile.getStartTime() + currentMarathonFile.getStopTime())/2 in currentDeviceFile.getStartTime()..currentDeviceFile.getStopTime()
(currentMarathonFile.getStartTime() + currentMarathonFile.getStopTime())/2 in currentDeviceFile.getStartTime()..currentDeviceFile.getStopTime() ||
currentMarathonFile.getStartTime() - currentDeviceFile.getStopTime() < 1000
)
}
56 changes: 38 additions & 18 deletions src/main/kotlin/io/github/sergkhram/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,50 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import kotlinx.coroutines.newFixedThreadPoolContext
import kotlinx.coroutines.runBlocking
import org.apache.tools.ant.taskdefs.condition.Os
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.io.IOException
import java.nio.file.*
import java.nio.file.Files.copy
import java.nio.file.Files.createDirectories
import java.nio.file.attribute.BasicFileAttributes


internal val buildType: String by lazy {
System.getProperty("buildType") ?: "debug"
}

internal fun copyVideos(projectDirectory: String) {
val marathonScreenRecordDirectory = "$projectDirectory/build/reports/marathon/${buildType}AndroidTest/${ScreenRecordAttachment.directoryName}"
try {
File(
"$projectDirectory/build/reports/marathon/${buildType}AndroidTest/${ScreenRecordAttachment.directoryName}/omni"
marathonScreenRecordDirectory
).listFiles()!!.filter { it.isDirectory }.forEach { vidDir ->
vidDir.listFiles()!!.filter { it.isFile }.forEach { video ->
video.copyFile(projectDirectory)
}
vidDir.copyFolder(projectDirectory)
}
} catch (e: KotlinNullPointerException) {
throw CustomException("There is no $projectDirectory/build/reports/marathon/${buildType}AndroidTest/${ScreenRecordAttachment.directoryName}/omni directory. Check the attachmentType property")
throw CustomException("There is no $marathonScreenRecordDirectory directory. Check the attachmentType property")
}
}

@Throws(IOException::class)
fun File.copyFolder(projectDirectory: String) {
val source = this
val target = Paths.get("$projectDirectory/build/allure-results/${this.name}")
Files.walkFileTree(source.toPath(), object : SimpleFileVisitor<Path>() {
@Throws(IOException::class)
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
createDirectories(target.resolve(source.toPath().relativize(dir)))
return FileVisitResult.CONTINUE
}

@Throws(IOException::class)
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
copy(file, target.resolve(source.toPath().relativize(file)))
return FileVisitResult.CONTINUE
}
})
}

internal fun copyFiles(dir: File, projectDirectory: String, condition: (File) -> Boolean) {
val listOfAllureFiles = dir.listFiles()!!.filter { it.isFile && condition(it) }
listOfAllureFiles?.let {
Expand All @@ -46,8 +67,8 @@ internal fun copyFiles(dir: File, projectDirectory: String, condition: (File) ->

internal fun File.copyFile(projectDirectory: String) {
Files.copy(
Paths.get(this.path),
Paths.get("$projectDirectory/build/allure-results/${this.name}")
Paths.get(this.path),
Paths.get("$projectDirectory/build/allure-results/${this.name}")
)
}

Expand All @@ -57,22 +78,21 @@ internal fun createAllureResultsDirectory(projectDirectory: String) {
directory.mkdir();
} else {
directory.listFiles().forEach {
it.delete()
if(it.isDirectory) it.deleteRecursively() else it.delete()
}
}
}

internal fun prepareVideoAttachments(mapper: ObjectMapper, videoAtt: List<JsonNode>) =
mapper.createObjectNode().apply {
internal fun prepareVideoAttachments(mapper: ObjectMapper, videoAtt: List<JsonNode>): JsonNode {
val path = videoAtt.first()["source"].asText()
val separator = Paths.get(path).fileSystem.separator
return mapper.createObjectNode().apply {
this.put("name", "Video")
this.put(
"source",
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
videoAtt.first()["source"].asText().split("\\\\", "\\").last()
} else {
videoAtt.first()["source"].asText().split("/").last()
}
path.split("${ScreenRecordAttachment.directoryName}$separator").last()
)
this.put("type", ScreenRecordAttachment.allureType)
}!!
}

0 comments on commit 43b35aa

Please sign in to comment.