private void initClassPath() { RuntimeClassLoaderFactory classLoaderFactory = new RuntimeClassLoaderFactory(getProject()); Set<File> classpath = new HashSet<>(); classpath.addAll(classLoaderFactory.getProjectLibraries()); try { classpath.add(Paths.get(classLoaderFactory.getPluginUrl().toURI()).toFile()); } catch (URISyntaxException e) { throw new IllegalStateException(e); } Project project = getProject(); ConfigurableFileCollection files = project.files(classpath.toArray()); setClasspath(files); }
/** * Adds execution data generated by a task to the list of those to merge. Only tasks with a {@link JacocoTaskExtension} will be included; all others will be ignored. * * @param tasks one or more tasks to merge */ public void executionData(Task... tasks) { for (Task task : tasks) { JacocoTaskExtension extension = task.getExtensions().findByType(JacocoTaskExtension.class); if (extension != null) { ConfigurableFileCollection files = getProject().files(extension.getDestinationFile()); files.builtBy(task); executionData(files); } } }
private void configureGroovydoc() { project.getTasks().withType(Groovydoc.class, new Action<Groovydoc>() { public void execute(final Groovydoc groovydoc) { groovydoc.getConventionMapping().map("groovyClasspath", new Callable<Object>() { public Object call() throws Exception { FileCollection groovyClasspath = groovyRuntime.inferGroovyClasspath(groovydoc.getClasspath()); // Jansi is required to log errors when generating Groovydoc ConfigurableFileCollection jansi = project.files(moduleRegistry.getExternalModule("jansi").getImplementationClasspath().getAsFiles()); return groovyClasspath.plus(jansi); } }); groovydoc.getConventionMapping().map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return new File(java(project.getConvention()).getDocsDir(), "groovydoc"); } }); groovydoc.getConventionMapping().map("docTitle", new Callable<Object>() { public Object call() throws Exception { return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle(); } }); groovydoc.getConventionMapping().map("windowTitle", new Callable<Object>() { public Object call() throws Exception { return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle(); } }); } }); }
/** * Adds a set of library files to be linked. The provided libs object is evaluated as per {@link org.gradle.api.Project#files(Object...)}. */ public void lib(Object libs) { ((ConfigurableFileCollection) this.libs).from(libs); }
/** * Adds a set of library files to be installed. The provided libs object is evaluated as per {@link org.gradle.api.Project#files(Object...)}. */ public void lib(Object libs) { ((ConfigurableFileCollection) this.libs).from(libs); }
public ConfigurableFileCollection files(Object... paths) { return getFileOperations().files(paths); }
public ConfigurableFileCollection files(Object paths, Closure closure) { return ConfigureUtil.configure(closure, getFileOperations().files(paths)); }
public ConfigurableFileCollection from(Object... paths) { GUtil.addToCollection(files, Arrays.asList(paths)); return this; }
public ConfigurableFileCollection builtBy(Object... tasks) { buildDependency.add(tasks); return this; }
public ConfigurableFileCollection setBuiltBy(Iterable<?> tasks) { buildDependency.setValues(tasks); return this; }
@Override public ConfigurableFileCollection files(Object... paths) { return fileOperations.files(paths); }
@Override public ConfigurableFileCollection files(Object paths, Closure configureClosure) { return ConfigureUtil.configure(configureClosure, fileOperations.files(paths)); }
private void createUnitTestTask(@NonNull TaskFactory tasks, @NonNull final TestVariantData variantData) { final BaseVariantData testedVariantData = (BaseVariantData) variantData.getTestedVariantData(); final Test runTestsTask = project.getTasks().create( variantData.getScope().getTaskName(UNIT_TEST.getPrefix()), Test.class); runTestsTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP); runTestsTask.setDescription( "Run unit tests for the " + testedVariantData.getVariantConfiguration().getFullName() + " build."); fixTestTaskSources(runTestsTask); runTestsTask.dependsOn(variantData.assembleVariantTask); final AbstractCompile testCompileTask = variantData.javacTask; runTestsTask.setTestClassesDir(testCompileTask.getDestinationDir()); ConventionMappingHelper.map(runTestsTask, "classpath", new Callable<ConfigurableFileCollection>() { @Override public ConfigurableFileCollection call() throws Exception { Iterable<File> filteredBootClasspath = Iterables.filter( androidBuilder.getBootClasspath(), new Predicate<File>() { @Override public boolean apply(@Nullable File file) { return file != null && !SdkConstants.FN_FRAMEWORK_LIBRARY .equals(file.getName()); } }); return project.files( testCompileTask.getClasspath(), testCompileTask.getOutputs().getFiles(), variantData.processJavaResourcesTask.getOutputs(), testedVariantData.processJavaResourcesTask.getOutputs(), filteredBootClasspath, // Mockable JAR is last, to make sure you can shadow the classes // withdependencies. createMockableJar.getOutputFile()); } }); // Put the variant name in the report path, so that different testing tasks don't // overwrite each other's reports. TestTaskReports testTaskReports = runTestsTask.getReports(); for (ConfigurableReport report : new ConfigurableReport[] { testTaskReports.getJunitXml(), testTaskReports.getHtml()}) { report.setDestination(new File(report.getDestination(), testedVariantData.getName())); } tasks.named(JavaPlugin.TEST_TASK_NAME, new Action<Task>() { @Override public void execute(Task test) { test.dependsOn(runTestsTask); } }); extension.getTestOptions().getUnitTests().applyConfiguration(runTestsTask); }
public ConfigurableFileCollection files(Object... paths) { return fileOperations.files(paths); }
public ConfigurableFileCollection files(Object paths, Closure configureClosure) { return ConfigureUtil.configure(configureClosure, fileOperations.files(paths)); }
public ConfigurableFileCollection files(Object paths, Closure closure) { return fileOperations.files(paths, closure); }
public ConfigurableFileCollection files(Object paths, Closure configureClosure) { return fileOperations.files(paths, configureClosure); }
/** * <p>Returns a {@link ConfigurableFileCollection} containing the given files. This works as described for {@link * Project#files(Object...)}. Relative paths are resolved relative to the directory containing this script.</p> * * @param paths The paths to the files. May be empty. * @return The file collection. Never returns null. */ ConfigurableFileCollection files(Object... paths);
/** * <p>Creates a new {@code ConfigurableFileCollection} using the given paths. The file collection is configured * using the given closure. This method works as described for {@link Project#files(Object, groovy.lang.Closure)}. * Relative paths are resolved relative to the directory containing this script.</p> * * @param paths The contents of the file collection. Evaluated as per {@link #files(Object...)}. * @param configureClosure The closure to use to configure the file collection. * @return the configured file tree. Never returns null. */ ConfigurableFileCollection files(Object paths, Closure configureClosure);
/** * <p>Returns a {@link ConfigurableFileCollection} containing the given files. You can pass any of the following * types to this method:</p> * * <ul> <li>A {@link CharSequence}, including {@link String} or {@link groovy.lang.GString}. Interpreted relative to the project directory, as per {@link #file(Object)}. A string * that starts with {@code file:} is treated as a file URL.</li> * * <li>A {@link File}. Interpreted relative to the project directory, as per {@link #file(Object)}.</li> * * <li>A {@link java.net.URI} or {@link java.net.URL}. The URL's path is interpreted as a file path. Currently, only * {@code file:} URLs are supported. * * <li>A {@link java.util.Collection}, {@link Iterable}, or an array. May contain any of the types listed here. The elements of the collection * are recursively converted to files.</li> * * <li>A {@link org.gradle.api.file.FileCollection}. The contents of the collection are included in the returned * collection.</li> * * <li>A {@link java.util.concurrent.Callable}. The {@code call()} method may return any of the types listed here. * The return value of the {@code call()} method is recursively converted to files. A {@code null} return value is * treated as an empty collection.</li> * * <li>A Closure. May return any of the types listed here. The return value of the closure is recursively converted * to files. A {@code null} return value is treated as an empty collection.</li> * * <li>A {@link Task}. Converted to the task's output files.</li> * * <li>A {@link org.gradle.api.tasks.TaskOutputs}. Converted to the output files the related task.</li> * * <li>Anything else is treated as a failure.</li> * * </ul> * * <p>The returned file collection is lazy, so that the paths are evaluated only when the contents of the file * collection are queried. The file collection is also live, so that it evaluates the above each time the contents * of the collection is queried.</p> * * <p>The returned file collection maintains the iteration order of the supplied paths.</p> * * @param paths The paths to the files. May be empty. * @return The file collection. Never returns null. */ ConfigurableFileCollection files(Object... paths);
/** * <p>Creates a new {@code ConfigurableFileCollection} using the given paths. The paths are evaluated as per {@link * #files(Object...)}. The file collection is configured using the given closure. The file collection is passed to * the closure as its delegate. Example:</p> * <pre> * files "$buildDir/classes" { * builtBy 'compile' * } * </pre> * <p>The returned file collection is lazy, so that the paths are evaluated only when the contents of the file * collection are queried. The file collection is also live, so that it evaluates the above each time the contents * of the collection is queried.</p> * * @param paths The contents of the file collection. Evaluated as per {@link #files(Object...)}. * @param configureClosure The closure to use to configure the file collection. * @return the configured file tree. Never returns null. */ ConfigurableFileCollection files(Object paths, Closure configureClosure);
private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) { War warTask = overlay.getWarTask(); String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName()); String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName()); dependency.setTransitive(false); Configuration configuration = project.getConfigurations().create(overlay.getConfigurationName()); configuration.setDescription(String.format("Contents of the overlay '%s' for the task '%s'.", overlay.getName(), warTask.getName())); configuration.getDependencies().add(dependency); File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName())); Action<CopySpec> extractOverlay = copySpec -> { copySpec.into(destinationDir); copySpec.from((Callable<FileTree>) () -> project.zipTree(configuration.getSingleFile())); }; Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay); overlay.getWarCopySpec().from(extractOverlayTask); if (overlay.isEnableCompilation()) { project.sync(extractOverlay); project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask); ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes")) .builtBy(extractOverlayTask); project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, classes); project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, classes); FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree() .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**")); project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, libs); project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, libs); } }
/** * <p>Returns a {@link ConfigurableFileCollection} containing the given files. You can pass any of the following * types to this method:</p> * * <ul> <li>A {@link CharSequence}, including {@link String} or {@link groovy.lang.GString}. Interpreted relative to the project directory, as per {@link #file(Object)}. A string * that starts with {@code file:} is treated as a file URL.</li> * * <li>A {@link File}. Interpreted relative to the project directory, as per {@link #file(Object)}.</li> * * <li>A {@link java.net.URI} or {@link java.net.URL}. The URL's path is interpreted as a file path. Currently, only * {@code file:} URLs are supported. * * <li>A {@link java.util.Collection}, {@link Iterable}, or an array. May contain any of the types listed here. The elements of the collection * are recursively converted to files.</li> * * <li>A {@link org.gradle.api.file.FileCollection}. The contents of the collection are included in the returned * collection.</li> * * <li>A {@link java.util.concurrent.Callable}. The {@code call()} method may return any of the types listed here. * The return value of the {@code call()} method is recursively converted to files. A {@code null} return value is * treated as an empty collection.</li> * * <li>A Closure. May return any of the types listed here. The return value of the closure is recursively converted * to files. A {@code null} return value is treated as an empty collection.</li> * * <li>A {@link Task}. Converted to the task's output files.</li> * * <li>A {@link org.gradle.api.tasks.TaskOutputs}. Converted to the output files the related task.</li> * * <li>An Object. Its {@code toString()} value is treated the same way as a String, as per {@link #file(Object)}. * This has been deprecated and will be removed in the next version of Gradle.</li> * * </ul> * * <p>The returned file collection is lazy, so that the paths are evaluated only when the contents of the file * collection are queried. The file collection is also live, so that it evaluates the above each time the contents * of the collection is queried.</p> * * <p>The returned file collection maintains the iteration order of the supplied paths.</p> * * @param paths The paths to the files. May be empty. * @return The file collection. Never returns null. */ ConfigurableFileCollection files(Object... paths);