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

[SUGGEST] Introduce sbt #155

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add packager
  • Loading branch information
i10416 committed Sep 22, 2021
commit f3194ac737d963a5d74ee3da72cce3c6afd43901
91 changes: 66 additions & 25 deletions examples/metrics/build.sbt
Original file line number Diff line number Diff line change
@@ -1,58 +1,99 @@
import sbt._
import com.typesafe.sbt.packager.windows._
import Pack._
import Utils._
import Dependencies._
import scala.sys.process._

resolvers += "jetbrain skija" at "https://packages.jetbrains.team/maven/p/skija/maven"

// general
name := "metrics"
version := "0.0.0"
ThisBuild / organization := "org.jetbrains.jwm"
javaOptions ++= Seq(
"enablesystemassertions",
"-enableassertions",
"-Xcheck:jni",
"-Dfile.encoding=UTF-8",
"-release",
"16"
)

// package stuff
maintainer := "john doe"
packageSummary := "example jwm application"
packageDescription := """example jwm application."""

enablePlugins(JavaAppPackaging, WindowsPlugin)

wixProductId := java.util.UUID.randomUUID().toString
wixProductUpgradeId := java.util.UUID.randomUUID().toString

ThisBuild / crossPaths := false
ThisBuild / autoScalaLibrary := false

Compile / run := (Compile / run).dependsOn(genIconIfNotExists).evaluated

lazy val genIconIfNotExists = taskKey[Unit]("generate icon for title bar")

lazy val packageApp = taskKey[Unit]("package application via jpackage")

packageApp := {
system match {
case OS.Linux =>
Pack.packageLinuxAppCmd(
name.value,
organization.value,
version.value,
None,
false,
baseDirectory.value
)
case OS.Mac => ???
case OS.Windows =>
Def.task {
println("use windows/packageBin from sbt-native-packager instead.")
(Windows / packageBin).value
}.value
}
println(s"save package installer at ${baseDirectory.value}/target/${system.name}")
}

genIconIfNotExists := {
val macIcon = (Compile / resourceDirectory).value / "macos.icns"
val macIcon = (Compile / resourceDirectory).value / "macos.icns"
val winIcon = (Compile / resourceDirectory).value / "windows.ico"
System.getProperty("os.name").toLowerCase match {
case mac if mac.contains("mac") && !macIcon.exists() => {
system match {
case OS.Mac if !macIcon.exists() => {
Process(
Seq(
"iconutil",
"-c",
"icns",
"macos.iconset"
),
( Compile / resourceDirectory).value
)!
(Compile / resourceDirectory).value
) !
}
case win if win.contains("win") && !winIcon.exists() => {
case OS.Windows if !winIcon.exists() => {
Process(
"convert" +: Seq(16, 24, 32, 48, 256)
.map(dim => s"windows/icon_${dim}x${dim}.png") :+ "windows.ico",
(Compile / resourceDirectory).value
)!
(Compile / resourceDirectory).value
) !
}
case _ => ()
}
}

Compile / run := (Compile / run).dependsOn(genIconIfNotExists).evaluated

ThisBuild / organization := "org.jetbrains.jwm"
javaOptions ++= Seq(
"enablesystemassertions",
"-enableassertions",
"-Xcheck:jni",
"-Dfile.encoding=UTF-8",
"-release","16"
)
name := "metrics"
version := "0.1.0-SNAPSHOT"

ThisBuild / crossPaths := false
ThisBuild / autoScalaLibrary := false
lazy val metrics = project
.in(file("."))
.settings(
libraryDependencies ++= Dependencies.deps,
assembly / mainClass := Some("org.jetbrains.jwm.examples.Example"),
assembly / assemblyMergeStrategy := {
case PathList(ps @ _*) if ps.last endsWith "module-info.class" => MergeStrategy.discard
assembly / assemblyMergeStrategy := {
case PathList(ps @ _*) if ps.last endsWith "module-info.class" =>
MergeStrategy.discard
case other =>
MergeStrategy.defaultMergeStrategy(other)
}
Expand Down
35 changes: 35 additions & 0 deletions examples/metrics/project/Pack.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sbt._
import scala.sys.process._
import sbt.Keys._
import Utils._
object Pack {
def packageLinuxAppCmd(
name: String,
organization: String,
version: String,
appIconPath: Option[String],
genShortcut: Boolean,
baseDir: File
) = {
Process(
Seq(
"jpackage",
"--name",
name,
"--app-version",
version,
"--type",
"deb",
"-i",
"target",
"--main-class",
s"${organization}.example.Example",
// relative path from directory specified by -i option
"--main-jar",
s"${name}-assembly-${version}.jar"
) ++ appIconPath.map(p => s"--icon $p").toSeq
++ { if (genShortcut) Seq("--linux-shortcut") else Seq.empty },
baseDir
).!
}
}
26 changes: 26 additions & 0 deletions examples/metrics/project/Utils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
object Utils {

lazy val system = {
System.getProperty("os.name").toLowerCase match {
case win if win.contains("win") => OS.Windows
case linux if linux.contains("linux") => OS.Linux
case mac if mac.contains("mac") => OS.Mac
}
}
}

sealed trait OS {
def name: String
}

object OS {
object Mac extends OS {
val name = "macos"
}
object Linux extends OS {
val name = "linux"
}
object Windows extends OS {
val name = "windows"
}
}
1 change: 1 addition & 0 deletions examples/metrics/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.3")