Skip to content

Commit

Permalink
Merge pull request #78 from ThoughtWorksInc/cross-subdirectory
Browse files Browse the repository at this point in the history
Support subdirectory organization for crossProject
  • Loading branch information
Atry authored Jun 23, 2019
2 parents 7a0c65f + c225c42 commit c8aef61
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.thoughtworks.sbtBestPractice.subdirectoryOrganization

import sbt.Keys.{baseDirectory, organization}
import sbt.Keys._
import sbt._
import scala.collection.JavaConverters._

/**
* @author 杨博 (Yang Bo)
Expand All @@ -16,11 +17,18 @@ object SubdirectoryOrganization extends AutoPlugin {
case None =>
organization.value
case Some(relativeBaseDirectory) =>
relativeBaseDirectory.getParent match {
case null =>
val pathElements = relativeBaseDirectory.toPath.asScala.toSeq
pathElements.lastIndexWhere(_.toString == name.value) match {
case -1 =>
organization.value
case parent =>
parent.split('/').map(Project.normalizeModuleID).mkString(organization.value, ".", "")
case pathDepth =>
val parentPathElements = pathElements.view(0, pathDepth)
(organization.value match {
case "" =>
parentPathElements
case oldOrganization =>
oldOrganization +: parentPathElements
}).mkString(".")
}
}
}
Expand Down

0 comments on commit c8aef61

Please sign in to comment.