Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some duplication in Jib builder #1465

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions pkg/skaffold/jib/jib_gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,20 @@ func GetDependenciesGradle(ctx context.Context, workspace string, a *latest.JibG
}

func getCommandGradle(ctx context.Context, workspace string, a *latest.JibGradleArtifact) *exec.Cmd {
task := "_jibSkaffoldFiles"

var command string
if a.Project == "" {
command = task
} else {
// multi-module
command = fmt.Sprintf(":%s:%s", a.Project, task)
}
args := []string{command, "-q"}

args := []string{gradleCommand(a, "_jibSkaffoldFiles"), "-q"}
return GradleCommand.CreateCommand(ctx, workspace, args)
}

// GenerateGradleArgs generates the arguments to Gradle for building the project as an image.
func GenerateGradleArgs(task string, imageName string, a *latest.JibGradleArtifact) []string {
var command string
return []string{gradleCommand(a, task), "--image=" + imageName}
}

func gradleCommand(a *latest.JibGradleArtifact, task string) string {
if a.Project == "" {
command = ":" + task
} else {
// multi-module
command = fmt.Sprintf(":%s:%s", a.Project, task)
return ":" + task
}

return []string{command, "--image=" + imageName}
// multi-module
return fmt.Sprintf(":%s:%s", a.Project, task)
}
4 changes: 2 additions & 2 deletions pkg/skaffold/jib/jib_gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestGetCommandGradle(t *testing.T) {
jibGradleArtifact: latest.JibGradleArtifact{},
filesInWorkspace: []string{},
expectedCmd: func(workspace string) *exec.Cmd {
return GradleCommand.CreateCommand(ctx, workspace, []string{"_jibSkaffoldFiles", "-q"})
return GradleCommand.CreateCommand(ctx, workspace, []string{":_jibSkaffoldFiles", "-q"})
},
},
{
Expand All @@ -113,7 +113,7 @@ func TestGetCommandGradle(t *testing.T) {
jibGradleArtifact: latest.JibGradleArtifact{},
filesInWorkspace: []string{"gradlew", "gradlew.cmd"},
expectedCmd: func(workspace string) *exec.Cmd {
return GradleCommand.CreateCommand(ctx, workspace, []string{"_jibSkaffoldFiles", "-q"})
return GradleCommand.CreateCommand(ctx, workspace, []string{":_jibSkaffoldFiles", "-q"})
},
},
{
Expand Down
36 changes: 20 additions & 16 deletions pkg/skaffold/jib/jib_maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,43 @@ func GetDependenciesMaven(ctx context.Context, workspace string, a *latest.JibMa
}

func getCommandMaven(ctx context.Context, workspace string, a *latest.JibMavenArtifact) *exec.Cmd {
var args []string
args = append(args, "--quiet")
if a.Profile != "" {
args = append(args, "--activate-profiles", a.Profile)
}
args := mavenArgs(a)
args = append(args, "jib:_skaffold-files", "--quiet")

return MavenCommand.CreateCommand(ctx, workspace, args)
}

// GenerateMavenArgs generates the arguments to Maven for building the project as an image.
func GenerateMavenArgs(goal string, imageName string, a *latest.JibMavenArtifact) []string {
args := mavenArgs(a)

if a.Module == "" {
// single-module project
args = append(args, "--non-recursive")
args = append(args, "prepare-package", "jib:"+goal)
} else {
// multi-module project
args = append(args, "--projects", a.Module, "--also-make")
// multi-module project: we assume `package` is bound to `jib:<goal>`
args = append(args, "package")
}
args = append(args, "jib:_skaffold-files")

return MavenCommand.CreateCommand(ctx, workspace, args)
args = append(args, "-Dimage="+imageName)

return args
}

// GenerateMavenArgs generates the arguments to Maven for building the project as an image.
func GenerateMavenArgs(goal string, imageName string, a *latest.JibMavenArtifact) []string {
func mavenArgs(a *latest.JibMavenArtifact) []string {
var args []string

if a.Profile != "" {
args = append(args, "--activate-profiles", a.Profile)
}

if a.Module == "" {
// single-module project
args = append(args, "--non-recursive")
args = append(args, "prepare-package", "jib:"+goal)
} else {
// multi-module project: we assume `package` is bound to `jib:<goal>`
// multi-module project
args = append(args, "--projects", a.Module, "--also-make")
args = append(args, "package")
}
args = append(args, "-Dimage="+imageName)

return args
}
12 changes: 6 additions & 6 deletions pkg/skaffold/jib/jib_maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,47 +96,47 @@ func TestGetCommandMaven(t *testing.T) {
jibMavenArtifact: latest.JibMavenArtifact{},
filesInWorkspace: []string{},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--non-recursive", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--non-recursive", "jib:_skaffold-files", "--quiet"})
},
},
{
description: "maven with profile",
jibMavenArtifact: latest.JibMavenArtifact{Profile: "profile"},
filesInWorkspace: []string{},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--activate-profiles", "profile", "--non-recursive", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--activate-profiles", "profile", "--non-recursive", "jib:_skaffold-files", "--quiet"})
},
},
{
description: "maven with wrapper no profile",
jibMavenArtifact: latest.JibMavenArtifact{},
filesInWorkspace: []string{"mvnw", "mvnw.bat"},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--non-recursive", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--non-recursive", "jib:_skaffold-files", "--quiet"})
},
},
{
description: "maven with wrapper no profile",
jibMavenArtifact: latest.JibMavenArtifact{},
filesInWorkspace: []string{"mvnw", "mvnw.cmd"},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--non-recursive", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--non-recursive", "jib:_skaffold-files", "--quiet"})
},
},
{
description: "maven with wrapper and profile",
jibMavenArtifact: latest.JibMavenArtifact{Profile: "profile"},
filesInWorkspace: []string{"mvnw", "mvnw.bat"},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--activate-profiles", "profile", "--non-recursive", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--activate-profiles", "profile", "--non-recursive", "jib:_skaffold-files", "--quiet"})
},
},
{
description: "maven with multi-modules",
jibMavenArtifact: latest.JibMavenArtifact{Module: "module"},
filesInWorkspace: []string{"mvnw", "mvnw.bat"},
expectedCmd: func(workspace string) *exec.Cmd {
return MavenCommand.CreateCommand(ctx, workspace, []string{"--quiet", "--projects", "module", "--also-make", "jib:_skaffold-files"})
return MavenCommand.CreateCommand(ctx, workspace, []string{"--projects", "module", "--also-make", "jib:_skaffold-files", "--quiet"})
},
},
}
Expand Down