@Override public void exec() { if (Utils.isNullOrEmpty(url) || Utils.isNullOrEmpty(output)) { throw new IllegalArgumentException("Schema URL and output path can't be empty"); } setScript(new File(getProject().getTasks().getByPath(ApolloCodegenInstallTask.NAME).getOutputs().getFiles() .getAsPath(), ApolloLocalCodegenGenerationTask.APOLLO_CODEGEN_EXEC_FILE)); List<String> args = Lists.newArrayList("introspect-schema", url, "--output", getProject().file(output) .getAbsolutePath()); if (!headers.isEmpty()) { for(String h : headers) { args.add("--header"); args.add(h); } } if (insecure) { args.add("--insecure"); args.add("true"); } setArgs(args); super.exec(); }
@Override public void applyTo(final Project project) { // XXX: This needs to be adjusted to work with a build matrix one day. Until // that is ready, we always assume pure Python 2.7 on Linux. String version = project.getVersion().toString().replace("-", "_"); String name = project.getName().replace("-", "_"); final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); /* * Create a Python wheel distribution. */ project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); task.getOutputs().file(wheelArtifact); task.doLast(it -> project.exec(execSpec -> { execSpec.environment(settings.pythonEnvironmentDistgradle); execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); })); }); LinkedHashMap<String, Object> wheelArtifactInfo = new LinkedHashMap<>(5); wheelArtifactInfo.put("name", name); wheelArtifactInfo.put("classifier", "py2-none-any"); wheelArtifactInfo.put("type", "whl"); wheelArtifactInfo.put("file", wheelArtifact); wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); if (!version.contains("SNAPSHOT")) { project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); } }
private void _configureTaskNpmRun( NpmRunTask npmRunTask, NodeExtension nodeExtension) { npmRunTask.setNodeVersion(nodeExtension.getNodeVersion()); npmRunTask.setNpmVersion(nodeExtension.getNpmVersion()); Project project = npmRunTask.getProject(); PluginContainer pluginContainer = project.getPlugins(); if (pluginContainer.hasPlugin(JavaPlugin.class)) { SourceSet sourceSet = GradleUtil.getSourceSet( npmRunTask.getProject(), SourceSet.MAIN_SOURCE_SET_NAME); SourceSetOutput sourceSetOutput = sourceSet.getOutput(); File classesDir = sourceSetOutput.getClassesDir(); if (!classesDir.exists()) { TaskOutputs taskOutputs = npmRunTask.getOutputs(); taskOutputs.upToDateWhen( new Spec<Task>() { @Override public boolean isSatisfiedBy(Task task) { return false; } }); } } }
action.getOutputs().doNotCacheIf("When package packageFilter is set", task -> ((SupportsPackageFiltering) task).getPackageExcludeFilter() != null); }); task.getOutputs().file(settings.getDetails().getActivateLink());
public void apply(Project rootProject) { this.project = rootProject; if (!rootProject.equals(rootProject.getRootProject())) { throw new IllegalArgumentException( BaselineConfig.class.getCanonicalName() + " plugin can only be applied to the root project."); } Configuration configuration = rootProject.getConfigurations().create("baseline"); // users can still override this default dependency, it just reduces boilerplate Optional<String> version = Optional.ofNullable(getClass().getPackage().getImplementationVersion()); configuration.defaultDependencies(d -> d.add(rootProject.getDependencies().create(String.format( "com.palantir.baseline:gradle-baseline-java-config%s@zip", version.map(v -> ":" + v).orElse(""))))); // Create task for generating configuration. rootProject.getTasks().register("baselineUpdateConfig", task -> { task.setGroup("Baseline"); task.setDescription("Installs or updates Baseline configuration files in .baseline/"); task.getInputs().files(configuration); task.getOutputs().dir(getConfigDir()); task.getOutputs().dir(rootProject.getRootDir().toPath().resolve("project")); task.doLast(new BaselineUpdateConfigAction(configuration, rootProject)); }); }
@Override public void applyTo(final Project project) { // XXX: This needs to be adjusted to work with a build matrix one day. Until // that is ready, we always assume pure Python 2.7 on Linux. String version = project.getVersion().toString().replace("-", "_"); String name = project.getName().replace("-", "_"); final File wheelArtifact = new File(project.getProjectDir(), "/dist/" + name + "-" + version + "-py2-none-any.whl"); /* * Create a Python wheel distribution. */ project.getTasks().create(TASK_PACKAGE_WHEEL, task -> { task.dependsOn(project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue())); task.getOutputs().file(wheelArtifact); task.doLast(it -> project.exec(execSpec -> { execSpec.environment(settings.pythonEnvironmentDistgradle); execSpec.commandLine(settings.getDetails().getVirtualEnvInterpreter(), "setup.py", "bdist_wheel"); })); }); LinkedHashMap<String, Object> wheelArtifactInfo = new LinkedHashMap<>(5); wheelArtifactInfo.put("name", name); wheelArtifactInfo.put("classifier", "py2-none-any"); wheelArtifactInfo.put("type", "whl"); wheelArtifactInfo.put("file", wheelArtifact); wheelArtifactInfo.put("builtBy", project.getTasks().getByName(TASK_PACKAGE_WHEEL)); if (!version.contains("SNAPSHOT")) { project.getArtifacts().add(StandardTextValues.CONFIGURATION_WHEEL.getValue(), wheelArtifactInfo); } }
private void _configureTaskNpmRun( NpmRunTask npmRunTask, NodeExtension nodeExtension) { npmRunTask.setNodeVersion(nodeExtension.getNodeVersion()); npmRunTask.setNpmVersion(nodeExtension.getNpmVersion()); Project project = npmRunTask.getProject(); PluginContainer pluginContainer = project.getPlugins(); if (pluginContainer.hasPlugin(JavaPlugin.class)) { SourceSet sourceSet = GradleUtil.getSourceSet( npmRunTask.getProject(), SourceSet.MAIN_SOURCE_SET_NAME); SourceSetOutput sourceSetOutput = sourceSet.getOutput(); File classesDir = sourceSetOutput.getClassesDir(); if (!classesDir.exists()) { TaskOutputs taskOutputs = npmRunTask.getOutputs(); taskOutputs.upToDateWhen( new Spec<Task>() { @Override public boolean isSatisfiedBy(Task task) { return false; } }); } } }
action.getOutputs().doNotCacheIf("When package packageFilter is set", task -> ((SupportsPackageFiltering) task).getPackageExcludeFilter() != null); }); task.getOutputs().file(settings.getDetails().getActivateLink());
protected Task addTaskBuildXSDGenerate(BuildXSDTask buildXSDTask) { Project project = buildXSDTask.getProject(); JavaExec javaExec = GradleUtil.addTask( project, buildXSDTask.getName() + "Generate", JavaExec.class); File tmpSrcDir = new File( project.getBuildDir(), buildXSDTask.getName() + "/src"); javaExec.args("-d"); javaExec.args(FileUtil.getAbsolutePath(tmpSrcDir)); javaExec.args("-srconly"); Iterable<File> xsdFiles = buildXSDTask.getInputFiles(); for (File xsdFile : xsdFiles) { javaExec.args(FileUtil.getAbsolutePath(xsdFile)); } javaExec.dependsOn( BasePlugin.CLEAN_TASK_NAME + StringUtil.capitalize(javaExec.getName())); javaExec.setClasspath( GradleUtil.getConfiguration(project, CONFIGURATION_NAME)); javaExec.setDescription( "Invokes the XMLBeans Schema Compiler in order to generate Java " + "types from XML Schema."); javaExec.setMain("org.apache.xmlbeans.impl.tool.SchemaCompiler"); TaskInputs taskInputs = javaExec.getInputs(); taskInputs.files(xsdFiles); TaskOutputs taskOutputs = javaExec.getOutputs(); taskOutputs.dir(tmpSrcDir); return javaExec; }
@Override public Void call() { File runnableJarFile = executableJarTask.getOutputs() .getFiles().iterator().next(); Path stubPath = Paths.get(outputDir.getAbsolutePath() + File.separator + "stub.sh"); try { Files.copy(this.getClass().getResourceAsStream("/stub.sh"), stubPath); TFiles.cat(jarshFile.getAbsolutePath(), stubPath.toFile() .getAbsolutePath(), runnableJarFile .getAbsolutePath()); Files.delete(stubPath); jarshFile.setExecutable(true); } catch (Exception e) { throw new RuntimeException(e); } return null; }
final File jarshFile = new File(outputDir + File.separator + project.getName() + ".sh"); task.getOutputs().file(jarshFile);
private Task _addTaskBuildWSDLGenerate( BuildWSDLTask buildWSDLTask, FileCollection classpath, File inputFile, final File destinationDir, boolean deleteDestinationDir) { Project project = buildWSDLTask.getProject(); String taskName = GradleUtil.getTaskName( buildWSDLTask.getName() + "Generate", inputFile); JavaExec javaExec = GradleUtil.addTask( project, taskName, JavaExec.class); GenerateOptions generateOptions = buildWSDLTask.getGenerateOptions(); javaExec.args(generateOptions.getArgs()); javaExec.args("--output=" + FileUtil.getAbsolutePath(destinationDir)); javaExec.args(FileUtil.getAbsolutePath(inputFile)); if (deleteDestinationDir) { javaExec.doFirst( new Action<Task>() { @Override public void execute(Task task) { Project project = task.getProject(); project.delete(destinationDir); } }); } javaExec.setClasspath(classpath); javaExec.setMain("org.apache.axis.wsdl.WSDL2Java"); TaskInputs taskInputs = javaExec.getInputs(); taskInputs.file(inputFile); TaskOutputs taskOutputs = javaExec.getOutputs(); taskOutputs.dir(destinationDir); return javaExec; }
} else if (element instanceof Task) { Task task = (Task) element; queue.add(0, task.getOutputs().getFiles()); } else if (element instanceof TaskOutputs) { TaskOutputs outputs = (TaskOutputs) element; queue.add(0, outputs.getFiles()); } else if (element instanceof Callable) { Callable callable = (Callable) element;
private void _addTaskBuildWSDLTasks( BuildWSDLTask buildWSDLTask, File inputFile, Configuration wsdlBuilderConfiguration) { Project project = buildWSDLTask.getProject(); if (buildWSDLTask.isBuildLibs()) { String tmpDirName = "build-wsdl/" + FileUtil.stripExtension(inputFile.getName()); File tmpDir = new File(project.getBuildDir(), tmpDirName); File tmpSrcDir = new File(tmpDir, "src"); Task generateTask = _addTaskBuildWSDLGenerate( buildWSDLTask, wsdlBuilderConfiguration, inputFile, tmpSrcDir, true); Task compileTask = _addTaskBuildWSDLCompile( buildWSDLTask, wsdlBuilderConfiguration, inputFile, tmpDir, generateTask); Jar jar = _addTaskBuildWSDLJar( buildWSDLTask, inputFile, compileTask, generateTask); buildWSDLTask.dependsOn(jar); TaskOutputs taskOutputs = buildWSDLTask.getOutputs(); taskOutputs.file(jar.getArchivePath()); } else { Task generateTask = _addTaskBuildWSDLGenerate( buildWSDLTask, wsdlBuilderConfiguration, inputFile, buildWSDLTask.getDestinationDir(), false); buildWSDLTask.dependsOn(generateTask); } }
/** * Returns the input files for a task. * * @param extraDirectory the image's configured extra directory * @param project the gradle project * @return the input files to the task are all the output files for all the dependencies of the * {@code classes} task */ static FileCollection getInputFiles(File extraDirectory, Project project) { Task classesTask = project.getTasks().getByPath("classes"); Set<? extends Task> classesDependencies = classesTask.getTaskDependencies().getDependencies(classesTask); List<FileCollection> dependencyFileCollections = new ArrayList<>(); for (Task task : classesDependencies) { dependencyFileCollections.add(task.getOutputs().getFiles()); } if (Files.exists(extraDirectory.toPath())) { return project.files(dependencyFileCollections, extraDirectory); } else { return project.files(dependencyFileCollections); } }
private Task createClassycleTask(final Project project, final ClassycleExtension extension, final SourceSet sourceSet) { final String taskName = sourceSet.getTaskName("classycle", null); final FileCollection classesDirs = sourceSet.getOutput().getClassesDirs(); final File reportFile = getReportingExtension(project).file("classycle_" + sourceSet.getName() + ".txt"); final Task task = project.task(taskName); task.getInputs().files(classesDirs, extension.getDefinitionFile()); task.getOutputs().file(reportFile); task.doLast(new ClassyclePlugin.ClassycleAction(classesDirs, reportFile, extension)); // the classycle task depends on the corresponding classes task final String classesTask = sourceSet.getClassesTaskName(); task.dependsOn(classesTask); if (project.getLogger().isDebugEnabled()) { final StringBuilder sb = new StringBuilder(); for (final File file : classesDirs) { sb.append(file.getAbsolutePath()).append(" "); } project.getLogger() .debug("Created classycle task: " + taskName + ", report file: " + reportFile + ", depends on: " + classesTask + " - sourceSetDirs: " + sb.toString()); } return task; }
@Override public void exec() { if (Utils.isNullOrEmpty(url) || Utils.isNullOrEmpty(output)) { throw new IllegalArgumentException("Schema URL and output path can't be empty"); } setScript(new File(getProject().getTasks().getByPath(ApolloCodeGenInstallTask.NAME).getOutputs().getFiles() .getAsPath(), ApolloIRGenTask.APOLLO_CODEGEN_EXEC_FILE)); List<String> args = Lists.newArrayList("introspect-schema", url, "--output", getProject().file(output) .getAbsolutePath()); if (!headers.isEmpty()) { for(String h : headers) { args.add("--header"); args.add(h); } } if (insecure) { args.add("--insecure"); args.add("true"); } setArgs(args); super.exec(); }
final Task task = project.task(taskName); task.getInputs().files(classDir, definitionFile); task.getOutputs().file(reportFile); log.debug("Created classycle task: " + taskName + ", report file: " + reportFile); task.doLast(new Action<Task>() {
/** * Returns the appengine service directory for this project and modifies the task dependencies of * run/start to ensure {@code serviceProject} is built first. */ public File projectAsService(Project serviceProject) { if (!serviceProject.equals(project)) { project.evaluationDependsOn(serviceProject.getPath()); } project .getTasks() .findByName(AppEngineStandardPlugin.RUN_TASK_NAME) .dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME)); project .getTasks() .findByName(AppEngineStandardPlugin.START_TASK_NAME) .dependsOn(serviceProject.getTasks().findByPath(BasePlugin.ASSEMBLE_TASK_NAME)); return serviceProject .getTasks() .findByName(AppEngineStandardPlugin.EXPLODE_WAR_TASK_NAME) .getOutputs() .getFiles() .getSingleFile(); }
public static Delete createCleanupTask(TaskContainer tasks, Task task) { String cleanTaskName = getCleanTaskName(task); Delete clean = tasks.create(cleanTaskName, Delete.class); clean.setGroup(task.getGroup()); clean.setDescription("Cleans for " + task.getName()); clean.delete(task.getOutputs().getFiles()); task.mustRunAfter(clean); return clean; }