// Copyright 2014 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.rules.java; import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.LanguageDependentFragment.LibraryLanguage; import com.google.devtools.build.lib.analysis.OutputGroupProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.analysis.Runfiles.Builder; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.packages.Attribute.LateBoundLabel; import com.google.devtools.build.lib.packages.Attribute.LateBoundLabelList; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression; import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Collection; import java.util.List; import javax.annotation.Nullable; /** * Pluggable Java compilation semantics. */ public interface JavaSemantics { LibraryLanguage LANGUAGE = new LibraryLanguage("Java"); SafeImplicitOutputsFunction JAVA_LIBRARY_CLASS_JAR = fromTemplates("lib%{name}.jar"); SafeImplicitOutputsFunction JAVA_LIBRARY_SOURCE_JAR = fromTemplates("lib%{name}-src.jar"); SafeImplicitOutputsFunction JAVA_BINARY_CLASS_JAR = fromTemplates("%{name}.jar"); SafeImplicitOutputsFunction JAVA_BINARY_SOURCE_JAR = fromTemplates("%{name}-src.jar"); SafeImplicitOutputsFunction JAVA_BINARY_DEPLOY_JAR = fromTemplates("%{name}_deploy.jar"); SafeImplicitOutputsFunction JAVA_BINARY_MERGED_JAR = fromTemplates("%{name}_merged.jar"); SafeImplicitOutputsFunction JAVA_UNSTRIPPED_BINARY_DEPLOY_JAR = fromTemplates("%{name}_deploy.jar.unstripped"); SafeImplicitOutputsFunction JAVA_BINARY_PROGUARD_MAP = fromTemplates("%{name}_proguard.map"); SafeImplicitOutputsFunction JAVA_BINARY_PROGUARD_PROTO_MAP = fromTemplates("%{name}_proguard.pbmap"); SafeImplicitOutputsFunction JAVA_BINARY_PROGUARD_CONFIG = fromTemplates("%{name}_proguard.config"); SafeImplicitOutputsFunction JAVA_BINARY_DEPLOY_SOURCE_JAR = fromTemplates("%{name}_deploy-src.jar"); FileType JAVA_SOURCE = FileType.of(".java"); FileType JAR = FileType.of(".jar"); FileType PROPERTIES = FileType.of(".properties"); FileType SOURCE_JAR = FileType.of(".srcjar"); // TODO(bazel-team): Rename this metadata extension to something meaningful. FileType COVERAGE_METADATA = FileType.of(".em"); /** * Label to the Java Toolchain rule. It is resolved from a label given in the java options. */ String JAVA_TOOLCHAIN_LABEL = "//tools/defaults:java_toolchain"; /** The java_toolchain.compatible_javacopts key for Java 7 javacopts */ public static final String JAVA7_JAVACOPTS_KEY = "java7"; LateBoundLabel JAVA_TOOLCHAIN = new LateBoundLabel(JAVA_TOOLCHAIN_LABEL, JavaConfiguration.class) { @Override public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { return configuration.getFragment(JavaConfiguration.class).getToolchainLabel(); } }; /** * Name of the output group used for source jars. */ String SOURCE_JARS_OUTPUT_GROUP = OutputGroupProvider.HIDDEN_OUTPUT_GROUP_PREFIX + "source_jars"; /** * Name of the output group used for gen jars (the jars containing the class files for sources * generated from annotation processors). */ String GENERATED_JARS_OUTPUT_GROUP = OutputGroupProvider.HIDDEN_OUTPUT_GROUP_PREFIX + "gen_jars"; /** * Implementation for the :jvm attribute. */ LateBoundLabel JVM = new LateBoundLabel(JavaImplicitAttributes.JDK_LABEL, Jvm.class) { @Override public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { return configuration.getFragment(Jvm.class).getJvmLabel(); } }; /** * Implementation for the :host_jdk attribute. */ LateBoundLabel HOST_JDK = new LateBoundLabel(JavaImplicitAttributes.JDK_LABEL, Jvm.class) { @Override public boolean useHostConfiguration() { return true; } @Override public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) { return configuration.getFragment(Jvm.class).getJvmLabel(); } }; LateBoundLabelList JAVA_PLUGINS = new LateBoundLabelList() { @Override public List