Skip to content

Add support for building Maven multimodule projects #1152

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

Merged
merged 13 commits into from
Oct 19, 2018
4 changes: 1 addition & 3 deletions pkg/skaffold/build/local/jib_maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package local
import (
"context"
"io"
"strings"

"fmt"

Expand Down Expand Up @@ -99,8 +98,7 @@ func verifyJibPackageGoal(ctx context.Context, requiredGoal string, workspace st
if err != nil {
return errors.Wrap(err, "could not obtain jib package goals")
}
// need to trim last newline
goals := strings.Split(strings.TrimSpace(string(stdout)), "\n")
goals := util.NonEmptyLines(stdout)
logrus.Debugf("jib bound package goals for %s %s: %v (%d)", workspace, a.Module, goals, len(goals))
if len(goals) != 1 {
return errors.New("skaffold requires a single jib goal bound to 'package'")
Expand Down
3 changes: 1 addition & 2 deletions pkg/skaffold/jib/jib.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package jib
import (
"os/exec"
"sort"
"strings"

"os"

Expand All @@ -36,7 +35,7 @@ func getDependencies(cmd *exec.Cmd) ([]string, error) {
}

// Parses stdout for the dependencies, one per line
lines := strings.Split(string(stdout), "\n")
lines := util.NonEmptyLines(stdout)

var deps []string
for _, dep := range lines {
Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package util

import (
"bufio"
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -227,3 +229,15 @@ func AbsFile(workspace string, filename string) (string, error) {
}
return filepath.Abs(file)
}

// NonEmptyLines scans the provided input and returns the non-empty strings found as an array
func NonEmptyLines(input []byte) []string {
var result = []string{}
scanner := bufio.NewScanner(bytes.NewReader(input))
for scanner.Scan() {
if line := scanner.Text(); len(line) > 0 {
result = append(result, line)
}
}
return result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should handle scanner.Err() here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions on what should happen? The input is a bag o' bytes rather than real I/O.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just ignore my comment then.

}
20 changes: 20 additions & 0 deletions pkg/skaffold/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,23 @@ func TestAbsFile(t *testing.T) {
_, err = AbsFile(tmpDir.Root(), "does-not-exist")
testutil.CheckError(t, true, err)
}

func TestNonEmptyLines(t *testing.T) {
var testCases = []struct {
in string
out []string
}{
{"", []string{}},
{"a\n", []string{"a"}},
{"a\r\n", []string{"a"}},
{"a\r\nb", []string{"a", "b"}},
{"a\r\nb\n\n", []string{"a", "b"}},
{"\na\r\n\n\n", []string{"a"}},
}
for _, tt := range testCases {
t.Run(tt.in, func(t *testing.T) {
result := NonEmptyLines([]byte(tt.in))
testutil.CheckDeepEqual(t, tt.out, result)
})
}
}