All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gesellix.docker.remote.api.client.BuildInfoExtensions.kt Maven / Gradle / Ivy

There is a newer version: 2024-09-15T21-00-00
Show newest version
package de.gesellix.docker.remote.api.client

import de.gesellix.docker.remote.api.BuildInfo
import de.gesellix.docker.remote.api.ImageID

fun List.getImageId(): ImageID? {
  val reversedInfos = this.reversed()
  val firstAux = reversedInfos.stream()
    .filter { (_, _, _, _, _, _, _, aux): BuildInfo -> aux != null }
    .findFirst()
  if (firstAux.isPresent) {
    return firstAux.get().aux
  } else {
    val idFromStream = reversedInfos.stream()
      .filter { (_, stream): BuildInfo ->
        val contains = stream?.contains("Successfully built ")
        contains != null && contains
      }
      .findFirst()
    return if (idFromStream.isPresent) {
      ImageID(idFromStream.get().stream!!.removePrefix("Successfully built ").replaceAfter('\n', "").trim())
    } else {
      val tagFromStream = reversedInfos.stream()
        .filter { (_, stream): BuildInfo ->
          val contains = stream?.contains("Successfully tagged ")
          contains != null && contains
        }
        .findFirst()
      tagFromStream.map { (_, stream): BuildInfo ->
        ImageID(stream!!.removePrefix("Successfully tagged ").replaceAfter('\n', "").trim())
      }
        .orElse(null)
    }
  }
}

fun List.getError(): BuildInfo? {
  return this.stream()
    .filter { (_, _, error): BuildInfo -> error != null }
    .findFirst()
    .orElse(null)
}

fun List.hasError(): Boolean {
  return this.stream()
    .anyMatch { (_, _, error): BuildInfo -> error != null }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy