private static <T extends Task> T createTask(TaskContainer tasks, String preferredName, Class<T> type) { String name = preferredName; int count = 1; while (true) { try { Task existingTask = tasks.getByName(name); if (type.isInstance(existingTask)) { return null; } } catch (UnknownTaskException e) { return tasks.create(name, type); } count++; name = preferredName + count; } }
@Override public Task resolveTask(TaskReference reference) { for (TaskReferenceResolver taskResolver : project.getServices().getAll(TaskReferenceResolver.class)) { Task constructed = taskResolver.constructTask(reference, this); if (constructed != null) { return constructed; } } throw new UnknownTaskException(String.format("Task reference '%s' could not be resolved in %s.", reference.getName(), project)); }
public Task getByPath(String path) throws UnknownTaskException { Task task = findByPath(path); if (task == null) { throw new UnknownTaskException(String.format("Task with path '%s' not found in %s.", path, project)); } return task; }
private void addFinalizedBy(String taskName, Project project, TestHTMLReporterPluginTask junit5HTMLReport) { try { Task task = project.getTasks().getByName(taskName); task.finalizedBy(junit5HTMLReport); } catch (UnknownTaskException e) { System.out.println("unable to finalize " + taskName); } }
private Set<Task> getAntTargetDependencies() { Set<Task> tasks = new LinkedHashSet<Task>(); Enumeration dependencies = target.getDependencies(); while (dependencies.hasMoreElements()) { String name = (String) dependencies.nextElement(); Task dependency = getProject().getTasks().findByName(name); if (dependency == null) { throw new UnknownTaskException(String.format("Imported Ant target '%s' depends on target or task '%s' which does not exist", getName(), name)); } tasks.add(dependency); } return tasks; }
@Override protected UnknownDomainObjectException createNotFoundException(String name) { return new UnknownTaskException(String.format("Task with name '%s' not found in %s.", name, project)); }
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().file(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); }
/** * {@inheritDoc} */ T getByName(String name, Closure configureClosure) throws UnknownTaskException;
/** * {@inheritDoc} */ T getByName(String name) throws UnknownTaskException;
/** * {@inheritDoc} */ T getAt(String name) throws UnknownTaskException;