Skip to content

Commit

Permalink
(feat) add android check to java scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
TP Honey committed Jul 15, 2022
1 parent 06cae73 commit 9d05726
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 71 deletions.
60 changes: 0 additions & 60 deletions .drone.yml.multiarch

This file was deleted.

66 changes: 55 additions & 11 deletions scanner/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ type scannerConfig struct {
}

const (
mavenFolderLocation = ".mvn"
androidManifest = "AndroidManifest.xml"
antBuildFile = "build.xml"
gradleSettingsFile = "settings.gradle"
bazelBuildFile = "BUILD.bazel"
Name = scanner.JavaScannerName
BuildCheck = "java build"
TestCheck = "java test"
DroneCheck = "java drone build"
gradleSettingsFile = "settings.gradle"
mavenFolderLocation = ".mvn"

Name = scanner.JavaScannerName
BuildCheck = "java build"
TestCheck = "java test"
AndroidCheck = "java android"
DroneCheck = "java drone build"
)

func New(opts ...Option) (types.Scanner, error) {
Expand All @@ -57,7 +60,7 @@ func (sc *scannerConfig) Description() string {
}

func (sc *scannerConfig) AvailableChecks() []string {
return []string{BuildCheck, TestCheck, DroneCheck}
return []string{BuildCheck, TestCheck, DroneCheck, AndroidCheck}
}

func (sc *scannerConfig) Scan(ctx context.Context, requestedOutputs []string) (returnVal []types.Scanlet, err error) {
Expand Down Expand Up @@ -107,8 +110,31 @@ func (sc *scannerConfig) Scan(ctx context.Context, requestedOutputs []string) (r
returnVal = append(returnVal, outputResults...)
}
}
// check for android
foundAndroid := false
if sc.runAll || slices.Contains(requestedOutputs, AndroidCheck) {
androidMatches, err := scanner.FindMatchingFiles(sc.workingDirectory, androidManifest)
if err == nil || len(androidMatches) > 0 {
androidScanlet := types.Scanlet{
Name: "android",
ScannerFamily: Name,
Description: "run android specific project tools",
OutputRenderer: outputter.DroneBuildMaker,
Spec: dronebuildmaker.OutputFields{
Command: "sdkmanager --list",
HelpURL: "https://developer.android.com/studio/command-line/sdkmanager.html",
RawYaml: ` - name: android sdk
image: androidsdk/android-31
commands:
- sdkmanager --list`,
},
}
foundAndroid = true
returnVal = append(returnVal, androidScanlet)
}
}
if sc.runAll || slices.Contains(requestedOutputs, DroneCheck) {
outputResults, err := sc.droneCheck(buildTypes)
outputResults, err := sc.droneCheck(buildTypes, foundAndroid)
if err == nil {
returnVal = append(returnVal, outputResults...)
}
Expand Down Expand Up @@ -243,19 +269,19 @@ func (sc *scannerConfig) buildCheck(hasTests bool) (buildType []string, outputRe
return buildType, outputResults
}

func (sc *scannerConfig) droneCheck(buildTypes []string) (outputResults []types.Scanlet, err error) {
func (sc *scannerConfig) droneCheck(buildTypes []string, hasAndroid bool) (outputResults []types.Scanlet, err error) {
pipelines, err := dronescanner.ReadDroneFile(sc.workingDirectory, dronescanner.DroneFileLocation)
if err != nil {
return outputResults, err
}
// iterate over the pipelines
foundBazelTest := false
foundBazelBuild := false
foundMavenTest := false
foundMavenBuild := false
foundGradleTest := false
foundGradleBuild := false

foundAndroidCommands := false
// iterate over the pipelines
for i := range pipelines {
for j := range pipelines[i].Steps {
commands := pipelines[i].Steps[j].Commands
Expand All @@ -278,6 +304,9 @@ func (sc *scannerConfig) droneCheck(buildTypes []string) (outputResults []types.
if strings.Contains(commands[k], "gradlew clean build") {
foundGradleBuild = true
}
if strings.Contains(commands[k], "sdkmanager") || strings.Contains(commands[k], "adb") {
foundAndroidCommands = true
}
}
}
if foundBazelTest {
Expand Down Expand Up @@ -370,6 +399,21 @@ func (sc *scannerConfig) droneCheck(buildTypes []string) (outputResults []types.
}
outputResults = append(outputResults, buildResult)
}
if hasAndroid && !foundAndroidCommands {
buildResult := types.Scanlet{
Name: BuildCheck,
ScannerFamily: Name,
Description: "run android tests and builds with the android sdk",
OutputRenderer: outputter.DroneBuildAnalysis,
Spec: buildanalysis.OutputFields{
RawYaml: ` - name: build
image: android/sdk
commands:
- sdkmanager --update --no-prompt --all`,
},
}
outputResults = append(outputResults, buildResult)
}
}

return outputResults, err
Expand Down

0 comments on commit 9d05726

Please sign in to comment.