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

izumi.sbtgen.impl.WithArtifactExt.scala Maven / Gradle / Ivy

The newest version!
package izumi.sbtgen.impl

import izumi.sbtgen.model.Platform.BasePlatform
import izumi.sbtgen.model.{Aggregate, Artifact, GenConfig, Platform}

trait WithArtifactExt {
  this: WithProjectIndex with WithBasicRenderers =>

  protected val config: GenConfig

  protected implicit class AggregateExt(agg: Aggregate) {
    def filteredArtifacts: Seq[Artifact] = {
      agg.artifacts.filter(a => config.onlyGroups.isEmpty || (agg.groups ++ a.groups).intersect(config.onlyGroups).nonEmpty)
    }
  }

  protected implicit class ArtifactExt(a: Artifact) {
    def supportsPlatform(p: Platform): Boolean = {
      val enabled = p match {
        case platform: BasePlatform =>
          platformEnabled(platform)
        case Platform.All =>
          true
      }
      enabled && a.platforms.exists(_.platform == p)
    }

    def isJvmOnly: Boolean = {
      config.jvmOnly || a.platforms.size == 1 && supportsPlatform(Platform.Jvm)
    }

    def nameOn(platform: Platform): String = {
      val n = platform match {
        case Platform.All =>
          a.name.value
        case x: BasePlatform if isJvmOnly =>
          if (x == Platform.Jvm) {
            a.name.value
          } else {
            throw new RuntimeException(s"JVM-only project do not support platform: $a / $platform")
          }
        case x: BasePlatform =>
          if (a.supportsPlatform(x)) {
            a.name.value + platformName(x).toUpperCase
          } else {
            throw new RuntimeException(s"Project do not support platform: $a / $platform")
          }


      }
      renderName(n)
    }
  }

  protected def platformEnabled(p: Platform.BasePlatform): Boolean = {
    p match {
      case Platform.Jvm =>
        config.jvm
      case Platform.Js =>
        config.js
      case Platform.Native =>
        config.native
    }
  }

  protected def platformName(p: Platform.BasePlatform): String = {
    p match {
      case Platform.Jvm =>
        "jvm"
      case Platform.Js =>
        "js"
      case Platform.Native =>
        "native"
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy