Search in sources :

Example 1 with ConfigurableFileTree

use of org.gradle.api.file.ConfigurableFileTree in project atlas by alibaba.

the class AwbDataBindingExportBuildInfoConfigAction method execute.

@Override
public void execute(DataBindingExportBuildInfoTask task) {
    final BaseVariantData<? extends BaseVariantOutputData> variantData = appVariantContext.getScope().getVariantData();
    task.setXmlProcessor(AwbXmlProcessor.getLayoutXmlProcessor(appVariantContext, awbBundle, dataBindingBuilder));
    task.setSdkDir(appVariantContext.getScope().getGlobalScope().getSdkHandler().getSdkFolder());
    task.setXmlOutFolder(appVariantContext.getAwbLayoutInfoOutputForDataBinding(awbBundle));
    ConventionMappingHelper.map(task, "compilerClasspath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            return appVariantContext.getScope().getJavaClasspath();
        }
    });
    ConventionMappingHelper.map(task, "compilerSources", new Callable<Iterable<ConfigurableFileTree>>() {

        @Override
        public Iterable<ConfigurableFileTree> call() throws Exception {
            return Iterables.filter(appVariantContext.getAwSourceOutputDir(awbBundle), new Predicate<ConfigurableFileTree>() {

                @Override
                public boolean apply(ConfigurableFileTree input) {
                    File dataBindingOut = appVariantContext.getAwbClassOutputForDataBinding(awbBundle);
                    return !dataBindingOut.equals(input.getDir());
                }
            });
        }
    });
    task.setExportClassListTo(variantData.getType().isExportDataBindingClassList() ? new File(appVariantContext.getAwbLayoutFolderOutputForDataBinding(awbBundle), "_generated.txt") : null);
    task.setPrintMachineReadableErrors(printMachineReadableErrors);
    task.setDataBindingClassOutput(appVariantContext.getAwbClassOutputForDataBinding(awbBundle));
}
Also used : ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) Predicate(com.google.common.base.Predicate)

Example 2 with ConfigurableFileTree

use of org.gradle.api.file.ConfigurableFileTree in project crnk-framework by crnk-project.

the class TSGeneratorPlugin method setupPackageTasks.

void setupPackageTasks(Project project, Task generateTask) {
    final File buildDir = new File(project.getBuildDir(), "npm_compile");
    final File distDir = getNpmOutputDir(project);
    project.getTasks().create(PublishTypescriptStubsTask.NAME, PublishTypescriptStubsTask.class);
    TSGeneratorConfig config = project.getExtensions().getByType(TSGeneratorConfig.class);
    Copy copySources = project.getTasks().create("processTypescript", Copy.class);
    copySources.from(config.getGenDir());
    copySources.into(buildDir);
    copySources.dependsOn(generateTask);
    // copy .npmrc file from root to working directory if available
    final File npmrcFile = new File(project.getProjectDir(), ".npmrc");
    if (npmrcFile.exists()) {
        copySources.getInputs().file(npmrcFile);
        copySources.doFirst(new Action<Task>() {

            @Override
            public void execute(Task task) {
                File targetFile = new File(buildDir, ".npmrc");
                buildDir.mkdirs();
                TypescriptUtils.copyFile(npmrcFile, targetFile);
            }
        });
    }
    CompileTypescriptStubsTask compileTypescriptTask = project.getTasks().create(CompileTypescriptStubsTask.NAME, CompileTypescriptStubsTask.class);
    try {
        NpmInstallTask npmInstall = (NpmInstallTask) project.getTasks().getByName("npmInstall");
        npmInstall.setWorkingDir(buildDir);
        npmInstall.dependsOn(copySources);
        npmInstall.getInputs().files(new File(buildDir, "package.json"));
        npmInstall.getOutputs().dir(new File(buildDir, "node_modules"));
        compileTypescriptTask.dependsOn(npmInstall);
    } catch (UnknownTaskException e) {
        LOGGER.warn("task not found, ok in testing", e);
    }
    ConfigurableFileTree fileTree = project.fileTree(buildDir);
    fileTree.include("package.json");
    fileTree.include(".npmrc");
    fileTree.include("**/*.ts");
    fileTree.exclude("**/*.d.ts");
    compileTypescriptTask.getInputs().files(fileTree);
    compileTypescriptTask.setWorkingDir(buildDir);
    compileTypescriptTask.getOutputs().dir(buildDir);
    ConfigurableFileTree assembleFileTree = project.fileTree(new File(buildDir, "src"));
    assembleFileTree.include("**/*.ts");
    assembleFileTree.include("**/*.js");
    assembleFileTree.include("**/*.js.map");
    Copy assembleSources = project.getTasks().create("assembleTypescript", Copy.class);
    assembleSources.from(assembleFileTree);
    assembleSources.from(new File(buildDir, "package.json"));
    assembleSources.into(distDir);
    assembleSources.dependsOn(compileTypescriptTask);
}
Also used : UnknownTaskException(org.gradle.api.UnknownTaskException) Task(org.gradle.api.Task) NpmInstallTask(com.moowork.gradle.node.npm.NpmInstallTask) NpmInstallTask(com.moowork.gradle.node.npm.NpmInstallTask) Copy(org.gradle.api.tasks.Copy) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) File(java.io.File)

Example 3 with ConfigurableFileTree

use of org.gradle.api.file.ConfigurableFileTree in project atlas by alibaba.

the class AppVariantContext method getAwSourceOutputDir.

public List<ConfigurableFileTree> getAwSourceOutputDir(AwbBundle awbBundle) {
    Project project = scope.getGlobalScope().getProject();
    // Build the list of source folders.
    ImmutableList.Builder<ConfigurableFileTree> sourceSets = ImmutableList.builder();
    // then all the generated src folders.
    if (getAwbRClassSourceOutputDir(awbBundle) != null) {
        sourceSets.add(project.fileTree(getAwbRClassSourceOutputDir(awbBundle)));
    }
    sourceSets.add(project.fileTree(getAwbMergeResourcesOutputDir(awbBundle)));
    if (scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) {
        sourceSets.add(project.fileTree(getAwbClassOutputForDataBinding(awbBundle)));
    }
    return sourceSets.build();
}
Also used : Project(org.gradle.api.Project) ImmutableList(com.google.common.collect.ImmutableList) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree)

Example 4 with ConfigurableFileTree

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

the class JettyRun method validateConfiguration.

public void validateConfiguration() {
    // check the location of the static content/jsps etc
    try {
        if ((getWebAppSourceDirectory() == null) || !getWebAppSourceDirectory().exists()) {
            throw new InvalidUserDataException("Webapp source directory " + (getWebAppSourceDirectory() == null ? "null" : getWebAppSourceDirectory().getCanonicalPath()) + " does not exist");
        } else {
            LOGGER.info("Webapp source directory = " + getWebAppSourceDirectory().getCanonicalPath());
        }
    } catch (IOException e) {
        throw new InvalidUserDataException("Webapp source directory does not exist", e);
    }
    // check reload mechanic
    if (!"automatic".equalsIgnoreCase(reload) && !"manual".equalsIgnoreCase(reload)) {
        throw new InvalidUserDataException("invalid reload mechanic specified, must be 'automatic' or 'manual'");
    } else {
        LOGGER.info("Reload Mechanic: " + reload);
    }
    // get the web.xml file if one has been provided, otherwise assume it is in the webapp src directory
    if (getWebXml() == null) {
        setWebXml(new File(new File(getWebAppSourceDirectory(), "WEB-INF"), "web.xml"));
    }
    LOGGER.info("web.xml file = " + getWebXml());
    //check if a jetty-env.xml location has been provided, if so, it must exist
    if (getJettyEnvXml() != null) {
        setJettyEnvXmlFile(jettyEnvXml);
        try {
            if (!getJettyEnvXmlFile().exists()) {
                throw new InvalidUserDataException("jetty-env.xml file does not exist at location " + jettyEnvXml);
            } else {
                LOGGER.info(" jetty-env.xml = " + getJettyEnvXmlFile().getCanonicalPath());
            }
        } catch (IOException e) {
            throw new InvalidUserDataException("jetty-env.xml does not exist");
        }
    }
    setExtraScanTargets(new ArrayList<File>());
    if (scanTargets != null) {
        for (File scanTarget : scanTargets) {
            LOGGER.info("Added extra scan target:" + scanTarget);
            getExtraScanTargets().add(scanTarget);
        }
    }
    if (scanTargetPatterns != null) {
        for (ScanTargetPattern scanTargetPattern : scanTargetPatterns) {
            ConfigurableFileTree files = getProject().fileTree(scanTargetPattern.getDirectory());
            files.include(scanTargetPattern.getIncludes());
            files.exclude(scanTargetPattern.getExcludes());
            Set<File> currentTargets = getExtraScanTargets();
            if (currentTargets != null && !currentTargets.isEmpty()) {
                currentTargets.addAll(files.getFiles());
            } else {
                setExtraScanTargets(files.getFiles());
            }
        }
    }
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) IOException(java.io.IOException) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile)

Example 5 with ConfigurableFileTree

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

the class GradleBuildDocumentationPlugin method applyConventions.

private void applyConventions(Project project, TaskContainer tasks, ObjectFactory objects, ProjectLayout layout, GradleDocumentationExtension extension) {
    TaskProvider<Sync> stageDocs = tasks.register("stageDocs", Sync.class, task -> {
        // release notes goes in the root of the docs
        task.from(extension.getReleaseNotes().getRenderedDocumentation());
        // DSL reference goes into dsl/
        task.from(extension.getDslReference().getRenderedDocumentation(), sub -> sub.into("dsl"));
        // Javadocs reference goes into javadoc/
        task.from(extension.getJavadocs().getRenderedDocumentation(), sub -> sub.into("javadoc"));
        // User manual goes into userguide/ (for historical reasons)
        task.from(extension.getUserManual().getRenderedDocumentation(), sub -> sub.into("userguide"));
        task.into(extension.getDocumentationRenderedRoot());
    });
    extension.getSourceRoot().convention(layout.getProjectDirectory().dir("src/docs"));
    extension.getDocumentationRenderedRoot().convention(layout.getBuildDirectory().dir("docs"));
    extension.getStagingRoot().convention(layout.getBuildDirectory().dir("working"));
    ConfigurableFileTree css = objects.fileTree();
    css.from(extension.getSourceRoot().dir("css"));
    css.include("*.css");
    extension.getCssFiles().from(css);
    extension.getRenderedDocumentation().from(stageDocs);
    Configuration runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath");
    Configuration sourcesPath = project.getConfigurations().create("sourcesPath");
    sourcesPath.attributes(a -> {
        a.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME));
        a.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.DOCUMENTATION));
        a.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.class, "gradle-source-folders"));
    });
    sourcesPath.setCanBeConsumed(false);
    sourcesPath.setCanBeResolved(true);
    sourcesPath.setVisible(false);
    sourcesPath.extendsFrom(runtimeClasspath);
    extension.getClasspath().from(runtimeClasspath);
    extension.getDocumentedSource().from(sourcesPath.getIncoming().artifactView(v -> v.lenient(true)).getFiles().getAsFileTree().matching(f -> {
        // Filter out any non-public APIs
        f.include(PublicApi.INSTANCE.getIncludes());
        f.exclude(PublicApi.INSTANCE.getExcludes());
    }));
}
Also used : PublicApi(gradlebuild.basics.PublicApi) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Category(org.gradle.api.attributes.Category) DocsType(org.gradle.api.attributes.DocsType) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) Configuration(org.gradle.api.artifacts.Configuration) ProviderFactory(org.gradle.api.provider.ProviderFactory) Task(org.gradle.api.Task) ProjectLayout(org.gradle.api.file.ProjectLayout) Sync(org.gradle.api.tasks.Sync) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) PathSensitivity(org.gradle.api.tasks.PathSensitivity) Exec(org.gradle.api.tasks.Exec) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) Test(org.gradle.api.tasks.testing.Test) Usage(org.gradle.api.attributes.Usage) Usage(org.gradle.api.attributes.Usage) Category(org.gradle.api.attributes.Category) Configuration(org.gradle.api.artifacts.Configuration) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree) DocsType(org.gradle.api.attributes.DocsType) Sync(org.gradle.api.tasks.Sync)

Aggregations

ConfigurableFileTree (org.gradle.api.file.ConfigurableFileTree)9 File (java.io.File)3 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Configuration (org.gradle.api.artifacts.Configuration)2 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 NpmInstallTask (com.moowork.gradle.node.npm.NpmInstallTask)1 PublicApi (gradlebuild.basics.PublicApi)1 AssembleDslDocTask (gradlebuild.docs.dsl.docbook.AssembleDslDocTask)1 ExtractDslMetaDataTask (gradlebuild.docs.dsl.source.ExtractDslMetaDataTask)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 Action (org.gradle.api.Action)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Plugin (org.gradle.api.Plugin)1 UnknownTaskException (org.gradle.api.UnknownTaskException)1 Category (org.gradle.api.attributes.Category)1 DocsType (org.gradle.api.attributes.DocsType)1 Usage (org.gradle.api.attributes.Usage)1