/** * 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]; }
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); } } }
/** * 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(); }
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); } }
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(); }
String getOriginalPackage() { if (originalPackageName == null) { Document manifestXml = XmlUtil.loadXml(getProject().file(getMainManifest())); originalPackageName = manifestXml.getDocumentElement().getAttribute("package").trim(); } return originalPackageName; }
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); }
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(); }
@OutputFile public File okbuckTargets() { return getProject().file(OKBUCK_TARGETS_FILE); }
@OutputFile public File okbuckPrebuilt() { return getProject().file(OKBUCK_PREBUILT_FILE); }
@OutputFile public File okbuckBuckConfig() { return getProject().file(OkBuckGradlePlugin.OKBUCK_CONFIG + "/okbuck.buckconfig"); }
@OutputFile public File dotBuckConfig() { return getProject().file(".buckconfig"); }
/** Write the buck file for the java_annotation_processor rules. */ public void finalizeProcessors() { buckFileManager.writeToBuckFile( JavaAnnotationProcessorRuleComposer.compose(dependencyToScopeMap.values()), project.getRootProject().file(processorBuckFile)); }
/** 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); }
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()); } }
@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(); }
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); } } }
@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")); } }
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; } }); }
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)); } } }