-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild.sbt
113 lines (87 loc) · 2.95 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import com.typesafe.sbt.packager.docker._
import sbt.Keys._
import sbt._
import Dependencies._
name := "codacy-scalameta"
scalaVersion := scalaV
organization := "com.codacy"
lazy val root = project
.in(file("."))
.dependsOn(common, macros, genResources, basePatterns)
//generates the resources a codacy-engine expects
lazy val genResources = project
.in(file("genResources"))
.settings(scalaVersion := scalaV)
.settings(
(unmanagedClasspath in Compile) ++= Option((baseDirectory.value / ".." / "lib").listFiles()).toList
.flatMap(_.toList)
)
.dependsOn(macros, basePatterns)
//the core that defines patterns and results
lazy val core = project
.in(file("core"))
.settings(scalaVersion := scalaV)
//our base package of scala patterns
lazy val basePatterns = project
.in(file("patterns-base"))
.settings(scalaVersion := scalaV)
.dependsOn(core)
//the bridge between a codacy-engine and scala.meta patterns
lazy val common = project
.in(file("common"))
.dependsOn(core)
.settings(scalaVersion := scalaV)
.settings(libraryDependencies ++= Seq(Dependencies.codacyEngine, Dependencies.betterFiles))
lazy val macros = project
.in(file("macros"))
.settings(scalaVersion := scalaV)
.settings(libraryDependencies += Def.setting(scalaReflect).value)
.dependsOn(common)
enablePlugins(AshScriptPlugin)
enablePlugins(DockerPlugin)
version in Docker := "latest"
resourceGenerators in Compile += Def.task {
val file: File = (resourceManaged in Compile).value
def allFiles(dir: File): Set[File] = {
Option(dir.listFiles())
.map(_.toList)
.getOrElse(List.empty)
.flatMap {
case cDir if cDir.isDirectory =>
allFiles(cDir)
case cFile =>
List(cFile)
}
.toSet
}
val curFiles = allFiles(file)
val result = (runner in Compile).value.run(
"codacy.CheckResources",
(dependencyClasspath in Compile).value.files ++ (unmanagedClasspath in Compile).value.files,
Array(file.getPath),
streams.value.log
)
//this ensures that compilation fails on erroneous resources!
result.failed.foreach(r => throw new Exception(s"resource generation failed $r"))
val newFiles = allFiles(file) -- curFiles
newFiles.toList
}.taskValue
mappings in Universal ++= {
val src = (resourceDirectory in Compile).value / "docs"
val base = resourceManaged.value / "main"
val files = (managedResourceDirectories in Compile).value.allPaths.get
val dest = "/docs"
val staticResources = for {
path <- src.allPaths.get if !path.isDirectory
} yield path -> path.toString.replaceFirst(src.toString, dest)
staticResources ++
(files pair Path.rebase(base, ""))
}
val dockerUser = "docker"
daemonUser in Docker := dockerUser
dockerBaseImage := "amazoncorretto:8-alpine3.14-jre"
dockerCommands := dockerCommands.value.flatMap {
case cmd @ Cmd("ADD", _) =>
List(Cmd("RUN", s"adduser -u 2004 -D $dockerUser"), cmd, Cmd("RUN", "mv /opt/docker/docs /docs"))
case other => List(other)
}