Search in sources :

Example 6 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class BuildDependenciesOnlyFileCollectionResolveContext method add.

@Override
public FileCollectionResolveContext add(Object element) {
    // TODO - need to sync with DefaultFileCollectionResolveContext
    if (element instanceof FileCollection) {
        taskContext.add(element);
    } else if (element instanceof MinimalFileCollection && element instanceof Buildable) {
        taskContext.add(element);
    } else if (element instanceof Task) {
        Task task = (Task) element;
        taskContext.add(task);
    } else if (element instanceof TaskOutputs) {
        TaskOutputs outputs = (TaskOutputs) element;
        taskContext.add(outputs.getFiles());
    } else if (element instanceof Closure) {
        Closure closure = (Closure) element;
        Object closureResult = closure.call();
        if (closureResult != null) {
            add(closureResult);
        }
    } else if (element instanceof Callable) {
        Callable callable = (Callable) element;
        Object callableResult = uncheckedCall(callable);
        if (callableResult != null) {
            add(callableResult);
        }
    } else if (element instanceof Iterable) {
        Iterable<?> iterable = (Iterable) element;
        for (Object value : iterable) {
            add(value);
        }
    } else if (element instanceof Object[]) {
        Object[] array = (Object[]) element;
        for (Object value : array) {
            add(value);
        }
    }
    // Everything else assume has no dependencies
    return this;
}
Also used : Task(org.gradle.api.Task) Closure(groovy.lang.Closure) TaskOutputs(org.gradle.api.tasks.TaskOutputs) FileCollection(org.gradle.api.file.FileCollection) Buildable(org.gradle.api.Buildable) Callable(java.util.concurrent.Callable)

Example 7 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class CompositeFileCollection method getAsFileTrees.

@Override
protected Collection<DirectoryFileTree> getAsFileTrees() {
    List<DirectoryFileTree> fileTree = new ArrayList<DirectoryFileTree>();
    for (FileCollection source : getSourceCollections()) {
        AbstractFileCollection collection = (AbstractFileCollection) source;
        fileTree.addAll(collection.getAsFileTrees());
    }
    return fileTree;
}
Also used : ArrayList(java.util.ArrayList) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) FileCollection(org.gradle.api.file.FileCollection)

Example 8 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class DefaultConfiguration method registerWatchPoints.

@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);
}
Also used : FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) TaskDependency(org.gradle.api.tasks.TaskDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AbstractTaskDependency(org.gradle.api.internal.tasks.AbstractTaskDependency) Dependency(org.gradle.api.artifacts.Dependency) AbstractFileCollection(org.gradle.api.internal.file.AbstractFileCollection) FileCollection(org.gradle.api.file.FileCollection) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency)

Example 9 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class JavaCompilerArgumentsBuilder method addMainOptions.

private void addMainOptions() {
    if (!includeMainOptions) {
        return;
    }
    CompileOptions compileOptions = spec.getCompileOptions();
    List<String> compilerArgs = compileOptions.getCompilerArgs();
    if (!releaseOptionIsSet(compilerArgs)) {
        String sourceCompatibility = spec.getSourceCompatibility();
        if (sourceCompatibility != null) {
            args.add("-source");
            args.add(sourceCompatibility);
        }
        String targetCompatibility = spec.getTargetCompatibility();
        if (targetCompatibility != null) {
            args.add("-target");
            args.add(targetCompatibility);
        }
    }
    File destinationDir = spec.getDestinationDir();
    if (destinationDir != null) {
        args.add("-d");
        args.add(destinationDir.getPath());
    }
    if (compileOptions.isVerbose()) {
        args.add("-verbose");
    }
    if (compileOptions.isDeprecation()) {
        args.add("-deprecation");
    }
    if (!compileOptions.isWarnings()) {
        args.add("-nowarn");
    }
    if (compileOptions.getEncoding() != null) {
        args.add("-encoding");
        args.add(compileOptions.getEncoding());
    }
    if (compileOptions.getBootClasspath() != null) {
        //TODO: move bootclasspath to platform
        args.add("-bootclasspath");
        args.add(compileOptions.getBootClasspath());
    }
    if (compileOptions.getExtensionDirs() != null) {
        args.add("-extdirs");
        args.add(compileOptions.getExtensionDirs());
    }
    if (compileOptions.isDebug()) {
        if (compileOptions.getDebugOptions().getDebugLevel() != null) {
            args.add("-g:" + compileOptions.getDebugOptions().getDebugLevel().trim());
        } else {
            args.add("-g");
        }
    } else {
        args.add("-g:none");
    }
    FileCollection sourcepath = compileOptions.getSourcepath();
    if (!noEmptySourcePath || sourcepath != null && sourcepath.isEmpty()) {
        args.add("-sourcepath");
        args.add(sourcepath == null ? "" : sourcepath.getAsPath());
    }
    if (spec.getSourceCompatibility() == null || JavaVersion.toVersion(spec.getSourceCompatibility()).compareTo(JavaVersion.VERSION_1_6) >= 0) {
        List<File> annotationProcessorPath = spec.getAnnotationProcessorPath();
        if (annotationProcessorPath == null || annotationProcessorPath.isEmpty()) {
            args.add("-proc:none");
        } else {
            args.add("-processorpath");
            args.add(Joiner.on(File.pathSeparator).join(annotationProcessorPath));
        }
    }
    /*This is an internal option, it's used in com.sun.tools.javac.util.Names#createTable(Options options). The -XD backdoor switch is used to set it, as described in a comment
        in com.sun.tools.javac.main.RecognizedOptions#getAll(OptionHelper helper). This option was introduced in JDK 7 and controls if compiler's name tables should be reused.
        Without this option being set they are stored in a static list using soft references which can lead to memory pressure and performance deterioration
        when using the daemon, especially when using small heap and building a large project.
        Due to a bug (https://builds.gradle.org/viewLog.html?buildId=284033&tab=buildResultsDiv&buildTypeId=Gradle_Master_Performance_PerformanceExperimentsLinux) no instances of
        SharedNameTable are actually ever reused. It has been fixed for JDK9 and we should consider not using this option with JDK9 as not using it  will quite probably improve the
        performance of compilation.
        Using this option leads to significant performance improvements when using daemon and compiling java sources with JDK7 and JDK8.*/
    args.add(USE_UNSHARED_COMPILER_TABLE_OPTION);
}
Also used : CompileOptions(org.gradle.api.tasks.compile.CompileOptions) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 10 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class CompileTaskConfig method configureCompileTaskCommon.

private void configureCompileTaskCommon(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());
    task.setPositionIndependentCode(binary instanceof SharedLibraryBinarySpec);
    task.includes(((HeaderExportingSourceSet) sourceSet).getExportedHeaders().getSourceDirectories());
    task.includes(new Callable<List<FileCollection>>() {

        public List<FileCollection> call() {
            Collection<NativeDependencySet> libs = binary.getLibs((DependentSourceSet) sourceSet);
            return CollectionUtils.collect(libs, new Transformer<FileCollection, NativeDependencySet>() {

                public FileCollection transform(NativeDependencySet original) {
                    return original.getIncludeRoots();
                }
            });
        }
    });
    for (String toolName : languageTransform.getBinaryTools().keySet()) {
        Tool tool = binary.getToolByName(toolName);
        if (tool instanceof PreprocessingTool) {
            task.setMacros(((PreprocessingTool) tool).getMacros());
        }
        task.setCompilerArgs(tool.getArgs());
    }
}
Also used : DependentSourceSet(org.gradle.language.nativeplatform.DependentSourceSet) Transformer(org.gradle.api.Transformer) HeaderExportingSourceSet(org.gradle.language.nativeplatform.HeaderExportingSourceSet) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool) Collection(java.util.Collection) FileCollection(org.gradle.api.file.FileCollection) List(java.util.List) SharedLibraryBinarySpec(org.gradle.nativeplatform.SharedLibraryBinarySpec) NativeDependencySet(org.gradle.nativeplatform.NativeDependencySet) Tool(org.gradle.nativeplatform.Tool) PreprocessingTool(org.gradle.nativeplatform.PreprocessingTool)

Aggregations

FileCollection (org.gradle.api.file.FileCollection)32 File (java.io.File)16 Callable (java.util.concurrent.Callable)6 ArrayList (java.util.ArrayList)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)4 Set (java.util.Set)3 CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 List (java.util.List)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Configuration (org.gradle.api.artifacts.Configuration)2 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)1 Injector (com.google.inject.Injector)1 Closure (groovy.lang.Closure)1