-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting on multi-module project support.
- Loading branch information
1 parent
e3a0585
commit 2781ea8
Showing
3 changed files
with
92 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
// | |||
// sbt-pom-plugin - Makes Maven project metadata usable from SBT | |||
// http://github.com/samskivert/sbt-pom-plugin | |||
|
|||
package samskivert | |||
|
|||
import java.io.File | |||
|
|||
import sbt._ | |||
import sbt.Keys._ | |||
|
|||
import pomutil.{POM, Dependency} | |||
|
|||
/** | |||
* Makes Maven project metadata usable from SBT. | |||
*/ | |||
object POMPlugin extends Plugin | |||
{ | |||
/** Reads SBT settings from the POM file at the specified path. */ | |||
def pomToSettings (path :String) :Seq[Setting[_]] = pomToSettings(new File(path)) | |||
|
|||
/** Reads SBT settings from the supplied POM file. */ | |||
def pomToSettings (file :File) :Seq[Setting[_]] = | |||
pomToSettings(POM.fromFile(file).getOrElse(sys.error("Invalid POM file: " + file))) | |||
|
|||
/** Reads SBT settings from the supplied POM. | |||
* @param excludeDepends if true, dependency configuration omitted from settings. */ | |||
def pomToSettings (pom :POM, excludeDepends :Boolean = false) :Seq[Setting[_]] = { | |||
val meta = Seq( | |||
organization := pom.groupId, | |||
name := pom.artifactId, | |||
version := pom.version | |||
// TODO: add support for various standard build settings | |||
) | |||
if (excludeDepends) meta | |||
else meta ++ Seq(libraryDependencies ++= pom.depends.map(toIvyDepend)) | |||
} | |||
|
|||
/** Converts a Maven dependency to an Ivy dependency. */ | |||
def toIvyDepend (depend :Dependency) = { | |||
// TODO: handle type, classifier, scope, etc. | |||
depend.groupId % depend.artifactId % depend.version | |||
} | |||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
// | |||
// sbt-pom-plugin - Makes Maven project metadata usable from SBT | |||
// http://github.com/samskivert/sbt-pom-plugin | |||
|
|||
package samskivert | |||
|
|||
import java.io.File | |||
|
|||
import sbt._ | |||
import sbt.Keys._ | |||
|
|||
import pomutil.{POM, Dependency} | |||
|
|||
/** | |||
* Handles multimodule projects. Sub-module interdependencies will automatically be wired up as SBT | |||
* project dependencies. Other Maven dependencies will be mapped to Ivy dependencies. | |||
* | |||
* Instantiate a project builder with the top-level POM. Use it to create SBT sub-projects like so: | |||
* {{{ | |||
* val builder = new ProjectBuilder("pom.xml") | |||
* lazy val core = builder("core", extraSettings) | |||
* lazy val tools = builder("tools", extraSettings) | |||
* lazy val client = builder("client", extraSettings) | |||
* }}} | |||
* The stock SBT settings will be automatically included, and `extraSettings` is optional. | |||
*/ | |||
class ProjectBuilder (path :String) | |||
{ | |||
/** Creates an SBT project for the specified sub-module. */ | |||
def apply (name :String, settings :Seq[Setting[_]]) :Project = { | |||
val pom = _modules.getOrElse(name, sys.error("No sub-module POM in " + name + ".")) | |||
|
|||
// extract any sibling dependencies and turn them into project dependencies | |||
sys.error("TODO") | |||
} | |||
|
|||
private def resolveSubPOM (name :String) = { | |||
val pomFile = new File(new File(name), "pom.xml") | |||
POM.fromFile(pomFile) map(p => Some(name -> p)) getOrElse { | |||
System.err.println("Failed to read sub-module POM: " + pomFile) | |||
None | |||
} | |||
} | |||
|
|||
private val _pom = POM.fromFile(new File(path)).getOrElse( | |||
sys.error("Unable to load POM from " + path)) | |||
private val _modules = _pom.modules.flatMap(resolveSubPOM).toMap | |||
} |