org.gradle.api.Project.file()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.gradle.api.Project.file()方法的一些代码示例,展示了Project.file()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.file()方法的具体详情如下:
包路径:org.gradle.api.Project
类名称:Project
方法名:file

Project.file介绍

暂无

代码示例

代码示例来源:origin: apollographql/apollo-android

/**
 * Returns the source set folder name given a file path. Assumes the source set name follows the "src" folder based on
 * the inputs received from GraphQLSourceDirectorySet.
 *
 * @return - sourceSet name
 */
private String getSourceSetNameFromFile(File file) {
 Path absolutePath = Paths.get(file.getAbsolutePath());
 Path basePath = Paths.get(task.getProject().file("src").getAbsolutePath());
 return basePath.relativize(absolutePath).toString().split(Matcher.quoteReplacement(File.separator))[0];
}

代码示例来源:origin: uber/okbuck

public void finalizeDependencies() {
  if (realBuckBinaryPath != null) {
   Path linkedBinaryPath =
     rootProject.file(BUCK_BINARY_LOCATION).toPath().resolve(realBuckBinaryPath.getFileName());

   // Delete already existing folder
   FileUtil.deleteQuietly(linkedBinaryPath.getParent());

   // Make dirs
   linkedBinaryPath.getParent().toFile().mkdirs();

   FileUtil.symlink(linkedBinaryPath, realBuckBinaryPath);
  }
 }
}

代码示例来源:origin: apollographql/apollo-android

/**
 * Returns the file path relative to the sourceSet directory
 *
 * @return path relative to sourceSet directory
 */
private String getPathRelativeToSourceSet(File file) {
 Path absolutePath = Paths.get(file.getAbsolutePath());
 Path basePath = Paths.get(task.getProject().file("src").getAbsolutePath() + File.separator + getSourceSetNameFromFile(file));
 return basePath.relativize(absolutePath).toString();
}

代码示例来源:origin: uber/okbuck

public void finalizeDependencies() {
 Path cacheDir = rootProject.file(TRANSFORM_CACHE).toPath();
 FileUtil.deleteQuietly(cacheDir);
 if (dependencies != null && dependencies.size() > 0) {
  cacheDir.toFile().mkdirs();
  copyFiles(cacheDir);
  composeBuckFile(cacheDir);
 }
}

代码示例来源:origin: uber/okbuck

public Set<File> getSources(BaseVariant variant) {
 ImmutableSet.Builder<File> srcs = new ImmutableSet.Builder<>();
 Set<File> javaSrcs =
   variant
     .getSourceSets()
     .stream()
     .map(SourceProvider::getJavaDirectories)
     .flatMap(Collection::stream)
     .collect(Collectors.toSet());
 srcs.addAll(javaSrcs);
 if (isKotlinAndroid) {
  srcs.addAll(
    javaSrcs
      .stream()
      .filter(i -> i.getName().equals("java"))
      .map(i -> getProject().file(i.getAbsolutePath().replaceFirst("/java$", "/kotlin")))
      .collect(Collectors.toSet()));
 }
 return srcs.build();
}

代码示例来源:origin: uber/okbuck

String getOriginalPackage() {
 if (originalPackageName == null) {
  Document manifestXml = XmlUtil.loadXml(getProject().file(getMainManifest()));
  originalPackageName = manifestXml.getDocumentElement().getAttribute("package").trim();
 }
 return originalPackageName;
}

代码示例来源:origin: uber/okbuck

private static Pair<String, String> getBashCommandAndTransformDeps(
  AndroidAppTarget target, Map<String, String> options) {
 String transformClass = options.get(OPT_TRANSFORM_CLASS);
 String configFile = options.get(OPT_CONFIG_FILE);
 StringBuilder bashCmd = new StringBuilder(PREFIX);
 @Var String configFileRule = null;
 if (transformClass != null) {
  bashCmd.append("-Dokbuck.transformClass=").append(transformClass).append(" ");
 }
 if (configFile != null) {
  configFileRule =
    getTransformConfigRuleForFile(
      target.getProject(), target.getRootProject().file(configFile));
  bashCmd.append("-Dokbuck.configFile=$(location ").append(configFileRule).append(") ");
 }
 bashCmd.append(SUFFIX);
 return Pair.of(bashCmd.toString(), configFileRule);
}

代码示例来源:origin: uber/okbuck

public void fetchLintDeps(String version) {
 // Invalidate lint deps when versions change
 File lintVersionFile = project.file(LINT_VERSION_FILE);
 try {
  if (!lintVersionFile.exists()
    || !version.equals(
      new String(Files.readAllBytes(lintVersionFile.toPath()), StandardCharsets.UTF_8))) {
   FileUtils.deleteDirectory(lintVersionFile.getParentFile());
   lintVersionFile.getParentFile().mkdirs();
   Files.write(lintVersionFile.toPath(), Collections.singleton(version));
  }
 } catch (Exception e) {
  throw new RuntimeException(e);
 }
 project.getConfigurations().maybeCreate(LINT_DEPS_CONFIG);
 project.getDependencies().add(LINT_DEPS_CONFIG, LINT_GROUP + ":" + LINT_MODULE + ":" + version);
 getLintDepsCache();
}

代码示例来源:origin: uber/okbuck

@OutputFile
public File okbuckTargets() {
 return getProject().file(OKBUCK_TARGETS_FILE);
}

代码示例来源:origin: uber/okbuck

@OutputFile
public File okbuckPrebuilt() {
 return getProject().file(OKBUCK_PREBUILT_FILE);
}

代码示例来源:origin: uber/okbuck

@OutputFile
public File okbuckBuckConfig() {
 return getProject().file(OkBuckGradlePlugin.OKBUCK_CONFIG + "/okbuck.buckconfig");
}

代码示例来源:origin: uber/okbuck

@OutputFile
public File dotBuckConfig() {
 return getProject().file(".buckconfig");
}

代码示例来源:origin: uber/okbuck

/** Write the buck file for the java_annotation_processor rules. */
public void finalizeProcessors() {
 buckFileManager.writeToBuckFile(
   JavaAnnotationProcessorRuleComposer.compose(dependencyToScopeMap.values()),
   project.getRootProject().file(processorBuckFile));
}

代码示例来源:origin: uber/okbuck

/** generate {@code BUCKFile} */
public static void generate(
  Project project, BuckFileManager buckFileManager, VisibilityExtension visibilityExtension) {
 List<Rule> rules = createRules(project);
 File moduleDir = project.getBuildFile().getParentFile();
 File visibilityFile = new File(moduleDir, visibilityExtension.visibilityFileName);
 boolean hasVisibilityFile = visibilityFile.isFile();
 Multimap<String, String> extraLoadStatements = TreeMultimap.create();
 if (hasVisibilityFile) {
  rules.forEach(rule -> rule.fileConfiguredVisibility(true));
  extraLoadStatements.put(
    ":" + visibilityExtension.visibilityFileName, visibilityExtension.visibilityFunction);
 }
 File buckFile = project.file(OkBuckGradlePlugin.BUCK);
 buckFileManager.writeToBuckFile(rules, buckFile, extraLoadStatements);
}

代码示例来源:origin: uber/okbuck

public void finalizeDependencies() {
 if (dependencies != null && dependencies.size() > 0) {
  Path robolectricCache = rootProject.file(ROBOLECTRIC_CACHE).toPath();
  FileUtil.deleteQuietly(robolectricCache);
  robolectricCache.toFile().mkdirs();
  Map<String, String> targetsNameMap =
    dependencies
      .stream()
      .collect(
        Collectors.toMap(BuckRuleComposer::external, ExternalDependency::getTargetName));
  Rule fileGroup =
    new SymlinkBuckFile()
      .targetsNameMap(targetsNameMap)
      .base("")
      .name(ROBOLECTRIC_TARGET_NAME);
  buckFileManager.writeToBuckFile(
    ImmutableList.of(fileGroup), robolectricCache.resolve(OkBuckGradlePlugin.BUCK).toFile());
 }
}

代码示例来源:origin: apollographql/apollo-android

@Override
public void exec() {
 if (Utils.isNullOrEmpty(url) || Utils.isNullOrEmpty(output)) {
  throw new IllegalArgumentException("Schema URL and output path can't be empty");
 }
 setScript(new File(getProject().getTasks().getByPath(ApolloCodegenInstallTask.NAME).getOutputs().getFiles()
   .getAsPath(), ApolloLocalCodegenGenerationTask.APOLLO_CODEGEN_EXEC_FILE));
 List<String> args = Lists.newArrayList("introspect-schema", url, "--output", getProject().file(output)
   .getAbsolutePath());
 if (!headers.isEmpty()) {
  for(String h : headers) {
   args.add("--header");
   args.add(h);
  }
 }
 if (insecure) {
  args.add("--insecure");
  args.add("true");
 }
 setArgs(args);
 super.exec();
}

代码示例来源:origin: uber/okbuck

public void finalizeDependencies() {
  if (dependencies != null && dependencies.size() > 0) {
   List<Rule> scalaCompiler =
     Collections.singletonList(
       new JvmBinaryRule()
         .mainClassName("scala.tools.nsc.Main")
         .deps(BuckRuleComposer.external(dependencies))
         .ruleType(RuleType.JAVA_BINARY.getBuckName())
         .name("scala-compiler.jar")
         .defaultVisibility());

   File buckFile =
     rootProject
       .file(SCALA_COMPILER_LOCATION)
       .toPath()
       .resolve(OkBuckGradlePlugin.BUCK)
       .toFile();
   buckFileManager.writeToBuckFile(scalaCompiler, buckFile);
  }
 }
}

代码示例来源:origin: uber/okbuck

@TaskAction
void installWrapper() {
 new BuckWrapper()
   .customBuckRepo(repo)
   .watch(toWatchmanMatchers(watch))
   .sourceRoots(toWatchmanMatchers(sourceRoots))
   .ignoredDirs(toWatchmanIgnoredDirs(ignoredDirs))
   .render(wrapper);
 wrapper.setExecutable(true);
 File watchmanConfig = getProject().file(".watchmanconfig");
 if (!watchmanConfig.exists()) {
  FileUtil.copyResourceToProject(
    "wrapper/WATCHMAN_CONFIG", getProject().file(".watchmanconfig"));
 }
}

代码示例来源:origin: apollographql/apollo-android

public ApolloCodegenInstallTask() {
 // TODO: set to const when ApolloPlugin is in java
 setGroup("apollo");
 setDescription("Runs npm install for apollo-codegen");
 installDir = getProject().file(getProject().getBuildDir() + File.separator + INSTALL_DIR);
 File workingDir = new File(getProject().getBuildDir(), "apollo-codegen");
 setWorkingDir(workingDir);
 apolloPackageFile = getProject().file(workingDir + File.separator + "package.json");
 final boolean isSameCodegenVersion = isSameApolloCodegenVersion(getApolloVersion());
 if (!isSameCodegenVersion) {
  Utils.deleteDirectory(installDir);
 }
 getOutputs().upToDateWhen(new Spec<Task>() {
  public boolean isSatisfiedBy(Task element) {
   return apolloPackageFile.isFile() && isSameCodegenVersion;
  }
 });
}

代码示例来源:origin: uber/okbuck

public void finalizeDependencies() {
  if (dependencies != null && dependencies.size() > 0) {
   FileUtil.copyResourceToProject(
     "manifest/" + MANIFEST_MERGER_CLI_JAR,
     new File(MANIFEST_MERGER_CACHE, MANIFEST_MERGER_CLI_JAR));

   Set<String> deps = BuckRuleComposer.external(dependencies);
   deps.add(":" + MANIFEST_MERGER_CLI_RULE_NAME);

   List<Rule> rules =
     ImmutableList.of(
       new JvmBinaryRule()
         .excludes(MANIFEST_MERGER_EXCLUDES)
         .mainClassName(MANIFEST_MERGER_CLI_CLASS)
         .deps(deps)
         .ruleType(RuleType.JAVA_BINARY.getBuckName())
         .name(MANIFEST_MERGER_RULE_NAME)
         .defaultVisibility(),
       new NativePrebuilt()
         .prebuiltType(RuleType.PREBUILT_JAR.getProperties().get(0))
         .prebuilt(MANIFEST_MERGER_CLI_JAR)
         .ruleType(RuleType.PREBUILT_JAR.getBuckName())
         .name(MANIFEST_MERGER_CLI_RULE_NAME));

   buckFileManager.writeToBuckFile(rules, rootProject.file(MANIFEST_MERGER_BUCK_FILE));
  }
 }
}

相关文章