public static void createBuildDependentComponentsTasks(ModelMap<Task> tasks, ComponentSpecContainer components) { for (final VariantComponentSpec component : components.withType(NativeComponentSpec.class).withType(VariantComponentSpec.class)) { tasks.create(getAssembleDependentComponentsTaskName(component), DefaultTask.class, new Action<DefaultTask>() { @Override public void execute(DefaultTask assembleDependents) { assembleDependents.setGroup("Build Dependents"); assembleDependents.setDescription("Assemble dependents of " + component.getDisplayName() + "."); } }); tasks.create(getBuildDependentComponentsTaskName(component), DefaultTask.class, new Action<DefaultTask>() { @Override public void execute(DefaultTask buildDependents) { buildDependents.setGroup("Build Dependents"); buildDependents.setDescription("Build dependents of " + component.getDisplayName() + "."); } }); } }
@Mutate void configurePreCompiledHeaderCompileTasks(final TaskContainer tasks, BinaryContainer binaries, final LanguageTransformContainer languageTransforms, final ServiceRegistry serviceRegistry) { for (final NativeBinarySpecInternal nativeBinarySpec : binaries.withType(NativeBinarySpecInternal.class)) { for (final PchEnabledLanguageTransform<?> transform : languageTransforms.withType(PchEnabledLanguageTransform.class)) { nativeBinarySpec.getInputs().withType(transform.getSourceSetType(), new Action<LanguageSourceSet>() { @Override public void execute(final LanguageSourceSet languageSourceSet) { final DependentSourceSet dependentSourceSet = (DependentSourceSet) languageSourceSet; if (dependentSourceSet.getPreCompiledHeader() != null) { nativeBinarySpec.addPreCompiledHeaderFor(dependentSourceSet); final SourceTransformTaskConfig pchTransformTaskConfig = transform.getPchTransformTask(); String pchTaskName = pchTransformTaskConfig.getTaskPrefix() + StringUtils.capitalize(nativeBinarySpec.getProjectScopedName()) + StringUtils.capitalize(dependentSourceSet.getName()) + "PreCompiledHeader"; Task pchTask = tasks.create(pchTaskName, pchTransformTaskConfig.getTaskType(), new Action<DefaultTask>() { @Override public void execute(DefaultTask task) { pchTransformTaskConfig.configureTask(task, nativeBinarySpec, dependentSourceSet, serviceRegistry); } }); nativeBinarySpec.getTasks().add(pchTask); } } }); } } }
@Override public <S extends TaskInternal> S create(String name, final Class<S> type) { if (!Task.class.isAssignableFrom(type)) { throw new InvalidUserDataException(String.format( "Cannot create task of type '%s' as it does not implement the Task interface.", type.getSimpleName())); } final Class<? extends Task> generatedType; if (type.isAssignableFrom(DefaultTask.class)) { generatedType = generator.generate(DefaultTask.class); } else { generatedType = generator.generate(type); } return type.cast(AbstractTask.injectIntoNewInstance(project, name, type, new Callable<Task>() { public Task call() throws Exception { try { return instantiator.newInstance(generatedType); } catch (ObjectInstantiationException e) { throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()), e.getCause()); } } })); }
@Override public void apply(Project target) { super.apply(target); makeTask("download", DownloadTask.class); makeTask("mapJars", MapJarsTask.class).dependsOn("download"); makeTask("mergeJars", MergeJarsTask.class).dependsOn("mapJars"); makeTask("decompile", DecompileTask.class).dependsOn("mergeJars"); makeTask("applyPatches", PatchMinecraftTask.class).dependsOn("decompile"); makeTask("setupOML", DefaultTask.class).dependsOn("applyPatches"); makeTask("genPatches", GenPatchesTask.class); makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download"); makeTask("genIdeaRuns", GenIdeaProjectTask.class).dependsOn("cleanIdea").dependsOn("idea").dependsOn("extractNatives"); }
@Override public void apply(Project target) { super.apply(target); makeTask("download", DownloadTask.class); makeTask("mergeJars", MergeJarsTask.class).dependsOn("download"); makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars"); makeTask("processMods", ProcessModsTask.class).dependsOn("mapJars"); makeTask("setupFabric", DefaultTask.class).dependsOn("processMods"); makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download"); makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea"); makeTask("vscode", GenVSCodeProjectTask.class).dependsOn("extractNatives"); makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded"); makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded"); }
private void addAssemble(ProjectInternal project) { addPlaceholderAction(project, ASSEMBLE_TASK_NAME, DefaultTask.class, new Action<TaskInternal>() { @Override public void execute(TaskInternal assembleTask) { assembleTask.setDescription("Assembles the outputs of this project."); assembleTask.setGroup(BUILD_GROUP); } }); }
private void addCheck(ProjectInternal project) { addPlaceholderAction(project, CHECK_TASK_NAME, DefaultTask.class, new Action<TaskInternal>() { @Override public void execute(TaskInternal checkTask) { checkTask.setDescription("Runs all checks."); checkTask.setGroup(VERIFICATION_GROUP); } }); }
private void addBuild(final ProjectInternal project) { addPlaceholderAction(project, BUILD_TASK_NAME, DefaultTask.class, new Action<DefaultTask>() { @Override public void execute(DefaultTask buildTask) { buildTask.setDescription("Assembles and tests this project."); buildTask.setGroup(BUILD_GROUP); buildTask.dependsOn(ASSEMBLE_TASK_NAME); buildTask.dependsOn(CHECK_TASK_NAME); } }); }
@Finalize public void defineBinariesCheckTasks(@Each BinarySpecInternal binary, ITaskFactory taskFactory) { if (binary.isLegacyBinary()) { return; } TaskInternal binaryLifecycleTask = taskFactory.create(binary.getNamingScheme().getTaskName("check"), DefaultTask.class); binaryLifecycleTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); binaryLifecycleTask.setDescription("Check " + binary); binary.setCheckTask(binaryLifecycleTask); }
private Class getDeclaredTaskType(Task original) { Class clazz = new DslObject(original).getDeclaredType(); if (clazz.equals(DefaultTask.class)) { return org.gradle.api.Task.class; } else { return clazz; } }
@Override public SourceTransformTaskConfig getTransformTask() { return new SourceTransformTaskConfig() { public String getTaskPrefix() { return "compile"; } public Class<? extends DefaultTask> getTaskType() { return RoutesCompile.class; } public void configureTask(Task task, BinarySpec binarySpec, LanguageSourceSet sourceSet, ServiceRegistry serviceRegistry) { PlayApplicationBinarySpecInternal binary = (PlayApplicationBinarySpecInternal) binarySpec; RoutesSourceSet routesSourceSet = (RoutesSourceSet) sourceSet; RoutesCompile routesCompile = (RoutesCompile) task; ScalaLanguageSourceSet routesScalaSources = binary.getGeneratedScala().get(routesSourceSet); File generatedSourceDir = binary.getNamingScheme().getOutputDirectory(task.getProject().getBuildDir(), "src"); File routesCompileOutputDirectory = new File(generatedSourceDir, routesScalaSources.getName()); routesCompile.setDescription("Generates routes for the '" + routesSourceSet.getName() + "' source set."); routesCompile.setPlatform(binary.getTargetPlatform()); routesCompile.setAdditionalImports(new ArrayList<String>()); routesCompile.setSource(routesSourceSet.getSource()); routesCompile.setOutputDirectory(routesCompileOutputDirectory); routesCompile.setInjectedRoutesGenerator(binary.getApplication().getInjectedRoutesGenerator()); routesScalaSources.getSource().srcDir(routesCompileOutputDirectory); routesScalaSources.builtBy(routesCompile); } }; }
@Override public SourceTransformTaskConfig getTransformTask() { return new SourceTransformTaskConfig() { public String getTaskPrefix() { return "compile"; } public Class<? extends DefaultTask> getTaskType() { return TwirlCompile.class; } public void configureTask(Task task, BinarySpec binarySpec, LanguageSourceSet sourceSet, ServiceRegistry serviceRegistry) { PlayApplicationBinarySpecInternal binary = (PlayApplicationBinarySpecInternal) binarySpec; TwirlSourceSet twirlSourceSet = (TwirlSourceSet) sourceSet; TwirlCompile twirlCompile = (TwirlCompile) task; ScalaLanguageSourceSet twirlScalaSources = binary.getGeneratedScala().get(twirlSourceSet); File generatedSourceDir = binary.getNamingScheme().getOutputDirectory(task.getProject().getBuildDir(), "src"); File twirlCompileOutputDirectory = new File(generatedSourceDir, twirlScalaSources.getName()); twirlCompile.setDescription("Compiles twirl templates for the '" + twirlSourceSet.getName() + "' source set."); twirlCompile.setPlatform(binary.getTargetPlatform()); twirlCompile.setSource(twirlSourceSet.getSource()); twirlCompile.setOutputDirectory(twirlCompileOutputDirectory); twirlCompile.setDefaultImports(twirlSourceSet.getDefaultImports()); twirlScalaSources.getSource().srcDir(twirlCompileOutputDirectory); twirlScalaSources.builtBy(twirlCompile); } }; }
private void configureBuildDependents(Project project) { DefaultTask buildTask = project.getTasks().create(BUILD_DEPENDENTS_TASK_NAME, DefaultTask.class); buildTask.setDescription("Assembles and tests this project and all projects that depend on it."); buildTask.setGroup(BasePlugin.BUILD_GROUP); buildTask.dependsOn(BUILD_TASK_NAME); buildTask.doFirst(new Action<Task>() { @Override public void execute(Task task) { if (!task.getProject().getGradle().getIncludedBuilds().isEmpty()) { task.getProject().getLogger().warn("[composite-build] Warning: `" + task.getPath() + "` task does not build included builds."); } } }); }
public void addDependenciesToPrepareTask( @NonNull TaskFactory tasks, @NonNull BaseVariantData<? extends BaseVariantOutputData> variantData, @NonNull AndroidTask<PrepareDependenciesTask> prepareDependenciesTask) { VariantDependencies variantDeps = variantData.getVariantDependency(); final AndroidTask<DefaultTask> preBuildTask = variantData.getScope().getPreBuildTask(); final ImmutableList<AndroidDependency> compileLibraries = variantDeps .getCompileDependencies().getAllAndroidDependencies(); final ImmutableList<AndroidDependency> packageLibraries = variantDeps .getPackageDependencies().getAllAndroidDependencies(); // gather all the libraries first, then make the task depend on the list in a single // pass. List<PrepareLibraryTask> prepareLibraryTasks = Lists .newArrayListWithCapacity(compileLibraries.size() + packageLibraries.size()); for (AndroidDependency dependency : Iterables.concat(compileLibraries, packageLibraries)) { // skip sub-module since we don't extract them anymore. if (dependency.getProjectPath() == null) { PrepareLibraryTask prepareLibTask = prepareLibTaskMap .get(dependency.getCoordinates().toString()); if (prepareLibTask != null) { prepareLibraryTasks.add(prepareLibTask); prepareLibTask.dependsOn(preBuildTask.getName()); } } } if (!prepareLibraryTasks.isEmpty()) { prepareDependenciesTask.dependsOn(tasks, prepareLibraryTasks.toArray()); } }
@Override public void apply(Project project) { if (!project.getPlugins().hasPlugin(AppPlugin.class)) { throw new RuntimeException("should be declared after 'com.android.application'"); } AppExtension ext = project.getExtensions().getByType(AppExtension.class); ext.getApplicationVariants().all(v -> { String taskName = "open"+capitalize(v.getName()); DefaultTask parentTask = v.getInstall(); File adb = ext.getAdbExe(); if (v.isSigningReady()) { String packageId = v.getApplicationId(); HashMap variantAction = new HashMap(); variantAction.put("dependsOn", parentTask); variantAction.put("description", "Installs and opens " + v.getDescription()); variantAction.put("type", Exec.class); variantAction.put("group", "Open"); Exec t = (Exec) project.task(variantAction, taskName); t.setCommandLine(adb, "shell", "monkey", "-p", packageId, "-c", "android.intent.category.LAUNCHER", "1"); } }); }
private void registerTransformEntryOutputs(Project project, DefaultTask task, List<ImageTransformEntry> transformEntries) { if( transformEntries == null || transformEntries.isEmpty() ){ return; } // register all generated files as task-output for "up-to-date"-checking task.getOutputs().upToDateWhen(upToDateTask -> { List<File> possibleDestinationFiles = transformEntries.stream().parallel().map(transformEntry -> { return new File(transformEntry.destination); }).collect(Collectors.toList()); long existingDestinationFilesCount = possibleDestinationFiles.stream().parallel().filter(File::exists).count(); // if existing files are equal to possible files, this task is up2date return possibleDestinationFiles.size() == existingDestinationFilesCount; }); }
public void configure(Project project) throws IOException { revision = RevisionUtil.getRevision(project); AndroidTasks.getOrCreateProjectInfoTask(project, releaseVersion, revision); project.getTasks().create("runUnitTests", DefaultTask.class); Task build = project.getTasks().create("build", DefaultTask.class); build.setGroup(TaskGroup.BUILD.getLabel()); Task buildAndroid = project.getTasks().create("buildAndroid", DefaultTask.class); Task assembleDebug = AndroidTasks.getTaskByName(project, "assembleDebug"); Task assembleRelease = AndroidTasks.getTaskByName(project, "assembleRelease"); Task buildDebug = project.getTasks().create("buildAndroidDebug", DefaultTask.class); Environment debug = generateEnvironmentForBuildDebug(project); addUtilityTasksForBuildDebug(project, debug); Task buildRelease = project.getTasks().create("buildAndroidRelease", DefaultTask.class); Environment release = generateEnvironmentForBuildRelease(project); addUtilityTasksForBuildRelease(project, release); buildDebug.dependsOn(assembleDebug); buildRelease.dependsOn(assembleRelease); buildAndroid.dependsOn(buildRelease); build.dependsOn(buildAndroid); }
static Task getOrCreateBuildTask(Project project) { String taskName = "build"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.BUILD.getLabel()); newTask.setDescription("Builds all project's environments"); return newTask; } else { return existingTask; } }
static Task getOrCreateCleanTask(Project project) { String taskName = "clean"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.UTILITY.getLabel()); return newTask; } else { return existingTask; } }
static Task getOrCreateRestoreDependenciesTask(Project project) { String taskName = "restoreDependencies"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.BUILD.getLabel()); return newTask; } else { return existingTask; } }
static Task getOrCreateBuildTask(Project project) { String taskName = "build"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.BUILD.getLabel()); return newTask; } else { return existingTask; } }
static Task getOrCreateBuildIosTask(Project project) { String taskName = "buildIos"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.BUILD.getLabel()); newTask.setDescription("Builds project's iOS target environments"); return newTask; } else { return existingTask; } }
static Task getOrCreateBuildAndroidTask(Project project) { String taskName = "buildAndroid"; Task existingTask = project.getTasks().findByName(taskName); if (existingTask == null) { DefaultTask newTask = project.getTasks().create(taskName, DefaultTask.class); newTask.setGroup(TaskGroup.BUILD.getLabel()); newTask.setDescription("Builds project's iOS target environments"); return newTask; } else { return existingTask; } }
public synchronized AndroidTask<Task> create( TaskFactory taskFactory, String taskName, Closure configAction) { taskFactory.create(taskName, DefaultTask.class, new ClosureBackedAction<Task>(configAction)); final AndroidTask<Task> newTask = new AndroidTask<Task>(taskName, Task.class); tasks.put(taskName, newTask); return newTask; }
public SourceTransformTaskConfig getTransformTask() { return new SourceTransformTaskConfig() { public String getTaskPrefix() { return "compile"; } public Class<? extends DefaultTask> getTaskType() { return PlatformJavaCompile.class; } public void configureTask(Task task, BinarySpec binarySpec, LanguageSourceSet sourceSet) { PlatformJavaCompile compile = (PlatformJavaCompile) task; JavaSourceSet javaSourceSet = (JavaSourceSet) sourceSet; JvmBinarySpec binary = (JvmBinarySpec) binarySpec; compile.setDescription(String.format("Compiles %s.", javaSourceSet)); compile.setDestinationDir(binary.getClassesDir()); compile.setToolChain(binary.getToolChain()); compile.setPlatform(binary.getTargetPlatform()); compile.setSource(javaSourceSet.getSource()); compile.setClasspath(javaSourceSet.getCompileClasspath().getFiles()); compile.setTargetCompatibility(binary.getTargetPlatform().getTargetCompatibility().toString()); compile.setSourceCompatibility(binary.getTargetPlatform().getTargetCompatibility().toString()); compile.setDependencyCacheDir(new File(compile.getProject().getBuildDir(), "jvm-dep-cache")); compile.dependsOn(javaSourceSet); binary.getTasks().getJar().dependsOn(compile); } }; }
private void checkTaskArgsAndCreateDefaultValues(Map<String, Object> args) { validateArgs(args); setIfNull(args, Task.TASK_NAME, ""); setIfNull(args, Task.TASK_TYPE, DefaultTask.class); if (((Class) args.get(Task.TASK_TYPE)).isAssignableFrom(DefaultTask.class)) { args.put(Task.TASK_TYPE, DefaultTask.class); } setIfNull(args, GENERATE_SUBCLASS, "true"); }
@Test public void testApply() { project.apply(Collections.singletonMap("plugin", "java")); project.apply(Collections.singletonMap("plugin", "org.anarres.velocity")); assertTrue("Project is missing plugin", project.getPlugins().hasPlugin(VelocityPlugin.class)); Task task = project.getTasks().findByName("processVelocity"); assertNotNull("Project is missing velocity task", task); assertTrue("Velocity task is the wrong type", task instanceof DefaultTask); assertTrue("Velocity task should be enabled", ((DefaultTask) task).isEnabled()); }
@Test public void testApply() { project.apply(Collections.singletonMap("plugin", "java")); // project.apply(Collections.singletonMap("plugin", "org.anarres.jnaerator")); project.getPlugins().apply(JNAeratorPlugin.class); assertTrue("Project is missing plugin", project.getPlugins().hasPlugin(JNAeratorPlugin.class)); Task task = project.getTasks().findByName("jnaerator"); assertNotNull("Project is missing jnaerator task", task); assertTrue("JNAerator task is the wrong type", task instanceof DefaultTask); assertTrue("JNAerator task should be enabled", ((DefaultTask) task).isEnabled()); }
public CompileTaskConfig(LanguageTransform<? extends LanguageSourceSet, ObjectFile> languageTransform, Class<? extends DefaultTask> taskType) { this.languageTransform = languageTransform; this.taskType = taskType; }
@Override public Class<? extends DefaultTask> getTaskType() { return taskType; }
public PCHCompileTaskConfig(LanguageTransform<? extends LanguageSourceSet, ObjectFile> languageTransform, Class<? extends DefaultTask> taskType) { super(languageTransform, taskType); }
public SourceCompileTaskConfig(LanguageTransform<? extends LanguageSourceSet, ObjectFile> languageTransform, Class<? extends DefaultTask> taskType) { super(languageTransform, taskType); }
@Override public Class<? extends DefaultTask> getTaskType() { return WindowsResourceCompile.class; }
@Override public Class<? extends DefaultTask> getTaskType() { return Assemble.class; }
private void checkTaskArgsAndCreateDefaultValues(Map<String, Object> args) { validateArgs(args); setIfNull(args, Task.TASK_NAME, ""); setIfNull(args, Task.TASK_TYPE, DefaultTask.class); }
private void configureBuildNeeded(Project project) { DefaultTask buildTask = project.getTasks().create(BUILD_NEEDED_TASK_NAME, DefaultTask.class); buildTask.setDescription("Assembles and tests this project and all projects it depends on."); buildTask.setGroup(BasePlugin.BUILD_GROUP); buildTask.dependsOn(BUILD_TASK_NAME); }
@Override public void execute(MtlParallelTask parallelTask) { super.execute(parallelTask); AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get( parallelTask.getVariantName()); if (null == atlasDependencyTree) { return; } List<DefaultTask> tasks = new ArrayList<DefaultTask>(); for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) { MergeAwbResourceConfigAction mergeAwbResourceConfigAction = new MergeAwbResourceConfigAction( appVariantContext, baseVariantOutputData, awbBundle); final CachedMergeResources mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbResourceConfigAction.getName(), mergeAwbResourceConfigAction.getType()); mergeTask.setBlameLogFolder(appVariantContext.getAwbBlameLogFolder(awbBundle)); mergeAwbResourceConfigAction.execute(mergeTask); tasks.add(mergeTask); mergeTask.doLast(new Action<Task>() { @Override public void execute(Task task) { File publicRes = new File(awbBundle.getAndroidLibrary().getResFolder(), "values/public.xml"); if (publicRes.exists()) { try { FileUtils.copyFile(publicRes, new File(mergeTask.getOutputDir(), "values/public.xml")); } catch (IOException e) { e.printStackTrace(); } } } }); } parallelTask.parallelTask = tasks; parallelTask.uniqueTaskName = getName(); parallelTask.concurrent = true; }