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


Java SourcePath.resolve方法代码示例

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


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

示例1: addSourcePathToSourcesBuildPhase

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
private void addSourcePathToSourcesBuildPhase(
    SourcePath sourcePath,
    PBXGroup sourcesGroup,
    PBXSourcesBuildPhase sourcesBuildPhase,
    ImmutableMap<SourcePath, String> sourceFlags) {
  Path path = sourcePath.resolve();
  PBXFileReference fileReference = sourcesGroup.getOrCreateFileReferenceBySourceTreePath(
      new SourceTreePath(
          PBXReference.SourceTree.SOURCE_ROOT,
          repoRootRelativeToOutputDirectory.resolve(path)));
  PBXBuildFile buildFile = new PBXBuildFile(fileReference);
  sourcesBuildPhase.getFiles().add(buildFile);
  String customFlags = sourceFlags.get(sourcePath);
  if (customFlags != null) {
    NSDictionary settings = new NSDictionary();
    settings.put("COMPILER_FLAGS", customFlags);
    buildFile.setSettings(Optional.of(settings));
  }
  LOG.verbose(
      "Added source path %s to group %s, flags %s, PBXFileReference %s",
      sourcePath,
      sourcesGroup.getName(),
      customFlags,
      fileReference);
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:26,代码来源:ProjectGenerator.java

示例2: getExpandedSourcePaths

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
private ImmutableList<Path> getExpandedSourcePaths(ExecutionContext context)
    throws IOException {
  ProjectFilesystem projectFilesystem = context.getProjectFilesystem();

  // Add sources file or sources list to command
  ImmutableList.Builder<Path> sources = ImmutableList.builder();
  for (SourcePath sourcePath : javaSourceFilePaths) {
    Path path = sourcePath.resolve();

    if (path.toString().endsWith(".java")) {
      sources.add(path);
    } else if (path.toString().endsWith(SRC_ZIP)) {
      if (!workingDirectory.isPresent()) {
        throw new HumanReadableException(
            "Attempting to compile target %s which specified a .src.zip input %s but no " +
                "working directory was specified.",
            target.toString(),
            path);
      }
      // For a Zip of .java files, create a JavaFileObject for each .java entry.
      ImmutableList<Path> zipPaths = Unzip.extractZipFile(
          projectFilesystem.resolve(path),
          projectFilesystem.resolve(workingDirectory.get()),
          /* overwriteExistingFiles */ true);
      sources.addAll(
          FluentIterable.from(zipPaths)
              .filter(
                  new Predicate<Path>() {
                    @Override
                    public boolean apply(Path input) {
                      return input.toString().endsWith(".java");
                    }
                  }));
    }
  }
  return sources.build();
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:38,代码来源:ExternalJavacStep.java

示例3: createCompilationUnits

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
private Iterable<? extends JavaFileObject> createCompilationUnits(
    StandardJavaFileManager fileManager,
    Function<Path, Path> absolutifier) throws IOException {
  List<JavaFileObject> compilationUnits = Lists.newArrayList();
  for (SourcePath srcPath : javaSourceFilePaths) {
    Path path = srcPath.resolve();

    if (path.toString().endsWith(".java")) {
      // For an ordinary .java file, create a corresponding JavaFileObject.
      Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(
          absolutifier.apply(path).toFile());
      compilationUnits.add(Iterables.getOnlyElement(javaFileObjects));
    } else if (path.toString().endsWith(SRC_ZIP)) {
      // For a Zip of .java files, create a JavaFileObject for each .java entry.
      ZipFile zipFile = new ZipFile(absolutifier.apply(path).toFile());
      for (Enumeration<? extends ZipEntry> entries = zipFile.entries();
           entries.hasMoreElements();
          ) {
        ZipEntry entry = entries.nextElement();
        if (!entry.getName().endsWith(".java")) {
          continue;
        }

        compilationUnits.add(new ZipEntryJavaFileObject(zipFile, entry));
      }
    }
  }
  return compilationUnits;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:30,代码来源:JavacInMemoryStep.java

示例4: getBuildSteps

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
@Override
public ImmutableList<Step> getBuildSteps(
    final BuildContext buildContext,
    BuildableContext buildableContext) {
  Step step = new Step() {

    @Override
    public int execute(ExecutionContext executionContext) {
      for (SourcePath sourcePath : srcs) {
        Path src = sourcePath.resolve();
        File file = executionContext.getProjectFilesystem().getFileForRelativePath(src);
        try {
          // Generate the Java code for the Parcelable class.
          ParcelableClass parcelableClass = Parser.parse(file);
          String generatedJava = new Generator(parcelableClass).generate();

          // Write the generated Java code to a file.
          File outputPath = getOutputPathForParcelableClass(parcelableClass).toFile();
          Files.createParentDirs(outputPath);
          Files.write(generatedJava, outputPath, Charsets.UTF_8);
        } catch (IOException e) {
          executionContext.logError(e, "Error creating parcelable from file: %s", src);
          return 1;
        }
      }
      return 0;
    }

    @Override
    public String getShortName() {
      return "gen_parcelable";
    }

    @Override
    public String getDescription(ExecutionContext context) {
      return "gen_parcelable";
    }};

  return ImmutableList.of(step);
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:41,代码来源:GenParcelable.java

示例5: addSourcePathToHeadersBuildPhase

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
private void addSourcePathToHeadersBuildPhase(
    SourcePath headerPath,
    PBXGroup headersGroup,
    Optional<PBXHeadersBuildPhase> headersBuildPhase,
    ImmutableMap<SourcePath, String> sourceFlags) {
  Path path = headerPath.resolve();
  Path repoRootRelativePath = repoRootRelativeToOutputDirectory.resolve(path);
  PBXFileReference fileReference = headersGroup.getOrCreateFileReferenceBySourceTreePath(
      new SourceTreePath(
          PBXReference.SourceTree.SOURCE_ROOT,
          repoRootRelativePath));
  PBXBuildFile buildFile = new PBXBuildFile(fileReference);
  String headerFlags = sourceFlags.get(headerPath);
  if (headerFlags != null) {
    // If we specify nothing, Xcode will use "project" visibility.
    NSDictionary settings = new NSDictionary();
    settings.put(
        "ATTRIBUTES",
        new NSArray(new NSString(HeaderVisibility.fromString(headerFlags).toXcodeAttribute())));
    buildFile.setSettings(Optional.of(settings));
  } else {
    buildFile.setSettings(Optional.<NSDictionary>absent());
  }
  if (headersBuildPhase.isPresent()) {
    headersBuildPhase.get().getFiles().add(buildFile);
    LOG.verbose(
        "Added header path %s to headers group %s, flags %s, PBXFileReference %s",
        headerPath,
        headersGroup.getName(),
        headerFlags,
        fileReference);
  } else {
    LOG.verbose(
        "Skipped header path %s to headers group %s, flags %s, PBXFileReference %s",
        headerPath,
        headersGroup.getName(),
        headerFlags,
        fileReference);
  }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:41,代码来源:ProjectGenerator.java

示例6: getBuildSteps

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
@Override
public ImmutableList<Step> getBuildSteps(
    BuildContext context,
    BuildableContext buildableContext) {
  ImmutableList.Builder<Step> steps = ImmutableList.builder();
  ImmutableSortedSet.Builder<Path> objectFiles = ImmutableSortedSet.naturalOrder();
  Set<Path> createdDirectories = Sets.newHashSet();

  addMkdirStepIfNeeded(createdDirectories, steps, getPathToOutputFile().getParent());

  for (SourcePath src : srcs) {
    Path srcFile = src.resolve();
    // We expect srcFile to be relative to the buck root
    Preconditions.checkState(!srcFile.isAbsolute());
    Path parent = srcFile.getParent();
    if (parent == null) {
      parent = Paths.get("");
    }
    // To avoid collisions, objects files are created in directories that reflects the path to
    // source files rather than the (path-like) name of build targets
    Path targetDir = BuckConstant.GEN_PATH.resolve(parent);
    addMkdirStepIfNeeded(createdDirectories, steps, targetDir);

    Path objectFile = targetDir.resolve(
        Files.getNameWithoutExtension(srcFile.getFileName().toString()) + OBJECT_EXTENSION);
    steps.add(new CompilerStep(
          /* compiler */ getCompiler(),
          /* shouldLink */ false,
          /* srcs */ ImmutableSortedSet.of(src.resolve()),
          /* outputFile */ objectFile,
          /* shouldAddProjectRootToIncludePaths */ true,
          /* includePaths */ ImmutableSortedSet.<Path>of(),
          /* commandLineArgs */ commandLineArgsForFile(src, perSrcFileFlags)));
    objectFiles.add(objectFile);
  }

  for (BuildRule dep : getDeps()) {
    // Only c++ static libraries are supported for now.
    if (dep instanceof CxxLibrary) {
      objectFiles.add(dep.getPathToOutputFile());
    }
  }

  steps.addAll(getFinalBuildSteps(objectFiles.build(), getPathToOutputFile()));

  return steps.build();
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:48,代码来源:AbstractNativeBuildRule.java

示例7: createGwtModule

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
@VisibleForTesting
static BuildRule createGwtModule(BuildRuleParams params, Arg arg) {
  // Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar
  // is a BuildRuleSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this
  // becomes a performance issue in practice, then we will explore reducing the dependencies of
  // the GWT module.
  final SourcePath inputToCompareToOutput;
  if (arg.gwtJar.isPresent()) {
    inputToCompareToOutput = arg.gwtJar.get();
  } else if (arg.sourceJar.isPresent()) {
    inputToCompareToOutput = arg.sourceJar.get();
  } else {
    inputToCompareToOutput = arg.binaryJar;
  }
  final ImmutableCollection<Path> inputsToCompareToOutput =
      SourcePaths.filterInputsToCompareToOutput(Collections.singleton(inputToCompareToOutput));
  final Path pathToExistingJarFile = inputToCompareToOutput.resolve();

  BuildRule buildRule = new AbstractBuildRule(params) {
    @Override
    protected Iterable<Path> getInputsToCompareToOutput() {
      return inputsToCompareToOutput;
    }

    @Override
    protected Builder appendDetailsToRuleKey(Builder builder) {
      return builder;
    }

    @Override
    public ImmutableList<Step> getBuildSteps(
        BuildContext context,
        BuildableContext buildableContext) {
      buildableContext.recordArtifact(getPathToOutputFile());
      return ImmutableList.of();
    }

    @Override
    public Path getPathToOutputFile() {
      return pathToExistingJarFile;
    }
  };
  return buildRule;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:45,代码来源:PrebuiltJarDescription.java

示例8: getClassNamesForSources

import com.facebook.buck.rules.SourcePath; //导入方法依赖的package包/类
/**
 * When a collection of .java files is compiled into a directory, that directory will have a
 * subfolder structure that matches the package structure of the input .java files. In general,
 * the .java files will be 1:1 with the .class files with two notable exceptions:
 * (1) There will be an additional .class file for each inner/anonymous class generated. These
 *     types of classes are easy to identify because they will contain a '$' in the name.
 * (2) A .java file that defines multiple top-level classes (yes, this can exist:
 *     http://stackoverflow.com/questions/2336692/java-multiple-class-declarations-in-one-file)
 *     will generate multiple .class files that do not have '$' in the name.
 * In this method, we perform a strict check for (1) and use a heuristic for (2). It is possible
 * to filter out the type (2) situation with a stricter check that aligns the package
 * directories of the .java files and the .class files, but it is a pain to implement.
 * If this heuristic turns out to be insufficient in practice, then we can fix it.
 *
 * @param sources paths to .java source files that were passed to javac
 * @param jarFile jar where the generated .class files were written
 */
@VisibleForTesting
static Set<String>  getClassNamesForSources(Set<SourcePath> sources, @Nullable Path jarFile) {
  if (jarFile == null) {
    return ImmutableSet.of();
  }

  final Set<String> sourceClassNames = Sets.newHashSetWithExpectedSize(sources.size());
  for (SourcePath sourcePath : sources) {
    Path path = sourcePath.resolve();
    String source = path.toString();
    int lastSlashIndex = source.lastIndexOf('/');
    if (lastSlashIndex >= 0) {
      source = source.substring(lastSlashIndex + 1);
    }
    source = source.substring(0, source.length() - ".java".length());
    sourceClassNames.add(source);
  }

  final ImmutableSet.Builder<String> testClassNames = ImmutableSet.builder();
  ZipFileTraversal traversal = new ZipFileTraversal(jarFile.toFile()) {

    @Override
    public void visit(ZipFile zipFile, ZipEntry zipEntry) {
      final String name = new File(zipEntry.getName()).getName();

      // Ignore non-.class files.
      if (!name.endsWith(".class")) {
        return;
      }

      // As a heuristic for case (2) as described in the Javadoc, make sure the name of the
      // .class file matches the name of a .java file.
      String nameWithoutDotClass = name.substring(0, name.length() - ".class".length());
      if (!sourceClassNames.contains(nameWithoutDotClass)) {
        return;
      }

      // Make sure it is a .class file that corresponds to a top-level .class file and not an
      // inner class.
      if (!name.contains("$")) {
        String fullyQualifiedNameWithDotClassSuffix = zipEntry.getName().replace('/', '.');
        String className = fullyQualifiedNameWithDotClassSuffix
            .substring(0, fullyQualifiedNameWithDotClassSuffix.length() - ".class".length());
        testClassNames.add(className);
      }
    }
  };
  try {
    traversal.traverse();
  } catch (IOException e) {
    // There's nothing sane to do here. The jar file really should exist.
    throw Throwables.propagate(e);
  }

  return testClassNames.build();
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:74,代码来源:JavaTest.java


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