代码之家  ›  专栏  ›  技术社区  ›  wwagner4

在sbteclipse插件中使用classpathTransformerFactories排除Scala库?

  •  3
  • wwagner4  · 技术社区  · 12 年前

    我在单独的模块中提取Scala Swing应用程序。我不想 Scala Library 因为它还包括Scala Swing。

    我更改了以下内容 classpathentry

    <classpathentry
      kind="con"
      path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
    

    <classpathentry
      sourcepath="C:\Users\wwagner\.ivy2\cache\org.scala-lang\scala-library\srcs\scala-library-2.10.3-sources.jar" 
      kind="lib" 
      path="C:\Users\wwagner\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.10.3.jar"/>
    

    这和预期的一样,但我发现sbteclipse插件支持 classpathTransformerFactories ,可以自动执行。

    怎么可能 classpath转换器工厂 帮我处理用例?

    1 回复  |  直到 12 年前
        1
  •  0
  •   wwagner4    12 年前

    我要做的是在Build.scala中实现以下内容

      // sbteclipse rewrite rules
      object ClasspathentryRewriteRule extends RewriteRule {
        override def transform(parent: Node): Seq[Node] = {
          parent match {
            case c @ <classpathentry/> if (c \ "@path").toString().endsWith("SCALA_CONTAINER") =>
              val home = System.getProperty("user.home")
              val base = s"""$home\\.ivy2\\cache\\org.scala-lang\\scala-library"""
              val srcPath = s"""${base}\\srcs\\scala-library-${D.scalaVersion}-sources.jar"""
              val path = s"""${base}\\jars\\scala-library-${D.scalaVersion}.jar"""
              <classpathentry sourcepath={ srcPath } kind="lib" path={ path }/>
            case other => other
          }
        }
      }
    
      // sbteclipse transformer
      object ClasspathentryTransformer extends EclipseTransformerFactory[RewriteRule] {
        override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] = {
          ClasspathentryRewriteRule.success
        }
      }
    

    在设置中,以下代码完成了作业:

          ....
          EclipseKeys.classpathTransformerFactories := Seq(ClasspathentryTransformer)
          ....