Skip to content

Commit

Permalink
fixed chained regex pattern, added extra log and raw output warning (#78
Browse files Browse the repository at this point in the history
)
  • Loading branch information
trapacska authored Dec 19, 2018
1 parent 4ec5548 commit dd02ec7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 128 deletions.
61 changes: 44 additions & 17 deletions uploaders/apkuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"regexp"
"strings"

"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
Expand All @@ -14,23 +15,29 @@ import (

// ApkInfo ...
type ApkInfo struct {
AppName string
PackageName string
VersionCode string
VersionName string
MinSDKVersion string
AppName string
PackageName string
VersionCode string
VersionName string
MinSDKVersion string
RawPackageContent string
}

func filterPackageInfos(aaptOut string) (string, string, string) {
// build tools version >= 28 package: name='sample.results.test.multiple.bitrise.com.multipletestresultssample' versionCode='1' versionName='1.0'
// build tools version < 28 package: name='sample.results.test.multiple.bitrise.com.multipletestresultssample' versionCode='1' versionName='1.0' platformBuildVersionName=''
pattern := `package: name=\'(?P<package_name>.*)\' versionCode=\'(?P<version_code>.*)\' versionName=\'(?P<version_name>.[^\s]*)\'`
func packageField(data, key string) string {
pattern := fmt.Sprintf(`%s=['"](.*?)['"]`, key)

re := regexp.MustCompile(pattern)
if matches := re.FindStringSubmatch(aaptOut); len(matches) == 4 {
return matches[1], matches[2], matches[3]
if matches := re.FindStringSubmatch(data); len(matches) == 2 {
return matches[1]
}
return "", "", ""

return ""
}

func filterPackageInfos(aaptOut string) (string, string, string) {
return packageField(aaptOut, "name"),
packageField(aaptOut, "versionCode"),
packageField(aaptOut, "versionName")
}

func filterAppLable(aaptOut string) string {
Expand Down Expand Up @@ -83,12 +90,20 @@ func getAPKInfo(apkPth string) (ApkInfo, error) {
packageName, versionCode, versionName := filterPackageInfos(aaptOut)
minSDKVersion := filterMinSDKVersion(aaptOut)

packageContent := ""
for _, line := range strings.Split(aaptOut, "\n") {
if strings.HasPrefix(line, "package:") {
packageContent = line
}
}

return ApkInfo{
AppName: appName,
PackageName: packageName,
VersionCode: versionCode,
VersionName: versionName,
MinSDKVersion: minSDKVersion,
AppName: appName,
PackageName: packageName,
VersionCode: versionCode,
VersionName: versionName,
MinSDKVersion: minSDKVersion,
RawPackageContent: packageContent,
}, nil
}

Expand All @@ -111,6 +126,18 @@ func DeployAPK(pth, buildURL, token, notifyUserGroups, notifyEmails, isEnablePub

log.Printf(" apk infos: %v", appInfo)

if apkInfo.PackageName == "" {
log.Warnf("Package name is undefined, AndroidManifest.xml package content:\n%s", apkInfo.RawPackageContent)
}

if apkInfo.VersionCode == "" {
log.Warnf("Version code is undefined, AndroidManifest.xml package content:\n%s", apkInfo.RawPackageContent)
}

if apkInfo.VersionName == "" {
log.Warnf("Version name is undefined, AndroidManifest.xml package content:\n%s", apkInfo.RawPackageContent)
}

// ---

fileSize, err := fileSizeInBytes(pth)
Expand Down
141 changes: 30 additions & 111 deletions uploaders/apkuploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Test_filterPackageInfos(t *testing.T) {
}{
{
name: "test_with_empty_platformBuildVersionName",
aaptOut: aaptOutEmptyPlatformBuildVersionName,
aaptOut: `package: name='com.example.birmachera.myapplication' versionCode='1' versionName='1.0' platformBuildVersionName=''`,
want: "com.example.birmachera.myapplication",
want1: "1",
want2: "1.0",
Expand All @@ -27,11 +27,39 @@ func Test_filterPackageInfos(t *testing.T) {
},
{
name: "test_with_platformBuildVersionName",
aaptOut: `package: name='com.example.birmachera.myapplication' versionCode='1' versionName='1.0' platformBuildVersionName='3'`,
aaptOut: `package: name='com.example.birmachera.myapplication' versionCode='1' versionName='1.0' platformBuildVersionName='3'`,
want: "com.example.birmachera.myapplication",
want1: "1",
want2: "1.0",
},
{
name: "test_without_name",
aaptOut: `package: name='' versionCode='1' versionName='1.0' platformBuildVersionName='3'`,
want: "",
want1: "1",
want2: "1.0",
},
{
name: "test_without_name_and_versionCode",
aaptOut: `package: name='' versionCode='' versionName='1.0' platformBuildVersionName='3'`,
want: "",
want1: "",
want2: "1.0",
},
{
name: "test_without_name_and_versionCode_and_versionName",
aaptOut: `package: name='' versionCode='' versionName='' platformBuildVersionName='3'`,
want: "",
want1: "",
want2: "",
},
{
name: "test_without_name_and_versionCode_and_versionName",
aaptOut: `package: name='' versionCode='2' versionName='' platformBuildVersionName='3'`,
want: "",
want1: "2",
want2: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -48,112 +76,3 @@ func Test_filterPackageInfos(t *testing.T) {
})
}
}

var aaptOutEmptyPlatformBuildVersionName = `package: name='com.example.birmachera.myapplication' versionCode='1' versionName='1.0' platformBuildVersionName=''
sdkVersion:'17'
targetSdkVersion:'28'
uses-permission: name='android.permission.INTERNET'
application-label:'My Application'
application-label-af:'My Application'
application-label-am:'My Application'
application-label-ar:'My Application'
application-label-as:'My Application'
application-label-az:'My Application'
application-label-be:'My Application'
application-label-bg:'My Application'
application-label-bn:'My Application'
application-label-bs:'My Application'
application-label-ca:'My Application'
application-label-cs:'My Application'
application-label-da:'My Application'
application-label-de:'My Application'
application-label-el:'My Application'
application-label-en-AU:'My Application'
application-label-en-CA:'My Application'
application-label-en-GB:'My Application'
application-label-en-IN:'My Application'
application-label-en-XC:'My Application'
application-label-es:'My Application'
application-label-es-US:'My Application'
application-label-et:'My Application'
application-label-eu:'My Application'
application-label-fa:'My Application'
application-label-fi:'My Application'
application-label-fr:'My Application'
application-label-fr-CA:'My Application'
application-label-gl:'My Application'
application-label-gu:'My Application'
application-label-hi:'My Application'
application-label-hr:'My Application'
application-label-hu:'My Application'
application-label-hy:'My Application'
application-label-in:'My Application'
application-label-is:'My Application'
application-label-it:'My Application'
application-label-iw:'My Application'
application-label-ja:'My Application'
application-label-ka:'My Application'
application-label-kk:'My Application'
application-label-km:'My Application'
application-label-kn:'My Application'
application-label-ko:'My Application'
application-label-ky:'My Application'
application-label-lo:'My Application'
application-label-lt:'My Application'
application-label-lv:'My Application'
application-label-mk:'My Application'
application-label-ml:'My Application'
application-label-mn:'My Application'
application-label-mr:'My Application'
application-label-ms:'My Application'
application-label-my:'My Application'
application-label-nb:'My Application'
application-label-ne:'My Application'
application-label-nl:'My Application'
application-label-or:'My Application'
application-label-pa:'My Application'
application-label-pl:'My Application'
application-label-pt:'My Application'
application-label-pt-BR:'My Application'
application-label-pt-PT:'My Application'
application-label-ro:'My Application'
application-label-ru:'My Application'
application-label-si:'My Application'
application-label-sk:'My Application'
application-label-sl:'My Application'
application-label-sq:'My Application'
application-label-sr:'My Application'
application-label-sr-Latn:'My Application'
application-label-sv:'My Application'
application-label-sw:'My Application'
application-label-ta:'My Application'
application-label-te:'My Application'
application-label-th:'My Application'
application-label-tl:'My Application'
application-label-tr:'My Application'
application-label-uk:'My Application'
application-label-ur:'My Application'
application-label-uz:'My Application'
application-label-vi:'My Application'
application-label-zh-CN:'My Application'
application-label-zh-HK:'My Application'
application-label-zh-TW:'My Application'
application-label-zu:'My Application'
application-icon-120:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-160:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-240:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-320:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-480:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-640:'res/mipmap-anydpi-v26/ic_launcher.xml'
application-icon-65534:'res/mipmap-anydpi-v26/ic_launcher.xml'
application: label='My Application' icon='res/mipmap-anydpi-v26/ic_launcher.xml'
application-debuggable
launchable-activity: name='com.example.birmachera.myapplication.MainActivity' label='' icon=''
feature-group: label=''
uses-feature: name='android.hardware.faketouch'
uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps'
main
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--' 'af' 'am' 'ar' 'as' 'az' 'be' 'bg' 'bn' 'bs' 'ca' 'cs' 'da' 'de' 'el' 'en-AU' 'en-CA' 'en-GB' 'en-IN' 'en-XC' 'es' 'es-US' 'et' 'eu' 'fa' 'fi' 'fr' 'fr-CA' 'gl' 'gu' 'hi' 'hr' 'hu' 'hy' 'in' 'is' 'it' 'iw' 'ja' 'ka' 'kk' 'km' 'kn' 'ko' 'ky' 'lo' 'lt' 'lv' 'mk' 'ml' 'mn' 'mr' 'ms' 'my' 'nb' 'ne' 'nl' 'or' 'pa' 'pl' 'pt' 'pt-BR' 'pt-PT' 'ro' 'ru' 'si' 'sk' 'sl' 'sq' 'sr' 'sr-Latn' 'sv' 'sw' 'ta' 'te' 'th' 'tl' 'tr' 'uk' 'ur' 'uz' 'vi' 'zh-CN' 'zh-HK' 'zh-TW' 'zu'
densities: '120' '160' '240' '320' '480' '640' '65534'`

0 comments on commit dd02ec7

Please sign in to comment.