forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of maven_jar rule in Skylark.
This is an initial implementation of the maven_jar rule in Skylark, targeted at the FRs in issue bazelbuild#1410. Attributes `name`, `artifact`, `repository`, `sha1` have been implemented, but not `server`. Implemented a wrapper around the maven binary to pull dependencies from remote repositories into a directory under {output_base}/external. Caveat: this rule assumes that the Maven dependency is installed in the system. Hence, the maven_skylark_test integration tests are tagged with "manual" because the Bazel CI isn't configured with the Maven binary yet. Added a serve_not_found helper for 404 response tests. Added a `maven_local_repository` rule to fetch the initial maven dependency plugin for bazel tests. With regards to server, there are some limitations with retrieving a maven_server's attribute at Loading Phase without the use of hacky macros (issue bazelbuild#1704), and even if macros are used, the maven_server is not treated as an actual dependency by maven_jar. There is a test (`test_unimplemented_server_attr`) to ensure that the error message to shown to users if they use the server attribute with this rule. I will have to put more work into implementing maven_server appropriately, and possibly proposing an API review of maven_jar in another change set. Change-Id: I167f9d13835c30be971928b4cc60167a8e396893
- Loading branch information
Showing
8 changed files
with
591 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2016 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Test //external mechanisms | ||
# | ||
|
||
# Load test environment | ||
src=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd) | ||
source $src/test-setup.sh \ | ||
|| { echo "test-setup.sh not found!" >&2; exit 1; } | ||
source $src/remote_helpers.sh \ | ||
|| { echo "remote_helpers.sh not found!" >&2; exit 1; } | ||
|
||
function setup_zoo() { | ||
mkdir -p zoo | ||
cat > zoo/BUILD <<EOF | ||
java_binary( | ||
name = "ball-pit", | ||
srcs = ["BallPit.java"], | ||
main_class = "BallPit", | ||
deps = ["//external:mongoose"], | ||
) | ||
EOF | ||
|
||
cat > zoo/BallPit.java <<EOF | ||
import carnivore.Mongoose; | ||
public class BallPit { | ||
public static void main(String args[]) { | ||
Mongoose.frolic(); | ||
} | ||
} | ||
EOF | ||
} | ||
|
||
function tear_down() { | ||
shutdown_server | ||
} | ||
|
||
function test_maven_jar_skylark() { | ||
setup_zoo | ||
version="1.21" | ||
serve_artifact com.example.carnivore carnivore $version | ||
|
||
cat > WORKSPACE <<EOF | ||
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") | ||
maven_jar( | ||
name = 'endangered', | ||
artifact = "com.example.carnivore:carnivore:$version", | ||
repository = 'http://localhost:$fileserver_port/', | ||
sha1 = '$sha1', | ||
) | ||
local_repository( | ||
name = "m2", | ||
path = "$TEST_SRCDIR/m2", | ||
) | ||
bind(name = 'mongoose', actual = '@endangered//jar') | ||
EOF | ||
|
||
bazel run //zoo:ball-pit >& $TEST_log || fail "Expected run to succeed" | ||
expect_log "Tra-la!" | ||
} | ||
|
||
# Same as test_maven_jar, except omit sha1 implying "we don't care". | ||
function test_maven_jar_no_sha1_skylark() { | ||
setup_zoo | ||
version="1.22" | ||
serve_artifact com.example.carnivore carnivore $version | ||
|
||
cat > WORKSPACE <<EOF | ||
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") | ||
maven_jar( | ||
name = 'endangered', | ||
artifact = "com.example.carnivore:carnivore:$version", | ||
repository = 'http://localhost:$fileserver_port/', | ||
) | ||
local_repository( | ||
name = "m2", | ||
path = "$TEST_SRCDIR/m2", | ||
) | ||
bind(name = 'mongoose', actual = '@endangered//jar') | ||
EOF | ||
|
||
bazel run //zoo:ball-pit >& $TEST_log || fail "Expected run to succeed" | ||
expect_log "Tra-la!" | ||
} | ||
|
||
function test_maven_jar_404_skylark() { | ||
setup_zoo | ||
version="1.23" | ||
serve_not_found | ||
|
||
cat > WORKSPACE <<EOF | ||
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") | ||
maven_jar( | ||
name = 'endangered', | ||
artifact = "com.example.carnivore:carnivore:$version", | ||
repository = 'http://localhost:$nc_port/', | ||
) | ||
local_repository( | ||
name = "m2", | ||
path = "$TEST_SRCDIR/m2", | ||
) | ||
bind(name = 'mongoose', actual = '@endangered//jar') | ||
EOF | ||
|
||
bazel clean --expunge | ||
bazel build //zoo:ball-pit >& $TEST_log && echo "Expected build to fail" | ||
kill_nc | ||
expect_log "Failed to fetch Maven dependency" | ||
} | ||
|
||
function test_maven_jar_mismatched_sha1_skylark() { | ||
setup_zoo | ||
version="1.24" | ||
serve_artifact com.example.carnivore carnivore 1.24 | ||
|
||
wrong_sha1="0123456789012345678901234567890123456789" | ||
cat > WORKSPACE <<EOF | ||
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") | ||
maven_jar( | ||
name = 'endangered', | ||
artifact = "com.example.carnivore:carnivore:1.24", | ||
repository = 'http://localhost:$fileserver_port/', | ||
sha1 = '$wrong_sha1', | ||
) | ||
local_repository( | ||
name = "m2", | ||
path = "$TEST_SRCDIR/m2", | ||
) | ||
bind(name = 'mongoose', actual = '@endangered//jar') | ||
EOF | ||
|
||
bazel fetch //zoo:ball-pit >& $TEST_log && echo "Expected fetch to fail" | ||
expect_log "has SHA-1 of $sha1, does not match expected SHA-1 ($wrong_sha1)" | ||
} | ||
|
||
function test_unimplemented_server_attr_skylark() { | ||
setup_zoo | ||
version="1.25" | ||
serve_jar | ||
|
||
cat > WORKSPACE <<EOF | ||
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") | ||
maven_jar( | ||
name = 'endangered', | ||
artifact = "com.example.carnivore:carnivore:$version", | ||
server = "attr_not_implemented" | ||
) | ||
local_repository( | ||
name = "m2", | ||
path = "$TEST_SRCDIR/m2", | ||
) | ||
bind(name = 'mongoose', actual = '@endangered//jar') | ||
EOF | ||
|
||
bazel build //zoo:ball-pit >& $TEST_log && echo "Expected build to fail" | ||
kill_nc | ||
expect_log "specifies a 'server' attribute which is currently not supported." | ||
} | ||
|
||
run_suite "maven skylark tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
filegroup( | ||
name = "files", | ||
srcs = glob(['**']), | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.