Search in sources :

Example 1 with BuiltInCommand

use of org.gradle.configuration.project.BuiltInCommand in project gradle by gradle.

the class DefaultTasksBuildExecutionAction method configure.

@Override
public void configure(BuildExecutionContext context) {
    StartParameter startParameter = context.getGradle().getStartParameter();
    for (TaskExecutionRequest request : startParameter.getTaskRequests()) {
        if (!request.getArgs().isEmpty()) {
            context.proceed();
            return;
        }
    }
    // Gather the default tasks from this first group project
    ProjectInternal project = context.getGradle().getDefaultProject();
    // so that we don't miss out default tasks
    projectConfigurer.configure(project);
    List<String> defaultTasks = project.getDefaultTasks();
    if (defaultTasks.size() == 0) {
        defaultTasks = new ArrayList<>();
        for (BuiltInCommand command : builtInCommands) {
            defaultTasks.addAll(command.asDefaultTask());
        }
        LOGGER.info("No tasks specified. Using default task {}", GUtil.toString(defaultTasks));
    } else {
        LOGGER.info("No tasks specified. Using project default tasks {}", GUtil.toString(defaultTasks));
    }
    startParameter.setTaskNames(defaultTasks);
    context.proceed();
}
Also used : StartParameter(org.gradle.StartParameter) TaskExecutionRequest(org.gradle.TaskExecutionRequest) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) BuiltInCommand(org.gradle.configuration.project.BuiltInCommand)

Example 2 with BuiltInCommand

use of org.gradle.configuration.project.BuiltInCommand in project gradle by gradle.

the class BuildLayoutValidator method validate.

public void validate(StartParameterInternal startParameter) {
    BuildLayout buildLayout = buildLayoutFactory.getLayoutFor(new BuildLayoutConfiguration(startParameter));
    if (!buildLayout.isBuildDefinitionMissing()) {
        // All good
        return;
    }
    for (BuiltInCommand command : builtInCommands) {
        if (command.commandLineMatches(startParameter.getTaskNames())) {
            // Allow missing settings and build scripts when running a built-in command
            return;
        }
    }
    StringBuilder message = new StringBuilder();
    message.append("Directory '");
    message.append(startParameter.getCurrentDir());
    message.append("' does not contain a Gradle build.\n\n");
    message.append("A Gradle build should contain a 'settings.gradle' or 'settings.gradle.kts' file in its root directory. ");
    message.append("It may also contain a 'build.gradle' or 'build.gradle.kts' file.\n\n");
    message.append("To create a new Gradle build in this directory run '");
    clientMetaData.describeCommand(message, "init");
    message.append("'\n\n");
    message.append("For more detail on the 'init' task see ");
    message.append(documentationRegistry.getDocumentationFor("build_init_plugin"));
    message.append("\n\n");
    message.append("For more detail on creating a Gradle build see ");
    // this is the "build script basics" chapter, we're missing some kind of "how to write a Gradle build chapter"
    message.append(documentationRegistry.getDocumentationFor("tutorial_using_tasks"));
    throw new BuildLayoutException(message.toString());
}
Also used : BuildLayoutConfiguration(org.gradle.initialization.layout.BuildLayoutConfiguration) BuiltInCommand(org.gradle.configuration.project.BuiltInCommand) BuildLayout(org.gradle.initialization.layout.BuildLayout)

Aggregations

BuiltInCommand (org.gradle.configuration.project.BuiltInCommand)2 StartParameter (org.gradle.StartParameter)1 TaskExecutionRequest (org.gradle.TaskExecutionRequest)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 BuildLayout (org.gradle.initialization.layout.BuildLayout)1 BuildLayoutConfiguration (org.gradle.initialization.layout.BuildLayoutConfiguration)1