use of org.gradle.api.UnknownTaskException 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);
}
use of org.gradle.api.UnknownTaskException in project curiostack by curioswitch.
the class CurioGenericCiPlugin method apply.
@Override
public void apply(Project project) {
if (project.getParent() != null) {
throw new IllegalStateException("curio-generic-ci-plugin can only be applied to the root project.");
}
var config = CiExtension.createAndAdd(project);
var state = CiState.createAndAdd(project);
if (!state.isCi()) {
return;
}
var cleanWrapper = project.getTasks().register("cleanWrapper", Delete.class, t -> {
File gradleHome = project.getGradle().getGradleHomeDir();
t.delete(new File(gradleHome, "docs"));
t.delete(new File(gradleHome, "media"));
t.delete(new File(gradleHome, "samples"));
t.delete(new File(gradleHome, "src"));
// Zip file should always be foldername-all.zip
var archive = new File(gradleHome.getParent(), gradleHome.getName() + "-all.zip");
t.delete(archive);
});
Task continuousBuild = project.task("continuousBuild");
if (state.isMasterBuild()) {
continuousBuild.dependsOn(cleanWrapper);
}
project.allprojects(proj -> proj.getPlugins().withType(GolangPlugin.class, unused -> proj.getExtensions().getByType(GolangExtension.class).jib(jib -> jib.getAdditionalTags().addAll(state.getRevisionTags()))));
if (state.isReleaseBuild()) {
project.afterEvaluate(unused -> configureReleaseBuild(project, config, state));
return;
}
var fetchCodeCovCache = project.getTasks().create("fetchCodeCovCache", FetchCodeCovCacheTask.class);
var uploadCodeCovCache = project.getTasks().create("uploadCodeCovCache", UploadCodeCovCacheTask.class);
var uploadCoverage = project.getTasks().create("uploadToCodeCov", UploadToCodeCovTask.class, t -> {
t.dependsOn(DownloadToolUtil.getSetupTask(project, "miniconda-build"));
if (state.isMasterBuild()) {
t.finalizedBy(uploadCodeCovCache);
}
});
// Don't need to slow down local builds with coverage.
if (!state.isLocalBuild() && !"true".equals(project.findProperty("org.curioswitch.curiostack.ci.disableCoverage"))) {
continuousBuild.dependsOn(uploadCoverage);
project.allprojects(proj -> {
proj.getPlugins().withType(JavaPlugin.class, unused -> proj.getPlugins().apply(JacocoPlugin.class));
proj.getPlugins().withType(GolangPlugin.class, unused -> proj.getTasks().withType(GoTestTask.class).configureEach(t -> {
t.coverage(true);
uploadCoverage.mustRunAfter(t);
}));
});
project.subprojects(proj -> proj.getPlugins().withType(JacocoPlugin.class, unused -> {
var testReport = proj.getTasks().named("jacocoTestReport", JacocoReport.class);
uploadCoverage.mustRunAfter(testReport);
testReport.configure(t -> t.reports(reports -> {
reports.getXml().setEnabled(true);
reports.getHtml().setEnabled(true);
reports.getCsv().setEnabled(false);
}));
try {
proj.getTasks().named("build").configure(t -> t.dependsOn(testReport));
} catch (UnknownTaskException e) {
// Ignore.
}
}));
}
final Set<Project> affectedProjects;
try {
affectedProjects = computeAffectedProjects(project);
} catch (Throwable t) {
// Don't prevent further gradle configuration due to issues computing the git state.
project.getLogger().warn("Couldn't compute affected targets.", t);
return;
}
final Set<Project> projectsToBuild;
if (affectedProjects.contains(project.getRootProject())) {
// Rebuild everything when the root project is changed.
projectsToBuild = ImmutableSet.copyOf(project.getAllprojects());
} else {
projectsToBuild = affectedProjects;
// We only fetch the code cov cache on non-full builds since we don't need to propagate for
// full ones.
uploadCoverage.dependsOn(fetchCodeCovCache);
}
for (var proj : projectsToBuild) {
proj.getPlugins().withType(GolangPlugin.class, unused -> {
// TODO(choko): Figure out whether it's better to register plugins outside this
// artifact here or in each plugin somehow.
proj.getTasks().withType(JibTask.class, t -> addToMasterBuild(proj, t));
});
proj.getPlugins().withType(LifecycleBasePlugin.class, unused -> continuousBuild.dependsOn(proj.getTasks().named(LifecycleBasePlugin.BUILD_TASK_NAME)));
proj.getPlugins().withType(JavaBasePlugin.class, unused -> continuousBuild.dependsOn(proj.getTasks().named(JavaBasePlugin.BUILD_DEPENDENTS_TASK_NAME)));
}
}
use of org.gradle.api.UnknownTaskException in project curiostack by curioswitch.
the class GolangPlugin method apply.
@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GolangSetupPlugin.class);
project.getPlugins().apply(BasePlugin.class);
var golang = GolangExtension.createAndAdd(project);
var toolManager = DownloadedToolManager.get(project);
project.getTasks().addRule(new Rule() {
@Override
public String getDescription() {
return "Pattern: \"go_<command>\": Executes a go command.";
}
@Override
public void apply(String taskName) {
if (taskName.startsWith("go_")) {
project.getTasks().register(taskName, GoTask.class, t -> {
List<String> tokens = TASK_NAME_SPLITTER.splitToList(taskName);
t.args(tokens.subList(1, tokens.size()));
});
}
}
});
var setupGo = DownloadToolUtil.getSetupTask(project, "go");
setupGo.configure(t -> t.dependsOn(DownloadToolUtil.getSetupTask(project, "miniconda-build")));
project.getTasks().withType(GoTask.class).configureEach(t -> t.dependsOn(setupGo));
project.getRootProject().mkdir("build");
project.getExtensions().getByType(ExtraPropertiesExtension.class).set("gopath", project.getGradle().getGradleUserHomeDir().toPath().resolve("curiostack").resolve("gopath"));
var downloadDeps = project.getTasks().register("goDownloadDeps", GoTask.class, t -> {
t.args("mod", "download");
project.getRootProject().mkdir("build");
});
project.getTasks().register("goUpdateDeps", GoTask.class, t -> {
t.args("get", "-u");
// Go get often has a failed status code yet still basically worked so we let it go.
t.execCustomizer(exec -> exec.setIgnoreExitValue(true));
});
var checkFormat = project.getTasks().register("goCheck", GoTask.class, t -> {
t.command("gofmt");
t.args("-s", "-d", ".");
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
t.doLast(unused -> {
if (stdOut.size() > 0) {
throw new GradleException("There were formatting violations. Run :goFormat to fix.\n" + stdOut.toString());
}
});
t.execCustomizer(exec -> exec.setStandardOutput(stdOut));
});
var check = project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME);
check.configure(t -> t.dependsOn(checkFormat));
project.getTasks().register("goFormat", GoTask.class, t -> {
t.command("gofmt");
t.args("-s", "-w", ".");
});
var goTest = project.getTasks().register("goTest", GoTestTask.class, t -> {
t.execCustomizer(exec -> CondaExecUtil.condaExec(exec, toolManager, golang.getConda().get()));
t.dependsOn(DownloadToolUtil.getSetupTask(project, golang.getConda().get()), downloadDeps);
});
var goBuildAll = project.getTasks().register("goBuildAll");
project.getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(t -> t.dependsOn(goBuildAll));
project.afterEvaluate(unused -> {
TaskProvider<Task> test;
try {
test = project.getTasks().named("test");
} catch (UnknownTaskException e) {
test = project.getTasks().register("test");
TaskProvider<Task> testCopy = test;
check.configure(t -> t.dependsOn(testCopy));
}
test.configure(t -> t.dependsOn(goTest));
List<String> goOses = golang.getGoOses().get();
if (goOses.isEmpty()) {
goOses = ImmutableList.of("");
}
List<String> goArchs = golang.getGoArchs().get();
if (goArchs.isEmpty()) {
goArchs = ImmutableList.of("");
}
var goBuildDir = project.file("build/exe").toPath();
var exeName = golang.getExecutableName().getOrElse(project.getProjectDir().getName());
for (String goOs : goOses) {
for (String goArch : goArchs) {
String outputDir = goOs.isEmpty() ? "current" : goOs;
if (!goArch.isEmpty()) {
outputDir += '-' + goArch;
}
String outPath = goBuildDir.resolve(outputDir).resolve(exeName).toString() + (goOs.equals("windows") ? ".exe" : "");
var goBuild = project.getTasks().register("goBuild" + toTaskSuffix(goOs) + toTaskSuffix(goArch), GoTask.class, t -> {
t.args("build", "-o", outPath);
t.execCustomizer(exec -> {
if (!goOs.isEmpty()) {
exec.environment("GOOS", goOs);
}
if (!goArch.isEmpty()) {
exec.environment("GOARCH", goArch);
}
CondaExecUtil.condaExec(exec, DownloadedToolManager.get(project), golang.getConda().get());
});
t.dependsOn(DownloadToolUtil.getSetupTask(project, golang.getConda().get()), downloadDeps);
});
project.getTasks().register("jib" + toTaskSuffix(goOs) + toTaskSuffix(goArch), JibTask.class, t -> {
t.dependsOn(goBuild);
t.setExePath(Paths.get(outPath));
});
goBuildAll.configure(t -> t.dependsOn(goBuild));
}
}
});
}
Aggregations