Search in sources :

Example 11 with FileCollection

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

the class JavaGradlePluginPlugin method createAndConfigurePluginUnderTestMetadataTask.

private PluginUnderTestMetadata createAndConfigurePluginUnderTestMetadataTask(final Project project, final GradlePluginDevelopmentExtension extension) {
    final PluginUnderTestMetadata pluginUnderTestMetadataTask = project.getTasks().create(PLUGIN_UNDER_TEST_METADATA_TASK_NAME, PluginUnderTestMetadata.class);
    final Configuration gradlePluginConfiguration = project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi());
    ConventionMapping conventionMapping = new DslObject(pluginUnderTestMetadataTask).getConventionMapping();
    conventionMapping.map("pluginClasspath", new Callable<Object>() {

        public Object call() throws Exception {
            FileCollection gradleApi = gradlePluginConfiguration.getIncoming().getFiles();
            return extension.getPluginSourceSet().getRuntimeClasspath().minus(gradleApi);
        }
    });
    conventionMapping.map("outputDirectory", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(project.getBuildDir(), pluginUnderTestMetadataTask.getName());
        }
    });
    return pluginUnderTestMetadataTask;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) PluginUnderTestMetadata(org.gradle.plugin.devel.tasks.PluginUnderTestMetadata) DslObject(org.gradle.api.internal.plugins.DslObject) DslObject(org.gradle.api.internal.plugins.DslObject) FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException)

Example 12 with FileCollection

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

the class WarPlugin method apply.

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);
}
Also used : DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) Configuration(org.gradle.api.artifacts.Configuration) ArchivePublishArtifact(org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact) War(org.gradle.api.tasks.bundling.War) FileCollection(org.gradle.api.file.FileCollection) Callable(java.util.concurrent.Callable)

Example 13 with FileCollection

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

the class DefaultTaskInputs method prepareValue.

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);
        }
    }
}
Also used : FileCollection(org.gradle.api.file.FileCollection) CompositeFileCollection(org.gradle.api.internal.file.CompositeFileCollection) Callable(java.util.concurrent.Callable)

Example 14 with FileCollection

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

the class TemplateCompilerTask method compileImpl.

public void compileImpl(TemplateCompileOptions options) throws IOException {
    File buildDir = getProject().getBuildDir();
    //need to make customizable...
    File groovySrcGen = new File(buildDir, "groovysrc");
    System.out.println("groovy src directory=" + groovySrcGen);
    Charset encoding = Charset.forName(options.getEncoding());
    TemplateCompileConfig config = new TemplateCompileConfig(false);
    config.setFileEncoding(encoding);
    config.setPluginClient(true);
    config.setGroovySrcWriteDirectory(groovySrcGen);
    System.out.println("custom tags=" + options.getCustomTags());
    config.setCustomTagsFromPlugin(options.getCustomTags());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    File destinationDir = getDestinationDir();
    System.out.println("destDir=" + destinationDir);
    File routeIdFile = new File(destinationDir, ProdTemplateModule.ROUTE_META_FILE);
    if (routeIdFile.exists())
        routeIdFile.delete();
    routeIdFile.createNewFile();
    System.out.println("routeId.txt file=" + routeIdFile.getAbsolutePath());
    FileCollection srcCollection = getSource();
    Set<File> files = srcCollection.getFiles();
    File firstFile = files.iterator().next();
    File baseDir = findBase(firstFile);
    try (FileOutputStream routeOut = new FileOutputStream(routeIdFile);
        OutputStreamWriter write = new OutputStreamWriter(routeOut, encoding.name());
        BufferedWriter bufWrite = new BufferedWriter(write)) {
        Injector injector = Guice.createInjector(new StubModule(), new DevTemplateModule(config, new PluginCompileCallback(destinationDir, bufWrite)));
        HtmlToJavaClassCompiler compiler = injector.getInstance(HtmlToJavaClassCompiler.class);
        GroovyClassLoader cl = new GroovyClassLoader();
        for (File f : files) {
            System.out.println("file=" + f);
            String fullName = findFullName(baseDir, f);
            System.out.println("name=" + fullName);
            String source = readSource(f);
            compiler.compile(cl, fullName, source);
        }
    }
    setDidWork(true);
}
Also used : Charset(java.nio.charset.Charset) HtmlToJavaClassCompiler(org.webpieces.templatingdev.impl.HtmlToJavaClassCompiler) FileCollection(org.gradle.api.file.FileCollection) LogLevel(org.gradle.api.logging.LogLevel) BufferedWriter(java.io.BufferedWriter) GroovyClassLoader(groovy.lang.GroovyClassLoader) StubModule(org.webpieces.templatingdev.api.StubModule) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Injector(com.google.inject.Injector) FileOutputStream(java.io.FileOutputStream) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 15 with FileCollection

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

the class SkipEmptySourceFilesTaskExecuter method execute.

public void execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    FileCollection sourceFiles = task.getInputs().getSourceFiles();
    if (task.getInputs().getHasSourceFiles() && sourceFiles.isEmpty()) {
        TaskArtifactState taskArtifactState = context.getTaskArtifactState();
        FileCollection outputFiles = taskArtifactState.getExecutionHistory().getOutputFiles();
        if (outputFiles == null) {
            state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            LOGGER.info("Skipping {} as it has no source files and no history of previous output files.", task);
        } else if (outputFiles.isEmpty()) {
            state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            LOGGER.info("Skipping {} as it has no source files and no previous output files.", task);
        } else {
            Set<File> outputFileSet = outputFiles.getFiles();
            boolean deletedFiles = false;
            boolean debugEnabled = LOGGER.isDebugEnabled();
            for (File file : outputFileSet) {
                if (file.isFile()) {
                    if (file.delete()) {
                        if (debugEnabled) {
                            LOGGER.debug("Deleted stale output file '{}'.", file.getAbsolutePath());
                        }
                    } else {
                        state.setOutcome(new GradleException(String.format("Could not delete file: '%s'.", file.getAbsolutePath())));
                        return;
                    }
                    deletedFiles = true;
                }
            }
            if (deletedFiles) {
                LOGGER.info("Cleaned previous output of {} as it has no source files.", task);
                state.setOutcome(TaskExecutionOutcome.EXECUTED);
            } else {
                state.setOutcome(TaskExecutionOutcome.NO_SOURCE);
            }
        }
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, sourceFiles));
        return;
    } else {
        taskInputsListener.onExecute(task, Cast.cast(FileCollectionInternal.class, task.getInputs().getFiles()));
    }
    executer.execute(task, state, context);
}
Also used : Set(java.util.Set) TaskArtifactState(org.gradle.api.internal.changedetection.TaskArtifactState) GradleException(org.gradle.api.GradleException) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

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