Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The first step to derivate from sbteclipse.

  • Loading branch information...
commit f8ee973ccc69895c7ef4ceb3241a4b894b2d8fdf 1 parent e0440ef
@dcaoyuan authored
Showing with 2,110 additions and 1 deletion.
  1. +27 −0 .gitignore
  2. +15 −1 README.md
  3. +202 −0 nbsbt-core/src/main/resources/LICENSE-2.0.txt
  4. +571 −0 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeans.scala
  5. +32 −0 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansOpts.scala
  6. +285 −0 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansPlugin.scala
  7. +101 −0 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansSDTConfig.scala
  8. +81 −0 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/package.scala
  9. +202 −0 nbsbt-plugin/src/main/resources/LICENSE-2.0.txt
  10. +26 −0 nbsbt-plugin/src/main/scala/org/netbeans/nbsbt/plugin/NetBeansPlugin.scala
  11. +10 −0 nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/build.sbt
  12. +2 −0  nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/project/plugins.sbt
  13. +2 −0  nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/test
  14. +51 −0 nbsbt-plugin/src/sbt-test/nbsbt/01-structure/project/Build.scala
  15. +2 −0  nbsbt-plugin/src/sbt-test/nbsbt/01-structure/project/plugins.sbt
  16. +50 −0 nbsbt-plugin/src/sbt-test/nbsbt/01-structure/test
  17. +211 −0 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/build.sbt
  18. +146 −0 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/project/Build.scala
  19. +2 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/project/plugins.sbt
  20. +1 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/main/java/JavaRoot.java
  21. +1 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/main/scala/Root.scala
  22. +1 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/test/scala/RootSpec.scala
  23. +3 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/src/main/scala/Sub.scala
  24. +4 −0 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/suba/src/main/scala/SubA.scala
  25. +1 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subb/src/it/scala/RootIt.scala
  26. +4 −0 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subb/src/main/scala/SubB.scala
  27. +3 −0  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subc/src/main/scala/SubC.scala
  28. +14 −0 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/test
  29. +52 −0 project/Build.scala
  30. +1 −0  project/build.properties
  31. +6 −0 project/plugins.sbt
  32. +1 −0  version.sbt
View
27 .gitignore
@@ -0,0 +1,27 @@
+# SBT
+boot/
+lib_managed/
+target/
+.history
+
+# Eclipse
+.cache
+.classpath
+.project
+.classpath_nb
+.scala_dependencies
+.settings
+.target/
+
+# IntelliJ
+.idea/
+*.iml
+*.ipr
+*.iws
+out/
+
+# TextMate
+*.tmproj
+
+# Mac
+.DS_Store
View
16 README.md
@@ -1,4 +1,18 @@
nbsbt
=====
-Plugin for sbt to create Netbeans project definition.
+Plugin for sbt to create Netbeans project definition.
+
+This project is derivated from [sbteclipse](https://github.com/typesafehub/sbteclipse)
+
+1. nbsbt requires sbt 0.12+
+
+1. Add nbsbt to your plugin definition file. You can use either the global one at ~/.sbt/plugins/plugins.sbt or the project-specific one at PROJECT_DIR/project/plugins.sbt:
+
+ addSbtPlugin("org.netbeans.sbt" % "sbt-plugin" % "1.0.0")
+
+1. In sbt, you can use the command "netbeans" to generate NetBeans project files:
+
+ > netbeans
+
+4. Or, in NetBeans, you do not need to run "netbeans" command manually, NetBeans will handle it automatically.
View
202 nbsbt-core/src/main/resources/LICENSE-2.0.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
View
571 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeans.scala
@@ -0,0 +1,571 @@
+/*
+ * Copyright 2011 Typesafe Inc.
+ *
+ * This work is based on the original contribution of WeigleWilczek.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.netbeans.nbsbt.core
+
+import NetBeansPlugin.{
+ NetBeansClasspathEntry,
+ NetBeansTransformerFactory,
+ NetBeansClasspathEntryTransformerFactory,
+ NetBeansRewriteRuleTransformerFactory,
+ NetBeansCreateSrc,
+ NetBeansProjectFlavor,
+ NetBeansExecutionEnvironment,
+ NetBeansKeys
+}
+import java.io.{ FileWriter, Writer }
+import java.util.Properties
+import sbt.{
+ Attributed,
+ Artifact,
+ ClasspathDep,
+ Classpaths,
+ Command,
+ Configuration,
+ Configurations,
+ File,
+ IO,
+ Keys,
+ ModuleID,
+ Project,
+ ProjectRef,
+ Reference,
+ ResolvedProject,
+ SettingKey,
+ State,
+ TaskKey,
+ ThisBuild,
+ UpdateReport,
+ richFile
+}
+import sbt.complete.Parser
+import scala.xml.{ Node, PrettyPrinter }
+import scala.xml.transform.{ RewriteRule, RuleTransformer }
+import scalaz.{ Failure, NonEmptyList, Success }
+import scalaz.Scalaz._
+import scalaz.effects._
+
+private object NetBeans extends NetBeansSDTConfig {
+ val SettingFormat = """-([^:]*):?(.*)""".r
+
+ val FileSepPattern = FileSep.replaceAll("""\\""", """\\\\""")
+
+ val JreContainer = "org.eclipse.jdt.launching.JRE_CONTAINER"
+
+ val StandardVmType = "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"
+
+ val ScalaBuilder = "org.scala-ide.sdt.core.scalabuilder"
+
+ val ScalaNature = "org.scala-ide.sdt.core.scalanature"
+
+ val JavaBuilder = "org.eclipse.jdt.core.javabuilder"
+
+ val JavaNature = "org.eclipse.jdt.core.javanature"
+
+ def netbeansCommand(commandName: String): Command =
+ Command(commandName)(_ => parser)((state, args) => action(args.toMap, state))
+
+ def parser: Parser[Seq[(String, Any)]] = {
+ import NetBeansOpts._
+ (executionEnvironmentOpt | boolOpt(SkipParents) | boolOpt(WithSource) | boolOpt(GenNetBeans)).*
+ }
+
+ def executionEnvironmentOpt: Parser[(String, NetBeansExecutionEnvironment.Value)] = {
+ import NetBeansExecutionEnvironment._
+ import NetBeansOpts._
+ import sbt.complete.DefaultParsers._
+ val (head :: tail) = valueSeq map (_.toString)
+ val executionEnvironments = tail.foldLeft(head: Parser[String])(_ | _)
+ (Space ~> ExecutionEnvironment ~ ("=" ~> executionEnvironments)) map { case (k, v) => k -> withName(v) }
+ }
+
+ def action(args: Map[String, Any], state: State): State = {
+ state.log.info("About to create NetBeans project files for your project(s).")
+ import NetBeansOpts._
+ handleProjects(
+ (args get ExecutionEnvironment).asInstanceOf[Option[NetBeansExecutionEnvironment.Value]],
+ (args get SkipParents).asInstanceOf[Option[Boolean]] getOrElse skipParents(ThisBuild, state),
+ (args get WithSource).asInstanceOf[Option[Boolean]],
+ (args get GenNetBeans).asInstanceOf[Option[Boolean]] getOrElse true,
+ state
+ ).fold(onFailure(state), onSuccess(state))
+ }
+
+ def handleProjects(
+ executionEnvironmentArg: Option[NetBeansExecutionEnvironment.Value],
+ skipParents: Boolean,
+ withSourceArg: Option[Boolean],
+ genNetBeans: Boolean,
+ state: State): Validation[IO[Seq[String]]] = {
+ val effects = for {
+ ref <- structure(state).allProjectRefs
+ project <- Project.getProject(ref, structure(state)) if !skip(ref, project, skipParents, state)
+ } yield {
+ val configs = configurations(ref, state)
+ val applic = classpathEntryTransformerFactory(ref, state).createTransformer(ref, state) |@|
+ (classpathTransformerFactories(ref, state) map (_.createTransformer(ref, state))).sequence[Validation, RewriteRule] |@|
+ (projectTransformerFactories(ref, state) map (_.createTransformer(ref, state))).sequence[Validation, RewriteRule] |@|
+ name(ref, state) |@|
+ buildDirectory(state) |@|
+ baseDirectory(ref, state) |@|
+ mapConfigurations(configs, config => srcDirectories(ref, createSrc(ref, state)(config), netbeansOutput(ref, state)(config), state)(config)) |@|
+ scalacOptions(ref, state) |@|
+ mapConfigurations(configs, externalDependencies(ref, withSourceArg getOrElse withSource(ref, state), state)) |@|
+ mapConfigurations(configs, projectDependencies(ref, project, state)) |@|
+ projectAggregate(ref, project, state)
+ applic(
+ handleProject(
+ jreContainer(executionEnvironmentArg orElse executionEnvironment(ref, state)),
+ preTasks(ref, state),
+ relativizeLibs(ref, state),
+ builderAndNatures(projectFlavor(ref, state)),
+ genNetBeans,
+ state
+ )
+ )
+ }
+ effects.sequence[Validation, IO[String]] map (_.sequence)
+ }
+
+ def onFailure(state: State)(errors: NonEmptyList[String]): State = {
+ state.log.error(
+ "Could not create NetBeans project files:%s%s".format(NewLine, errors.list mkString NewLine)
+ )
+ state.fail
+ }
+
+ def onSuccess(state: State)(effects: IO[Seq[String]]): State = {
+ val names = effects.unsafePerformIO
+ if (names.isEmpty)
+ state.log.warn("There was no project to create NetBeans project files for!")
+ else
+ state.log.info(
+ "Successfully created NetBeans project files for project(s):%s%s".format(
+ NewLine,
+ names mkString NewLine
+ )
+ )
+ state
+ }
+
+ def skip(ref: ProjectRef, project: ResolvedProject, skipParents: Boolean, state: State): Boolean =
+ skip(ref, state) || (skipParents && !project.aggregate.isEmpty)
+
+ def mapConfigurations[A](
+ configurations: Seq[Configuration],
+ f: Configuration => Validation[Seq[A]]): Validation[Seq[(Configuration, Seq[A])]] = {
+ def scoped(c: Configuration): Validation[(Configuration, Seq[A])] = f(c) fold (e => e.fail, s => success(c -> s.distinct))
+ (configurations map scoped).sequence
+ }
+
+ def handleProject(
+ jreContainer: String,
+ preTasks: Seq[(TaskKey[_], ProjectRef)],
+ relativizeLibs: Boolean,
+ builderAndNatures: (String, Seq[String]),
+ genNetBeans: Boolean,
+ state: State)(
+ classpathEntryTransformer: Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry],
+ classpathTransformers: Seq[RewriteRule],
+ projectTransformers: Seq[RewriteRule],
+ name: String,
+ buildDirectory: File,
+ baseDirectory: File,
+ srcDirectories: Seq[(Configuration, Seq[(File, File)])],
+ scalacOptions: Seq[(String, String)],
+ externalDependencies: Seq[(Configuration, Seq[Lib])],
+ projectDependencies: Seq[(Configuration, Seq[Prj])],
+ projectAggregate: Seq[Prj]): IO[String] = {
+ for {
+ _ <- executePreTasks(preTasks, state)
+ n <- io(name)
+ _ <- if (genNetBeans) io(()) else saveXml(baseDirectory / ".project", new RuleTransformer(projectTransformers: _*)(projectXml(name, builderAndNatures)))
+ cp <- classpath(
+ classpathEntryTransformer,
+ name,
+ buildDirectory,
+ baseDirectory,
+ relativizeLibs,
+ srcDirectories,
+ externalDependencies,
+ projectDependencies,
+ projectAggregate,
+ jreContainer,
+ genNetBeans,
+ state
+ )
+ _ <- if (genNetBeans) saveXml(baseDirectory / ".classpath_nb", cp) else saveXml(baseDirectory / ".classpath", new RuleTransformer(classpathTransformers: _*)(cp))
+ _ <- if (genNetBeans) io(()) else saveProperties(baseDirectory / ".settings" / "org.scala-ide.sdt.core.prefs", scalacOptions)
+ } yield n
+ }
+
+ def executePreTasks(preTasks: Seq[(TaskKey[_], ProjectRef)], state: State): IO[Unit] =
+ io(for ((preTask, ref) <- preTasks) evaluateTask(preTask, ref, state))
+
+ def projectXml(name: String, builderAndNatures: (String, Seq[String])): Node =
+ <projectDescription>
+ <name>{ name }</name>
+ <buildSpec>
+ <buildCommand>
+ <name>{ builderAndNatures._1 }</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ { builderAndNatures._2.map(n => <nature>{ n }</nature>) }
+ </natures>
+ </projectDescription>
+
+ def classpath(
+ classpathEntryTransformer: Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry],
+ name: String,
+ buildDirectory: File,
+ baseDirectory: File,
+ relativizeLibs: Boolean,
+ srcDirectories: Seq[(Configuration, Seq[(File, File)])],
+ externalDependencies: Seq[(Configuration, Seq[Lib])],
+ projectDependencies: Seq[(Configuration, Seq[Prj])],
+ projectAggregate: Seq[Prj],
+ jreContainer: String,
+ genNetBeans: Boolean,
+ state: State): IO[Node] = {
+ val srcEntriesIoSeq =
+ for ((config, dirs) <- srcDirectories; (dir, output) <- dirs) yield srcEntry(config, baseDirectory, dir, output, genNetBeans, state)
+ for (srcEntries <- srcEntriesIoSeq.sequence) yield {
+ val entries = srcEntries ++
+ (externalDependencies map { case (config, libs) => libs map libEntry(config, buildDirectory, baseDirectory, relativizeLibs, state) }).flatten ++
+ (projectDependencies map { case (config, prjs) => prjs map projectEntry(config, baseDirectory, state) }).flatten ++
+ (if (genNetBeans) (projectAggregate map aggProjectEntry(baseDirectory, state)) else Seq()) ++
+ (Seq(jreContainer) map NetBeansClasspathEntry.Con) ++
+ (Seq("bin") map NetBeansClasspathEntry.Output)
+ if (genNetBeans) <classpath name={ name }>{ classpathEntryTransformer(entries) map (_.toXmlNetBeans) }</classpath>
+ else <classpath>{ classpathEntryTransformer(entries) map (_.toXml) }</classpath>
+ }
+ }
+
+ def srcEntry(
+ config: Configuration,
+ baseDirectory: File,
+ srcDirectory: File,
+ classDirectory: File,
+ genNetBeans: Boolean,
+ state: State): IO[NetBeansClasspathEntry.Src] =
+ io {
+ if (!srcDirectory.exists() && !genNetBeans) srcDirectory.mkdirs()
+ NetBeansClasspathEntry.Src(
+ config.name,
+ relativize(baseDirectory, srcDirectory),
+ relativize(baseDirectory, classDirectory)
+ )
+ }
+
+ def libEntry(
+ config: Configuration,
+ buildDirectory: File,
+ baseDirectory: File,
+ relativizeLibs: Boolean,
+ state: State)(
+ lib: Lib): NetBeansClasspathEntry.Lib = {
+ def path(file: File) = {
+ val relativizedBase =
+ if (buildDirectory === baseDirectory) Some(".") else IO.relativize(buildDirectory, baseDirectory)
+ val relativizedFile = IO.relativize(buildDirectory, file)
+ val relativized = (relativizedBase |@| relativizedFile)((base, file) =>
+ "%s%s%s".format(
+ base split FileSepPattern map (part => if (part != ".") ".." else part) mkString FileSep,
+ FileSep,
+ file
+ )
+ )
+ if (relativizeLibs) relativized getOrElse file.getAbsolutePath else file.getAbsolutePath
+ }
+ NetBeansClasspathEntry.Lib(config.name, path(lib.binary), lib.source map path)
+ }
+
+ def projectEntry(
+ config: Configuration,
+ baseDirectory: File,
+ state: State)(
+ prj: Prj): NetBeansClasspathEntry.Project = {
+ NetBeansClasspathEntry.Project(
+ prj.name,
+ prj.baseDirectory.getAbsolutePath,
+ prj.classDirectory map (_.getAbsolutePath) getOrElse ""
+ )
+ }
+
+ def aggProjectEntry(
+ baseDirectory: File,
+ state: State)(
+ prj: Prj): NetBeansClasspathEntry.AggProject = {
+ NetBeansClasspathEntry.AggProject(
+ prj.name,
+ prj.baseDirectory.getAbsolutePath
+ )
+ }
+
+ def jreContainer(executionEnvironment: Option[NetBeansExecutionEnvironment.Value]): String =
+ executionEnvironment match {
+ case Some(ee) => "%s/%s/%s".format(JreContainer, StandardVmType, ee)
+ case None => JreContainer
+ }
+
+ def builderAndNatures(projectFlavor: NetBeansProjectFlavor.Value) =
+ if (projectFlavor == NetBeansProjectFlavor.Scala)
+ ScalaBuilder -> Seq(ScalaNature, JavaNature)
+ else
+ JavaBuilder -> Seq(JavaNature)
+
+ // Getting and transforming mandatory settings and task results
+
+ def name(ref: Reference, state: State): Validation[String] =
+ if (setting(NetBeansKeys.useProjectId in ref, state).fold(_ => false, id))
+ setting(Keys.thisProject in ref, state) map (_.id)
+ else
+ setting(Keys.name in ref, state)
+
+ def buildDirectory(state: State): Validation[File] =
+ setting(Keys.baseDirectory in ThisBuild, state)
+
+ def baseDirectory(ref: Reference, state: State): Validation[File] =
+ setting(Keys.baseDirectory in ref, state)
+
+ def target(ref: Reference, state: State): Validation[File] =
+ setting(Keys.target in ref, state)
+
+ def srcDirectories(
+ ref: Reference,
+ createSrc: NetBeansCreateSrc.ValueSet,
+ netbeansOutput: Option[String],
+ state: State)(
+ configuration: Configuration): Validation[Seq[(File, File)]] = {
+ import NetBeansCreateSrc._
+ val classDirectory = netbeansOutput match {
+ case Some(name) => baseDirectory(ref, state) map (new File(_, name))
+ case None => setting(Keys.classDirectory in (ref, configuration), state)
+ }
+ def dirs(values: ValueSet, key: SettingKey[Seq[File]]) =
+ if (values subsetOf createSrc)
+ (setting(key in (ref, configuration), state) <**> classDirectory)((sds, cd) => sds map (_ -> cd))
+ else
+ success(Seq.empty)
+ Seq(
+ dirs(ValueSet(Unmanaged, Source), Keys.unmanagedSourceDirectories),
+ dirs(ValueSet(Managed, Source), Keys.managedSourceDirectories),
+ dirs(ValueSet(Unmanaged, Resource), Keys.unmanagedResourceDirectories),
+ dirs(ValueSet(Managed, Resource), Keys.managedResourceDirectories)
+ ) reduceLeft (_ >>*<< _)
+ }
+
+ def scalacOptions(ref: ProjectRef, state: State): Validation[Seq[(String, String)]] =
+ evaluateTask(Keys.scalacOptions, ref, state) map (options =>
+ if (options.isEmpty)
+ Nil
+ else {
+ fromScalacToSDT(options) match {
+ case Seq() => Seq()
+ case options => ("scala.compiler.useProjectSettings" -> "true") +: options
+ }
+ }
+ )
+
+ def externalDependencies(
+ ref: ProjectRef,
+ withSource: Boolean,
+ state: State)(
+ configuration: Configuration): Validation[Seq[Lib]] = {
+ def moduleToFile(key: TaskKey[UpdateReport], p: (Artifact, File) => Boolean = (_, _) => true) =
+ evaluateTask(key in configuration, ref, state) map { updateReport =>
+ val moduleToFile =
+ for {
+ configurationReport <- (updateReport configuration configuration.name).toSeq
+ moduleReport <- configurationReport.modules
+ (artifact, file) <- moduleReport.artifacts if p(artifact, file)
+ } yield moduleReport.module -> file
+ moduleToFile.toMap
+ }
+ def libs(files: Seq[Attributed[File]], binaries: Map[ModuleID, File], sources: Map[ModuleID, File]) = {
+ val binaryFilesToSourceFiles =
+ for {
+ (moduleId, binaryFile) <- binaries
+ sourceFile <- sources get moduleId
+ } yield binaryFile -> sourceFile
+ files.files map (file => Lib(file)(binaryFilesToSourceFiles get file))
+ }
+ val externalDependencyClasspath =
+ evaluateTask(Keys.externalDependencyClasspath in configuration, ref, state)
+ val binaryModuleToFile = moduleToFile(Keys.update)
+ val sourceModuleToFile =
+ if (withSource)
+ moduleToFile(Keys.updateClassifiers, (artifact, _) => artifact.classifier === Some("sources"))
+ else
+ Map[ModuleID, File]().success
+ val externalDependencies =
+ (externalDependencyClasspath |@| binaryModuleToFile |@| sourceModuleToFile)(libs)
+ state.log.debug(
+ "External dependencies for configuration '%s' and withSource '%s': %s".format(
+ configuration,
+ withSource,
+ externalDependencies
+ )
+ )
+ externalDependencies
+ }
+
+ def projectDependencies(
+ ref: ProjectRef,
+ project: ResolvedProject,
+ state: State)(
+ configuration: Configuration): Validation[Seq[Prj]] = {
+ val projectDependencies: Seq[Validation[Prj]] = project.dependencies collect {
+ case dependency if isInConfiguration(configuration, ref, dependency, state) =>
+ val dependencyRef = dependency.project
+ val name = setting(Keys.name in dependencyRef, state)
+ val baseDir = setting(Keys.baseDirectory in dependencyRef, state)
+ val classDir = setting(Keys.classDirectory in (dependencyRef, configuration), state) fold (f => f.fail, s => success(Option(s)))
+ (name |@| baseDir |@| classDir)(Prj)
+ }
+ val projectDependenciesSeq = projectDependencies.sequence
+ state.log.debug("Project dependencies for configuration '%s': %s".format(configuration, projectDependenciesSeq))
+ projectDependenciesSeq
+ }
+
+ def projectAggregate(
+ ref: ProjectRef,
+ project: ResolvedProject,
+ state: State): Validation[Seq[Prj]] = {
+ val projects: Seq[Validation[Prj]] = project.aggregate collect {
+ case prj =>
+ val prjRef = prj.project
+ val name = setting(Keys.name in prjRef, state)
+ val baseDir = setting(Keys.baseDirectory in prjRef, state)
+ (name |@| baseDir |@| success(None))(Prj)
+ }
+ val projectsSeq = projects.sequence
+ state.log.debug("Project aggregate: %s".format(projectsSeq))
+ projectsSeq
+ }
+
+ def isInConfiguration(
+ configuration: Configuration,
+ ref: ProjectRef,
+ dependency: ClasspathDep[ProjectRef],
+ state: State): Boolean = {
+ val map = Classpaths.mapped(
+ dependency.configuration,
+ Configurations.names(Classpaths.getConfigurations(ref, structure(state).data)),
+ Configurations.names(Classpaths.getConfigurations(dependency.project, structure(state).data)),
+ "compile", "*->compile"
+ )
+ !map(configuration.name).isEmpty
+ }
+
+ // Getting and transforming optional settings and task results
+
+ def executionEnvironment(ref: Reference, state: State): Option[NetBeansExecutionEnvironment.Value] =
+ setting(NetBeansKeys.executionEnvironment in ref, state).fold(_ => None, id)
+
+ def skipParents(ref: Reference, state: State): Boolean =
+ setting(NetBeansKeys.skipParents in ref, state).fold(_ => false, id)
+
+ def withSource(ref: Reference, state: State): Boolean =
+ setting(NetBeansKeys.withSource in ref, state).fold(_ => false, id)
+
+ def classpathEntryTransformerFactory(ref: Reference, state: State): NetBeansTransformerFactory[Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry]] =
+ setting(NetBeansKeys.classpathEntryTransformerFactory in ref, state).fold(
+ _ => NetBeansClasspathEntryTransformerFactory.Identity,
+ id
+ )
+
+ def classpathTransformerFactories(ref: Reference, state: State): Seq[NetBeansTransformerFactory[RewriteRule]] =
+ setting(NetBeansKeys.classpathTransformerFactories in ref, state).fold(
+ _ => Seq(NetBeansRewriteRuleTransformerFactory.ClasspathDefault),
+ NetBeansRewriteRuleTransformerFactory.ClasspathDefault +: _
+ )
+
+ def projectTransformerFactories(ref: Reference, state: State): Seq[NetBeansTransformerFactory[RewriteRule]] =
+ setting(NetBeansKeys.projectTransformerFactories in ref, state).fold(
+ _ => Seq(NetBeansRewriteRuleTransformerFactory.Identity),
+ id
+ )
+
+ def configurations(ref: Reference, state: State): Seq[Configuration] =
+ setting(NetBeansKeys.configurations in ref, state).fold(
+ _ => Seq(Configurations.Compile, Configurations.Test),
+ _.toSeq
+ )
+
+ def createSrc(ref: Reference, state: State)(configuration: Configuration): NetBeansCreateSrc.ValueSet =
+ setting(NetBeansKeys.createSrc in (ref, configuration), state).fold(_ => NetBeansCreateSrc.Default, id)
+
+ def projectFlavor(ref: Reference, state: State) =
+ setting(NetBeansKeys.projectFlavor in ref, state).fold(_ => NetBeansProjectFlavor.Scala, id)
+
+ def netbeansOutput(ref: ProjectRef, state: State)(config: Configuration): Option[String] =
+ setting(NetBeansKeys.netbeansOutput in (ref, config), state).fold(_ => None, id)
+
+ def preTasks(ref: ProjectRef, state: State): Seq[(TaskKey[_], ProjectRef)] =
+ setting(NetBeansKeys.preTasks in ref, state).fold(_ => Seq.empty, _.zipAll(Seq.empty, null, ref))
+
+ def relativizeLibs(ref: ProjectRef, state: State): Boolean =
+ setting(NetBeansKeys.relativizeLibs in ref, state).fold(_ => true, id)
+
+ def skip(ref: ProjectRef, state: State): Boolean =
+ setting(NetBeansKeys.skipProject in ref, state).fold(_ => false, id)
+
+ // IO
+
+ def saveXml(file: File, xml: Node): IO[Unit] =
+ fileWriter(file).bracket(closeWriter)(writer => io(writer.write(new PrettyPrinter(999, 2) format xml)))
+
+ def saveProperties(file: File, settings: Seq[(String, String)]): IO[Unit] =
+ if (!settings.isEmpty) {
+ val properties = new Properties
+ for ((key, value) <- settings) properties.setProperty(key, value)
+ fileWriterMkdirs(file).bracket(closeWriter)(writer =>
+ io(properties.store(writer, "Generated by nbsbt"))
+ )
+ } else
+ io(())
+
+ def fileWriter(file: File): IO[FileWriter] =
+ io(new FileWriter(file))
+
+ def fileWriterMkdirs(file: File): IO[FileWriter] =
+ io {
+ file.getParentFile.mkdirs()
+ new FileWriter(file)
+ }
+
+ def closeWriter(writer: Writer): IO[Unit] =
+ io(writer.close())
+
+ // Utilities
+
+ def relativize(baseDirectory: File, file: File): String =
+ IO.relativize(baseDirectory, file).get
+}
+
+private case class Content(
+ name: String,
+ dir: File,
+ project: Node,
+ classpath: Node,
+ scalacOptions: Seq[(String, String)])
+
+private case class Lib(binary: File)(val source: Option[File])
+private case class Prj(name: String, baseDirectory: File, classDirectory: Option[File])
View
32 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansOpts.scala
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Typesafe Inc.
+ *
+ * This work is based on the original contribution of WeigleWilczek.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.netbeans.nbsbt.core
+
+private object NetBeansOpts {
+
+ val ExecutionEnvironment = "execution-environment"
+
+ val SkipParents = "skip-parents"
+
+ val WithSource = "with-source"
+
+ val UseProjectId = "use-project-id"
+
+ val GenNetBeans = "gen-netbeans"
+}
View
285 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansPlugin.scala
@@ -0,0 +1,285 @@
+/*
+ * Copyright 2011 Typesafe Inc.
+ *
+ * This work is based on the original contribution of WeigleWilczek.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.netbeans.nbsbt.core
+
+import sbt.{
+ Configuration,
+ Configurations,
+ File,
+ Plugin,
+ ProjectRef,
+ ResolvedProject,
+ Setting,
+ SettingKey,
+ State,
+ TaskKey
+}
+import sbt.Keys.{ baseDirectory, commands }
+import scala.util.control.Exception
+import scala.xml.{ Attribute, Elem, MetaData, Node, Null, Text }
+import scala.xml.transform.RewriteRule
+
+object NetBeansPlugin extends NetBeansPlugin
+
+trait NetBeansPlugin {
+
+ def netbeansSettings: Seq[Setting[_]] = {
+ import NetBeansKeys._
+ Seq(
+ commandName := "netbeans",
+ commands <+= (commandName)(NetBeans.netbeansCommand)
+ )
+ }
+
+ object NetBeansKeys {
+ import NetBeansOpts._
+
+ val executionEnvironment: SettingKey[Option[NetBeansExecutionEnvironment.Value]] = SettingKey(
+ prefix(ExecutionEnvironment),
+ "The optional NetBeans execution environment."
+ )
+
+ val skipParents: SettingKey[Boolean] = SettingKey(
+ prefix(SkipParents),
+ "Skip creating NetBeans files for parent project?"
+ )
+
+ val withSource: SettingKey[Boolean] = SettingKey(
+ prefix(WithSource),
+ "Download and link sources for library dependencies?"
+ )
+
+ val useProjectId: SettingKey[Boolean] = SettingKey(
+ prefix(UseProjectId),
+ "Use the sbt project id as the NetBeans project name?"
+ )
+
+ @deprecated("Use classpathTransformerFactories instead!", "2.1.0")
+ val classpathEntryTransformerFactory: SettingKey[NetBeansTransformerFactory[Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry]]] = SettingKey(
+ prefix("classpathEntryTransformerFactory"),
+ "Creates a transformer for classpath entries."
+ )
+
+ val classpathTransformerFactories: SettingKey[Seq[NetBeansTransformerFactory[RewriteRule]]] = SettingKey(
+ prefix("classpathTransformerFactory"),
+ "Factories for a rewrite rule for the .classpath file."
+ )
+
+ val projectTransformerFactories: SettingKey[Seq[NetBeansTransformerFactory[RewriteRule]]] = SettingKey(
+ prefix("projectTransformerFactory"),
+ "Factories for a rewrite rule for the .project file."
+ )
+
+ val commandName: SettingKey[String] = SettingKey(
+ prefix("command-name"),
+ "The name of the command."
+ )
+
+ val configurations: SettingKey[Set[Configuration]] = SettingKey(
+ prefix("configurations"),
+ "The configurations to take into account."
+ )
+
+ val createSrc: SettingKey[NetBeansCreateSrc.ValueSet] = SettingKey(
+ prefix("create-src"),
+ "The source kinds to be included."
+ )
+
+ val projectFlavor: SettingKey[NetBeansProjectFlavor.Value] = SettingKey(
+ prefix("project-flavor"),
+ "The flavor of project (Scala or Java) to build."
+ )
+
+ val netbeansOutput: SettingKey[Option[String]] = SettingKey(
+ prefix("netbeans-output"),
+ "The optional output for NetBeans."
+ )
+
+ val preTasks: SettingKey[Seq[TaskKey[_]]] = SettingKey(
+ prefix("pre-tasks"),
+ "The tasks to be evaluated prior to creating the NetBeans project definition."
+ )
+
+ val relativizeLibs: SettingKey[Boolean] = SettingKey(
+ prefix("relativize-libs"),
+ "Relativize the paths to the libraries?"
+ )
+
+ val skipProject: SettingKey[Boolean] = SettingKey(
+ prefix("skipProject"),
+ "Skip creating NetBeans files for a given project?"
+ )
+
+ private def prefix(key: String) = "netbeans-" + key
+ }
+
+ object NetBeansExecutionEnvironment extends Enumeration {
+
+ val JavaSE17 = Value("JavaSE-1.7")
+
+ val JavaSE16 = Value("JavaSE-1.6")
+
+ val J2SE15 = Value("J2SE-1.5")
+
+ val J2SE14 = Value("J2SE-1.4")
+
+ val J2SE13 = Value("J2SE-1.3")
+
+ val J2SE12 = Value("J2SE-1.2")
+
+ val JRE11 = Value("JRE-1.1")
+
+ val valueSeq: Seq[Value] = JavaSE17 :: JavaSE16 :: J2SE15 :: J2SE14 :: J2SE13 :: J2SE12 :: JRE11 :: Nil
+ }
+
+ sealed trait NetBeansClasspathEntry {
+ def toXml: Node
+ def toXmlNetBeans: Node
+ }
+
+ object NetBeansClasspathEntry {
+
+ case class Src(scope: String, path: String, output: String) extends NetBeansClasspathEntry {
+ override def toXml = <classpathentry kind="src" path={ path } output={ output }/>
+ override def toXmlNetBeans = <classpathentry kind="src" path={ path } output={ output } scope={ scope }/>
+ }
+
+ case class Lib(scope: String, path: String, sourcePath: Option[String] = None) extends NetBeansClasspathEntry {
+ override def toXml =
+ sourcePath.foldLeft(<classpathentry kind="lib" path={ path }/>)((xml, sp) =>
+ xml % Attribute("sourcepath", Text(sp), Null)
+ )
+ override def toXmlNetBeans =
+ sourcePath.foldLeft(<classpathentry kind="lib" path={ path } scope={ scope }/>)((xml, sp) =>
+ xml % Attribute("sourcepath", Text(sp), Null)
+ )
+ }
+
+ case class Project(name: String, path: String, output: String) extends NetBeansClasspathEntry {
+ override def toXml =
+ <classpathentry kind="src" path={ "/" + name } exported="true" combineaccessrules="false"/>
+ override def toXmlNetBeans =
+ <classpathentry kind="src" path={ name } exported="true" combineaccessrules="false" base={ path } output={ output }/>
+ }
+
+ case class AggProject(name: String, path: String) extends NetBeansClasspathEntry {
+ override def toXml =
+ <classpathentry kind="agg" path={ "/" + name }/>
+ override def toXmlNetBeans =
+ <classpathentry kind="agg" path={ name } base={ path }/>
+ }
+
+ case class Con(path: String) extends NetBeansClasspathEntry {
+ override def toXml = <classpathentry kind="con" path={ path }/>
+ override def toXmlNetBeans = <classpathentry kind="con" path={ path }/>
+ }
+
+ case class Output(path: String) extends NetBeansClasspathEntry {
+ override def toXml = <classpathentry kind="output" path={ path }/>
+ override def toXmlNetBeans = <classpathentry kind="output" path={ path }/>
+ }
+ }
+
+ object NetBeansCreateSrc extends Enumeration {
+
+ val Unmanaged = Value
+
+ val Managed = Value
+
+ val Source = Value
+
+ val Resource = Value
+
+ val Default = ValueSet(Unmanaged, Source)
+
+ val All = ValueSet(Unmanaged, Managed, Source, Resource)
+ }
+
+ object NetBeansProjectFlavor extends Enumeration {
+
+ val Scala = Value
+
+ val Java = Value
+ }
+
+ trait NetBeansTransformerFactory[A] {
+ def createTransformer(ref: ProjectRef, state: State): Validation[A]
+ }
+
+ object NetBeansClasspathEntryTransformerFactory {
+
+ object Identity extends NetBeansTransformerFactory[Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry]] {
+ import scalaz.Scalaz._
+ override def createTransformer(
+ ref: ProjectRef,
+ state: State): Validation[Seq[NetBeansClasspathEntry] => Seq[NetBeansClasspathEntry]] = {
+ val transformer = (entries: Seq[NetBeansClasspathEntry]) => entries
+ transformer.success
+ }
+ }
+ }
+
+ object NetBeansRewriteRuleTransformerFactory {
+
+ object IdentityRewriteRule extends RewriteRule {
+ override def transform(node: Node): Node = node
+ }
+
+ object ClasspathDefaultRule extends RewriteRule {
+
+ private val CpEntry = "classpathentry"
+
+ private val ScalaContainer = "org.scala-ide.sdt.launching.SCALA_CONTAINER"
+
+ private val ScalaCompilerContainer = "org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER"
+
+ override def transform(node: Node): Seq[Node] = node match {
+ case Elem(pf, CpEntry, attrs, scope, child @ _*) if isScalaLibrary(attrs) =>
+ Elem(pf, CpEntry, container(ScalaContainer), scope, child: _*)
+ case Elem(pf, CpEntry, attrs, scope, child @ _*) if isScalaCompiler(attrs) =>
+ Elem(pf, CpEntry, container(ScalaCompilerContainer), scope, child: _*)
+ case other =>
+ other
+ }
+
+ private def container(name: String) =
+ Attribute("kind", Text("con"), Attribute("path", Text(name), Null))
+
+ private def isScalaLibrary(metaData: MetaData) =
+ metaData("kind") == Text("lib") &&
+ (Option(metaData("path").text) map (_ contains "scala-library.jar") getOrElse false)
+
+ private def isScalaCompiler(metaData: MetaData) =
+ metaData("kind") == Text("lib") &&
+ (Option(metaData("path").text) map (_ contains "scala-compiler.jar") getOrElse false)
+ }
+
+ object Identity extends NetBeansTransformerFactory[RewriteRule] {
+ import scalaz.Scalaz._
+ override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] =
+ IdentityRewriteRule.success
+ }
+
+ object ClasspathDefault extends NetBeansTransformerFactory[RewriteRule] {
+ import scalaz.Scalaz._
+ override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] =
+ ClasspathDefaultRule.success
+ }
+ }
+}
View
101 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/NetBeansSDTConfig.scala
@@ -0,0 +1,101 @@
+package org.netbeans.nbsbt.core
+
+import collection.breakOut
+
+private trait NetBeansSDTConfig {
+ def fromScalacToSDT(options: Seq[String]): Seq[(String, String)] =
+ aggregate((Map() withDefaultValue "", options))._1.toSeq
+
+ private type Aggregate = (String Map String, Seq[String])
+ private type ArgumentConsumer = Aggregate PartialFunction Aggregate
+
+ private lazy val aggregate: ArgumentConsumer = {
+ case done @ (_, Seq()) => done
+ case formerResult => aggregate(consumeOptionsFrom(formerResult) getOrElse formerResult)
+ }
+
+ private lazy val consumeOptionsFrom = supportedOptions.foldRight(Unsupported.classify)(_.classify orElse _).lift
+
+ private lazy val supportedOptions = Set(
+ ColonSeparated("P", once = false),
+ Flag("deprecation"),
+ Flag("explaintypes"),
+ ColonSeparated("g"),
+ Flag("no-specialization"),
+ Flag("nowarn"),
+ Flag("optimise"),
+ ColonSeparated("target"),
+ Flag("unchecked"),
+ Flag("verbose"),
+
+ Flag("Xcheck-null"),
+ Flag("Xcheckinit"),
+ Flag("Xdisable-assertions"),
+ TakesArg("Xelide-below"),
+ Flag("Xexperimental"),
+ Flag("Xfatal-warnings"),
+ Flag("Xfuture"),
+ Flag("Xlog-implicits"),
+ Flag("Xmigration"),
+ Flag("Xno-uescape"),
+ ColonSeparated("Xplugin"),
+ ColonSeparated("Xplugin-disable"),
+ ColonSeparated("Xplugin-require"),
+ TakesArg("Xpluginsdir"),
+
+ Flag("Yno-generic-signatures"),
+ Flag("Yno-imports"),
+ TakesArg("Ypresentation-delay"),
+ TakesArg("Ypresentation-log"),
+ TakesArg("Ypresentation-replay"),
+ Flag("Ypresentation-verbose"),
+ TakesArg("Yrecursion"),
+ Flag("Yself-in-annots"),
+ ColonSeparated("Ystruct-dispatch"),
+ Flag("Ywarn-dead-code"))
+
+ private sealed trait SDTOption {
+ def name: String
+ def classify: ArgumentConsumer
+ }
+
+ private sealed trait ScalacOption { this: SDTOption =>
+ lazy val scalacOption = "-" + name
+ }
+
+ private case class Flag(name: String) extends SDTOption with ScalacOption {
+ val classify: ArgumentConsumer = {
+ case (akku, Seq(`scalacOption`, tail @ _*)) => (akku + (name -> String.valueOf(true)), tail)
+ }
+ }
+
+ private case class ColonSeparated(name: String, once: Boolean = true) extends SDTOption with ScalacOption {
+ val nameThenColonThen = scalacOption + ":(.+)" r
+
+ val classify: ArgumentConsumer = {
+ case (akku, Seq(nameThenColonThen(value), tail @ _*)) =>
+ (akku + (name -> maybeAppend(akku(name), value)), tail)
+ }
+
+ def maybeAppend(pre: String, post: String) =
+ if (once) post else append(pre, post, ",")
+ }
+
+ private case class TakesArg(name: String) extends SDTOption with ScalacOption {
+ val classify: ArgumentConsumer = {
+ case (akku, Seq(`scalacOption`, value, tail @ _*)) => (akku + (name -> value), tail)
+ }
+ }
+
+ private object Unsupported extends SDTOption {
+ def name = "scala.compiler.additionalParams"
+ val classify: ArgumentConsumer = {
+ case (akku, Seq(option, tail @ _*)) =>
+ (akku + (name -> append(akku(name), option, " ")), tail)
+ }
+ }
+
+ private def append(pre: String, post: String, separator: String) =
+ if (pre isEmpty) post else pre + separator + post
+}
+
View
81 nbsbt-core/src/main/scala/org/netbeans/nbsbt/core/package.scala
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 Typesafe Inc.
+ *
+ * This work is based on the original contribution of WeigleWilczek.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.netbeans.nbsbt
+
+import java.util.Properties
+import sbt.{
+ Configuration,
+ Configurations,
+ Extracted,
+ EvaluateConfig,
+ EvaluateTask,
+ File,
+ Inc,
+ Incomplete,
+ Project,
+ ProjectRef,
+ Reference,
+ Result,
+ TaskKey,
+ SettingKey,
+ State,
+ Task,
+ Value
+}
+import sbt.Load.BuildStructure
+import sbt.complete.Parser
+import scalaz.{ Equal, NonEmptyList, Validation => ScalazValidation }
+import scalaz.Scalaz._
+
+package object core {
+
+ val NewLine = System.getProperty("line.separator")
+
+ val FileSep = System.getProperty("file.separator")
+
+ implicit val fileEqual = new Equal[File] {
+ def equal(file1: File, file2: File): Boolean = file1 == file2
+ }
+
+ def id[A](a: A): A = a
+
+ def boolOpt(key: String): Parser[(String, Boolean)] = {
+ import sbt.complete.DefaultParsers._
+ (Space ~> key ~ ("=" ~> ("true" | "false"))) map { case (k, v) => k -> v.toBoolean }
+ }
+
+ def setting[A](key: SettingKey[A], state: State): Validation[A] =
+ key get structure(state).data match {
+ case Some(a) => a.success
+ case None => "Undefined setting '%s'!".format(key.key).failNel
+ }
+
+ def evaluateTask[A](key: TaskKey[A], ref: ProjectRef, state: State): Validation[A] =
+ EvaluateTask(structure(state), key, state, ref, EvaluateTask defaultConfig state) match {
+ case Some((_, Value(a))) => a.success
+ case Some((_, Inc(inc))) => "Error evaluating task '%s': %s".format(key.key, Incomplete.show(inc.tpe)).failNel
+ case None => "Undefined task '%s' for '%s'!".format(key.key, ref.project).failNel
+ }
+
+ def extracted(state: State): Extracted = Project.extract(state)
+
+ def structure(state: State): BuildStructure = extracted(state).structure
+
+ type Validation[A] = ScalazValidation[NonEmptyList[String], A]
+}
View
202 nbsbt-plugin/src/main/resources/LICENSE-2.0.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
View
26 nbsbt-plugin/src/main/scala/org/netbeans/nbsbt/plugin/NetBeansPlugin.scala
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2011 Typesafe Inc.
+ *
+ * This work is based on the original contribution of WeigleWilczek.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.netbeans.nbsbt.plugin
+
+import org.netbeans.nbsbt.core.{ NetBeansPlugin => CoreNetBeansPlugin }
+import sbt.{ Plugin, Setting }
+
+object NetBeansPlugin extends Plugin with CoreNetBeansPlugin {
+ override def settings: Seq[Setting[_]] = CoreNetBeansPlugin.netbeansSettings
+}
View
10 nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/build.sbt
@@ -0,0 +1,10 @@
+
+organization := "com.typesafe.sbteclipse"
+
+name := "sbteclipse-test"
+
+version := "1.2.3"
+
+TaskKey[Unit]("verify-command-name") <<= EclipseKeys.commandName map (name =>
+ if (name != "eclipse") error("Expected command-name to be eclipse, but was %s!" format name)
+)
View
2  nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/project/plugins.sbt
@@ -0,0 +1,2 @@
+
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0-SNAPSHOT")
View
2  nbsbt-plugin/src/sbt-test/nbsbt/00-defaults/test
@@ -0,0 +1,2 @@
+# Default settings
+> verify-command-name
View
51 nbsbt-plugin/src/sbt-test/nbsbt/01-structure/project/Build.scala
@@ -0,0 +1,51 @@
+import sbt._
+import sbt.Keys._
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.{ EclipseKeys }
+
+object Build extends Build {
+
+ lazy val root = Project(
+ "root",
+ new File("."),
+ aggregate = Seq(sub)
+ )
+
+ lazy val sub = Project(
+ "sub",
+ new File("sub"),
+ aggregate = Seq(suba, subb)
+ )
+
+ lazy val suba = Project(
+ "suba",
+ new File("sub/suba"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "ch.qos.logback" % "logback-classic" % "1.0.1"
+ )
+ )
+ )
+
+ lazy val subb = Project(
+ "subb",
+ new File("sub/subb"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "ch.qos.logback" % "logback-classic" % "1.0.1" % "test",
+ "biz.aQute" % "bndlib" % "1.50.0"
+ ),
+ scalacOptions := Seq("-unchecked", "-deprecation"),
+ TaskKey[Unit]("touch-pre-task") <<= baseDirectory map { dir => new File(dir, "touch-pre-task").mkdirs() },
+ EclipseKeys.preTasks := Seq(TaskKey[Unit]("touch-pre-task"))
+ ),
+ dependencies = Seq(suba, suba % "test->test")
+ )
+
+ lazy val subc = Project(
+ "subc",
+ new File("sub/subc"),
+ settings = Project.defaultSettings ++ Seq(
+ EclipseKeys.skipProject := true
+ )
+ )
+}
View
2  nbsbt-plugin/src/sbt-test/nbsbt/01-structure/project/plugins.sbt
@@ -0,0 +1,2 @@
+
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0-SNAPSHOT")
View
50 nbsbt-plugin/src/sbt-test/nbsbt/01-structure/test
@@ -0,0 +1,50 @@
+# Default settings (skip-parents=true)
+$ exec find . -path "*.classpath*" -delete
+$ exec find . -path "*.project*" -delete
+$ exec find . -path "*/.settings*" -delete
+$ exec find . -path "*/touch-pre-task" -delete
+> eclipse
+$ absent .classpath
+$ absent .project
+$ absent .settings
+$ absent touch-pre-task
+$ absent sub/.classpath
+$ absent sub/.project
+$ absent sub/.settings
+$ absent sub/touch-pre-task
+$ exists sub/suba/.classpath
+$ exists sub/suba/.project
+$ absent sub/suba/.settings
+$ exists sub/subb/.classpath
+$ exists sub/subb/.project
+$ exists sub/subb/.settings/org.scala-ide.sdt.core.prefs
+$ exists sub/subb/touch-pre-task
+$ absent sub/subc/.classpath
+$ absent sub/subc/.project
+$ absent sub/subc/.settings
+$ absent sub/subc/touch-pre-task
+
+# skip-parents=false
+$ exec find . -path "*.classpath*" -delete
+$ exec find . -path "*.project*" -delete
+$ exec find . -path "*/.settings*" -delete
+> eclipse skip-parents=false
+$ exists .classpath
+$ exists .project
+$ absent .settings
+$ absent touch-pre-task
+$ exists sub/.classpath
+$ exists sub/.project
+$ absent sub/.settings
+$ absent sub/touch-pre-task
+$ exists sub/suba/.classpath
+$ exists sub/suba/.project
+$ absent sub/suba/.settings
+$ exists sub/subb/.classpath
+$ exists sub/subb/.project
+$ exists sub/subb/.settings/org.scala-ide.sdt.core.prefs
+$ exists sub/subb/touch-pre-task
+$ absent sub/subc/.classpath
+$ absent sub/subc/.project
+$ absent sub/subc/.settings
+$ absent sub/subc/touch-pre-task
View
211 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/build.sbt
@@ -0,0 +1,211 @@
+import java.io.FileInputStream
+import java.util.Properties
+import scala.collection.JavaConverters._
+import scala.xml.XML
+
+organization := "com.typesafe.sbteclipse"
+
+name := "sbteclipse-test"
+
+version := "1.2.3"
+
+TaskKey[Unit]("verify-project-xml") <<= baseDirectory map { dir =>
+ val projectDescription = XML.loadFile(dir / ".project")
+ // verifier method
+ def verify[A](name: String, expected: A, actual: A) =
+ if (actual != expected) error("Expected .project to contain %s '%s', but was '%s'!".format(name, expected, actual))
+ // project name
+ verify("name", "sbteclipse-test", (projectDescription \ "name").text)
+ // scala project nature
+ verify("buildCommand", "org.scala-ide.sdt.core.scalabuilder", (projectDescription \ "buildSpec" \ "buildCommand" \ "name").text)
+ verify("natures", Set("org.scala-ide.sdt.core.scalanature", "org.eclipse.jdt.core.javanature"), (projectDescription \ "natures" \ "nature").map(_.text).toSet)
+}
+
+TaskKey[Unit]("verify-project-xml-java") <<= baseDirectory map { dir =>
+ val projectDescription = XML.loadFile(dir / "java" / ".project")
+ // verifier method
+ def verify[A](name: String, expected: A, actual: A) =
+ if (actual != expected) error("Expected .project to contain %s '%s', but was '%s'!".format(name, expected, actual))
+ // project name
+ verify("name", "java", (projectDescription \ "name").text)
+ // java project nature
+ verify("buildCommand", "org.eclipse.jdt.core.javabuilder", (projectDescription \ "buildSpec" \ "buildCommand" \ "name").text)
+ verify("natures", "org.eclipse.jdt.core.javanature", (projectDescription \ "natures" \ "nature").text)
+}
+
+TaskKey[Unit]("verify-project-xml-subd") <<= baseDirectory map { dir =>
+ val projectDescription = XML.loadFile(dir / "sub" / "subd" / ".project")
+ val name = (projectDescription \ "name").text
+ if (name != "subd-id")
+ error("Expected .project to contain name '%s', but was '%s'!".format("subd-id", name))
+}
+
+TaskKey[Unit]("verify-project-xml-sube") <<= baseDirectory map { dir =>
+ val projectDescription = XML.loadFile(dir / "sub" / "sube" / ".project")
+ val name = (projectDescription \ "name").text
+ if (name != "sube")
+ error("Expected .project to contain name '%s', but was '%s'!".format("sube", name))
+}
+
+TaskKey[Unit]("verify-classpath-xml-root") <<= baseDirectory map { dir =>
+ val classpath = XML.loadFile(dir / ".classpath")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ error("Expected .classpath of root project not to contain duplicate entries: %s" format classpath)
+ // src entries
+ if (!(classpath.child contains <classpathentry kind="src" path="src/main/scala" output="target/scala-2.9.2/classes" />))
+ error("""Expected .classpath of root project to contain <classpathentry kind="src" path="src/main/scala" output="target/scala-2.9.2/classes" /> """)
+ if (!(classpath.child contains <classpathentry kind="src" path="src/main/java" output="target/scala-2.9.2/classes" />))
+ error("""Expected .classpath of root project to contain <classpathentry kind="src" path="src/main/java" output="target/scala-2.9.2/classes" /> """)
+ if (!(classpath.child contains <classpathentry kind="src" path="src/test/scala" output="target/scala-2.9.2/test-classes" />))
+ error("""Expected .classpath of root project to contain <classpathentry kind="src" path="src/test/scala" output="target/scala-2.9.2/test-classes" /> """)
+ if (!(classpath.child contains <classpathentry kind="src" path="src/test/java" output="target/scala-2.9.2/test-classes" />))
+ error("""Expected .classpath of root project to contain <classpathentry kind="src" path="src/test/java" output="target/scala-2.9.2/test-classes" /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/main/resources")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="src/main/resources" output="..." /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/test/resources")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="src/test/resources" output="..." /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/src_managed/main")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="...src_managed/main" output="..." /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/src_managed/test")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="...src_managed/test" output="..." /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/resource_managed/main")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="...resource_managed/main" output="..." /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/resource_managed/test")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="...resource_managed/test" output="..." /> """)
+ // lib entries without sources
+ if (!(classpath.child contains <classpathentry kind="lib" path="./lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="./lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />: %s""" format classpath)
+ // other entries
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "scala-library.jar")
+ error("""Not expected .classpath of root project to contain <classpathentry path="...scala-library.jar" ... /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "scala-compiler.jar")
+ error("""Not expected .classpath of root project to contain <classpathentry path="...scala-compiler.jar" ... /> """)
+ if (!(classpath.child contains <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> """)
+ if (!(classpath.child contains <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER"/> """)
+ if (!(classpath.child contains <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> """)
+ if (!(classpath.child contains <classpathentry kind="output" path="bin"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="output" path="bin"/> """)
+}
+
+TaskKey[Unit]("verify-classpath-xml-sub") <<= baseDirectory map { dir =>
+ val home = System.getProperty("user.home")
+ val classpath = XML.loadFile(dir / "sub" / ".classpath")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ error("Expected .classpath of sub project not to contain duplicate entries: %s" format classpath)
+ // lib entries with sources
+ if (!(classpath.child contains <classpathentry kind="lib" path="../lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" sourcepath="../lib_managed/srcs/biz.aQute/bndlib/bndlib-1.50.0-sources.jar" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="../lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" sourcepath="../lib_managed/srcs/biz.aQute/bndlib/bndlib-1.50.0-sources.jar" />: %s""" format classpath)
+ // other entries
+ if (!(classpath.child contains <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>: %s""" format classpath)
+}
+
+TaskKey[Unit]("verify-classpath-xml-suba") <<= baseDirectory map { dir =>
+ val home = System.getProperty("user.home")
+ val classpath = XML.loadFile(dir / "sub" / "suba" / ".classpath")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ error("Expected .classpath of suba project not to contain duplicate entries: %s" format classpath)
+ // src entries
+ if (!(classpath.child contains <classpathentry kind="src" path="target/scala-2.9.2/resource_managed/main" output="target/scala-2.9.2/classes" />))
+ error("""Expected .classpath of suba project to contain <classpathentry kind="src" path="target/scala-2.9.2/resource_managed/main" output="target/scala-2.9.2/classes" />: %s """ format classpath)
+ if ((classpath.child contains <classpathentry kind="src" path="target/scala-2.9.2/resource_managed/test" output="target/scala-2.9.2/test-classes" />))
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="src" path="target/scala-2.9.2/resource_managed/test" output="target/scala-2.9.2/test-classes" />: %s """ format classpath)
+ if ((classpath.child contains <classpathentry kind="src" path="src/test/scala" output="target/scala-2.9.2/test-classes" />))
+ error("""Not expected .classpath of root project to contain <classpathentry kind="src" path="src/test/scala" output="target/scala-2.9.2/test-classes" /> """)
+ if ((classpath.child contains <classpathentry kind="src" path="src/test/java" output="target/scala-2.9.2/test-classes" />))
+ error("""Not expected .classpath of root project to contain <classpathentry kind="src" path="src/test/java" output="target/scala-2.9.2/test-classes" /> """)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/src_managed/main")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="...src_managed/main" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "target/scala-2.9.2/src_managed/test")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="...src_managed/test" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/main/scala")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/main/scala" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/main/java")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/main/java" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/main/resources")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/main/resources" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/test/scala")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/test/scala" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/test/java")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/test/java" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/test/resources")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/test/resources" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/it/scala")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/it/scala" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/it/java")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/it/java" output="..." />: %s """ format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/it/resources")
+ error("""Not expected .classpath of suba project to contain <classpathentry kind="..." path="src/it/resources" output="..." />: %s """ format classpath)
+ // lib entries with sources
+ if (!(classpath.child contains <classpathentry kind="lib" path={ home + "/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.1.jar" } sourcepath={ home + "/.ivy2/cache/ch.qos.logback/logback-classic/srcs/logback-classic-1.0.1-sources.jar" } />))
+ error("""Expected .classpath of suba project to contain <classpathentry kind="lib" path={ home + "/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.1.jar" } sourcepath={ home + "/.ivy2/cache/ch.qos.logback/logback-classic/srcs/logback-classic-1.0.1-sources.jar" } />: %s""" format classpath)
+ if (!(classpath.child contains <classpathentry kind="lib" path={ home + "/.ivy2/cache/biz.aQute/bndlib/jars/bndlib-1.50.0.jar" } sourcepath={ home + "/.ivy2/cache/biz.aQute/bndlib/srcs/bndlib-1.50.0-sources.jar" } />))
+ error("""Expected .classpath of suba project to contain <classpathentry kind="lib" path={ home + "/.ivy2/cache/biz.aQute/bndlib/jars/bndlib-1.50.0.jar" } sourcepath={ home + "/.ivy2/cache/biz.aQute/bndlib/srcs/bndlib-1.50.0-sources.jar" } />: %s""" format classpath)
+ if (!(classpath.child contains <classpathentry kind="lib" path={ home + "/.ivy2/cache/org.specs2/specs2_2.9.2/jars/specs2_2.9.2-1.9.jar" } sourcepath={ home + "/.ivy2/cache/org.specs2/specs2_2.9.2/srcs/specs2_2.9.2-1.9-sources.jar" } />))
+ error("""Expected .classpath of suba project to contain <classpathentry kind="lib" path={ home + "/.ivy2/cache/org.specs2/specs2_2.9.2/jars/specs2_2.9.2-1.9.jar" } sourcepath={ home + "/.ivy2/cache/org.specs2/specs2_2.9.2/srcs/specs2_2.9.2-1.9-sources.jar" } />: %s""" format classpath)
+}
+
+TaskKey[Unit]("verify-classpath-xml-subb") <<= baseDirectory map { dir =>
+ val classpath = XML.loadFile(dir / "sub" / "subb" / ".classpath")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ error("Expected .classpath of subb project not to contain duplicate entries: %s" format classpath)
+ // src entries
+ if (!(classpath.child contains <classpathentry kind="src" path="src/it/scala" output="target/scala-2.9.2/it-classes" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="src" path="src/it/scala" output="target/scala-2.9.2/it-classes" />: %s""" format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "src/test/scala")
+ error("""Not expected .classpath of root project to contain <classpathentry kind="..." path="src/test/scala" output="..." /> """)
+ // lib entries without sources
+ if (!(classpath.child contains <classpathentry kind="lib" path="../../lib_managed/jars/ch.qos.logback/logback-classic/logback-classic-1.0.1.jar" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="../../lib_managed/jars/ch.qos.logback/logback-classic/logback-classic-1.0.1.jar" />: %s""" format classpath)
+ if (!(classpath.child contains <classpathentry kind="lib" path="../../lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="../../lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />: %s""" format classpath)
+ if (!(classpath.child contains <classpathentry kind="lib" path="../../lib_managed/jars/junit/junit/junit-4.7.jar" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="../../lib_managed/jars/junit/junit/junit-4.7.jar" />: %s""" format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "specs2_2.9.2")
+ error("""Not expected .classpath of subb project to contain <classpathentry kind="..." path="...specs2_2.9.2..." output="..." /> """)
+ // project dependencies
+ if (!(classpath.child contains <classpathentry kind="src" path="/suba" exported="true" combineaccessrules="false" />))
+ error("""Expected .classpath of subb project to contain <classpathentry kind="src" path="/suba" exported="true" combineaccessrules="false" />: %s""" format classpath)
+ if ((classpath \ "classpathentry" \\ "@path") map (_.text) contains "/subc")
+ error("""Not expected .classpath of subb project to contain <classpathentry kind="..." path="...subc..." output="..." /> """)
+}
+
+TaskKey[Unit]("verify-classpath-xml-subc") <<= baseDirectory map { dir =>
+ val classpath = XML.loadFile(dir / "sub" / "subc" / ".classpath")
+ val project = XML.loadFile(dir / "sub" / "subc" / ".project")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ error("Expected .classpath of subc project not to contain duplicate entries: %s" format classpath)
+ // src entries
+ if (!(classpath.child contains <classpathentry kind="src" path="src/main/scala" output=".target" />))
+ error("""Expected .classpath of subc project to contain <classpathentry kind="src" path="src/main/scala" output=".target" /> """)
+ // lib entries with absolute paths
+ if (!(classpath.child contains <classpathentry kind="lib" path={ "%s/lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar".format(dir.getCanonicalPath) } />))
+ error("""Expected .classpath of subc project to contain <classpathentry kind="lib" path="%s/lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />: %s""".format(dir.getCanonicalPath, classpath))
+ // classpath transformer
+ if (!(classpath.child contains <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>))
+ error("""Expected .classpath of root project to contain <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> """)
+ if (!(classpath.child contains <foo bar="baz"/>))
+ error("""Expected .classpath of subc project to contain <foo bar="baz"/>!""")
+ if (!(project.child contains <foo bar="baz"/>))
+ error("""Expected .project of subc project to contain <foo bar="baz"/>!""")
+}
+
+TaskKey[Unit]("verify-settings") <<= baseDirectory map { dir =>
+ val settings = {
+ val p = new Properties
+ p.load(new FileInputStream(dir / "sub/subb/.settings/org.scala-ide.sdt.core.prefs"))
+ p.asScala.toMap
+ }
+ val expected = Map(
+ "scala.compiler.additionalParams" -> """-Xprompt -Ydependent-method-types""",
+ "verbose" -> "true",
+ "deprecation" -> "true",
+ "Xelide-below" -> "1000",
+ "unchecked" -> "true",
+ "scala.compiler.useProjectSettings" -> "true"
+ )
+ if (settings != expected) error("Expected settings to be '%s', but was '%s'!".format(expected, settings))
+}
View
146 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/project/Build.scala
@@ -0,0 +1,146 @@
+import sbt._
+import sbt.Keys._
+import com.typesafe.sbteclipse.plugin.EclipsePlugin._
+
+object Build extends Build {
+
+ lazy val root = Project(
+ "root",
+ new File("."),
+ settings = Project.defaultSettings ++ Seq(
+ unmanagedSourceDirectories in Compile <+= baseDirectory(new File(_, "src/main/scala")),
+ unmanagedSourceDirectories in Test <+= baseDirectory(new File(_, "src/test/scala")),
+ libraryDependencies ++= Seq(
+ "org.scala-lang" % "scala-compiler" % "2.9.2",
+ "biz.aQute" % "bndlib" % "1.50.0"
+ ),
+ retrieveManaged := true
+ ),
+ aggregate = Seq(sub, javaProject)
+ )
+
+ lazy val sub: Project = Project(
+ "sub",
+ new File("sub"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "biz.aQute" % "bndlib" % "1.50.0",
+ "javax.servlet" % "servlet-api" % "2.5",
+ "javax.servlet" % "servlet-api" % "2.5" % "provided"
+ ),
+ retrieveManaged := true,
+ EclipseKeys.executionEnvironment := Some(EclipseExecutionEnvironment.JavaSE16),
+ EclipseKeys.withSource := true
+ ),
+ aggregate = Seq(suba, subb, subc, subd, sube)
+ )
+
+ lazy val suba = Project(
+ "suba",
+ new File("sub/suba"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "ch.qos.logback" % "logback-classic" % "1.0.1",
+ "biz.aQute" % "bndlib" % "1.50.0",
+ "org.specs2" %% "specs2" % "1.9" % "test"
+ ),
+ EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.Managed, EclipseCreateSrc.Resource),
+ EclipseKeys.createSrc in Test := EclipseCreateSrc.ValueSet.empty,
+ EclipseKeys.withSource := true
+ )
+ )
+
+ lazy val subb = Project(
+ "subb",
+ new File("sub/subb"),
+ configurations = Configurations.default :+ Configurations.IntegrationTest,
+ settings = Project.defaultSettings ++ Defaults.itSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "biz.aQute" % "bndlib" % "1.50.0",
+ "junit" % "junit" % "4.7" % "it"
+ ),
+ retrieveManaged := true,
+ scalacOptions := Seq(
+ "-Xelide-below", "1000",
+ "-verbose",
+ "-Xprompt",
+ "-deprecation",
+ "-Ydependent-method-types",
+ "-unchecked"),
+ EclipseKeys.configurations := Set(Configurations.Compile, Configurations.IntegrationTest)
+ ),
+ dependencies = Seq(suba, suba % "test->compile", subc % "test->test")
+ )
+
+ lazy val subc = {
+ import com.typesafe.sbteclipse.core.Validation
+ import scala.xml._
+ import scala.xml.transform.RewriteRule
+ import scalaz.Scalaz._
+ Project(
+ "subc",
+ new File("sub/subc"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "biz.aQute" % "bndlib" % "1.50.0"
+ ),
+ retrieveManaged := true,
+ EclipseKeys.relativizeLibs := false,
+ EclipseKeys.eclipseOutput := Some(".target"),
+ EclipseKeys.classpathTransformerFactories := Seq(new EclipseTransformerFactory[RewriteRule] {
+ override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] = {
+ val rule = new RewriteRule {
+ override def transform(node: Node): Seq[Node] = node match {
+ case elem if (elem.label == "classpath") =>
+ val newChild = elem.child ++ Elem(elem.prefix, "foo", Attribute("bar", Text("baz"), Null), elem.scope)
+ Elem(elem.prefix, "classpath", elem.attributes, elem.scope, newChild: _*)
+ case other =>
+ other
+ }
+ }
+ rule.success
+ }
+ }),
+ EclipseKeys.projectTransformerFactories := Seq(new EclipseTransformerFactory[RewriteRule] {
+ override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] = {
+ val rule = new RewriteRule {
+ override def transform(node: Node): Seq[Node] = node match {
+ case elem if (elem.label == "projectDescription") =>
+ val newChild = elem.child ++ Elem(elem.prefix, "foo", Attribute("bar", Text("baz"), Null), elem.scope)
+ Elem(elem.prefix, "projectDescription", elem.attributes, elem.scope, newChild: _*)
+ case other =>
+ other
+ }
+ }
+ rule.success
+ }
+ })
+ )
+ )
+ }
+
+ lazy val javaProject = Project(
+ "java",
+ new File("java"),
+ settings = Project.defaultSettings ++ Seq(
+ EclipseKeys.projectFlavor := EclipseProjectFlavor.Java
+ )
+ )
+
+ lazy val subd = Project(
+ id = "subd-id",
+ base = new File("sub/subd"),
+ settings = Project.defaultSettings ++ Seq(
+ name := "subd",
+ EclipseKeys.useProjectId := true
+ )
+ )
+
+ lazy val sube = Project(
+ id = "sube-id",
+ base = new File("sub/sube"),
+ settings = Project.defaultSettings ++ Seq(
+ name := "sube"
+ )
+ )
+}
View
2  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/project/plugins.sbt
@@ -0,0 +1,2 @@
+
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0-SNAPSHOT")
View
1  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/main/java/JavaRoot.java
@@ -0,0 +1 @@
+public class JavaRoot {}
View
1  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/main/scala/Root.scala
@@ -0,0 +1 @@
+object Root
View
1  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/src/test/scala/RootSpec.scala
@@ -0,0 +1 @@
+object RootSpec
View
3  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/src/main/scala/Sub.scala
@@ -0,0 +1,3 @@
+object Sub {
+ def sub = "sub"
+}
View
4 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/suba/src/main/scala/SubA.scala
@@ -0,0 +1,4 @@
+object SubA {
+ val logger = org.slf4j.LoggerFactory.getLogger("suba")
+ def subA = "subA"
+}
View
1  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subb/src/it/scala/RootIt.scala
@@ -0,0 +1 @@
+object RootIt
View
4 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subb/src/main/scala/SubB.scala
@@ -0,0 +1,4 @@
+object SubB {
+ val logger = org.slf4j.LoggerFactory.getLogger("suba")
+ def subB = SubA.subA + " and subB"
+}
View
3  nbsbt-plugin/src/sbt-test/nbsbt/02-contents/sub/subc/src/main/scala/SubC.scala
@@ -0,0 +1,3 @@
+object SubC {
+ def subC = "subC"
+}
View
14 nbsbt-plugin/src/sbt-test/nbsbt/02-contents/test
@@ -0,0 +1,14 @@
+> clean
+> compile
+$ mkdir target/scala-2.9.1/src_managed/main
+> eclipse skip-parents=false
+> verify-project-xml
+> verify-project-xml-java
+> verify-project-xml-subd
+> verify-project-xml-sube
+> verify-classpath-xml-root
+> verify-classpath-xml-sub
+> verify-classpath-xml-suba
+> verify-classpath-xml-subb
+> verify-classpath-xml-subc
+> verify-settings
View
52 project/Build.scala
@@ -0,0 +1,52 @@
+import com.typesafe.sbtscalariform.ScalariformPlugin._
+import sbt._
+import sbt.Keys._
+import sbt.ScriptedPlugin._
+import sbtrelease.ReleasePlugin._
+
+object Build extends Build {
+
+ lazy val root = Project(
+ "nbsbt",
+ file("."),
+ aggregate = Seq(nbsbtCore, nbsbtPlugin),
+ settings = commonSettings ++ Seq(
+ publishArtifact := false
+ )
+ )
+
+ lazy val nbsbtCore = Project(
+ "nbsbt-core",
+ file("nbsbt-core"),
+ settings = commonSettings ++ Seq(
+ libraryDependencies ++= Seq("org.scalaz" %% "scalaz-core" % "6.0.4")
+ )
+ )
+
+ lazy val nbsbtPlugin = Project(
+ "nbsbt-plugin",
+ file("nbsbt-plugin"),
+ dependencies = Seq(nbsbtCore),
+ settings = commonSettings
+ )
+
+ def commonSettings = Defaults.defaultSettings ++
+ scalariformSettings ++
+ scriptedSettings ++
+ releaseSettings ++
+ Seq(
+ organization := "org.netbeans.nbsbt",
+ // version is defined in version.sbt in order to support sbt-release
+ scalacOptions ++= Seq("-unchecked", "-deprecation"),
+ publishTo <<= isSnapshot { isSnapshot =>
+ val id = if (isSnapshot) "snapshots" else "releases"
+ val uri = "https://typesafe.artifactoryonline.com/typesafe/ivy-" + id
+ Some(Resolver.url("typesafe-" + id, url(uri))(Resolver.ivyStylePatterns))
+ },
+ sbtPlugin := true,
+ publishMavenStyle := false,
+ publishArtifact in (Compile, packageDoc) := false,
+ publishArtifact in (Compile, packageSrc) := false,
+ scriptedLaunchOpts += "-Xmx1024m"
+ )
+}
View
1  project/build.properties
@@ -0,0 +1 @@
+sbt.version=0.12.2
View
6 project/plugins.sbt
@@ -0,0 +1,6 @@
+
+libraryDependencies <+= (sbtVersion)("org.scala-sbt" % "scripted-plugin" % _)
+
+addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.5")
+
+addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.5.1")