private void configureDescriptorGeneration(final Project project, final GradlePluginDevelopmentExtension extension) { final GeneratePluginDescriptors generatePluginDescriptors = project.getTasks().create(GENERATE_PLUGIN_DESCRIPTORS_TASK_NAME, GeneratePluginDescriptors.class); generatePluginDescriptors.conventionMapping("declarations", new Callable<List<PluginDeclaration>>() { @Override public List<PluginDeclaration> call() throws Exception { return Lists.newArrayList(extension.getPlugins()); } }); generatePluginDescriptors.conventionMapping("outputDirectory", new Callable<File>() { @Override public File call() throws Exception { return new File(project.getBuildDir(), generatePluginDescriptors.getName()); } }); Copy processResources = (Copy) project.getTasks().getByName(PROCESS_RESOURCES_TASK); CopySpec copyPluginDescriptors = processResources.getRootSpec().addChild(); copyPluginDescriptors.into("META-INF/gradle-plugins"); copyPluginDescriptors.from(new Callable<File>() { @Override public File call() throws Exception { return generatePluginDescriptors.getOutputDirectory(); } }); processResources.dependsOn(generatePluginDescriptors); }
public Copy getJacocoAgentTask() { if (jacocoAgentTask == null) { jacocoAgentTask = project.getTasks().create("unzipJacocoAgent", Copy.class); jacocoAgentTask.from(new Callable<List<FileTree>>() { @Override public List<FileTree> call() throws Exception { return Lists.newArrayList(Iterables.transform( project.getConfigurations().getByName( JacocoPlugin.AGENT_CONFIGURATION_NAME), new Function<Object, FileTree>() { @Override public FileTree apply(@Nullable Object it) { return project.zipTree(it); } })); } }); jacocoAgentTask.include(FILE_JACOCO_AGENT); jacocoAgentTask.into(new File(getGlobalScope().getIntermediatesDir(), "jacoco")); } return jacocoAgentTask; }
public static void createStlCopyTask(NdkHandler ndkHandler, String stl, ModelMap<Task> tasks, final File buildDir, final SharedLibraryBinarySpec binary) { if (stl.endsWith("_shared")) { final StlNativeToolSpecification stlConfig = new StlNativeToolSpecification(ndkHandler, stl, binary.getTargetPlatform()); String copyTaskName = NdkNamingScheme.getTaskName(binary, "copy", "StlSo"); tasks.create(copyTaskName, Copy.class, new Action<Copy>() { @Override public void execute(Copy copy) { copy.from(stlConfig.getStlLib(binary.getTargetPlatform().getName())); copy.into(new File(buildDir, NdkNamingScheme.getOutputDirectoryName(binary))); } }); binary.getBuildTask().dependsOn(copyTaskName); } }
private void createProcessResourcesTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) { final BinaryNamingScheme namingScheme = binary.getNamingScheme(); binary.getSource().withType(JvmResourceSet.class).all(new Action<JvmResourceSet>() { public void execute(JvmResourceSet resourceSet) { Copy resourcesTask = target.getTasks().create(namingScheme.getTaskName("process", "resources"), ProcessResources.class); resourcesTask.setDescription(String.format("Processes %s.", resourceSet)); new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() { public File call() throws Exception { return binary.getResourcesDir(); } }); binary.getTasks().add(resourcesTask); binary.builtBy(resourcesTask); resourcesTask.from(resourceSet.getSource()); } }); }
@BinaryTasks public void copyGracljTools(ModelMap<Task> tasks, JUnitTestSuiteBinarySpec binary, GracljInternal internal) { Test testTask = binary.getTasks().getRun(); // Need to provide explicit list of directories to scan for test namespaces in. Not sure it should be in this rule. JvmAssembly assembly = ((WithJvmAssembly) binary).getAssembly(); Stream<File> classDirs = assembly.getClassDirectories().stream(); Stream<File> resourceDirs = assembly.getResourceDirectories().stream(); String testDirs = Stream.concat(classDirs, resourceDirs) .map(File::getAbsolutePath) .collect(Collectors.joining(File.pathSeparator)); testTask.systemProperty("clojure.test.dirs", testDirs); tasks.create(binary.getName() + "GracljTools", Copy.class, task -> { testTask.dependsOn(task); File tools = internal.resolve("org.graclj:graclj-tools:" + internal.getGracljVersion() + "@jar").getSingleFile(); task.from(task.getProject().zipTree(tools)); task.into(binary.getClassesDir()); }); testTask.setClasspath(testTask.getClasspath().plus(internal.resolve("org.graclj:graclj-tools:" + internal.getGracljVersion()))); }
/** * Assign some standard tasks and tasks created by third-party plugins to their task groups according to the * order of things for Checkstyle Addons. */ public void adjustTaskGroupAssignments() { final TaskContainer tasks = project.getTasks(); tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME); tasks.getByName(JavaPlugin.JAR_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME); final SourceSet sqSourceSet = buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME); tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP); tasks.getByName(sqSourceSet.getCompileJavaTaskName()).setGroup(BasePlugin.BUILD_GROUP); tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP); for (final FindBugs fbTask : tasks.withType(FindBugs.class)) { fbTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); } for (final Checkstyle csTask : tasks.withType(Checkstyle.class)) { csTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); } for (final Copy task : tasks.withType(Copy.class)) { if (task.getName().startsWith("process") && task.getName().endsWith("Resources")) { task.setGroup(LifecycleBasePlugin.BUILD_GROUP); } } }
private void createProcessResourcesTaskForBinary(final SourceSet sourceSet, SourceDirectorySet resourceSet, final Project target) { Copy resourcesTask = target.getTasks().create(sourceSet.getProcessResourcesTaskName(), ProcessResources.class); resourcesTask.setDescription("Processes " + resourceSet + "."); new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() { public File call() throws Exception { return sourceSet.getOutput().getResourcesDir(); } }); resourcesTask.from(resourceSet); }
@Override public void apply(Project project) { jSassBasePlugin = project.getPlugins().apply(JSassBasePlugin.class); project.getPlugins().apply(JavaPlugin.class); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { String taskName = sourceSet.getTaskName("compile", "Sass"); Set<File> srcDirs = sourceSet.getResources().getSrcDirs(); int i = 1; for (File srcDir : srcDirs) { SassCompile sassCompile = project.getTasks().create(i == 1 ? taskName : taskName + i, SassCompile.class); i++; sassCompile.setGroup(BasePlugin.BUILD_GROUP); sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set"); sassCompile.setSourceDir(srcDir); Copy processResources = (Copy) project.getTasks().getByName(sourceSet.getProcessResourcesTaskName()); sassCompile.getConventionMapping().map("destinationDir", () -> { if (jSassBasePlugin.getExtension().isInplace()) { return srcDir; } else { return processResources.getDestinationDir(); } }); processResources.dependsOn(sassCompile); } }); }
@Override public void apply(Project project) { project.getExtensions().create("web", WebExtension.class); project.getPlugins().apply(NodePlugin.class); project.getPlugins().apply(JavaLibraryPlugin.class); JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class); java.getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME) .getOutput() .dir(ImmutableMap.of("builtBy", "copyWeb"), "build/javaweb"); CacheableYarnTask buildWeb = project.getTasks().create("buildWeb", CacheableYarnTask.class); buildWeb.dependsOn(project.getRootProject().getTasks().findByName("yarn")); buildWeb.setArgs(ImmutableList.of("run", "build")); buildWeb.getInputs().dir("app"); buildWeb.getInputs().dir("internals"); // We assume the yarn task correctly handles up-to-date checks for node_modules, so only // need to look at yarn.lock here. buildWeb.getInputs().file(project.getRootProject().file("yarn.lock")); buildWeb.getOutputs().dir("build"); Copy copyWeb = project.getTasks().create("copyWeb", Copy.class); copyWeb.dependsOn(buildWeb); copyWeb.from("build/web"); project.afterEvaluate( p -> { ImmutableWebExtension web = project.getExtensions().getByType(WebExtension.class); copyWeb.into("build/javaweb/" + web.javaPackage().replace('.', '/')); }); }
/** * Create task to update readme file from template * * @param tasks Task container to create new tasks * @param projectConfig Project configuration * @param projectContext Project context * @param extensions Extension container */ @Mutate public void createReadmeUpdateTasks(ModelMap<Task> tasks, ProjectConfig projectConfig, ProjectContext projectContext, ExtensionContainer extensions) { // Create task to update the README Map<String, Object> context = new HashMap<>(); extensions.getExtraProperties().getProperties().forEach((name, value) -> { context.put(name, value); }); context.put("project", projectContext); context.put("projectConfig", projectConfig); tasks.create("readmeUpdate", Copy.class, t -> { t.setDescription("Update README from template."); t.setGroup("documentation"); t.from("src/doc/templates"); t.include("README.template.md"); t.rename(n -> n.replace(".template.", ".")); t.expand(context); ConventionMapping parameters = t.getConventionMapping(); parameters.map("destinationDir", () -> projectContext.getProjectDir()); }); tasks.named("assemble", t -> { t.dependsOn("readmeUpdate"); }); }
void setupPackageTasks(Project project, Task generateTask) { final File buildDir = new File(project.getBuildDir(), "npm_compile"); final File distDir = getNpmOutputDir(project); project.getTasks().create(PublishTypescriptStubsTask.NAME, PublishTypescriptStubsTask.class); TSGeneratorConfig config = project.getExtensions().getByType(TSGeneratorConfig.class); Copy copySources = project.getTasks().create("processTypescript", Copy.class); copySources.from(config.getGenDir()); copySources.into(buildDir); copySources.dependsOn(generateTask); // copy .npmrc file from root to working directory if available final File npmrcFile = new File(project.getProjectDir(), ".npmrc"); if (npmrcFile.exists()) { copySources.getInputs().file(npmrcFile); copySources.doFirst(new Action<Task>() { @Override public void execute(Task task) { File targetFile = new File(buildDir, ".npmrc"); buildDir.mkdirs(); TypescriptUtils.copyFile(npmrcFile, targetFile); } }); } CompileTypescriptStubsTask compileTypescriptTask = project.getTasks().create(CompileTypescriptStubsTask.NAME, CompileTypescriptStubsTask.class); try { NpmInstallTask npmInstall = (NpmInstallTask) project.getTasks().getByName("npmInstall"); npmInstall.setWorkingDir(buildDir); npmInstall.dependsOn(copySources); npmInstall.getInputs().file(new File(buildDir, "package.json")); npmInstall.getOutputs().dir(new File(buildDir, "node_modules")); compileTypescriptTask.dependsOn(npmInstall); } catch (UnknownTaskException e) { LOGGER.warn("task not found, ok in testing", e); } ConfigurableFileTree fileTree = project.fileTree(buildDir); fileTree.include("package.json"); fileTree.include(".npmrc"); fileTree.include("**/*.ts"); fileTree.exclude("**/*.d.ts"); compileTypescriptTask.getInputs().files(fileTree); compileTypescriptTask.setWorkingDir(buildDir); compileTypescriptTask.getOutputs().dir(buildDir); ConfigurableFileTree assembleFileTree = project.fileTree(new File(buildDir, "src")); assembleFileTree.include("**/*.ts"); assembleFileTree.include("**/*.js"); assembleFileTree.include("**/*.js.map"); Copy assembleSources = project.getTasks().create("assembleTypescript", Copy.class); assembleSources.from(assembleFileTree); assembleSources.from(new File(buildDir, "package.json")); assembleSources.into(distDir); assembleSources.dependsOn(compileTypescriptTask); }
public AndroidTask<Copy> getProcessJavaResourcesTask() { return processJavaResourcesTask; }
public void setProcessJavaResourcesTask( AndroidTask<Copy> processJavaResourcesTask) { this.processJavaResourcesTask = processJavaResourcesTask; }
@Override public void execute(Object arg0) { if(arg0 instanceof FileCopyDetails) { FileCopyDetails detail = (FileCopyDetails)arg0; File file = detail.getFile(); if(!file.isFile()) return; String originMd5 = md5s.get(detail.getRelativePath().getPathString()); if(originMd5==null) return; String nowMd5 = getMD5(file); if(nowMd5.equals(originMd5)) detail.exclude(); //Only copy modified files. } else if(arg0 instanceof Copy) { Copy task = (Copy)arg0; md5s = new HashMap<String, String>(); if(started==false) { started = true; try { File dest = task.getDestinationDir(); if(dest.exists()) FileUtils.deleteDirectory(task.getDestinationDir()); task.getDestinationDir().mkdir(); } catch (IOException e1) { throw new RuntimeException("Failed to clear directory:"+task.getDestinationDir().getAbsolutePath(), e1); } if(inFile.exists()) { try { List<String> lines = Files.readLines(inFile, Charset.defaultCharset()); for(String line : lines) { if(line.trim().isEmpty()) continue; md5s.put(line.substring(0, line.lastIndexOf(':')), line.substring(line.lastIndexOf(':')+1, line.length()-1)); } } catch (Exception e) { e.printStackTrace(); } } else { throw new RuntimeException("Can't find md5 record:"+inFile.getAbsolutePath()); } } else { started = false; md5s.clear(); } } else { throw new RuntimeException("Unexpected arg when copying."); } }