使用sbt-native-packager和JDKPackager插件自定义Freedesktop文件

时间:2015-07-27 17:04:32

标签: scala sbt-native-packager

我想自定义javapackager创建的 document.getElementsByClassName("lstnetdays").onclick = function () { this.parentNode.className = "submenunew"; } 文件,作为sbt-native-packager的JDKPackager插件的一部分。它显然使用了一个模板:

.desktop

特别是,我想添加Gnome将使用的[info] Using default package resource [Menu shortcut descriptor] (add package/linux/Foo.desktop to the class path to customize) 条目来统一我的应用程序打开的所有窗口。

2 个答案:

答案 0 :(得分:3)

javapackager引用插件的目标目录,即target/jdkpackager。这是在编写javafx-ant构建文件时创建的。所以我们可以在这里捎带:

// rewrite the task so that after the ant build is created,
// we add package/linux/MyApp.desktop
writeAntBuild in JDKPackager := {
  val res  = (writeAntBuild in JDKPackager).value
  val main = (mainClass     in JDKPackager).value
    .getOrElse(sys.error("No main class specified"))
  val tgt  = (target        in JDKPackager).value
  val n    = (name          in JDKPackager).value
  val wm   = main.replace('.', '-')
  val desktop = 
    s"""[Desktop Entry]
       |Name=APPLICATION_NAME
       |Comment=APPLICATION_SUMMARY
       |Exec=/opt/APPLICATION_FS_NAME/APPLICATION_LAUNCHER_FILENAME
       |Icon=/opt/APPLICATION_FS_NAME/APPLICATION_LAUNCHER_FILENAME.png
       |Terminal=false
       |Type=Application
       |Categories=DEPLOY_BUNDLE_CATEGORY
       |DESKTOP_MIMES
       |StartupWMClass=$wm
       |""".stripMargin
  IO.write(tgt / "package" / "linux" / s"$n.desktop", desktop)
  res
}

答案 1 :(得分:0)

只要Ant task XML中有相应的设置,就有另一种解决方案:只需通过antBuildDefn 重写插件生成的XML就足够了

以下是通过添加category attribute指定.desktop文件的菜单类别的示例:

antBuildDefn in JDKPackager := {
  val origTask = (antBuildDefn in JDKPackager).value

  val InfoLabel = "info"
  val KeyRegex  = s"$InfoLabel\\.(.+)".r

  import scala.xml._
  import scala.xml.transform._
  val infoRewrite = new RewriteRule {
    override def transform(n: Node) = n match {
      case e: Elem if e.prefix == "fx" && e.label == InfoLabel =>
        e % Attribute("", "category", "Office", Null)
      case other => other
    }
  }

  new RuleTransformer(infoRewrite)(origTask)
}