forked from ToToTec/CmdOption
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sc
More file actions
150 lines (131 loc) · 4.87 KB
/
build.sc
File metadata and controls
150 lines (131 loc) · 4.87 KB
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
import cmdoption.{generateProperties, generatePropertiesPackage, millSourcePath, sources}
import mill._
import mill.define.{Source, Target}
import mill.scalalib._
import mill.scalalib.publish._
import $ivy.`de.tototec::de.tobiasroeser.mill.osgi:0.2.0`
import de.tobiasroeser.mill.osgi._
val baseDir = build.millSourcePath
val cmdOptionVersion = "0.7.0"
object Deps {
val junit = ivy"junit:junit:4.13.1"
val junitInterface = ivy"com.novocode:junit-interface:0.11"
val lambdatest = ivy"de.tototec:de.tobiasroeser.lambdatest:0.7.0"
val slf4j = ivy"org.slf4j:slf4j-api:1.7.25"
}
trait GettextJavaModule extends JavaModule {
def poSource: Source = 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())
}
}
object cmdoption extends MavenModule with GettextJavaModule with OsgiBundleModule with PublishModule {
override def millSourcePath = super.millSourcePath / os.up / "de.tototec.cmdoption"
val namespace = "de.tototec.cmdoption"
override def artifactName = namespace
override def publishVersion = cmdOptionVersion
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"))
)
}
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 Tests {
def testFrameworks = Seq("com.novocode.junit.JUnitFramework")
override def ivyDeps = Agg(
Deps.junit,
Deps.junitInterface,
Deps.lambdatest
)
override def javacOptions = Seq("-source", "1.8", "-target", "1.8", "-encoding", "UTF-8")
}
}