当前位置: 首页>>代码示例>>Java>>正文


Java SkylarkList.createImmutable方法代码示例

本文整理汇总了Java中com.google.devtools.build.lib.syntax.SkylarkList.createImmutable方法的典型用法代码示例。如果您正苦于以下问题:Java SkylarkList.createImmutable方法的具体用法?Java SkylarkList.createImmutable怎么用?Java SkylarkList.createImmutable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.devtools.build.lib.syntax.SkylarkList的用法示例。


在下文中一共展示了SkylarkList.createImmutable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public SkylarkList<Transformation> invoke(Core self, SkylarkList<Transformation> transforms,
    Location location)
    throws EvalException {

  ImmutableList.Builder<Transformation> builder = ImmutableList.builder();
  for (Transformation t : transforms.getContents(Transformation.class, "transformations")) {
    try {
      builder.add(t.reverse());
    } catch (NonReversibleValidationException e) {
      throw new EvalException(location, e.getMessage());
    }
  }

  return SkylarkList.createImmutable(builder.build().reverse());
}
 
开发者ID:google,项目名称:copybara,代码行数:17,代码来源:Core.java

示例2: transform

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@SkylarkCallable(
    name = "run", doc = "Run a glob or a transform. For example:<br>"
    + "<code>files = ctx.run(glob(['**.java']))</code><br>or<br>"
    + "<code>ctx.run(core.move(\"foo\", \"bar\"))</code><br>or<br>",
    parameters = {
        @Param(name = "runnable", type = Object.class,
            doc = "A glob or a transform (Transforms still not implemented)"),
    })
public Object run(Object runnable) throws EvalException, IOException, ValidationException {
  if (runnable instanceof Glob) {
    PathMatcher pathMatcher = ((Glob) runnable).relativeTo(checkoutDir);

    try (Stream<Path> stream = Files.walk(checkoutDir)) {
      return SkylarkList.createImmutable(
          stream
              .filter(Files::isRegularFile)
              .filter(pathMatcher::matches)
              .map(p -> new CheckoutPath(checkoutDir.relativize(p), checkoutDir))
              .collect(Collectors.toList()));
    }
  } else if (runnable instanceof Transformation) {
    // Works like Sequence. We keep always the latest transform work to allow
    // catching for two sequential replaces.
    skylarkTransformWork = skylarkTransformWork.withUpdatedTreeState();
    ((Transformation) runnable).transform(skylarkTransformWork);
    this.updateFrom(skylarkTransformWork);
    return Runtime.NONE;
  }

  throw new EvalException(null, String.format(
      "Only globs or transforms can be run, but '%s' is of type %s",
      runnable, runnable.getClass()));
}
 
开发者ID:google,项目名称:copybara,代码行数:34,代码来源:TransformWork.java

示例3: findLabelValues

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
private SkylarkList<String> findLabelValues(String label, boolean all) {
  Map<String, ImmutableList<String>> coreLabels = getCoreLabels();
  if (coreLabels.containsKey(label)) {
    return SkylarkList.createImmutable(coreLabels.get(label));
  }
  ArrayList<String> result = new ArrayList<>();
  ImmutableList<LabelFinder> msgLabel = getLabelInMessage(label);
  if (!msgLabel.isEmpty()) {
    result.addAll(Lists.transform(msgLabel, LabelFinder::getValue));
    if (!all) {
      return SkylarkList.createImmutable(result);
    }
  }
  // Try to find the label in the current changes migrated. We prioritize current
  // changes over resolvedReference. Since in iterative mode this would be more
  // specific to the current migration.
  for (Change<?> change : changes.getCurrent()) {
    SkylarkList<String> val = change.getLabelsAllForSkylark().get(label);
    if (val != null) {
      result.addAll(val);
      if (!all) {
        return SkylarkList.createImmutable(result);
      }
    }
  }

  // Try to find the label in the resolved reference
  String resolvedRefLabel = resolvedReference.associatedLabels().get(label);
  if (resolvedRefLabel != null) {
    result.add(resolvedRefLabel);
  }
  return SkylarkList.createImmutable(result);
}
 
开发者ID:google,项目名称:copybara,代码行数:34,代码来源:TransformWork.java

示例4: files

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@SkylarkCallable(
    name = "source_jars",
    doc = "Returns a list of jar files containing all the uncompiled source files (including "
    + "those generated by annotations) from the target itself, i.e. NOT including the sources of "
    + "the transitive dependencies",
    structField = true
)
public SkylarkList<Artifact> getSourceJars() {
  //TODO(#4221) change return type to NestedSet<Artifact>
  JavaSourceJarsProvider provider = providers.getProvider(JavaSourceJarsProvider.class);
  ImmutableList<Artifact> sourceJars =
      provider == null ? ImmutableList.of() : provider.getSourceJars();
  return SkylarkList.createImmutable(sourceJars);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:15,代码来源:JavaInfo.java

示例5: getSrcJarsSkylark

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@Nullable
@SkylarkCallable(
  name = "source_jars",
  doc = "A list of sources archive files.",
  allowReturnNones = true,
  structField = true
)
public SkylarkList<Artifact> getSrcJarsSkylark() {
  return SkylarkList.createImmutable(srcJars);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:11,代码来源:JavaRuleOutputJarsProvider.java

示例6: tokenize

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@SkylarkCallable(doc = "Splits a shell command to a list of tokens.", documented = false)
public SkylarkList<String> tokenize(String optionString) throws FuncallException, EvalException {
  checkMutable("tokenize");
  List<String> options = new ArrayList<>();
  try {
    ShellUtils.tokenize(options, optionString);
  } catch (TokenizationException e) {
    throw new FuncallException(e.getMessage() + " while tokenizing '" + optionString + "'");
  }
  return SkylarkList.createImmutable(options);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:SkylarkRuleContext.java

示例7: Changes

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
public Changes(Iterable<? extends Change<?>> current, Iterable<? extends Change<?>> migrated) {
  this.current = SkylarkList.createImmutable(current);
  this.migrated = SkylarkList.createImmutable(migrated);
}
 
开发者ID:google,项目名称:copybara,代码行数:5,代码来源:Changes.java

示例8: getSkylarkArgv

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
@Override
public SkylarkList<String> getSkylarkArgv() throws CommandLineExpansionException {
  return SkylarkList.createImmutable(getArguments());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:5,代码来源:SpawnAction.java

示例9: buildSplitAttributeInfo

import com.google.devtools.build.lib.syntax.SkylarkList; //导入方法依赖的package包/类
private static Info buildSplitAttributeInfo(
    Collection<Attribute> attributes, RuleContext ruleContext) {

  ImmutableMap.Builder<String, Object> splitAttrInfos = ImmutableMap.builder();
  for (Attribute attr : attributes) {

    if (attr.hasSplitConfigurationTransition()) {

      Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> splitPrereqs =
          ruleContext.getSplitPrerequisites(attr.getName());

      Map<Object, Object> splitPrereqsMap = new LinkedHashMap<>();
      for (Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> splitPrereq
          : splitPrereqs.entrySet()) {

        Object value;
        if (attr.getType() == BuildType.LABEL) {
          Preconditions.checkState(splitPrereq.getValue().size() == 1);
          value = splitPrereq.getValue().get(0);
        } else {
          // BuildType.LABEL_LIST
          value = SkylarkList.createImmutable(splitPrereq.getValue());
        }

        if (splitPrereq.getKey().isPresent()) {
          splitPrereqsMap.put(splitPrereq.getKey().get(), value);
        } else {
          // If the split transition is not in effect, then the key will be missing since there's
          // nothing to key on because the dependencies aren't split and getSplitPrerequisites()
          // behaves like getPrerequisites(). This also means there should be only one entry in
          // the map. Use None in Skylark to represent this.
          Preconditions.checkState(splitPrereqs.size() == 1);
          splitPrereqsMap.put(Runtime.NONE, value);
        }
      }

      splitAttrInfos.put(attr.getPublicName(), SkylarkDict.copyOf(null, splitPrereqsMap));
    }
  }

  return NativeProvider.STRUCT.create(
      splitAttrInfos.build(),
      "No attribute '%s' in split_attr. Make sure that this attribute is defined with a "
          + "split configuration.");
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:46,代码来源:SkylarkRuleContext.java


注:本文中的com.google.devtools.build.lib.syntax.SkylarkList.createImmutable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。