@@ -5,8 +5,8 @@ import com.github.plokhotnyuk.jsoniter_scala.macros.*
5
5
import org .eclipse .jgit .api .Git
6
6
import org .eclipse .jgit .lib .{Constants , Ref }
7
7
8
- import scala .build .{Position , Positioned }
9
8
import scala .build .errors .{BuildException , MalformedInputError }
9
+ import scala .build .{Position , Positioned }
10
10
import scala .io .Codec
11
11
import scala .jdk .CollectionConverters .*
12
12
import scala .util .{Success , Try , Using }
@@ -19,37 +19,37 @@ sealed abstract class ComputeVersion extends Product with Serializable {
19
19
20
20
object ComputeVersion {
21
21
22
- final case class Command (positions : Seq [Position ], command : Seq [String ]) extends ComputeVersion {
22
+ final case class Command (command : Seq [String ], positions : Seq [Position ]) extends ComputeVersion {
23
23
def get (workspace : os.Path ): Either [BuildException , String ] = {
24
24
val maybeRes = Try (os.proc(command).call(stdin = os.Inherit , cwd = workspace, check = false ))
25
25
maybeRes match {
26
26
case Success (res) if res.exitCode == 0 =>
27
27
Right (res.out.trim(Codec .default))
28
28
case _ =>
29
29
Left (new Command .ComputeVersionCommandError (
30
- positions,
31
30
command,
32
- maybeRes.map(_.exitCode).getOrElse(1 )
31
+ maybeRes.map(_.exitCode).getOrElse(1 ),
32
+ positions
33
33
))
34
34
}
35
35
}
36
36
}
37
37
38
38
object Command {
39
39
final class ComputeVersionCommandError (
40
- positions : Seq [Position ],
41
40
command : Seq [String ],
42
- exitCode : Int
41
+ exitCode : Int ,
42
+ positions : Seq [Position ]
43
43
) extends BuildException (
44
44
s " Error running command ${command.mkString(" " )} (exit code: $exitCode) " ,
45
45
positions = positions
46
46
)
47
47
}
48
48
49
49
final case class GitTag (
50
- positions : Seq [Position ],
51
50
repo : os.FilePath ,
52
51
dynVer : Boolean ,
52
+ positions : Seq [Position ],
53
53
defaultFirstVersion : String = " 0.1.0-SNAPSHOT"
54
54
) extends ComputeVersion {
55
55
import GitTag .GitTagError
@@ -166,25 +166,25 @@ object ComputeVersion {
166
166
167
167
def parse (input : Positioned [String ]): Either [BuildException , ComputeVersion ] =
168
168
if (input.value == " git" || input.value == " git:tag" )
169
- Right (ComputeVersion .GitTag (input.positions, os.rel, dynVer = false ))
169
+ Right (ComputeVersion .GitTag (os.rel, dynVer = false , positions = input.positions ))
170
170
else if (input.value.startsWith(" git:tag:" ))
171
171
Right (ComputeVersion .GitTag (
172
- input.positions,
173
172
os.FilePath (input.value.stripPrefix(" git:tag:" )),
174
- dynVer = false
173
+ dynVer = false ,
174
+ positions = input.positions
175
175
))
176
176
else if (input.value == " git:dynver" )
177
- Right (ComputeVersion .GitTag (input.positions, os.rel, dynVer = true ))
177
+ Right (ComputeVersion .GitTag (os.rel, dynVer = true , positions = input.positions ))
178
178
else if (input.value.startsWith(" git:dynver:" ))
179
179
Right (ComputeVersion .GitTag (
180
- input.positions,
181
180
os.FilePath (input.value.stripPrefix(" git:dynver:" )),
182
- dynVer = true
181
+ dynVer = true ,
182
+ positions = input.positions
183
183
))
184
184
else if (input.value.startsWith(" command:[" ))
185
185
try {
186
186
val command = readFromString(input.value.stripPrefix(" command:" ))(commandCodec)
187
- Right (ComputeVersion .Command (input.positions, command ))
187
+ Right (ComputeVersion .Command (command, input.positions))
188
188
}
189
189
catch {
190
190
case e : JsonReaderException =>
@@ -200,7 +200,7 @@ object ComputeVersion {
200
200
}
201
201
else if (input.value.startsWith(" command:" )) {
202
202
val command = input.value.stripPrefix(" command:" ).split(" \\ s+" ).toSeq
203
- Right (ComputeVersion .Command (input.positions, command ))
203
+ Right (ComputeVersion .Command (command, input.positions))
204
204
}
205
205
else
206
206
Left (
0 commit comments