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(); }
@SuppressWarnings("ResultOfMethodCallIgnored") public void setupKotlinHome(String kotlinVersion) { this.kotlinHomeEnabled = true; this.kotlinVersion = kotlinVersion; Configuration kotlinConfig = project.getConfigurations().maybeCreate(KOTLIN_DEPS_CONFIG); DependencyHandler handler = project.getDependencies(); kotlinModules .stream() .map(module -> String.format("%s:%s:%s", KOTLIN_GROUP, module, kotlinVersion)) .forEach(dependency -> handler.add(KOTLIN_DEPS_CONFIG, dependency)); dependencies = new DependencyCache(project, ProjectUtil.getDependencyManager(project)).build(kotlinConfig); }
public void setupJetifier(String version) { if (!version.equals(JetifierExtension.DEFAULT_JETIFIER_VERSION)) { LOG.warn( "Using jetifier version other than %s; This might result in problems with the tool", JetifierExtension.DEFAULT_JETIFIER_VERSION); } Configuration jetifierConfig = project.getConfigurations().maybeCreate(JETIFIER_DEPS_CONFIG); DependencyHandler handler = project.getDependencies(); JETIFIER_MODULES .stream() .map(module -> String.format("%s:%s:%s", JETIFIER_GROUP, module, version)) .forEach(dependency -> handler.add(JETIFIER_DEPS_CONFIG, dependency)); handler.add(JETIFIER_DEPS_CONFIG, COMMONS_CLI_DEP); dependencies = new DependencyCache(project, ProjectUtil.getDependencyManager(project)) .build(jetifierConfig); }
public void setupBuckBinary() { OkBuckExtension okbuckExt = ProjectUtil.getOkBuckExtension(rootProject); // Create dependency cache for buck binary if needed if (okbuckExt.buckBinary != null) { Configuration buckConfig = rootProject.getConfigurations().maybeCreate(BUCK_BINARY_CONFIGURATION); rootProject .getRepositories() .maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(JITPACK_URL)); rootProject.getDependencies().add(BUCK_BINARY_CONFIGURATION, okbuckExt.buckBinary); Set<File> resolvedFiles = buckConfig.getResolvedConfiguration().getFiles(); Preconditions.checkArgument(resolvedFiles.size() == 1); realBuckBinaryPath = resolvedFiles.iterator().next().toPath(); } }
public void download() { ImmutableSet.Builder<Configuration> runtimeDeps = ImmutableSet.builder(); Set<API> apisToDownload; Set<String> configuredApis = ProjectUtil.getOkBuckExtension(rootProject).getTestExtension().robolectricApis; if (configuredApis != null) { apisToDownload = configuredApis.stream().map(API::from).collect(Collectors.toSet()); } else { apisToDownload = EnumSet.allOf(API.class); } for (API api : apisToDownload) { Configuration runtimeApi = rootProject.getConfigurations().maybeCreate(ROBOLECTRIC_RUNTIME + "_" + api.name()); rootProject.getDependencies().add(runtimeApi.getName(), api.getCoordinates()); runtimeDeps.add(runtimeApi); } DependencyCache dependencyCache = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)); dependencies = runtimeDeps .build() .stream() .map(dependencyCache::build) .flatMap(Set::stream) .collect(com.uber.okbuck.core.util.MoreCollectors.toImmutableSet()); }
@SuppressWarnings("ResultOfMethodCallIgnored") public Set<ExternalDependency> setupScalaHome(String scalaVersion) { Configuration scalaConfig = rootProject.getConfigurations().maybeCreate(SCALA_DEPS_CONFIG); rootProject .getDependencies() .add(SCALA_DEPS_CONFIG, "org.scala-lang:scala-compiler:" + scalaVersion); dependencies = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(scalaConfig); return dependencies; }
@SuppressWarnings("ResultOfMethodCallIgnored") public void setupGroovyHome() { Configuration groovyConfig = rootProject.getConfigurations().maybeCreate(GROOVY_DEPS_CONFIG); rootProject .getDependencies() .add(GROOVY_DEPS_CONFIG, "org.codehaus.groovy:groovy:" + groovyVersion); dependencies = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(groovyConfig); }
public void fetchManifestMergerDeps() { Configuration manifestMergerConfiguration = rootProject.getConfigurations().maybeCreate(CONFIGURATION_MANIFEST_MERGER); rootProject .getDependencies() .add( CONFIGURATION_MANIFEST_MERGER, MANIFEST_MERGER_GROUP + ":" + MANIFEST_MERGER_MODULE + ":" + ProjectUtil.findVersionInClasspath( rootProject, MANIFEST_MERGER_GROUP, MANIFEST_MERGER_MODULE)); dependencies = ImmutableSet.copyOf( new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(manifestMergerConfiguration)); }
rootProject.getConfigurations().maybeCreate(TransformManager.CONFIGURATION_TRANSFORM); rootProject.getConfigurations().maybeCreate(FORCED_OKBUCK); rootBuckProject .getConfigurations() .maybeCreate(cacheName + "ExtraDepCache"))); .forEach( bp -> { bp.getConfigurations().maybeCreate(BUCK_LINT);
private Configuration getByVariant(String name) { return project.getConfigurations().maybeCreate(name + "CaptClasspath"); }
@Override public void apply(Project project) { final ConfigurationContainer configurations = project.getConfigurations(); configurations.maybeCreate("test"); configurations.maybeCreate("build"); configurations.maybeCreate("tool"); final ExtensionContainer extensions = project.getExtensions(); final ExtensionAware golang = (ExtensionAware) extensions.create("golang", GolangSettings.class, true, project); golang.getExtensions().create("build", BuildSettings.class, true, project); golang.getExtensions().create("toolchain", ToolchainSettings.class, true, project); golang.getExtensions().create("dependencies", DependenciesSettings.class, true, project); golang.getExtensions().create("testing", TestingSettings.class, true, project); extensions.create(INSTANCE_PROPERTY_NAME, Reference.class, this); final TaskContainer tasks = project.getTasks(); addTasks(tasks); }
@Override public Configuration getConfiguration(Project project, Dependency dependency) { String mavenScope = dependency.getScope() == null ? "compile" : dependency.getScope(); String gradleScope = mappings.containsKey(mavenScope) ? mappings.get(mavenScope) : mavenScope; return project.getConfigurations().maybeCreate(gradleScope); } }
@Override public void apply(Project project) { final DependencyHandlerExtension dependencyHandlerExtension = new DependencyHandlerExtension(_configurationContainer); final GroovyObject ext = (GroovyObject) _dependencyHandler.getProperty("ext"); for (final Entry<String, Closure<Dependency>> entry : dependencyHandlerExtension.getDependencyMethodsAsClosures().entrySet()) { ext.setProperty(entry.getKey(), entry.getValue()); } final ConfigurationContainer configurations = project.getConfigurations(); configurations.maybeCreate("test"); configurations.maybeCreate("build"); configurations.maybeCreate("tool"); final ExtensionContainer extensions = project.getExtensions(); final ExtensionAware golang = (ExtensionAware) extensions.create("golang", GolangSettings.class, true, project); golang.getExtensions().create("build", BuildSettings.class, true, project); golang.getExtensions().create("toolchain", ToolchainSettings.class, true, project); golang.getExtensions().create("dependencies", DependenciesSettings.class, true, project); golang.getExtensions().create("testing", TestingSettings.class, true, project); final TaskContainer tasks = project.getTasks(); tasks.create("clean", Clean.class); tasks.create("validate", Validate.class); tasks.create("prepare-toolchain", PrepareToolchain.class); tasks.create("prepare-sources", PrepareSources.class); tasks.create("get-tools", GetTools.class); tasks.create("test", Test.class); tasks.create("build", Build.class); }
@Override public void apply(Project project) { Configuration conjureIrConfiguration = project.getConfigurations().maybeCreate(CONJURE_CONFIGURATION); Configuration conjureGeneratorsConfiguration = project.getConfigurations().maybeCreate( CONJURE_GENERATORS_CONFIGURATION_NAME); ConjureExtension extension = project.getExtensions() .create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class); Task generateConjure = project.getTasks().create("generateConjure", task -> { task.setDescription("Generates code for all requested languages (for which there is a subproject) " + "from remote Conjure definitions."); task.setGroup(ConjurePlugin.TASK_GROUP); }); setupConjurePython( project, immutableOptionsSupplier(extension::getPython), conjureIrConfiguration, generateConjure); setupConjureTypeScript( project, immutableOptionsSupplier(extension::getTypescript), conjureIrConfiguration, generateConjure); setupGenericConjureProjects( project, extension, conjureIrConfiguration, generateConjure, conjureGeneratorsConfiguration); }
private static Task createCompileIrTask(Project project, Copy copyConjureSourcesTask) { Configuration conjureCompilerConfig = project.getConfigurations().maybeCreate(CONJURE_COMPILER); File conjureCompilerDir = new File(project.getBuildDir(), CONJURE_COMPILER); project.getDependencies().add(CONJURE_COMPILER, CONJURE_COMPILER_BINARY); ExtractExecutableTask extractCompilerTask = ExtractExecutableTask.createExtractTask( project, "extractConjure", conjureCompilerConfig, conjureCompilerDir, "conjure"); File irPath = Paths.get( project.getBuildDir().toString(), "conjure-ir", project.getName() + ".conjure.json").toFile(); return project.getTasks().create(CONJURE_IR, CompileIrTask.class, compileIr -> { compileIr.setDescription("Converts your Conjure YML files into a single portable JSON file in IR format."); compileIr.setGroup(TASK_GROUP); compileIr.setInputDirectory(copyConjureSourcesTask::getDestinationDir); compileIr.setExecutablePath(extractCompilerTask::getExecutable); compileIr.setOutputFile(irPath); compileIr.dependsOn(copyConjureSourcesTask); compileIr.dependsOn(extractCompilerTask); }); }
@Override public void apply(Project project) { project.getPluginManager().apply( "java" ); final SnifferExtension snifferExtension = Helper.maybeCreateExtension( project ); project.getConfigurations().maybeCreate( CONFIGURATION_NAME ); final CheckTask checkTask = project.getTasks().create( CheckTask.STANDARD_NAME, CheckTask.class ); project.getTasks().add( checkTask ); project.afterEvaluate( p -> { for ( SourceSet sourceSet : snifferExtension.getCheck().getSourceSets() ) { Task compileTask = p.getTasks().findByName( sourceSet.getCompileTaskName( "groovy" ) ); if ( compileTask == null ) { compileTask = p.getTasks().findByName( sourceSet.getCompileJavaTaskName() ); } if ( compileTask == null ) { throw new RuntimeException( "Could not locate compile task for sourceSet [" + sourceSet.getName() + "]" ); } checkTask.dependsOn( compileTask ); } } ); } }
@Override protected void applyVanillaUserPlugin() { final ConfigurationContainer configs = this.project.getConfigurations(); configs.maybeCreate(CONFIG_LL_DEOBF_COMPILE); configs.maybeCreate(CONFIG_LL_DC_RESOLVED); configs.getByName(CONFIG_DC_RESOLVED).extendsFrom(configs.getByName(CONFIG_LL_DC_RESOLVED)); final DelayedFile versionJson = delayedFile(VERSION_JSON_FILE); final DelayedFile versionJsonEtag = delayedFile(VERSION_JSON_FILE + ".etag"); setJson(JsonFactory.loadLiteLoaderJson(getWithEtag(VERSION_JSON_URL, versionJson.call(), versionJsonEtag.call()))); String baseName = MODFILE_PREFIX + this.project.property("archivesBaseName").toString().toLowerCase(); TaskContainer tasks = this.project.getTasks(); final Jar jar = (Jar)tasks.getByName("jar"); jar.setExtension(MODFILE_EXTENSION); jar.setBaseName(baseName); final Jar sourceJar = (Jar)tasks.getByName("sourceJar"); sourceJar.setBaseName(baseName); makeTask(TASK_LITEMOD, LiteModTask.class); }
private void setupConjurePython( Project project, Supplier<GeneratorOptions> optionsSupplier, Configuration conjureIrConfiguration, Task generateConjure) { Project subproj = project.findProject(PYTHON_PROJECT_NAME); if (subproj == null) { return; } Configuration conjurePythonConfig = project.getConfigurations().maybeCreate(ConjurePlugin.CONJURE_PYTHON); File conjurePythonDir = new File(project.getBuildDir(), ConjurePlugin.CONJURE_PYTHON); project.getDependencies().add(ConjurePlugin.CONJURE_PYTHON, ConjurePlugin.CONJURE_PYTHON_BINARY); ExtractExecutableTask extractConjurePythonTask = ExtractExecutableTask.createExtractTask( project, "extractConjurePython", conjurePythonConfig, conjurePythonDir, "conjure-python"); project.getTasks().create("generatePython", ConjureLocalGenerateTask.class, task -> { task.setDescription("Generates Python files from remote Conjure definitions."); task.setGroup(ConjurePlugin.TASK_GROUP); task.setSource(conjureIrConfiguration); task.setExecutablePath(extractConjurePythonTask::getExecutable); task.setOutputDirectory(subproj.file("python")); task.setOptions(() -> optionsSupplier.get().addFlag("rawSource")); task.dependsOn(extractConjurePythonTask); generateConjure.dependsOn(task); }); }
task.setInSources(sourceJar); task.setOutJar(outJar); task.getProject().getConfigurations().maybeCreate("test_configuration"); task.setClasspath("test_configuration"); task.setInResources(resourceJar);
@Test public void runTask() throws IOException { File outputDir = temporaryFolder.newFolder("extractedAts"); File shouldBeDeleted = new File(outputDir, "should_be_deleted_at.cfg"); if (!shouldBeDeleted.createNewFile()) throw new IOException("Couldn't create file in " + outputDir); File modWithAtJar = TestResource.MOD_WITH_AT.getFile(temporaryFolder); TaskExtractDepAts task = getTask(TaskExtractDepAts.class); task.getProject().getConfigurations().maybeCreate("test_at").getDependencies().add(new DefaultSelfResolvingDependency(new SimpleFileCollection(modWithAtJar))); task.addCollection("test_at"); task.setOutputDir(outputDir); task.doTask(); File[] files = outputDir.listFiles(); Assert.assertFalse(shouldBeDeleted + " should be deleted", shouldBeDeleted.exists()); Assert.assertNotNull(files); Assert.assertEquals(1, files.length); String name = files[0].getName(); Assert.assertTrue("Name " + name + " should contain test_at", name.contains("test_at")); } }