diff options
author | 2017-01-16 13:39:05 +0000 | |
---|---|---|
committer | 2017-01-16 13:48:59 +0000 | |
commit | a1dd398f2a7a022d8d04d4ce0d2d2934dd355195 (patch) | |
tree | b54d3e22b9647c82a899dca336f702bc1cdd5854 | |
parent | 56328986232dfe4d92f738ab3bbd26d89236a428 (diff) |
Adding output_licenses to bazel's java_plugin.
Fixes #2286.
--
PiperOrigin-RevId: 144627152
MOS_MIGRATED_REVID=144627152
3 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java index 86e97e0651..8749a70a41 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaPluginRule.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.bazel.rules.java; import static com.google.devtools.build.lib.packages.Attribute.attr; +import static com.google.devtools.build.lib.packages.BuildType.LICENSE; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; import static com.google.devtools.build.lib.syntax.Type.STRING; @@ -51,6 +52,11 @@ public final class BazelJavaPluginRule implements RuleDefinition { java.util.ServiceLoader</a>.) <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr("processor_class", STRING)) + /* <!-- #BLAZE_RULE(java_plugin).ATTRIBUTE(output_licenses) --> + See <a href="${link common-definitions#binary.output_licenses}"><code>common attributes + </code></a> + <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ + .add(attr("output_licenses", LICENSE)) /* <!-- #BLAZE_RULE(java_plugin).ATTRIBUTE(generates_api) --> This attribute marks annotation processors that generate API code. <p>If a rule uses an API-generating annotation processor, other rules diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD index bc018d7299..c48a0ddada 100644 --- a/src/test/java/com/google/devtools/build/lib/BUILD +++ b/src/test/java/com/google/devtools/build/lib/BUILD @@ -306,6 +306,7 @@ java_test( java_library( name = "analysis_testutil", srcs = glob([ + "analysis/LicensingTests.java", "analysis/mock/BazelAnalysisMock.java", "analysis/util/*.java", "exec/util/*.java", diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/java/BazelLicensingTests.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/java/BazelLicensingTests.java new file mode 100644 index 0000000000..977753a4c0 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/java/BazelLicensingTests.java @@ -0,0 +1,60 @@ +// Copyright 2015 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. + +package com.google.devtools.build.lib.bazel.rules.java; + + +import com.google.common.collect.Maps; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.LicensingTests; +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.packages.License; +import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Integration tests for {@link License}. + */ +@RunWith(JUnit4.class) +public class BazelLicensingTests extends LicensingTests { + @Test + public void testJavaPluginAllowsOutputLicenseDeclaration() throws Exception { + scratch.file("ise/BUILD", + "licenses(['restricted'])", + "java_library(name = 'dependency',", + " srcs = ['dependency.java'])", + "java_plugin(name = 'plugin',", + " deps = [':dependency'],", + " srcs = ['plugin.java'],", + " output_licenses = ['unencumbered'])"); + + scratch.file("gsa/BUILD", + "licenses(['unencumbered'])", + "java_library(name = 'library',", + " srcs = ['library.java'],", + " plugins = ['//ise:plugin'])"); + + ConfiguredTarget library = getConfiguredTarget("//gsa:library"); + Map<Label, License> actual = Maps.filterKeys(getTransitiveLicenses(library), + CC_OR_JAVA_OR_SH_LABEL_FILTER); + Map<Label, License> expected = licenses( + "//ise:plugin", "unencumbered", + "//gsa:library", "unencumbered" + ); + + assertSameMapEntries(expected, actual); + } +} |