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

Skaffold init support for polyglot-maven projects #4871

Merged
merged 2 commits into from
Oct 8, 2020
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
11 changes: 9 additions & 2 deletions pkg/skaffold/build/jib/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ func validate(path string, enableGradleAnalysis bool) []ArtifactConfig {
var builderType PluginType
var executable, wrapper, taskName, searchString, consoleFlag string
switch {
case strings.HasSuffix(path, "pom.xml"):
case isPomFile(path):
builderType = JibMaven
executable = "mvn"
wrapper = "mvnw"
searchString = "<artifactId>jib-maven-plugin</artifactId>"
searchString = "jib-maven-plugin"
taskName = "jib:_skaffold-init"
consoleFlag = "--batch-mode"

case enableGradleAnalysis && (strings.HasSuffix(path, "build.gradle") || strings.HasSuffix(path, "build.gradle.kts")):
builderType = JibGradle
executable = "gradle"
Expand Down Expand Up @@ -148,3 +149,9 @@ func validate(path string, enableGradleAnalysis bool) []ArtifactConfig {
}
return results
}

// checks that the file is a maven pom file, and returns the file extension
func isPomFile(path string) bool {
filename := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
return filename == "pom"
}
22 changes: 22 additions & 0 deletions pkg/skaffold/build/jib/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ BEGIN JIB JSON
{BuilderName: PluginName(JibMaven), File: "path/to/pom.xml", Project: "project2"},
},
},
{
description: "jib maven pom.atom single module",
path: "path/to/pom.atom",
fileContents: "com.google.cloud.tools:jib-maven-plugin",
command: "mvn jib:_skaffold-init -q --batch-mode",
stdout: `BEGIN JIB JSON
{"image":"image","project":"project"}`,
expectedConfig: []ArtifactConfig{
{BuilderName: PluginName(JibMaven), File: "path/to/pom.atom", Image: "image", Project: "project"},
},
},
{
description: "jib maven pom.scala single module",
path: "path/to/pom.scala",
fileContents: `"com.google.cloud.tools" % "jib-maven-plugin"`,
command: "mvn jib:_skaffold-init -q --batch-mode",
stdout: `BEGIN JIB JSON
{"image":"image","project":"project"}`,
expectedConfig: []ArtifactConfig{
{BuilderName: PluginName(JibMaven), File: "path/to/pom.scala", Image: "image", Project: "project"},
},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand Down