Search in sources :

Example 1 with YarnTask

use of com.moowork.gradle.node.yarn.YarnTask in project curiostack by curioswitch.

the class CuriostackPlugin method apply.

@Override
public void apply(Project rootProject) {
    PluginContainer plugins = rootProject.getPlugins();
    // Provides useful tasks like 'clean', 'assemble' to the root project.
    plugins.apply(BasePlugin.class);
    plugins.apply(BaselineIdea.class);
    plugins.apply(CurioGenericCiPlugin.class);
    plugins.apply(GcloudPlugin.class);
    plugins.apply(NodePlugin.class);
    plugins.apply(PythonEnvsPlugin.class);
    setupPyenvs(rootProject);
    YarnInstallTask yarnTask = rootProject.getTasks().withType(YarnInstallTask.class).getByName("yarn");
    yarnTask.setArgs(ImmutableList.of("--frozen-lockfile"));
    YarnInstallTask yarnUpdateTask = rootProject.getTasks().create("yarnUpdate", YarnInstallTask.class);
    Task yarnWarning = rootProject.getTasks().create("yarnWarning", task -> {
        task.onlyIf(unused -> yarnTask.getState().getFailure() != null);
        task.doFirst(unused -> rootProject.getLogger().warn("yarn task failed. If you have updated a dependency and the " + "error says 'Your lockfile needs to be updated.', run \n\n" + "./gradlew " + yarnUpdateTask.getPath()));
    });
    yarnTask.finalizedBy(yarnWarning);
    rootProject.getTasks().create("setupGitHooks", SetupGitHooks.class);
    CreateShellConfigTask rehash = rootProject.getTasks().create("rehash", CreateShellConfigTask.class, t -> t.path(CommandUtil.getPythonBinDir(rootProject, "dev")).path(CommandUtil.getGcloudSdkBinDir(rootProject)));
    setupNode(rootProject, rehash);
    rootProject.getTasks().create("setup", t -> {
        t.dependsOn("gcloudSetup");
        t.dependsOn("pythonSetup");
        t.dependsOn("nodeSetup");
        t.dependsOn("yarnSetup");
        t.dependsOn("rehash");
    });
    String baselineFiles;
    try {
        baselineFiles = Resources.toString(Resources.getResource("META-INF/org.curioswitch.curiostack.baseline_manifest.txt"), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    Task baselineUpdateConfig = rootProject.getTasks().create("baselineUpdateConfig").doLast(task -> {
        File baselineDir = rootProject.file(".baseline");
        baselineDir.mkdirs();
        for (String filePath : NEW_LINE_SPLITTER.split(baselineFiles)) {
            Path path = Paths.get(filePath);
            Path outputDirectory = Paths.get(baselineDir.getAbsolutePath()).resolve(path.getParent());
            rootProject.file(outputDirectory.toAbsolutePath()).mkdirs();
            try (FileOutputStream os = new FileOutputStream(outputDirectory.resolve(path.getFileName()).toFile());
                InputStream is = Resources.getResource(filePath).openStream()) {
                ByteStreams.copy(is, os);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
    if (!rootProject.file(".baseline").exists()) {
        rootProject.getTasks().getByName("ideaProject").dependsOn(baselineUpdateConfig);
    }
    rootProject.afterEvaluate((p) -> rootProject.getPlugins().withType(IdeaPlugin.class, plugin -> {
        plugin.getModel().getProject().getIpr().withXml(provider -> setupProjectXml(rootProject, provider));
        plugin.getModel().getWorkspace().getIws().withXml(provider -> setupWorkspaceXml(rootProject, provider));
    }));
    rootProject.allprojects(project -> {
        setupRepositories(project);
        project.getPlugins().apply(ResolutionRulesPlugin.class);
        project.getPlugins().withType(JavaPlugin.class, plugin -> setupJavaProject(project));
        project.getPlugins().withType(LicensePlugin.class, unused -> {
            LicenseExtension license = project.getExtensions().getByType(LicenseExtension.class);
            license.exclude("**/*.json");
            license.setHeader(rootProject.file("LICENSE"));
            license.mapping(ImmutableMap.of("conf", "DOUBLESLASH_STYLE", "java", "SLASHSTAR_STYLE", "proto", "SLASHSTAR_STYLE", "yml", "SCRIPT_STYLE"));
        });
    });
    setupDataSources(rootProject);
}
Also used : CreateShellConfigTask(org.curioswitch.gradle.plugins.curiostack.tasks.CreateShellConfigTask) Path(java.nio.file.Path) AptIdeaPlugin(net.ltgt.gradle.apt.AptIdeaPlugin) Closure(groovy.lang.Closure) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) ModuleAptConvention(net.ltgt.gradle.apt.AptIdeaPlugin.ModuleAptConvention) DependencyManagementPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin) DslObject(org.gradle.api.internal.plugins.DslObject) Task(org.gradle.api.Task) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) YarnTask(com.moowork.gradle.node.yarn.YarnTask) Map(java.util.Map) LicensePlugin(nl.javadude.gradle.plugins.license.LicensePlugin) ExtensionAware(org.gradle.api.plugins.ExtensionAware) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) PythonEnvsExtension(com.jetbrains.python.envs.PythonEnvsExtension) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) Delete(org.gradle.api.tasks.Delete) ImmutableMap(com.google.common.collect.ImmutableMap) Project(org.gradle.api.Project) NodeTask(com.moowork.gradle.node.task.NodeTask) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ProtobufPlugin(com.google.protobuf.gradle.ProtobufPlugin) SetupGitHooks(org.curioswitch.gradle.plugins.curiostack.tasks.SetupGitHooks) SpotlessExtension(com.diffplug.gradle.spotless.SpotlessExtension) AptPlugin(net.ltgt.gradle.apt.AptPlugin) JavaVersion(org.gradle.api.JavaVersion) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) JavaLibraryPlugin(org.gradle.api.plugins.JavaLibraryPlugin) List(java.util.List) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) VersionsPlugin(com.github.benmanes.gradle.versions.VersionsPlugin) YarnInstallTask(com.moowork.gradle.node.yarn.YarnInstallTask) BaselineIdea(com.palantir.baseline.plugins.BaselineIdea) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) PluginContainer(org.gradle.api.plugins.PluginContainer) ExecSpec(org.gradle.process.ExecSpec) DependencySet(org.curioswitch.gradle.plugins.curiostack.StandardDependencies.DependencySet) XmlProvider(org.gradle.api.XmlProvider) LicenseExtension(nl.javadude.gradle.plugins.license.LicenseExtension) JooqPlugin(nu.studer.gradle.jooq.JooqPlugin) CurioGenericCiPlugin(org.curioswitch.gradle.plugins.ci.CurioGenericCiPlugin) ErrorPronePlugin(net.ltgt.gradle.errorprone.ErrorPronePlugin) NodePlugin(com.moowork.gradle.node.NodePlugin) HashMap(java.util.HashMap) BasePlugin(org.gradle.api.plugins.BasePlugin) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) JMHPluginExtension(me.champeau.gradle.JMHPluginExtension) ImmutableList(com.google.common.collect.ImmutableList) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) DependencyManagementExtension(io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) JooqTask(nu.studer.gradle.jooq.JooqTask) CreateShellConfigTask(org.curioswitch.gradle.plugins.curiostack.tasks.CreateShellConfigTask) NodeExtension(com.moowork.gradle.node.NodeExtension) Test(org.gradle.api.tasks.testing.Test) PythonEnvsPlugin(com.jetbrains.python.envs.PythonEnvsPlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Resources(com.google.common.io.Resources) NpmTask(com.moowork.gradle.node.npm.NpmTask) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Jar(org.gradle.jvm.tasks.Jar) FileOutputStream(java.io.FileOutputStream) JMHPlugin(me.champeau.gradle.JMHPlugin) SpotlessTask(com.diffplug.gradle.spotless.SpotlessTask) IOException(java.io.IOException) Node(groovy.util.Node) GcloudPlugin(org.curioswitch.gradle.plugins.gcloud.GcloudPlugin) File(java.io.File) SpotlessPlugin(com.diffplug.gradle.spotless.SpotlessPlugin) ProtobufSourceDirectorySet(com.google.protobuf.gradle.ProtobufSourceDirectorySet) Os(org.apache.tools.ant.taskdefs.condition.Os) Paths(java.nio.file.Paths) ResolutionRulesPlugin(nebula.plugin.resolutionrules.ResolutionRulesPlugin) CommandUtil(org.curioswitch.gradle.plugins.shared.CommandUtil) JavaExec(org.gradle.api.tasks.JavaExec) LambdaClosure(org.curioswitch.gradle.common.LambdaClosure) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) InputStream(java.io.InputStream) Task(org.gradle.api.Task) YarnTask(com.moowork.gradle.node.yarn.YarnTask) NodeTask(com.moowork.gradle.node.task.NodeTask) YarnInstallTask(com.moowork.gradle.node.yarn.YarnInstallTask) JooqTask(nu.studer.gradle.jooq.JooqTask) CreateShellConfigTask(org.curioswitch.gradle.plugins.curiostack.tasks.CreateShellConfigTask) NpmTask(com.moowork.gradle.node.npm.NpmTask) SpotlessTask(com.diffplug.gradle.spotless.SpotlessTask) PluginContainer(org.gradle.api.plugins.PluginContainer) LicenseExtension(nl.javadude.gradle.plugins.license.LicenseExtension) InputStream(java.io.InputStream) AptIdeaPlugin(net.ltgt.gradle.apt.AptIdeaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) YarnInstallTask(com.moowork.gradle.node.yarn.YarnInstallTask) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 2 with YarnTask

use of com.moowork.gradle.node.yarn.YarnTask in project curiostack by curioswitch.

the class CloudbuildGithubPlugin method apply.

@Override
public void apply(Project project) {
    String path = project.getPath().replace(':', '_');
    YarnTask initTask = project.getRootProject().getTasks().create("init_" + path, YarnTask.class);
    initTask.setWorkingDir(project.getProjectDir());
    initTask.setArgs(ImmutableList.of("init", "--yes", "--private"));
    initTask.finalizedBy(project.getTasks().create("initAddDependency", YarnTask.class, task -> {
        task.setArgs(ImmutableList.of("add", "@curiostack/cloudbuild-github"));
        task.onlyIf(t -> !project.file("package.json").exists());
    }), "yarn");
    initTask.onlyIf(t -> !project.file("package.json").exists());
    ImmutableGcloudExtension gcloudConfig = project.getRootProject().getExtensions().getByType(GcloudExtension.class);
    Map<String, String> defaultEnvironment = ImmutableMap.of("GCLOUD_PROJECT", gcloudConfig.clusterProject());
    YarnTask setupTask = project.getRootProject().getTasks().create("setup_" + path, YarnTask.class);
    setupTask.setWorkingDir(project.getProjectDir());
    setupTask.setArgs(ImmutableList.of("run", "cloudbuild-cli", "setup", "--defaults"));
    setupTask.dependsOn(initTask);
    setupTask.onlyIf(t -> !project.file("config.yml").exists());
    setupTask.setExecOverrides(LambdaClosure.of(((ExecSpec exec) -> exec.setStandardInput(System.in).setStandardOutput(System.out))));
    setupTask.setEnvironment(defaultEnvironment);
    Map<String, String> environment = gcloudConfig.download() ? ImmutableMap.<String, String>builder().put("PATH", gcloudConfig.platformConfig().gcloudBinDir() + File.pathSeparator + System.getenv("PATH")).putAll(defaultEnvironment).build() : defaultEnvironment;
    YarnTask deployTask = project.getTasks().create("deploy_" + path, YarnTask.class);
    deployTask.setWorkingDir(project.getProjectDir());
    deployTask.setArgs(ImmutableList.of("run", "cloudbuild-cli", "deploy", "--delete"));
    deployTask.dependsOn(setupTask);
    deployTask.setEnvironment(environment);
    deployTask.dependsOn(":gcloudSetup");
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Project(org.gradle.api.Project) YarnTask(com.moowork.gradle.node.yarn.YarnTask) GcloudExtension(org.curioswitch.gradle.plugins.gcloud.GcloudExtension) ImmutableGcloudExtension(org.curioswitch.gradle.plugins.gcloud.ImmutableGcloudExtension) Map(java.util.Map) ExecSpec(org.gradle.process.ExecSpec) LambdaClosure(org.curioswitch.gradle.common.LambdaClosure) File(java.io.File) Plugin(org.gradle.api.Plugin) ImmutableGcloudExtension(org.curioswitch.gradle.plugins.gcloud.ImmutableGcloudExtension) YarnTask(com.moowork.gradle.node.yarn.YarnTask) ExecSpec(org.gradle.process.ExecSpec)

Example 3 with YarnTask

use of com.moowork.gradle.node.yarn.YarnTask in project curiostack by curioswitch.

the class CurioWebPlugin method apply.

@Override
public void apply(Project project) {
    project.getExtensions().create("web", WebExtension.class);
    project.getPlugins().apply(JavaLibraryPlugin.class);
    JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class);
    java.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().dir(ImmutableMap.of("builtBy", "copyWeb"), "build/javaweb");
    CacheableYarnTask buildWeb = project.getRootProject().getTasks().create(rootTaskName("buildWeb", project), CacheableYarnTask.class);
    buildWeb.dependsOn(project.getRootProject().getTasks().findByName("yarn"));
    buildWeb.setArgs(ImmutableList.of("run", "build"));
    buildWeb.setWorkingDir(project.getProjectDir());
    buildWeb.getInputs().dir(project.file("src"));
    buildWeb.getInputs().dir(project.file("internals"));
    // We assume the yarn task correctly handles up-to-date checks for node_modules, so only
    // need to look at yarn.lock here.
    buildWeb.getInputs().file(project.getRootProject().file("yarn.lock"));
    buildWeb.getOutputs().dir(project.file("build"));
    Copy copyWeb = project.getTasks().create("copyWeb", Copy.class);
    copyWeb.dependsOn(buildWeb);
    copyWeb.from("build/web");
    project.afterEvaluate(p -> {
        ImmutableWebExtension web = project.getExtensions().getByType(WebExtension.class);
        copyWeb.into("build/javaweb/" + web.javaPackage().replace('.', '/'));
    });
    // Copy in yarn rule from node plugin since we don't directly apply the plugin here.
    project.getTasks().addRule("Pattern: \"yarn_<command>\": Executes an Yarn command.", taskName -> {
        if (taskName.startsWith("yarn_")) {
            YarnTask yarnTask = project.getRootProject().getTasks().create(rootTaskName(taskName, project), YarnTask.class);
            yarnTask.setWorkingDir(project.getProjectDir());
            List<String> tokens = YARN_TASK_SPLITTER.splitToList(taskName);
            yarnTask.setYarnCommand(tokens.subList(1, tokens.size()).stream().toArray(String[]::new));
            project.getTasks().create(taskName).dependsOn(yarnTask);
        }
    });
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Copy(org.gradle.api.tasks.Copy) YarnTask(com.moowork.gradle.node.yarn.YarnTask)

Aggregations

YarnTask (com.moowork.gradle.node.yarn.YarnTask)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 Map (java.util.Map)2 SpotlessExtension (com.diffplug.gradle.spotless.SpotlessExtension)1 SpotlessPlugin (com.diffplug.gradle.spotless.SpotlessPlugin)1 SpotlessTask (com.diffplug.gradle.spotless.SpotlessTask)1 VersionsPlugin (com.github.benmanes.gradle.versions.VersionsPlugin)1 Splitter (com.google.common.base.Splitter)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ByteStreams (com.google.common.io.ByteStreams)1 Resources (com.google.common.io.Resources)1 ProtobufPlugin (com.google.protobuf.gradle.ProtobufPlugin)1 ProtobufSourceDirectorySet (com.google.protobuf.gradle.ProtobufSourceDirectorySet)1 PythonEnvsExtension (com.jetbrains.python.envs.PythonEnvsExtension)1 PythonEnvsPlugin (com.jetbrains.python.envs.PythonEnvsPlugin)1 NodeExtension (com.moowork.gradle.node.NodeExtension)1 NodePlugin (com.moowork.gradle.node.NodePlugin)1 NpmTask (com.moowork.gradle.node.npm.NpmTask)1