public static void createInstallTask(final NativeBinarySpecInternal binary, final NativeInstallationSpec installation, final NativeExecutableFileSpec executable, final BinaryNamingScheme namingScheme) { binary.getTasks().create(namingScheme.getTaskName("install"), InstallExecutable.class, new Action<InstallExecutable>() { @Override public void execute(InstallExecutable installTask) { installTask.setDescription("Installs a development image of " + binary.getDisplayName()); installTask.setGroup(LifecycleBasePlugin.BUILD_GROUP); installTask.setToolChain(executable.getToolChain()); installTask.setPlatform(binary.getTargetPlatform()); installTask.setExecutable(executable.getFile()); installTask.setDestinationDir(installation.getDirectory()); //TODO:HH wire binary libs via executable installTask.lib(new BinaryLibs(binary) { @Override protected FileCollection getFiles(NativeDependencySet nativeDependencySet) { return nativeDependencySet.getRuntimeFiles(); } }); //TODO:HH installTask.dependsOn(executable) installTask.dependsOn(binary); } }); }
public void convertInto(Object element, Collection<? super MinimalFileCollection> result, PathToFileResolver resolver) { if (element instanceof DefaultFileCollectionResolveContext) { DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element; result.addAll(nestedContext.resolveAsMinimalFileCollections()); } else if (element instanceof MinimalFileCollection) { MinimalFileCollection collection = (MinimalFileCollection) element; result.add(collection); } else if (element instanceof FileCollection) { throw new UnsupportedOperationException(String.format("Cannot convert instance of %s to MinimalFileCollection", element.getClass().getSimpleName())); } else if (element instanceof TaskDependency) { // Ignore return; } else { result.add(new ListBackedFileSet(resolver.resolve(element))); } }
public void execute(FileCollection classpath, final FileCollection executionData, final File destinationFile) { ant.withClasspath(classpath).execute(new Closure<Object>(this, this) { @SuppressWarnings("UnusedDeclaration") public Object doCall(Object it) { final GroovyObjectSupport antBuilder = (GroovyObjectSupport) it; antBuilder.invokeMethod("taskdef", ImmutableMap.of( "name", "jacocoMerge", "classname", "org.jacoco.ant.MergeTask" )); Map<String, File> arguments = ImmutableMap.of("destfile", destinationFile); antBuilder.invokeMethod("jacocoMerge", new Object[]{arguments, new Closure<Object>(this, this) { public Object doCall(Object ignore) { executionData.addToAntBuilder(antBuilder, "resources"); return null; } }}); return null; } }); }
@Override public void execute() { ImmutableMap.Builder<String, Object> options = ImmutableMap.builder(); options.put("destDir", getDestinationDir()); options.putAll(compileOptions.getDependOptions().optionMap()); if (compileOptions.getDependOptions().isUseCache()) { options.put("cache", dependencyCacheDir); } final AntBuilder ant = antBuilderFactory.create(); ant.getProject().addTaskDefinition("gradleDepend", AntDepend.class); ant.invokeMethod("gradleDepend", new Object[]{options.build(), new Closure<Object>(this, this) { @SuppressWarnings("UnusedDeclaration") public void doCall(Object ignore) { getSource().addToAntBuilder(ant, "src", FileCollection.AntType.MatchingTask); } }}); }
@Override public void registerWatchPoints(FileSystemSubset.Builder builder) { for (Dependency dependency : allDependencies) { if (dependency instanceof FileCollectionDependency) { FileCollection files = ((FileCollectionDependency) dependency).getFiles(); ((FileCollectionInternal) files).registerWatchPoints(builder); } } super.registerWatchPoints(builder); }
@Override public UnionFileTree add(FileCollection source) { if (!(source instanceof FileTree)) { throw new UnsupportedOperationException(String.format("Can only add FileTree instances to %s.", getDisplayName())); } sourceTrees.add(Cast.cast(FileTreeInternal.class, source)); return this; }
@Override public boolean isEmpty() { for (FileCollection collection : getSourceCollections()) { if (!collection.isEmpty()) { return false; } } return true; }
@Override public FileCollection fixed(final String displayName, File... files) { return new FileCollectionAdapter(new ListBackedFileSet(files) { @Override public String getDisplayName() { return displayName; } }); }
@Override public void execute(DataBindingExportBuildInfoTask task) { final BaseVariantData<? extends BaseVariantOutputData> variantData = appVariantContext.getScope() .getVariantData(); task.setXmlProcessor( AwbXmlProcessor.getLayoutXmlProcessor(appVariantContext, awbBundle, dataBindingBuilder)); task.setSdkDir(appVariantContext.getScope().getGlobalScope().getSdkHandler().getSdkFolder()); task.setXmlOutFolder(appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle)); ConventionMappingHelper.map(task, "compilerClasspath", new Callable<FileCollection>() { @Override public FileCollection call() { return appVariantContext.getScope().getJavaClasspath(); } }); ConventionMappingHelper .map(task, "compilerSources", new Callable<Iterable<ConfigurableFileTree>>() { @Override public Iterable<ConfigurableFileTree> call() throws Exception { return Iterables.filter(appVariantContext.getAwSourceOutputDir(awbBundle), new Predicate<ConfigurableFileTree>() { @Override public boolean apply(ConfigurableFileTree input) { File dataBindingOut = appVariantContext .getAwbClassOutputForDataBinding(awbBundle); return !dataBindingOut.equals(input.getDir()); } }); } }); task.setExportClassListTo(variantData.getType().isExportDataBindingClassList() ? new File(appVariantContext.getAwbLayoutFolderOutputForDataBinding(awbBundle), "_generated.txt") : null); //task.setPrintMachineReadableErrors(printMachineReadableErrors); task.setDataBindingClassOutput(appVariantContext.getAwbClassOutputForDataBinding(awbBundle)); }
/** * All of the files that will be signed by this operation. */ public FileCollection getFilesToSign() { return newSignatureFileCollection(new Function<Signature, File>() { @Override public File apply(Signature input) { return input.getToSign(); } }); }
private FindBugsWorker createWorkerProcess(File workingDir, WorkerProcessFactory workerFactory, FileCollection findBugsClasspath, FindBugsSpec spec) { SingleRequestWorkerProcessBuilder<FindBugsWorker> builder = workerFactory.singleRequestWorker(FindBugsWorker.class, FindBugsExecuter.class); builder.setBaseName("Gradle FindBugs Worker"); builder.applicationClasspath(findBugsClasspath); builder.sharedPackages(Arrays.asList("edu.umd.cs.findbugs")); JavaExecHandleBuilder javaCommand = builder.getJavaCommand(); javaCommand.setWorkingDir(workingDir); javaCommand.setMaxHeapSize(spec.getMaxHeapSize()); return builder.build(); }
private <T> List<T> doResolve(Converter<? extends T> converter) { List<T> result = new ArrayList<T>(); while (!queue.isEmpty()) { Object element = queue.remove(0); // TODO - need to sync with BuildDependenciesOnlyFileCollectionResolveContext if (element instanceof DefaultFileCollectionResolveContext) { DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element; converter.convertInto(nestedContext, result, fileResolver); } else if (element instanceof FileCollectionContainer) { FileCollectionContainer fileCollection = (FileCollectionContainer) element; resolveNested(fileCollection, result, converter); } else if (element instanceof FileCollection || element instanceof MinimalFileCollection) { converter.convertInto(element, result, fileResolver); } else if (element instanceof Task) { Task task = (Task) element; queue.add(0, task.getOutputs().getFiles()); } else if (element instanceof TaskOutputs) { TaskOutputs outputs = (TaskOutputs) element; queue.add(0, outputs.getFiles()); } else if (element instanceof Callable) { Callable callable = (Callable) element; Object callableResult = uncheckedCall(callable); if (callableResult != null) { queue.add(0, callableResult); } } else if (element instanceof Iterable) { Iterable<?> iterable = (Iterable) element; GUtil.addToCollection(queue.subList(0, 0), iterable); } else if (element instanceof Object[]) { Object[] array = (Object[]) element; GUtil.addToCollection(queue.subList(0, 0), Arrays.asList(array)); } else { converter.convertInto(element, result, fileResolver); } } return result; }
private void configureWithJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention, PluginContainer plugins) { plugins.withType(JavaPlugin.class, new Action<JavaPlugin>() { public void execute(JavaPlugin javaPlugin) { final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class); SourceSet sourceSet = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); sourceSet.getResources().srcDir(new Callable() { public Object call() throws Exception { return earPluginConvention.getAppDirName(); } }); project.getTasks().withType(Ear.class, new Action<Ear>() { public void execute(final Ear task) { task.dependsOn(new Callable<FileCollection>() { public FileCollection call() throws Exception { return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME) .getRuntimeClasspath(); } }); task.from(new Callable<FileCollection>() { public FileCollection call() throws Exception { return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput(); } }); } }); } }); }
public void apply(Project project) { project.getPluginManager().apply(JavaScriptBasePlugin.class); JavaScriptExtension jsExtension = project.getExtensions().findByType(JavaScriptExtension.class); final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().create(RhinoExtension.NAME, RhinoExtension.class); final Configuration configuration = addClasspathConfiguration(project.getConfigurations()); configureDefaultRhinoDependency(configuration, project.getDependencies(), rhinoExtension); ConventionMapping conventionMapping = ((IConventionAware) rhinoExtension).getConventionMapping(); conventionMapping.map("classpath", new Callable<Configuration>() { public Configuration call() { return configuration; } }); conventionMapping.map("version", new Callable<String>() { public String call() { return RhinoExtension.DEFAULT_RHINO_DEPENDENCY_VERSION; } }); project.getTasks().withType(RhinoShellExec.class, new Action<RhinoShellExec>() { public void execute(RhinoShellExec task) { task.getConventionMapping().map("classpath", new Callable<FileCollection>() { public FileCollection call() { return rhinoExtension.getClasspath(); } }); task.getConventionMapping().map("main", new Callable<String>() { public String call() { return RhinoExtension.RHINO_SHELL_MAIN; } }); task.setClasspath(rhinoExtension.getClasspath()); } }); }
private static ProjectLibrary createScalaSdkFromPlatform(ScalaPlatform platform, FileCollection scalaClasspath, boolean useScalaSdk) { String version = platform.getScalaVersion(); if (useScalaSdk) { return createScalaSdkLibrary("scala-sdk-" + version, scalaClasspath); } return createProjectLibrary("scala-compiler-" + version, scalaClasspath); }
private FileCollection filesFor(final Algorithm algo) { return getProject().fileTree(getOutputDir(), new Action<ConfigurableFileTree>() { @Override public void execute(ConfigurableFileTree files) { files.include("**/*." + algo.toString().toLowerCase()); } }); }
/** * Adds additional source directories to be used for any classes included in the report. * * @param dirs a {@code FileCollection} of directories containing source files for the classes included in the report */ public void additionalSourceDirs(FileCollection dirs) { if (additionalSourceDirs == null) { additionalSourceDirs = dirs; } else { additionalSourceDirs = additionalSourceDirs.plus(dirs); } }
/** * Gets the source directories for the classes that will be reported on. Source will be obtained from these directories only for the classes included in the report. * * @return source directories for the classes reported on * @see #getAllClassDirs() */ @Internal public FileCollection getAllSourceDirs() { FileCollection additionalDirs = getAdditionalSourceDirs(); if (additionalDirs == null) { return sourceDirectories; } return sourceDirectories.plus(getAdditionalSourceDirs()); }
public static void toRelativeFiles(final FileCollection source, final List<RelativeFile> targets) { FileTree fileTree = source.getAsFileTree(); fileTree.visit(new FileVisitor() { public void visitDir(FileVisitDetails dirDetails) {} public void visitFile(FileVisitDetails fileDetails) { targets.add(new RelativeFile(fileDetails.getFile(), fileDetails.getRelativePath())); } }); }
private Object prepareValue(Object value) { while (true) { if (value instanceof Callable) { Callable callable = (Callable) value; value = uncheckedCall(callable); } else if (value instanceof FileCollection) { FileCollection fileCollection = (FileCollection) value; return fileCollection.getFiles(); } else { return avoidGString(value); } } }
public void apply(final Project project) { project.getPluginManager().apply(JavaPlugin.class); final WarPluginConvention pluginConvention = new WarPluginConvention(project); project.getConvention().getPlugins().put("war", pluginConvention); project.getTasks().withType(War.class, new Action<War>() { public void execute(War task) { task.from(new Callable() { public Object call() throws Exception { return pluginConvention.getWebAppDir(); } }); task.dependsOn(new Callable() { public Object call() throws Exception { return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName( SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); } }); task.classpath(new Object[] {new Callable() { public Object call() throws Exception { FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); Configuration providedRuntime = project.getConfigurations().getByName( PROVIDED_RUNTIME_CONFIGURATION_NAME); return runtimeClasspath.minus(providedRuntime); } }}); } }); War war = project.getTasks().create(WAR_TASK_NAME, War.class); war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries."); war.setGroup(BasePlugin.BUILD_GROUP); ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact); configureConfigurations(project.getConfigurations()); configureComponent(project, warArtifact); }
@Override public FileCollection getPreviousOutputFiles() { if (history == null) { throw new IllegalStateException("Task history is currently not available for this task."); } return history.getOutputFiles(); }
@Override public FileCollection create(final TaskDependency builtBy, MinimalFileSet contents) { if (contents instanceof Buildable) { throw new UnsupportedOperationException("Not implemented yet."); } return new FileCollectionAdapter(contents) { @Override public TaskDependency getBuildDependencies() { return builtBy; } }; }
public void submit(Action<ClojureWorkerConfiguration> action) { ClojureWorkerConfiguration config = new ClojureWorkerConfiguration(); action.execute(config); FileCollection realClasspath = config.getClasspath().plus(resolveShim()); workerExecutor.submit(ClojureWorker.class, worker -> { worker.setIsolationMode(IsolationMode.PROCESS); worker.params(config.getNamespace(), config.getFunction(), config.getArgs()); config.getConfigureFork().forEach(worker::forkOptions); worker.forkOptions(fork -> fork.systemProperty("shim.classpath", realClasspath.getAsPath())); worker.classpath(resolveWorker()); }); }
@Override public FileCollection getFiles() { return source; }
public void setSource(FileCollection source) { this.source = source; }
private void configureTaskConventionMapping(Configuration configuration, Pmd task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("pmdClasspath", Callables.returning(configuration)); taskMapping.map("ruleSets", new Callable<List<String>>() { @Override public List<String> call() { return extension.getRuleSets(); } }); taskMapping.map("ruleSetConfig", new Callable<TextResource>() { @Override public TextResource call() { return extension.getRuleSetConfig(); } }); taskMapping.map("ruleSetFiles", new Callable<FileCollection>() { @Override public FileCollection call() { return extension.getRuleSetFiles(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); taskMapping.map("rulePriority", new Callable<Integer>() { @Override public Integer call() { return extension.getRulePriority(); } }); taskMapping.map("consoleOutput", new Callable<Boolean>() { @Override public Boolean call() { return extension.isConsoleOutput(); } }); taskMapping.map("targetJdk", new Callable<TargetJdk>() { @Override public TargetJdk call() { return extension.getTargetJdk(); } }); }
/** * Sets the classpath used to load the classes under validation. */ public void setClasspath(FileCollection classpath) { this.classpath = classpath; }
public void setPmdClasspath(FileCollection pmdClasspath) { this.pmdClasspath = pmdClasspath; }
/** * The custom rule set files to be used. See the <a href="http://pmd.sourceforge.net/howtomakearuleset.html">official documentation</a> for how to author a rule set file. * * Example: ruleSetFiles = files("config/pmd/myRuleSets.xml") */ @InputFiles @PathSensitive(PathSensitivity.NONE) public FileCollection getRuleSetFiles() { return ruleSetFiles; }
@Override public FileCollection getClasspath() { return classpath; }
private FileCollection getTestCompileClasspath(PlayApplicationBinarySpec binary, PlayToolProvider playToolProvider, PlayPluginConfigurations configurations) { return new SimpleFileCollection(binary.getJarFile()).plus(configurations.getPlayTest().getAllArtifacts()); }
/** * Source sets that coverage should be reported for. */ @PathSensitive(PathSensitivity.RELATIVE) @InputFiles public FileCollection getSourceDirectories() { return sourceDirectories; }
@Override public FileCollection getLinkFiles() { return createFileCollection(getSharedLibraryLinkFile(), "link files", "Shared library link files"); }
/** * Class path holding the FindBugs library. */ @Classpath public FileCollection getFindbugsClasspath() { return findbugsClasspath; }
public void setFindbugsClasspath(FileCollection findbugsClasspath) { this.findbugsClasspath = findbugsClasspath; }
/** * Class path holding any additional FindBugs plugins. */ @Classpath public FileCollection getPluginClasspath() { return pluginClasspath; }
@Override public FileCollection getPropertyFiles() { return files; }
public FindBugsSpecBuilder withSources(FileCollection sources) { this.sources = sources; return this; }
public void setBootstrapClasspath(FileCollection classpath) { javaOptions.setBootstrapClasspath(classpath); }