Skip to content

Commit aea0b5f

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 195a9ce + 6827090 commit aea0b5f

8 files changed

Lines changed: 47 additions & 8 deletions

File tree

android_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func applyVersionToAndroidXML(data []byte, newVersion string) []byte {
7272

7373
// edit versionCode attr
7474
acmt, err = mxj.Map(vmap).ValueForPath("#attr.android:versionCode.#text")
75-
acmt = strings.Replace(newVersion, ".", "", -1)
75+
acmt = buildAndroidVersionCode(newVersion)
7676
mxj.Map(vmap).SetValueForPath(acmt, "#attr.android:versionCode.#text")
7777
err = m.SetValueForPath(vmap, "manifest")
7878
check(err)

android_handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func Test_applyVersionToAndroidXML(t *testing.T) {
5959
if xml.VersionName != "1.0.2" {
6060
t.Errorf("VersionName mismatch; expected %v", "1.0.2")
6161
}
62-
if xml.Code != "102" {
63-
t.Errorf("code mismatch; expected %v", "102")
62+
if xml.Code != "1000200" {
63+
t.Errorf("code mismatch; actual %v, expected %v", xml.Code, "1000200")
6464
}
6565
}
6666

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func main() {
1313
app.Usage = "Command-line utility to automatically increase applications version"
1414
app.Author = "Gabriel Robert"
1515
app.Email = "[email protected]"
16-
app.Version = "1.0.0"
16+
app.Version = "1.1.0"
1717
app.Commands = commands()
1818

1919
err := app.Run(os.Args)

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Command-line utility to automatically increase iOS / Android / UWP applications
1414
Using [Chocolatey](https://chocolatey.org/):
1515

1616
```bash
17-
$ choco install xavtool
17+
$ choco install xavtool -version 1.1.0
1818
$ xavtool --version
1919
```
2020

@@ -59,7 +59,7 @@ USAGE:
5959
xavtool [global options] command [command options] [arguments...]
6060

6161
VERSION:
62-
1.0.0
62+
1.1.0
6363

6464
AUTHOR:
6565
Gabriel Robert <[email protected]>

test/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xavtool" android:versionCode="101" android:versionName="1.0.1">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xavtool" android:versionCode="1000100" android:versionName="1.0.1">
33
<permission android:name="android"/>
44
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.Sample">
55
<activity android:name="com.example.xavtool.MainActivity" android:label="@string/app_name" android:launchMode="singleTop">

version.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"fmt"
5+
"strconv"
6+
47
"github.com/Masterminds/semver"
58
)
69

@@ -35,3 +38,17 @@ func isVersion(version string) bool {
3538
}
3639
return true
3740
}
41+
42+
func buildAndroidVersionCode(version string) string {
43+
parsedVersion := parse(version)
44+
45+
versionCode := parsedVersion.Major() * 1000000
46+
versionCode += parsedVersion.Minor() * 10000
47+
versionCode += parsedVersion.Patch() * 100
48+
49+
if versionCode > 2000000000 {
50+
panic(fmt.Sprintf("Android versionCode cannot be greater than %v", 2000000000))
51+
}
52+
53+
return strconv.FormatInt(versionCode, 10)
54+
}

version_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ func Test_isVersion(t *testing.T) {
9292
})
9393
}
9494
}
95+
96+
func Test_buildAndroidVersionCode(t *testing.T) {
97+
type args struct {
98+
version string
99+
}
100+
tests := []struct {
101+
name string
102+
args args
103+
want string
104+
}{
105+
{"1.99.1", args{"1.99.1"}, "1990100"},
106+
{"2.0.0", args{"2.0.0"}, "2000000"},
107+
{"0.0.0", args{"0.0.0"}, "0"},
108+
}
109+
for _, tt := range tests {
110+
t.Run(tt.name, func(t *testing.T) {
111+
if got := buildAndroidVersionCode(tt.args.version); got != tt.want {
112+
t.Errorf("buildAndroidVersionCode() = %v, want %v", got, tt.want)
113+
}
114+
})
115+
}
116+
}

xavtool.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
33
<metadata>
44
<id>xavtool</id>
5-
<version>1.0.0</version>
5+
<version>1.1.0</version>
66
<title>xavtool</title>
77
<authors>gabrielrobert</authors>
88
<projectUrl>https://github.com/gabrielrobert/xavtool</projectUrl>

0 commit comments

Comments
 (0)