private void resolveAndFilterSourceFiles(final GroovyJavaJointCompileSpec spec) { final List<String> fileExtensions = CollectionUtils.collect(spec.getGroovyCompileOptions().getFileExtensions(), new Transformer<String, String>() { @Override public String transform(String extension) { return '.' + extension; } }); FileCollection filtered = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File element) { for (String fileExtension : fileExtensions) { if (hasExtension(element, fileExtension)) { return true; } } return false; } }); spec.setSource(new SimpleFileCollection(filtered.getFiles())); }
public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) { if (staleClasses.isEmpty()) { spec.setSource(new SimpleFileCollection()); return; //do nothing. No classes need recompilation. } Factory<PatternSet> patternSetFactory = fileOperations.getFileResolver().getPatternSetFactory(); PatternSet classesToDelete = patternSetFactory.create(); PatternSet sourceToCompile = patternSetFactory.create(); preparePatterns(staleClasses, classesToDelete, sourceToCompile); //selectively configure the source spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile)); //since we're compiling selectively we need to include the classes compiled previously spec.setClasspath(Iterables.concat(spec.getClasspath(), asList(spec.getDestinationDir()))); //get rid of stale files FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete); fileOperations.delete(deleteMe); }
private void addResourcesIfNecessary() { if (this.addResources) { SourceSet mainSourceSet = SourceSets.findMainSourceSet(getProject()); final File outputDir = (mainSourceSet == null ? null : mainSourceSet.getOutput().getResourcesDir()); final Set<File> resources = new LinkedHashSet<File>(); if (mainSourceSet != null) { resources.addAll(mainSourceSet.getResources().getSrcDirs()); } List<File> classPath = new ArrayList<File>(getClasspath().getFiles()); classPath.addAll(0, resources); getLogger().info("Adding classpath: " + resources); setClasspath(new SimpleFileCollection(classPath)); if (outputDir != null) { for (File directory : resources) { FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory); } } } }
static FileCollection fromLocalClassloader() { Set<File> files = new LinkedHashSet<>(); Consumer<Class<?>> addPeerClasses = clazz -> { URLClassLoader urlClassloader = (URLClassLoader) clazz.getClassLoader(); for (URL url : urlClassloader.getURLs()) { String name = url.getFile(); if (name != null) { files.add(new File(name)); } } }; // add the classes that goomph needs addPeerClasses.accept(JavaExecable.class); // add the gradle API addPeerClasses.accept(JavaExec.class); return new SimpleFileCollection(files); }
public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) { if (staleClasses.isEmpty()) { spec.setSource(new SimpleFileCollection()); return; //do nothing. No classes need recompilation. } PatternSet classesToDelete = new PatternSet(); PatternSet sourceToCompile = new PatternSet(); preparePatterns(staleClasses, classesToDelete, sourceToCompile); //selectively configure the source spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile)); //since we're compiling selectively we need to include the classes compiled previously spec.setClasspath(Iterables.concat(spec.getClasspath(), asList(spec.getDestinationDir()))); //get rid of stale files FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete); fileOperations.delete(deleteMe); }
private EnumMap<SysProp, String> getMetadataInternal(File jdkPath) { JavaExecAction exec = factory.newJavaExecAction(); exec.executable(javaExe(jdkPath, "java")); File workingDir = Files.createTempDir(); exec.setWorkingDir(workingDir); exec.setClasspath(new SimpleFileCollection(workingDir)); try { writeProbe(workingDir); exec.setMain(JavaProbe.CLASSNAME); ByteArrayOutputStream baos = new ByteArrayOutputStream(); exec.setStandardOutput(baos); ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); exec.setErrorOutput(errorOutput); exec.setIgnoreExitValue(true); ExecResult result = exec.execute(); int exitValue = result.getExitValue(); if (exitValue == 0) { return parseExecOutput(baos.toString()); } return error("Command returned unexpected result code: " + exitValue + "\nError output:\n" + errorOutput); } catch (ExecException ex) { return error(ex.getMessage()); } finally { try { FileUtils.deleteDirectory(workingDir); } catch (IOException e) { throw new GradleException("Unable to delete temp directory", e); } } }
private void resolveAndFilterSourceFiles(JavaCompileSpec spec) { // this mimics the behavior of the Ant javac task (and therefore AntJavaCompiler), // which silently excludes files not ending in .java FileCollection javaOnly = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File element) { return hasExtension(element, ".java"); } }); spec.setSource(new SimpleFileCollection(javaOnly.getFiles())); }
@Override public FileCollectionInternal createDelegate() { ImmutableSet.Builder<File> files = ImmutableSet.builder(); for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) { if ((artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) == matchProjectComponents) { files.add(artifact.getFile()); } } return new SimpleFileCollection(files.build()); }
private void resolveAndFilterSourceFiles(final GroovyJavaJointCompileSpec spec) { FileCollection filtered = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File element) { for (String fileExtension : spec.getGroovyCompileOptions().getFileExtensions()) { if (element.getName().endsWith("." + fileExtension)) { return true; } } return false; } }); spec.setSource(new SimpleFileCollection(filtered.getFiles())); }
private void resolveAndFilterSourceFiles(JavaCompileSpec spec) { // this mimics the behavior of the Ant javac task (and therefore AntJavaCompiler), // which silently excludes files not ending in .java FileCollection javaOnly = spec.getSource().filter(new Spec<File>() { public boolean isSatisfiedBy(File element) { return element.getName().endsWith(".java"); } }); spec.setSource(new SimpleFileCollection(javaOnly.getFiles())); }
public FileCollection getFiles() { List<File> files = new ArrayList<File>(); for (Map.Entry<String, IncrementalFileSnapshot> entry : snapshots.entrySet()) { if (entry.getValue() instanceof FileHashSnapshot) { files.add(new File(entry.getKey())); } } return new SimpleFileCollection(files); }
private void resolveClasspath(ScalaJavaJointCompileSpec spec) { spec.setClasspath(new SimpleFileCollection(Lists.newArrayList(spec.getClasspath()))); spec.setScalaClasspath(new SimpleFileCollection(Lists.newArrayList(spec.getScalaClasspath()))); spec.setZincClasspath(new SimpleFileCollection(Lists.newArrayList(spec.getZincClasspath()))); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Class path: {}", spec.getClasspath()); LOGGER.debug("Scala class path: {}", spec.getScalaClasspath()); LOGGER.debug("Zinc class path: {}", spec.getZincClasspath()); } }
public FileCollection getFiles() { List<File> files = new ArrayList<File>(); for (Map.Entry<String, FileSnapshot> entry : snapshots.entrySet()) { if (entry.getValue() instanceof FileHashSnapshot) { files.add(new File(entry.getKey())); } } return new SimpleFileCollection(files); }
public SelectiveCompilation(IncrementalTaskInputs inputs, FileTree source, FileCollection compileClasspath, final File compileDestination, final ClassDependencyInfoSerializer dependencyInfoSerializer, final JarSnapshotCache jarSnapshotCache, final SelectiveJavaCompiler compiler, Iterable<File> sourceDirs, final FileOperations operations) { this.operations = operations; this.jarSnapshotFeeder = new JarSnapshotFeeder(jarSnapshotCache, new JarSnapshotter(new DefaultHasher())); this.compiler = compiler; Clock clock = new Clock(); final InputOutputMapper mapper = new InputOutputMapper(sourceDirs, compileDestination); //load dependency info final ClassDependencyInfo dependencyInfo = dependencyInfoSerializer.readInfo(); //including only source java classes that were changed final PatternSet changedSourceOnly = new PatternSet(); InputFileDetailsAction action = new InputFileDetailsAction(mapper, compiler, changedSourceOnly, dependencyInfo); inputs.outOfDate(action); inputs.removed(action); if (fullRebuildNeeded != null) { LOG.lifecycle("Stale classes detection completed in {}. Rebuild needed: {}.", clock.getTime(), fullRebuildNeeded); this.classpath = compileClasspath; this.source = source; return; } compiler.deleteStaleClasses(); Set<File> filesToCompile = source.matching(changedSourceOnly).getFiles(); if (filesToCompile.isEmpty()) { this.compilationNeeded = false; this.classpath = compileClasspath; this.source = source; } else { this.classpath = compileClasspath.plus(new SimpleFileCollection(compileDestination)); this.source = source.matching(changedSourceOnly); } LOG.lifecycle("Stale classes detection completed in {}. Compile include patterns: {}.", clock.getTime(), changedSourceOnly.getIncludes()); }
@Override public FileCollection getOutputFiles() { ArrayList<File> newOuputFiles = new ArrayList<>(); for (File file : mTaskExecutionHistory.getOutputFiles()) { newOuputFiles.add( FileUtils.inFolder(file, mResFiles) ? new IgnoreResFileFile(file.getPath(), mResFiles) : file); } return new SimpleFileCollection(newOuputFiles); }
private FileCollection readListOfDepConfigs(@Nonnull final File pDepConfigDir) { File[] listOfFiles = pDepConfigDir.listFiles(new PropertyFileFilter()); if (listOfFiles == null) { throw new GradleException("no dependency configurations found in dir: " + pDepConfigDir); } return new SimpleFileCollection(listOfFiles); }
private FileCollection empty() { return new SimpleFileCollection(); }
@Override public FileCollection getFiles() { return new SimpleFileCollection(); }
private void resolveClasspath(JavaCompileSpec spec) { spec.setClasspath(new SimpleFileCollection(Lists.newArrayList(spec.getClasspath()))); }
private void resolveAndFilterSourceFiles(final ScalaJavaJointCompileSpec spec) { spec.setSource(new SimpleFileCollection(spec.getSource().getFiles())); }
public CacheableTaskOutputCompositeFilePropertyElementSpec(CompositeTaskOutputPropertySpec parentProperty, String propertySuffix, File file) { this.parentProperty = parentProperty; this.propertySuffix = propertySuffix; this.files = new SimpleFileCollection(Collections.singleton(file)); this.file = file; }
@Mutate void createTestTasks(ModelMap<Task> tasks, @Path("binaries") ModelMap<PlayApplicationBinarySpecInternal> playBinaries, final PlayPluginConfigurations configurations, final FileResolver fileResolver, final ProjectIdentifier projectIdentifier, @Path("buildDir") final File buildDir) { for (final PlayApplicationBinarySpecInternal binary : playBinaries) { final PlayToolProvider playToolProvider = binary.getToolChain().select(binary.getTargetPlatform()); final FileCollection testCompileClasspath = getTestCompileClasspath(binary, playToolProvider, configurations); final String testCompileTaskName = binary.getTasks().taskName("compile", "tests"); final File testSourceDir = fileResolver.resolve("test"); final FileCollection testSources = new SimpleFileCollection(testSourceDir).getAsFileTree().matching(new PatternSet().include("**/*.scala", "**/*.java")); final File testClassesDir = new File(buildDir, binary.getProjectScopedName() + "/testClasses"); tasks.create(testCompileTaskName, PlatformScalaCompile.class, new Action<PlatformScalaCompile>() { public void execute(PlatformScalaCompile scalaCompile) { scalaCompile.setDescription("Compiles the scala and java test sources for the " + binary.getDisplayName() + "."); scalaCompile.setClasspath(testCompileClasspath); scalaCompile.dependsOn(binary.getBuildTask()); scalaCompile.setPlatform(binary.getTargetPlatform().getScalaPlatform()); scalaCompile.setDestinationDir(testClassesDir); scalaCompile.setSource(testSources); String targetCompatibility = binary.getTargetPlatform().getJavaPlatform().getTargetCompatibility().getMajorVersion(); scalaCompile.setSourceCompatibility(targetCompatibility); scalaCompile.setTargetCompatibility(targetCompatibility); IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions(); incrementalOptions.setAnalysisFile(new File(buildDir, "tmp/scala/compilerAnalysis/" + testCompileTaskName + ".analysis")); } }); final String testTaskName = binary.getTasks().taskName("test"); final File binaryBuildDir = new File(buildDir, binary.getProjectScopedName()); tasks.create(testTaskName, Test.class, new Action<Test>() { public void execute(Test test) { test.setDescription("Runs " + WordUtils.uncapitalize(binary.getDisplayName() + ".")); test.setClasspath(getRuntimeClasspath(testClassesDir, testCompileClasspath)); test.setTestClassesDir(testClassesDir); test.setBinResultsDir(new File(binaryBuildDir, "results/" + testTaskName + "/bin")); test.getReports().getJunitXml().setDestination(new File(binaryBuildDir, "reports/test/xml")); test.getReports().getHtml().setDestination(new File(binaryBuildDir, "reports/test")); test.dependsOn(testCompileTaskName); test.setWorkingDir(projectIdentifier.getProjectDir()); } }); binary.getTasks().add(tasks.get(testTaskName)); } }
private FileCollection getTestCompileClasspath(PlayApplicationBinarySpec binary, PlayToolProvider playToolProvider, PlayPluginConfigurations configurations) { return new SimpleFileCollection(binary.getJarFile()).plus(configurations.getPlayTest().getAllArtifacts()); }
private FileCollection getRuntimeClasspath(File testClassesDir, FileCollection testCompileClasspath) { return new SimpleFileCollection(testClassesDir).plus(testCompileClasspath); }
private FileCollection newSignatureFileCollection(Function<Signature, File> getFile) { return new SimpleFileCollection(collectSignatureFiles(getFile)); }
public FileCollection getLinkFiles() { return new SimpleFileCollection(); }
public FileCollection getRuntimeFiles() { return new SimpleFileCollection(); }
public FileCollection getHeaderDirs() { return new SimpleFileCollection(library.getHeaders().getSrcDirs()); }
private FileCollection toFileCollection(Iterable<File> classpath) { if (classpath instanceof FileCollection) { return (FileCollection) classpath; } return new SimpleFileCollection(Lists.newArrayList(classpath)); }
public FileCollection getFiles() { return new SimpleFileCollection(); }
public FileCollection getOutputFiles() { TaskExecution lastExecution = history.getPreviousExecution(); return lastExecution != null && lastExecution.getOutputFilesSnapshot() != null ? lastExecution.getOutputFilesSnapshot().getFiles() : new SimpleFileCollection(); }