diff options
author | Kristina Chodorow <kchodorow@google.com> | 2015-08-20 16:24:17 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2015-08-21 09:43:16 +0000 |
commit | d34488544835edce8fa15abd07e00be472b959b9 (patch) | |
tree | 27890d457a07d764bdad52ee0c72d1f25eb99476 /src/test/shell | |
parent | 5b378dbb79d9b29c4a9ceea13c5f558c8f027744 (diff) |
Find parent and submodule definitions before fully resolving a pom
The Maven API has two options for parsing pom files: getting the "raw model"
(which parses the pom to ensure it is correct, but doesn't do any resolution nor
variable substitution) and getting the "effective model," which does all
resolution. Before this CL, generate_workspace was just getting the effective
model immediately, which is easily foiled by having an artifact that depends on
a "sibling" (the parent cannot be resolved until the siblings are and the
siblings can only be resolved if they happen to arrive in the right order).
This changes the code to get the raw models first to get locations of all
artifacts, then fully resolve them.
This fixes #383.
--
MOS_MIGRATED_REVID=101129094
Diffstat (limited to 'src/test/shell')
-rwxr-xr-x | src/test/shell/bazel/generate_workspace_test.sh | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/src/test/shell/bazel/generate_workspace_test.sh b/src/test/shell/bazel/generate_workspace_test.sh index 830bc5a4d0..893c4b502d 100755 --- a/src/test/shell/bazel/generate_workspace_test.sh +++ b/src/test/shell/bazel/generate_workspace_test.sh @@ -40,6 +40,10 @@ function tear_down() { rm -rf $m2 } +function generate_workspace() { + ${bazel_data}/src/main/java/com/google/devtools/build/workspace/generate_workspace $@ +} + # Takes: groupId, artifactId, and version. function make_artifact() { local groupId=$1 @@ -82,6 +86,14 @@ function wait_for_server_startup() { rm some-file } +function get_workspace_file() { + cat $TEST_log | tail -n 2 | head -n 1 +} + +function get_build_file() { + cat $TEST_log | tail -n 1 +} + function test_pom() { # Create a maven repo make_artifact blorp glorp 1.2.3 @@ -122,9 +134,22 @@ EOF assert_contains "\"@blorp/glorp//jar\"," build } -function test_profile() { +function test_invalid_pom() { + # No pom file. + rm -f $TEST_TMPDIR/pom.xml + generate_workspace -m $TEST_TMPDIR &> $TEST_log + expect_log "Non-readable POM $TEST_TMPDIR/pom.xml" + + # Invalid XML. cat > $TEST_TMPDIR/pom.xml <<EOF +<project> +EOF + generate_workspace -m $TEST_TMPDIR &> $TEST_log + expect_log "expected end tag </project>" +} +function test_profile() { + cat > $TEST_TMPDIR/pom.xml <<EOF <project> <modelVersion>4.0.0</modelVersion> <groupId>my</groupId> @@ -148,4 +173,57 @@ EOF --maven_project=$TEST_TMPDIR &> $TEST_log || fail "generating workspace failed" } +function test_submodules() { + cat > $TEST_TMPDIR/pom.xml <<EOF +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>xyz</groupId> + <artifactId>a</artifactId> + <version>1.0</version> + <packaging>pom</packaging> + <modules> + <module>b1</module> + <module>b2</module> + </modules> +</project> +EOF + + # Create submodules, version and group are inherited from parent. + mkdir -p $TEST_TMPDIR/{b1,b2} + cat > $TEST_TMPDIR/b1/pom.xml <<EOF +<project> + <modelVersion>4.0.0</modelVersion> + <artifactId>b1</artifactId> + <parent> + <groupId>xyz</groupId> + <artifactId>a</artifactId> + <version>1.0</version> + </parent> + <dependencies> + <dependency> + <groupId>xyz</groupId> + <artifactId>b2</artifactId> + <version>1.0</version> + </dependency> + </dependencies> +</project> +EOF + + cat > $TEST_TMPDIR/b2/pom.xml <<EOF +<project> + <modelVersion>4.0.0</modelVersion> + <artifactId>b2</artifactId> + <parent> + <groupId>xyz</groupId> + <artifactId>a</artifactId> + <version>1.0</version> + </parent> +</project> +EOF + + generate_workspace -m $TEST_TMPDIR/b1 &> $TEST_log || fail "generate failed" + expect_log "xyz/b2 was defined in $TEST_TMPDIR/b2/pom.xml which isn't a repository URL" + assert_contains "artifact = \"xyz:b2:1.0\"," $(get_workspace_file) +} + run_suite "maven tests" |