Skip to content

Commit

Permalink
gradle improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurm1 committed May 16, 2021
1 parent 4d9f966 commit 2274f92
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ case class BloopParametersExtension(project: Project) {
includeJavadoc_.set(false)
@Input @Optional def getIncludeJavadoc: Property[java.lang.Boolean] = includeJavadoc_

def createParameters: BloopParameters =
def createParameters: BloopParameters = {
val defaultTargetDir = project.getRootProject.workspacePath.resolve(".bloop").toFile
BloopParameters(
targetDir_.getOrElse(project.getRootProject.getProjectDir / ".bloop"),
targetDir_.getOrElse(defaultTargetDir),
compilerName_.getOrElse("scala-compiler"),
stdLibName_.getOrElse("scala-library"),
includeSources_.get,
includeJavadoc_.get,
getDottyVersionOption
)
}
}

case class BloopParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class BloopConverter(parameters: BloopParameters) {
val artifactVersion =
if (remaining.isEmpty) "+" else s"3.$minor.$patch-$milestone$remaining"
("org.scala-lang", "SCALA3-LIBRARY", s"$artifactID:$artifactVersion")
case "3" =>
("org.scala-lang", "SCALA3-LIBRARY", s"scala3-compiler_3:+")
}

val compilerDependencyName = s"$dottyOrgName:$artifactAndVersion"
Expand Down Expand Up @@ -253,7 +255,7 @@ class BloopConverter(parameters: BloopParameters) {
bloopProject = Config.Project(
name = projectName,
directory = project.getProjectDir.toPath,
workspaceDir = Option(project.getRootProject.getProjectDir.toPath),
workspaceDir = Option(project.getRootProject.workspacePath),
sources = sources,
sourcesGlobs = None,
sourceRoots = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.{Project, Task, GradleException}
import scala.collection.JavaConverters._
import scala.reflect.ClassTag
import scala.util.control.NonFatal
import java.nio.file.Path

object syntax {

Expand Down Expand Up @@ -49,6 +50,25 @@ object syntax {
def getExtension[T](implicit t: ClassTag[T]): T = {
project.getExtensions.getByType(t.runtimeClass.asInstanceOf[Class[T]])
}

private def getCommonRootPath(path1: Path, path2: Path): Path = {
var idx = 0
var finished = false
while (!finished) {
if (idx < path1.getNameCount() && idx < path2.getNameCount() && path1.getName(idx) == path2
.getName(idx))
idx = idx + 1
else
finished = true
}
path1.getRoot().resolve(path1.subpath(0, idx))
}

def workspacePath: Path = {
project.getAllprojects.asScala
.map(_.getProjectDir().toPath())
.foldLeft(project.getRootDir().toPath())(getCommonRootPath)
}
}

/**
Expand Down
Loading

0 comments on commit 2274f92

Please sign in to comment.