Skip to content

Commit

Permalink
Adding McPom
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorklang committed Dec 8, 2010
1 parent 8371fcf commit 9769d78
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion project/build/AkkaProject.scala
Expand Up @@ -441,7 +441,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val stressTestsEnabled = systemOptional[Boolean]("stress.tests",false)

// ------------------------------------------------------------
class AkkaDefaultProject(info: ProjectInfo, val deployPath: Path) extends DefaultProject(info) with DeployProject with OSGiProject {
class AkkaDefaultProject(info: ProjectInfo, val deployPath: Path) extends DefaultProject(info) with DeployProject with OSGiProject with McPom {
override def disableCrossPaths = true
lazy val sourceArtifact = Artifact(this.artifactID, "source", "jar", Some("sources"), Nil, None)
lazy val docsArtifact = Artifact(this.artifactID, "doc", "jar", Some("docs"), Nil, None)
Expand All @@ -450,6 +450,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
override def packageDocsJar = this.defaultJarPath("-docs.jar")
override def packageSrcJar = this.defaultJarPath("-sources.jar")
override def packageToPublishActions = super.packageToPublishActions ++ Seq(this.packageDocs, this.packageSrc)
override def pomPostProcess(node: scala.xml.Node): scala.xml.Node = mcPom(AkkaParentProject.this.moduleConfigurations)(super.pomPostProcess(node))

/**
* Used for testOptions, possibility to enable the running of integration and or stresstests
Expand Down Expand Up @@ -492,3 +493,49 @@ trait DeployProject { self: BasicScalaProject =>
trait OSGiProject extends BNDPlugin { self: DefaultProject =>
override def bndExportPackage = Seq("akka.*;version=%s".format(projectVersion.value))
}

trait McPom { self: DefaultProject =>
import scala.xml._

def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = {

def cleanUrl(url: String) = url match {
case null => ""
case "" => ""
case u if u endsWith "/" => u
case u => u + "/"
}

val oldRepos = (node \\ "project" \ "repositories" \ "repository").
map( n => cleanUrl((n \ "url").text) -> (n \ "name").text).toList
val newRepos = mcs.filter(_.resolver.isInstanceOf[MavenRepository]).map(m => {
val r = m.resolver.asInstanceOf[MavenRepository]
cleanUrl(r.root) -> r.name
})

val repos = Map((oldRepos ++ newRepos):_*).map( pair =>
<repository>
<id>{pair._2.toSeq.filter(_.isLetterOrDigit).mkString}</id>
<name>{pair._2}</name>
<url>{pair._1}</url>
</repository>
)

def rewrite(pf:PartialFunction[Node,Node])(ns: Seq[Node]): Seq[Node] = for(subnode <- ns) yield subnode match {
case e: Elem =>
if (pf isDefinedAt e) pf(e)
else Elem(e.prefix, e.label, e.attributes, e.scope, rewrite(pf)(e.child):_*)
case other => other
}

val rule: PartialFunction[Node,Node] = if ((node \\ "project" \ "repositories" ).isEmpty) {
case Elem(prefix, "project", attribs, scope, children @ _*) =>
Elem(prefix, "project", attribs, scope, children ++ <repositories>{repos}</repositories>:_*)
} else {
case Elem(prefix, "repositories", attribs, scope, children @ _*) =>
Elem(prefix, "repositories", attribs, scope, repos.toList:_*)
}

rewrite(rule)(node.theSeq)(0)
}
}

0 comments on commit 9769d78

Please sign in to comment.