Skip to content

Commit

Permalink
Merge pull request #6 from bzon/issue-3-use-ipapk-analyzer
Browse files Browse the repository at this point in the history
Issue 3 use ipapk analyzer

Closes #3
  • Loading branch information
bzon authored Apr 25, 2018
2 parents 22c6caa + 3141cbc commit e1b60bb
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 437 deletions.
57 changes: 0 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,8 @@ Get the executable binary for your platform from the [Release Page](https://gith

Gota command help `gota --help`

```bash
Go Over the Air installation for Android APK and iOS Ipa files! Source: https://github.com/bzon/gota

Usage:
gota [flags]
gota [command]

Available Commands:
help Help about any command
nexus Upload your apk or ipa file and create an over-the-air static site in a Nexus Site repository

Flags:
--buildNumber string the apk or ipa build number.
--bundleID string if srcFile type is '.ipa', this is required. (example: com.example.bundleid)
--bundleVersion string if srcFile type is '.ipa', this is required.
--destDir string root directory of the site to create.
-h, --help help for gota
--srcFile string the apk or ipa file.
--title string application name to be displayed in the site
--versionCode string if srcfile is '.apk', this is required.
--versionName string if srcFile is '.apk', this is required.

Use "gota [command] --help" for more information about a command.
```
Nexus command help `gota nexus --help`

```bash
Upload your apk or ipa file and create an over-the-air static site in a Nexus Site repository

Usage:
gota nexus [flags]

Flags:
-h, --help help for nexus
--nexusHost string nexus host url (including http protocol)
--nexusPassword string nexus password (can be passed as env variable $NEXUS_PASSWORD)
--nexusRepo string nexus site repository id (nexus v3 raw repository not maven!)
--nexusUser string nexus username (can be passed as env variable $NEXUS_USER)

Global Flags:
--buildNumber string the apk or ipa build number.
--bundleID string if srcFile type is '.ipa', this is required. (example: com.example.bundleid)
--bundleVersion string if srcFile type is '.ipa', this is required.
--destDir string root directory of the site to create.
--srcFile string the apk or ipa file.
--title string application name to be displayed in the site
--versionCode string if srcfile is '.apk', this is required.
--versionName string if srcFile is '.apk', this is required.
```
### Nexus APK Upload

Upload an APK file to a Nexus Site Repository
Expand All @@ -85,11 +36,7 @@ Upload an APK file to a Nexus Site Repository
--nexusUser admin \
--nexusPassword admin123 \
--destDir android \
--buildNumber 1 \
--srcFile pkg/resources/DarkSouls.apk \
--title "DarkSouls" \
--versionName "1.0.0" \
--versionCode "10222333"

uploaded to nexus: http://localhost:8081/repository/site/android/version.json
uploaded to nexus: http://localhost:8081/repository/site/android/1.0.0.10222333/index.html
Expand All @@ -112,11 +59,7 @@ Upload an IPA file to a Nexus Site Repository
--nexusUser admin \
--nexusPassword admin123 \
--destDir ios \
--buildNumber 1 \
--srcFile pkg/resources/DarkSouls.ipa \
--title DarkSouls \
--bundleVersion 1.0.0 \
--bundleID com.example.com

uploaded to nexus: http://localhost:8081/repository/site/ios/version.json
uploaded to nexus: http://localhost:8081/repository/site/ios/1.0.0.1/DarkSouls.plist
Expand Down
25 changes: 8 additions & 17 deletions cmd/nexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ package cmd

import (
"fmt"
"log"
"os"

"github.com/bzon/gota/parser"

nexuspkg "github.com/bzon/gota/nexus"
"github.com/spf13/cobra"
)
Expand All @@ -31,24 +30,16 @@ var nexusCmd = &cobra.Command{
Use: "nexus",
Short: "Upload your apk or ipa file and create an over-the-air static site in a Nexus Site repository",
Run: func(cmd *cobra.Command, args []string) {
validateAndParseArgs(cmd)
var assets []string
var err error
app := newApp()
switch app.(type) {
case parser.IOSIPA:
ipa := app.(parser.IOSIPA)
assets, err = nexus.NexusUploadIOSAssets(&ipa, destDir)
case parser.AndroidAPK:
apk := app.(parser.AndroidAPK)
assets, err = nexus.NexusUploadAndroidAssets(&apk, destDir)
app := NewMobileAppParser()
if err := app.GenerateAssets(); err != nil {
log.Fatal(err)
}
assets, err := nexus.NexusUploadAssets(app, destDir)
if err != nil {
fmt.Printf("failed uploading assets: %+v", err)
os.Exit(1)
log.Fatal(err)
}
for _, a := range assets {
fmt.Printf("uploaded to nexus: %s\n", a)
for _, v := range assets {
fmt.Println("nexus asset url:", v)
}
},
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ import (
"github.com/spf13/cobra"
)

var srcFile, destDir string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gota",
Short: "Go Over the Air installation for Android APK and iOS Ipa files! Source: https://github.com/bzon/gota",
Run: func(cmd *cobra.Command, args []string) {
validateAndParseArgs(cmd)
},
Short: "Go Over the Air installation for Android APK and iOS Ipa files!",
// Run: func(cmd *cobra.Command, args []string) {
// appInfo, err := ipapk.NewAppParser(srcFile)
// if err != nil {
// log.Fatal(err)
// }
// app.UploadDate = time.Now().Format(time.RFC1123)
// app.AppInfo = appInfo
// app.File = srcFile
// },
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -46,16 +54,8 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().StringVar(&title, "title", "", "application name to be displayed in the site")
rootCmd.PersistentFlags().StringVar(&srcFile, "srcFile", "", "the apk or ipa file.")
rootCmd.PersistentFlags().StringVar(&destDir, "destDir", "", "root directory of the site to create.")
rootCmd.PersistentFlags().StringVar(&buildNumber, "buildNumber", "", "the apk or ipa build number.")
rootCmd.PersistentFlags().StringVar(&bundleVersion, "bundleVersion", "", "if srcFile type is '.ipa', this is required.")
rootCmd.PersistentFlags().StringVar(&bundleID, "bundleID", "", "if srcFile type is '.ipa', this is required. (example: com.example.bundleid)")
rootCmd.PersistentFlags().StringVar(&versionName, "versionName", "", "if srcFile is '.apk', this is required.")
rootCmd.PersistentFlags().StringVar(&versionCode, "versionCode", "", "if srcfile is '.apk', this is required.")
rootCmd.MarkPersistentFlagRequired("title")
rootCmd.MarkPersistentFlagRequired("srcFile")
rootCmd.MarkPersistentFlagRequired("destDir")
rootCmd.MarkPersistentFlagRequired("buildNumber")
}
81 changes: 13 additions & 68 deletions cmd/utils.go
Original file line number Diff line number Diff line change
@@ -1,77 +1,22 @@
package cmd

import (
"fmt"
"os"
"path/filepath"
"log"
"time"

"github.com/bzon/ipapk"

"github.com/bzon/gota/parser"
"github.com/spf13/cobra"
)

// common
var title, srcFile, buildNumber, destDir string

// ios specific
var bundleID, bundleVersion string

// android specific
var versionName, versionCode string

func missingFlagError(cmd *cobra.Command, f string) {
fmt.Printf("Error: required flag(s) \"%s\" not set\n", f)
cmd.Usage()
os.Exit(1)
}

func newApp() parser.MobileApp {
appFile := parser.AppFile{
Title: title,
BuildNumber: buildNumber,
SourceFile: srcFile,
}
if fileExt() == ".ipa" {
return parser.IOSIPA{
AppFile: appFile,
BundleID: bundleID,
BundleVersion: bundleVersion,
}
} else {
return parser.AndroidAPK{
AppFile: appFile,
VersionCode: versionCode,
VersionName: versionName,
}
}
}

func fileExt() string {
return filepath.Ext(srcFile)
}

// This function must be called before executing any commands function!
func validateAndParseArgs(cmd *cobra.Command) {
if fileExt() == ".ipa" {
if bundleVersion == "" {
missingFlagError(cmd, "bundleVersion")
}
if bundleID == "" {
missingFlagError(cmd, "bundleID")
}
} else if fileExt() == ".apk" {
if versionName == "" {
missingFlagError(cmd, "versionName")
}
if versionCode == "" {
missingFlagError(cmd, "versionCode")
}
} else {
fmt.Printf("Error: srcFile %s does not have a file extension of .apk or .ipa\n", srcFile)
cmd.Usage()
os.Exit(1)
}
if _, err := os.Stat(srcFile); os.IsNotExist(err) {
fmt.Println(err)
os.Exit(1)
func NewMobileAppParser() *parser.MobileApp {
appInfo, err := ipapk.NewAppParser(srcFile)
if err != nil {
log.Fatal(err)
}
var app parser.MobileApp
app.UploadDate = time.Now().Format(time.RFC1123)
app.AppInfo = appInfo
app.File = srcFile
return &app
}
95 changes: 36 additions & 59 deletions nexus/nexus_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type Nexus struct {

// NexusComponent contains the fields that will be passed as a parameter for NexusUpload
type NexusComponent struct {
SourceFile, Filename, Directory string
File, Filename, Directory string
}

// NexusUpload uploads a file to Nexus returns the uploaded file url
func (n *Nexus) NexusUpload(c NexusComponent) (string, error) {
file, err := os.Open(c.SourceFile)
file, err := os.Open(c.File)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -53,71 +53,48 @@ func (n *Nexus) getRepoURL() string {
return n.HostURL + "/repository/" + n.SiteRepository
}

// NexusUploadIOSAssets wraps NexusUpload to upload all files for iOS to nexus
func (n *Nexus) NexusUploadIOSAssets(ipa *parser.IOSIPA, dir string) ([]string, error) {
// Upload in directory with FullVersion() as name
ipaSitePath := ipa.FullVersion() + "/" + filepath.Base(ipa.SourceFile)
ipaPlistSitePath := ipa.FullVersion() + "/" + ipa.Title + ".plist"
ipaIndexHTMLSitePath := ipa.FullVersion() + "/index.html"
// assume the url before uploaded for templating
ipa.DownloadURL = n.getRepoURL() + "/" + dir + "/" + ipaSitePath
ipa.PlistURL = htmltemp.URL(n.getRepoURL() + "/" + dir + "/" + ipaPlistSitePath)
// create the assets
assets := []string{}
if err := ipa.GenerateAssets(); err != nil {
return assets, err
}
// upload assets
uri, err := n.NexusUpload(NexusComponent{"ios_assets/version.json", "version.json", dir})
if err != nil {
return assets, err
}
assets = append(assets, uri)
uri, err = n.NexusUpload(NexusComponent{"ios_assets/app.plist", ipaPlistSitePath, dir})
if err != nil {
return assets, err
}
assets = append(assets, uri)
uri, err = n.NexusUpload(NexusComponent{"ios_assets/index.html", ipaIndexHTMLSitePath, dir})
if err != nil {
return assets, err
}
assets = append(assets, uri)
uri, err = n.NexusUpload(NexusComponent{ipa.SourceFile, ipaSitePath, dir})
if err != nil {
return assets, err
// NexusUploadAssets uploads the generated files by the parser package along with the ipa or apk file
func (n *Nexus) NexusUploadAssets(app *parser.MobileApp, dir string) ([]string, error) {
// create the site path names and assume the url before uploaded for templating
appIconPath := app.Version + "/" + parser.AppIconFile
appSitePath := app.Version + "/" + filepath.Base(app.File)
appIndexHTMLSitePath := app.Version + "/" + parser.IndexHTMLFile
app.DownloadURL = n.getRepoURL() + "/" + dir + "/" + appSitePath

// default directory of assets
assetsDir := parser.AndroidAssetsDir

// specific for ios
var appPlistSitePath string
if app.IsIOS() {
assetsDir = parser.IOSAssetsDir
appPlistSitePath = app.Version + "/" + parser.IOSPlistFile
app.PlistURL = htmltemp.URL(n.getRepoURL() + "/" + dir + "/" + appPlistSitePath)
}
assets = append(assets, uri)
return assets, nil
}

// NexusUploadAndroidAssets wraps NexusUpload to upload all files for android to nexus
func (n *Nexus) NexusUploadAndroidAssets(apk *parser.AndroidAPK, dir string) ([]string, error) {
// Upload in directory with FullVersion() as name
apkSitePath := apk.FullVersion() + "/" + filepath.Base(apk.SourceFile)
apkIndexHTMLSitePath := apk.FullVersion() + "/index.html"
// assume the url before uploaded for templating
apk.DownloadURL = n.getRepoURL() + "/" + dir + "/" + apkSitePath
// create the assets
assets := []string{}
if err := apk.GenerateAssets(); err != nil {
if err := app.GenerateAssets(); err != nil {
return assets, err
}
// upload assets
uri, err := n.NexusUpload(NexusComponent{"ios_assets/version.json", "version.json", dir})
if err != nil {
return assets, err

components := []NexusComponent{
{assetsDir + "/" + parser.AppIconFile, appIconPath, dir},
{assetsDir + "/" + parser.VersionJsonFile, parser.VersionJsonFile, dir},
{assetsDir + "/" + parser.IndexHTMLFile, appIndexHTMLSitePath, dir},
{app.File, appSitePath, dir},
}
assets = append(assets, uri)
uri, err = n.NexusUpload(NexusComponent{"ios_assets/index.html", apkIndexHTMLSitePath, dir})
if err != nil {
return assets, err
if app.IsIOS() {
components = append(components, NexusComponent{assetsDir + "/" + parser.IOSPlistFile, appPlistSitePath, dir})
}
assets = append(assets, uri)
uri, err = n.NexusUpload(NexusComponent{apk.SourceFile, apkSitePath, dir})
if err != nil {
return assets, err

for _, component := range components {
uri, err := n.NexusUpload(component)
if err != nil {
return assets, err
}
assets = append(assets, uri)
}
assets = append(assets, uri)

return assets, nil
}
Loading

0 comments on commit e1b60bb

Please sign in to comment.