Java Code Examples for org.gradle.api.DefaultTask

The following examples show how to use org.gradle.api.DefaultTask. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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;
    }
}
 
Example 2
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);
        }
    };
}
 
Example 3
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");
}
 
Example 4
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;
    }
}
 
Example 5
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");
}
 
Example 6
Source Project: javaide   Source File: LifecycleBasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 7
Source Project: javaide   Source File: LifecycleBasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 8
Source Project: javaide   Source File: LifecycleBasePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 9
Source Project: javaide   Source File: AndroidTaskRegistry.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 10
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;
    }
}
 
Example 11
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);
        }
    };
}
 
Example 12
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");
}
 
Example 13
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;
    }
}
 
Example 14
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");
}
 
Example 15
public CompileTaskConfig(LanguageRegistration<? extends LanguageSourceSet> languageRegistration, Class<? extends DefaultTask> taskType) {
    this.language = languageRegistration;
    this.taskType = taskType;
}
 
Example 16
public Class<? extends DefaultTask> getTaskType() {
    return taskType;
}
 
Example 17
public Class<? extends DefaultTask> getTaskType() {
    return WindowsResourceCompile.class;
}
 
Example 18
public Class<? extends DefaultTask> getTaskType() {
    return Assemble.class;
}
 
Example 19
Source Project: quarkus   Source File: QuarkusPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Convert2Lambda")
private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
    TaskContainer tasks = project.getTasks();
    tasks.create(LIST_EXTENSIONS_TASK_NAME, QuarkusListExtensions.class);
    tasks.create(ADD_EXTENSION_TASK_NAME, QuarkusAddExtension.class);
    tasks.create(REMOVE_EXTENSION_TASK_NAME, QuarkusRemoveExtension.class);
    tasks.create(GENERATE_CONFIG_TASK_NAME, QuarkusGenerateConfig.class);

    Task quarkusBuild = tasks.create(QUARKUS_BUILD_TASK_NAME, QuarkusBuild.class);
    Task quarkusDev = tasks.create(QUARKUS_DEV_TASK_NAME, QuarkusDev.class);
    Task quarkusRemoteDev = tasks.create(QUARKUS_REMOTE_DEV_TASK_NAME, QuarkusRemoteDev.class);
    tasks.create(QUARKUS_TEST_CONFIG_TASK_NAME, QuarkusTestConfig.class);

    Task buildNative = tasks.create(BUILD_NATIVE_TASK_NAME, DefaultTask.class);
    buildNative.finalizedBy(quarkusBuild);
    buildNative.doFirst(t -> project.getLogger()
            .warn("The 'buildNative' task has been deprecated in favor of 'build -Dquarkus.package.type=native'"));

    configureBuildNativeTask(project);

    final Consumer<Test> configureTestTask = t -> {
        // Quarkus test configuration action which should be executed before any Quarkus test
        // Use anonymous classes in order to leverage task avoidance.
        t.doFirst(new Action<Task>() {
            @Override
            public void execute(Task test) {
                quarkusExt.beforeTest(t);
            }
        });
        // also make each task use the JUnit platform since it's the only supported test environment
        t.useJUnitPlatform();
        // quarkusBuild is expected to run after the project has passed the tests
        quarkusBuild.shouldRunAfter(t);
    };

    project.getPlugins().withType(
            BasePlugin.class,
            basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild));
    project.getPlugins().withType(
            JavaPlugin.class,
            javaPlugin -> {
                project.afterEvaluate(this::afterEvaluate);

                Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);
                Task resourcesTask = tasks.getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME);
                quarkusDev.dependsOn(classesTask, resourcesTask);
                quarkusRemoteDev.dependsOn(classesTask, resourcesTask);
                quarkusBuild.dependsOn(classesTask, resourcesTask, tasks.getByName(JavaPlugin.JAR_TASK_NAME));

                SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
                        .getSourceSets();
                SourceSet nativeTestSourceSet = sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME);
                SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
                SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);

                nativeTestSourceSet.setCompileClasspath(
                        nativeTestSourceSet.getCompileClasspath()
                                .plus(mainSourceSet.getOutput())
                                .plus(testSourceSet.getOutput()));

                nativeTestSourceSet.setRuntimeClasspath(
                        nativeTestSourceSet.getRuntimeClasspath()
                                .plus(mainSourceSet.getOutput())
                                .plus(testSourceSet.getOutput()));

                // create a custom configuration to be used for the dependencies of the testNative task
                ConfigurationContainer configurations = project.getConfigurations();
                configurations.maybeCreate(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME)
                        .extendsFrom(configurations.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME));
                configurations.maybeCreate(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME)
                        .extendsFrom(configurations.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME));

                Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class);
                testNative.dependsOn(quarkusBuild);
                testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME)));

                tasks.withType(Test.class).forEach(configureTestTask);
                tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept);
            });
}
 
Example 20
Source Project: crnk-framework   Source File: GeneratorPlugin.java    License: Apache License 2.0 4 votes vote down vote up
private Task setupCleanTask(Project project, GeneratorModule module) {
	Task task = project.getTasks().create(getCleanTaskName(module), DefaultTask.class);
	task.doFirst(task1 -> project.delete(module.getConfig().getGenDir()));
	return task;
}
 
Example 21
Source Project: atlas   Source File: MergeResAwbsConfigAction.java    License: Apache License 2.0 4 votes vote down vote up
@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()) {
            if (awbBundle.isMBundle){
                continue;
            }

            MergeAwbResource.MergeAwbResourceConfigAction mergeAwbResourceConfigAction = new MergeAwbResource.MergeAwbResourceConfigAction(
                    appVariantContext,
                    baseVariantOutput,
                    awbBundle);

            final MergeAwbResource mergeTask = TaskCreater.create(appVariantContext.getProject(),
                                                                mergeAwbResourceConfigAction.getName(),
                                                                mergeAwbResourceConfigAction.getType());
//            mergeTask.getOutputs().cacheIf(new Spec<Task>() {
//                @Override
//                public boolean isSatisfiedBy(Task element) {
//                    return false;
//                }
//            });

            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;
    }
 
Example 22
Source Project: javaide   Source File: JavaBasePlugin.java    License: GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 23
Source Project: javaide   Source File: JavaBasePlugin.java    License: GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 24
Source Project: gradle-plugins   Source File: HelmPlugin.java    License: Apache License 2.0 4 votes vote down vote up
public void apply(Project project) {
	project.getPlugins().apply(CliExecPlugin.class);

	HelmExtension extension = project.getExtensions().create("helm", HelmExtension.class);
	extension.setProject(project);
	// extension.setKubeConfig(KubernetesUtils.getDefaultKubeConfig(project));

	HelmBootstrap helmBootstrap = project.getTasks().create("helmBootstrap", HelmBootstrap.class);

	DefaultTask helmPackages = project.getTasks().create("helmPackage", DefaultTask.class);
	HelmPublish helmPublish = project.getTasks().create("helmPublish", HelmPublish.class);
	Task helmUpdateRepository = project.getTasks().create("helmUpdateRepository", HelmUpdateRepository.class);
	DefaultTask helmPackagePrepare = project.getTasks().create("helmPackagePrepare", DefaultTask.class);
	helmPackagePrepare.dependsOn(helmBootstrap);

	helmUpdateRepository.dependsOn(helmBootstrap);
	helmPublish.dependsOn(helmUpdateRepository);
	helmPublish.dependsOn(helmPackages);

	CliExecExtension cliExec = project.getExtensions().getByType(CliExecExtension.class);
	cliExec.register("helm", extension.getCli());

	Set<String> packageNames = extension.getPackageNames();
	for (String packageName : packageNames) {
		HelmPackage helmPackage = project.getTasks().create("helmPackage" + toCamelCase(packageName), HelmPackage.class);
		helmPackage.setPackageName(packageName);
		helmPackage.dependsOn(helmPackagePrepare);
		helmPackages.dependsOn(helmPackage);
	}

	project.afterEvaluate(project1 -> {
		Cli cli = extension.getCli();

		if (cli.isDockerized()) {
			helmBootstrap.setEnabled(false);
		} else if (cli.getDownload()) {
			helmBootstrap.src(cli.getDownloadUrl());
			File downloadDir = cli.getDownloadDir();
			downloadDir.mkdirs();
			helmBootstrap.dest(downloadDir);
		} else {
			helmBootstrap.setEnabled(false);
		}
	});
}
 
Example 25
public CompileTaskConfig(LanguageRegistration<? extends LanguageSourceSet> languageRegistration, Class<? extends DefaultTask> taskType) {
    this.language = languageRegistration;
    this.taskType = taskType;
}
 
Example 26
public Class<? extends DefaultTask> getTaskType() {
    return taskType;
}
 
Example 27
public Class<? extends DefaultTask> getTaskType() {
    return WindowsResourceCompile.class;
}
 
Example 28
public Class<? extends DefaultTask> getTaskType() {
    return Assemble.class;
}
 
Example 29
Source Project: atlas   Source File: MergeManifestAwbsConfigAction.java    License: Apache License 2.0 3 votes vote down vote up
@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>();

    AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext();

    for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {

        MergeAwbManifests.ConfigAction configAction = new MergeAwbManifests.ConfigAction(
            appVariantOutputContext.getScope(),
            awbBundle, appVariantOutputContext);
        MergeAwbManifests mergeAwbManifests = TaskCreater.create(appVariantContext.getProject(),
                                                                 configAction.getName(), configAction.getType());

        configAction.execute(mergeAwbManifests);

        tasks.add(mergeAwbManifests);

    }

    parallelTask.parallelTask = tasks;
    parallelTask.uniqueTaskName = getName();

}
 
Example 30
Source Project: atlas   Source File: MergeAssetAwbsConfigAction.java    License: Apache License 2.0 3 votes vote down vote up
@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()) {
        if (awbBundle.isMBundle){
            continue;
        }

        MergeAwbAssets.MergeAwbAssetConfigAction mergeAwbAssetConfigAction = new MergeAwbAssets.MergeAwbAssetConfigAction(appVariantContext, baseVariantOutput, awbBundle);

        MergeAwbAssets mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbAssetConfigAction.getName(), mergeAwbAssetConfigAction.getType());

        mergeAwbAssetConfigAction.execute(mergeTask);

        tasks.add(mergeTask);

    }


    parallelTask.parallelTask = tasks;
    parallelTask.concurrent = false;
    parallelTask.uniqueTaskName = getName();

}