// Copyright 2015 Google Inc. 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 com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.rules.SkylarkApiProvider;
import com.google.devtools.build.lib.syntax.SkylarkCallable;
import com.google.devtools.build.lib.syntax.SkylarkModule;

/**
 * A class that exposes the Java providers to Skylark. It is intended to provide a
 * simple and stable interface for Skylark users.
 */
@SkylarkModule(
    name = "JavaSkylarkApiProvider", doc = "Provides access to information about Java rules")
public final class JavaSkylarkApiProvider extends SkylarkApiProvider {
  /** The name of the field in Skylark used to access this class. */
  static final String NAME = "java";

  @SkylarkCallable(
      name = "source_jars",
      doc = "Returns the Jars containing Java source files for the target",
      structField = true)
  public ImmutableList<Artifact> getSourceJars() {
    JavaSourceJarsProvider sourceJars = getInfo().getProvider(JavaSourceJarsProvider.class);
    return sourceJars.getSourceJars();
  }

  @SkylarkCallable(
      name = "transitive_source_jars",
      doc =
          "Returns the Jars containing Java source files for the target and all of its transitive "
              + "dependencies",
      structField = true)
  public NestedSet<Artifact> getTransitiveSourceJars() {
    JavaSourceJarsProvider sourceJars = getInfo().getProvider(JavaSourceJarsProvider.class);
    return sourceJars.getTransitiveSourceJars();
  }
}

@@ -657,56 +657,8 @@
 a;%0A%0A
-import com.google.common.collect.ImmutableList;%0A
 impo
@@ -774,16 +774,151 @@
 tedSet;%0A
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;%0Aimport com.google.devtools.build.lib.collect.nestedset.Order;%0A
 import c
@@ -1685,20 +1685,16 @@
 lic 
-ImmutableLis
+NestedSe
 t%3CAr
@@ -1827,27 +1827,861 @@
 urn 
-sourceJars.getSourc
+NestedSetBuilder.wrap(Order.STABLE_ORDER, sourceJars.getSourceJars());%0A  %7D%0A%0A  @SkylarkCallable(%0A      name = %22transitive_deps%22,%0A      doc =  %22Returns the transitive set of Jars required to build the target%22,%0A      structField = true)%0A  public NestedSet%3CArtifact%3E getTransitiveDeps() %7B%0A    JavaCompilationArgsProvider args = getInfo().getProvider(JavaCompilationArgsProvider.class);%0A    return args.getRecursiveJavaCompilationArgs().getCompileTimeJars();%0A  %7D%0A%0A  @SkylarkCallable(%0A      name = %22transitive_runtime_deps%22,%0A      doc =  %22Returns the transitive set of Jars required on the target's runtime classpath%22,%0A      structField = true)%0A  public NestedSet%3CArtifact%3E getTransitiveRuntimeDeps() %7B%0A    JavaCompilationArgsProvider args = getInfo().getProvider(JavaCompilationArgsProvider.class);%0A    return args.getRecursiveJavaCompilationArgs().getRuntim
 eJar

Make Java transitive runtime and compile time deps available to Skylark.