Skip to content

Commit af2c740

Browse files
Project scan xcode project for xcodeuitests (#97)
* feat xcode: scan the directory for project files * typo * moved the scanForProjectFiles() to cmd/utils.go * project dir scan for the project files like in the scanner * clean * deps: scanner/xamarin & scanner/ios * xamarin option for auto scan * warning message added about the --file flag usage * PR: IDEType enum renamed to ProjectType; and changed from String to Int; * PR: fix some log typo: solution => workspace / project * ref: scanXamarinProject: move the "search for the soulition file" block in to a separated func; * ref: scanXcodeProject: move the "search for the project file" block in to a separated func; * dep ensure * PR clean * PR: make ProjectType private * move the findXcodeProject & findXamarinProject methods to cmd/utils.go; add the auto scan function to the xcodeUITests as well * PR: fix return * clean the findXamarinSolution() just like the findXcodeProject()
1 parent 7c4a594 commit af2c740

File tree

4 files changed

+87
-80
lines changed

4 files changed

+87
-80
lines changed

cmd/utils.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"path"
67

78
"github.com/bitrise-core/bitrise-init/scanners/ios"
89
"github.com/bitrise-core/bitrise-init/scanners/xamarin"
910
"github.com/bitrise-core/bitrise-init/utility"
11+
"github.com/bitrise-io/go-utils/colorstring"
12+
"github.com/bitrise-io/go-utils/log"
13+
"github.com/bitrise-io/goinp/goinp"
1014
)
1115

1216
// projectType enum.
@@ -60,3 +64,73 @@ func scanForProjectFiles(projType projectType) ([]string, error) {
6064
}
6165
return paths, nil
6266
}
67+
68+
// findProject scans the directory for Xcode Project (.xcworkspace / .xcodeproject) file first
69+
// If can't find any, ask the user to drag-and-drop the file
70+
func findXcodeProject() (string, error) {
71+
var projpth string
72+
73+
projPaths, err := scanForProjectFiles(iOSProjectType)
74+
if err != nil {
75+
log.Printf("Failed: %s", err)
76+
fmt.Println()
77+
78+
log.Infof("Provide the project file manually")
79+
askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file,
80+
the one you usually open in Xcode, then hit Enter.
81+
(Note: if you have a Workspace file you should most likely use that)`
82+
projpth, err = goinp.AskForPath(askText)
83+
if err != nil {
84+
return "", fmt.Errorf("failed to read input: %s", err)
85+
}
86+
87+
return projpth, nil
88+
}
89+
90+
if len(projPaths) == 1 {
91+
log.Printf("Found one project file: %s.", path.Base(projPaths[0]))
92+
return projPaths[0], nil
93+
}
94+
95+
log.Printf("Found multiple project file: %s.", path.Base(projpth))
96+
projpth, err = goinp.SelectFromStringsWithDefault("Select the project file you want to scan", 1, projPaths)
97+
if err != nil {
98+
return "", fmt.Errorf("failed to select project file: %s", err)
99+
}
100+
101+
return projpth, nil
102+
}
103+
104+
// findSolution scans the directory for Xamarin.Solution file first
105+
// If can't find any, ask the user to drag-and-drop the file
106+
func findXamarinSolution() (string, error) {
107+
var solutionPth string
108+
solPaths, err := scanForProjectFiles(xamarinProjectType)
109+
if err != nil {
110+
log.Printf("Failed: %s", err)
111+
fmt.Println()
112+
113+
log.Infof("Provide the solution file manually")
114+
askText := `Please drag-and-drop your Xamarin Solution (` + colorstring.Green(".sln") + `) file,
115+
and then hit Enter`
116+
solutionPth, err = goinp.AskForPath(askText)
117+
if err != nil {
118+
return "", fmt.Errorf("failed to read input: %s", err)
119+
}
120+
121+
return solutionPth, nil
122+
}
123+
124+
if len(solPaths) == 1 {
125+
log.Printf("Found one solution file: %s.", path.Base(solPaths[0]))
126+
return solPaths[0], nil
127+
}
128+
129+
log.Printf("Found multiple solution file: %s.", path.Base(solutionPth))
130+
solutionPth, err = goinp.SelectFromStringsWithDefault("Select the solution file you want to scan", 1, solPaths)
131+
if err != nil {
132+
return "", fmt.Errorf("failed to select solution file: %s", err)
133+
}
134+
135+
return solutionPth, nil
136+
}

cmd/xamarin.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"path"
76
"path/filepath"
87
"sort"
98

@@ -76,38 +75,6 @@ func archivableSolutionConfigNames(projectsByID map[string]project.Model) []stri
7675
return archivableSolutionConfigNames
7776
}
7877

79-
// findSolution scans the directory for Xamarin.Solution file first
80-
// If can't find any, ask the user to drag-and-drop the file
81-
func findSolution() (string, error) {
82-
var solutionPth string
83-
solPaths, err := scanForProjectFiles(xamarinProjectType)
84-
if err != nil {
85-
log.Printf("Failed: %s", err)
86-
fmt.Println()
87-
88-
log.Infof("Provide the solution file manually")
89-
askText := `Please drag-and-drop your Xamarin Solution (` + colorstring.Green(".sln") + `) file,
90-
and then hit Enter`
91-
solutionPth, err = goinp.AskForPath(askText)
92-
if err != nil {
93-
return "", fmt.Errorf("failed to read input: %s", err)
94-
}
95-
} else {
96-
if len(solPaths) == 1 {
97-
log.Printf("Found one solution file: %s.", path.Base(solPaths[0]))
98-
solutionPth = solPaths[0]
99-
} else {
100-
log.Printf("Found multiple solution file: %s.", path.Base(solutionPth))
101-
solutionPth, err = goinp.SelectFromStringsWithDefault("Select the solution file you want to scan", 1, solPaths)
102-
if err != nil {
103-
return "", fmt.Errorf("failed to select solution file: %s", err)
104-
}
105-
}
106-
}
107-
108-
return solutionPth, nil
109-
}
110-
11178
func scanXamarinProject(cmd *cobra.Command, args []string) error {
11279
absExportOutputDirPath, err := initExportOutputDir()
11380
if err != nil {
@@ -127,7 +94,7 @@ func scanXamarinProject(cmd *cobra.Command, args []string) error {
12794
//
12895
// Scan the directory for Xamarin.Solution file first
12996
// If can't find any, ask the user to drag-and-drop the file
130-
xamarinCmd.SolutionFilePath, err = findSolution()
97+
xamarinCmd.SolutionFilePath, err = findXamarinSolution()
13198
if err != nil {
13299
return err
133100
}

cmd/xcode.go

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55
"os"
6-
"path"
76
"path/filepath"
87
"strings"
98

@@ -62,41 +61,6 @@ func initExportOutputDir() (string, error) {
6261
return absExportOutputDirPath, nil
6362
}
6463

65-
// findProject scans the directory for Xcode Project (.xcworkspace / .xcodeproject) file first
66-
// If can't find any, ask the user to drag-and-drop the file
67-
func findProject() (string, error) {
68-
var projpth string
69-
70-
projPaths, err := scanForProjectFiles(iOSProjectType)
71-
if err != nil {
72-
log.Printf("Failed: %s", err)
73-
fmt.Println()
74-
75-
log.Infof("Provide the project file manually")
76-
askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file,
77-
the one you usually open in Xcode, then hit Enter.
78-
(Note: if you have a Workspace file you should most likely use that)`
79-
projpth, err = goinp.AskForPath(askText)
80-
if err != nil {
81-
return "", fmt.Errorf("failed to read input: %s", err)
82-
}
83-
return projpth, err
84-
}
85-
86-
if len(projPaths) == 1 {
87-
log.Printf("Found one project file: %s.", path.Base(projPaths[0]))
88-
return projPaths[0], nil
89-
}
90-
91-
log.Printf("Found multiple project file: %s.", path.Base(projpth))
92-
projpth, err = goinp.SelectFromStringsWithDefault("Select the project file you want to scan", 1, projPaths)
93-
if err != nil {
94-
return "", fmt.Errorf("failed to select project file: %s", err)
95-
}
96-
97-
return projpth, nil
98-
}
99-
10064
func scanXcodeProject(cmd *cobra.Command, args []string) error {
10165
absExportOutputDirPath, err := initExportOutputDir()
10266
if err != nil {
@@ -120,14 +84,14 @@ func scanXcodeProject(cmd *cobra.Command, args []string) error {
12084
log.Infof("Scan the directory for project files")
12185
log.Warnf("You can specify the Xcode project/workscape file to scan with the --file flag.")
12286

123-
projpth, err := findProject()
87+
//
88+
// Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first
89+
// If can't find any, ask the user to drag-and-drop the file
90+
projpth, err := findXcodeProject()
12491
if err != nil {
12592
return err
12693
}
12794

128-
//
129-
// Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first
130-
// If can't find any, ask the user to drag-and-drop the file
13195
projectPath = strings.Trim(strings.TrimSpace(projpth), "'\"")
13296
}
13397
log.Debugf("projectPath: %s", projectPath)

cmd/xcodeUITests.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ func scanXcodeUITestsProject(cmd *cobra.Command, args []string) error {
5050

5151
projectPath := paramXcodeProjectFilePath
5252
if projectPath == "" {
53-
askText := `Please drag-and-drop your Xcode Project (` + colorstring.Green(".xcodeproj") + `) or Workspace (` + colorstring.Green(".xcworkspace") + `) file,
54-
the one you usually open in Xcode, then hit Enter.
55-
(Note: if you have a Workspace file you should most likely use that)`
56-
projpth, err := goinp.AskForPath(askText)
53+
log.Infof("Scan the directory for project files")
54+
log.Warnf("You can specify the Xcode project/workscape file to scan with the --file flag.")
55+
56+
//
57+
// Scan the directory for Xcode Project (.xcworkspace / .xcodeproject) file first
58+
// If can't find any, ask the user to drag-and-drop the file
59+
projpth, err := findXcodeProject()
5760
if err != nil {
58-
return fmt.Errorf("failed to read input: %s", err)
61+
return err
5962
}
6063

6164
projectPath = strings.Trim(strings.TrimSpace(projpth), "'\"")
6265
}
6366
log.Debugf("projectPath: %s", projectPath)
64-
6567
xcodeUITestsCmd := xcodeuitest.CommandModel{ProjectFilePath: projectPath}
6668

6769
schemeToUse := paramXcodeScheme

0 commit comments

Comments
 (0)