/** * Returns the set of binary test results to include in the report. */ @InputFiles @SkipWhenEmpty public FileCollection getTestResultDirs() { UnionFileCollection dirs = new UnionFileCollection(); for (Object result : results) { addTo(result, dirs); } return dirs; }
private void addTo(Object result, UnionFileCollection dirs) { if (result instanceof Test) { Test test = (Test) result; dirs.add(getProject().files(test.getBinResultsDir()).builtBy(test)); } else if (result instanceof Iterable<?>) { Iterable<?> iterable = (Iterable<?>) result; for (Object nested : iterable) { addTo(nested, dirs); } } else { dirs.add(getProject().files(result)); } }
public FileCollection resolve() { try { walker.add(queue); return new UnionFileCollection(walker.findValues()); } finally { queue.clear(); } }
@Override public void apply(Project project) { GeneratePluginExtension generatePluginExtension = project.getExtensions().create(EXTENSION_NAME, GeneratePluginExtension.class, project); GenerateTask generateTask = project.getTasks().create(TASK_NAME, GenerateTask.class); generateTask.setGroup(BasePlugin.BUILD_GROUP); generateTask.setDescription("Generates DDL scripts based on JPA model."); generateTask.setExtension(generatePluginExtension); generateTask.dependsOn(JavaBasePlugin.BUILD_TASK_NAME); project.afterEvaluate(evaluatedProject -> { fillDefaults(evaluatedProject, generatePluginExtension); SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets"); Set<File> paths; if (sourceSets != null) { UnionFileCollection mainClasspath = (UnionFileCollection) sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); paths = mainClasspath.getSources() .stream() .filter(fileCollection -> fileCollection instanceof DefaultSourceSetOutput) .map(DefaultSourceSetOutput.class::cast) .flatMap(fileCollection -> fileCollection.getClassesDirs().getFiles().stream()) .collect(Collectors.toSet()); } else { paths = new HashSet<>(); } generateTask.setOutputClassesDirs(paths); }); }
private Configuration findConfiguraion(FileCollection classpath) { if (classpath instanceof Configuration) { return (Configuration) classpath; } else if (classpath instanceof UnionFileCollection) { for (FileCollection files : ((UnionFileCollection) classpath).getSources()) { Configuration configuraion = findConfiguraion(files); if (configuraion != null) return configuraion; } } return null; }
/** * @param project the project on which we'll call {@link Project#javaexec(Action)}. * @param input the JavaExecable which we'll take as input and call run() on. * @param settings any extra settings you'd like to set on the JavaExec (e.g. heap) * @return the JavaExecable after it has had run() called. */ public static <T extends JavaExecable> T exec(Project project, T input, Action<JavaExecSpec> settings) throws Throwable { // copy the classpath from the project's buildscript (and its parents) List<FileCollection> classpaths = TreeStream.toParent(ProjectPlugin.treeDef(), project) .map(p -> p.getBuildscript().getConfigurations().getByName(BUILDSCRIPT_CLASSPATH)) .collect(Collectors.toList()); // add the gradleApi, workaround from https://discuss.gradle.org/t/gradle-doesnt-add-the-same-dependencies-to-classpath-when-applying-plugins/9759/6?u=ned_twigg classpaths.add(project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi())); // add stuff from the local classloader too, to fix testkit's classpath classpaths.add(JavaExecableImp.fromLocalClassloader()); // run it FileCollection classpath = new UnionFileCollection(classpaths); return JavaExecableImp.execInternal(input, classpath, settings, execSpec -> JavaExecWinFriendly.javaExec(project, execSpec)); }
public FileCollection getPublishableFiles() { return new UnionFileCollection(mavenArtifacts.getFiles(), pomFile); }
public FileCollection getPublishableFiles() { return new UnionFileCollection(ivyArtifacts.getFiles(), descriptorFile); }
public FileCollection getFiles() { return new UnionFileCollection(inputFiles, sourceFiles); }
/** * A henson navigator is a class that helps a consumer to consume the navigation api that it * declares in its dependencies. The henson navigator will wrap the intent builders. Thus, a * henson navigator, is driven by consumption of intent builders, whereas the henson classes are * driven by the production of an intent builder. * * <p>This task is created per android variant: * * <ul> * <li>we scan the variant compile configuration for navigation api dependencies * <li>we generate a henson navigator class for this variant that wraps the intent builders * </ul> * * @param variant the variant for which to create a builder. * @param hensonNavigatorPackageName the package name in which we create the class. */ public Task createHensonNavigatorGenerationTask( BaseVariant variant, String hensonNavigatorPackageName, File destinationFolder) { Task generateHensonNavigatorTask = project.getTasks().create("generate" + capitalize(variant.getName()) + "HensonNavigator"); generateHensonNavigatorTask.doFirst( task -> { JavaCompile javaCompiler = (JavaCompile) variant.getJavaCompiler(); FileCollection variantCompileClasspath = javaCompiler.getClasspath(); FileCollection uft = new UnionFileCollection( javaCompiler.getSource(), project.fileTree(destinationFolder)); javaCompiler.setSource(uft); logger.debug("Analyzing configuration: " + variantCompileClasspath.getFiles()); Set<String> targetActivities = new HashSet<>(); Streams.stream(variantCompileClasspath) .forEach( dependency -> { logger.debug("Detected dependency: {}", dependency.getName()); if (dependency.getName().matches("classes.jar")) { logger.debug("Detected navigation API dependency: {}", dependency.getName()); File file = dependency.getAbsoluteFile(); List<String> entries = getJarContent(file); entries.forEach( entry -> { if (entry.matches(".*__IntentBuilder.class")) { logger.debug("Detected intent builder: {}", entry); String targetActivityFQN = entry .substring( 0, entry.length() - "__IntentBuilder.class".length()) .replace('/', '.'); targetActivities.add(targetActivityFQN); } }); } String hensonNavigator = hensonNavigatorGenerator.generateHensonNavigatorClass( targetActivities, hensonNavigatorPackageName); destinationFolder.mkdirs(); String generatedFolderName = hensonNavigatorPackageName.replace('.', '/').concat("/"); File generatedFolder = new File(destinationFolder, generatedFolderName); generatedFolder.mkdirs(); File generatedFile = new File(generatedFolder, "HensonNavigator.java"); try { logger.debug( "Generating Henson navigator in " + generatedFile.getAbsolutePath()); logger.debug(hensonNavigator); Files.write(generatedFile.toPath(), singletonList(hensonNavigator)); } catch (IOException e) { throw new RuntimeException(e); } }); }); //we put the task right before compilation so that all dependencies are resolved // when the task is executed generateHensonNavigatorTask.setDependsOn(variant.getJavaCompiler().getDependsOn()); variant.getJavaCompiler().dependsOn(generateHensonNavigatorTask); return generateHensonNavigatorTask; }