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);
}
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");
}
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);
}
});
}
Aggregations