-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sc
155 lines (134 loc) · 5.04 KB
/
build.sc
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`de.tototec::de.tobiasroeser.mill.osgi::0.5.0`
import mill._
import mill.define.{Source, Target}
import mill.scalalib._
import mill.scalalib.publish._
import de.tobiasroeser.mill.osgi._
import mill.api.Loose
def baseDir = build.millSourcePath
object Deps {
val slf4j = ivy"org.slf4j:slf4j-api:1.7.36"
object Test {
val testNg = ivy"org.testng:testng:7.5"
val lambdatest = ivy"de.tototec:de.tobiasroeser.lambdatest:0.8.0"
}
}
trait GettextJavaModule extends JavaModule {
def poSource: T[PathRef] = T.source(millSourcePath / "src" / "main" / "po")
/**
* Generates a message catalog (messages.pot) from sources.
*/
def msgCatalog = T {
val dest = T.ctx().dest
val srcDir = sources().head.path
val src = srcDir.relativeTo(baseDir).toString()
val res = os.proc(
"xgettext",
"-ktr", "-kmarktr", "-kpreparetr",
"--sort-by-file",
"--directory", src,
"--output-dir", dest.toIO.getPath(),
"--output", "messages.pot",
os.walk(srcDir).filter(_.ext == "java").map(_.relativeTo(srcDir))
).call(cwd = baseDir)
println(res.out.text())
Console.err.println(res.err.text())
PathRef(dest / "messages.pot")
}
/**
* Updates all found translation files (`*.po`) with current extracted message catalog.
* @param backup If `true` creates a backup file for each updates translation file.
*/
def updateTranslations(backup: Boolean = false) = T.command {
val dest = T.ctx().dest
val poFiles: Seq[os.Path] = os.list(poSource().path).filter(_.ext == "po")
poFiles.map{ poFile =>
println(s"Updating ${poFile.relativeTo(baseDir)}")
val res = os.proc(
"msgmerge", "-v",
if(backup) Seq() else Seq("--backup=none"),
"--update",
poFile.toIO.getPath(),
msgCatalog().path.toIO.getPath()
).call(cwd = baseDir)
}
}
/**
* The Java package in which the generated properties files will end up.
*/
def generatePropertiesPackage: Target[String] = ""
/**
* Generate properties files for each translation file (`*.po`).
*/
def generateProperties: Target[PathRef] = T {
val dest = T.ctx().dest
val poFiles: Seq[os.Path] = os.list(poSource().path).filter(_.ext == "po")
poFiles.map { poFile =>
val lang = poFile.baseName
// hardcoded location
val target = dest / os.RelPath(generatePropertiesPackage()) / s"Messages_${lang}.properties"
println(s"Processing ${poFile.relativeTo(baseDir)} to ${target.relativeTo(baseDir)}")
os.makeDir.all(target / os.up)
val res = os.proc(
"msgmerge", "-v",
"--output-file",
target,
"--properties-output",
poFile.toIO.getPath(),
msgCatalog().path.toIO.getPath()
).call(cwd = baseDir)
}
println(s"You can update existing message catalogs with: mill ${updateTranslations()}")
PathRef(dest)
}
/**
* Add generated properties files to resources.
*/
override def resources = T.sources{
super.resources() ++ Seq(generateProperties())
}
}
trait PubSettings extends PublishModule {
override def publishVersion = de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState().format()
def pomSettings = T {
PomSettings(
description = "CmdOption is a simple annotation-driven command line parser toolkit for Java 5 applications that is configured through annotations",
organization = "de.tototec",
url = "https://github.com/ToToTec/CmdOption",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("ToToTec", "CmdOption"),
developers = Seq(Developer("TobiasRoeser", "Tobias Roeser", "https.//github.com/lefou"))
)
}
}
object cmdoption extends MavenModule with GettextJavaModule with OsgiBundleModule with PubSettings {
override def millSourcePath = super.millSourcePath / os.up / "de.tototec.cmdoption"
val namespace = "de.tototec.cmdoption"
override def artifactName = namespace
override def javacOptions = Seq("-source", "1.6", "-target", "1.6", "-encoding", "UTF-8")
override def compileIvyDeps = Agg(Deps.slf4j.optional(true))
override def sources = T.sources(millSourcePath / "src" / "main" / "java")
override def generatePropertiesPackage: Target[String] = "de.tototec.cmdoption"
override def osgiHeaders = T { super.osgiHeaders().copy(
`Bundle-SymbolicName` = namespace,
`Bundle-Name` = Some(s"CmdOption ${publishVersion()}"),
`Export-Package` = Seq(
namespace,
s"$namespace.handler"
),
`Import-Package` = Seq(
"org.slf4j.*;resolution:=optional",
"*"
)
)}
object test extends MavenModuleTests with TestModule.TestNg {
override def forkArgs = super.forkArgs() ++ Seq("-Dmill.testng.printProgress=0")
override def ivyDeps = super.ivyDeps() ++ Agg(
Deps.Test.lambdatest,
Deps.Test.testNg
)
override def runIvyDeps: Target[Loose.Agg[Dep]] = super.runIvyDeps() ++ Agg(Deps.slf4j)
override def javacOptions = Seq("-source", "1.8", "-target", "1.8", "-encoding", "UTF-8")
}
}