Search in sources :

Example 1 with InternalLaunchable

use of org.gradle.tooling.internal.protocol.InternalLaunchable in project gradle by gradle.

the class ProviderStartParameterConverter method toStartParameter.

public StartParameterInternal toStartParameter(ProviderOperationParameters parameters, BuildLayoutResult buildLayout, AllProperties properties) {
    // Important that this is constructed on the client so that it has the right gradleHomeDir and other state internally
    StartParameterInternal startParameter = new StartParameterInternal();
    List<InternalLaunchable> launchables = parameters.getLaunchables();
    if (launchables != null) {
        startParameter.setTaskRequests(unpack(launchables));
    } else if (parameters.getTasks() != null) {
        startParameter.setTaskNames(parameters.getTasks());
    }
    List<String> arguments = parameters.getArguments();
    StartParameterConverter converter = new StartParameterConverter();
    CommandLineParser parser = new CommandLineParser();
    new InitialPropertiesConverter().configure(parser);
    new BuildLayoutConverter().configure(parser);
    converter.configure(parser);
    ParsedCommandLine parsedCommandLine;
    try {
        parsedCommandLine = parser.parse(arguments != null ? arguments : Collections.emptyList());
    } catch (CommandLineArgumentException e) {
        throw new InternalUnsupportedBuildArgumentException("Problem with provided build arguments: " + arguments + ". " + "\n" + e.getMessage() + "\nEither it is not a valid build option or it is not supported in the target Gradle version." + "\nNot all of the Gradle command line options are supported build arguments." + "\nExamples of supported build arguments: '--info', '-p'." + "\nExamples of unsupported build options: '--daemon', '-?', '-v'." + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
    }
    converter.convert(parsedCommandLine, buildLayout, properties, startParameter);
    if (parameters.getBuildLogLevel() != null) {
        startParameter.setLogLevel(parameters.getBuildLogLevel());
    }
    return startParameter;
}
Also used : StartParameterConverter(org.gradle.launcher.cli.converter.StartParameterConverter) InitialPropertiesConverter(org.gradle.launcher.cli.converter.InitialPropertiesConverter) BuildLayoutConverter(org.gradle.launcher.cli.converter.BuildLayoutConverter) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) CommandLineParser(org.gradle.cli.CommandLineParser) InternalUnsupportedBuildArgumentException(org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) InternalLaunchable(org.gradle.tooling.internal.protocol.InternalLaunchable)

Example 2 with InternalLaunchable

use of org.gradle.tooling.internal.protocol.InternalLaunchable in project gradle by gradle.

the class ProviderStartParameterConverter method unpack.

private List<TaskExecutionRequest> unpack(final List<InternalLaunchable> launchables, File projectDir) {
    // Important that the launchables are unpacked on the client side, to avoid sending back any additional internal state that
    // the launchable may hold onto. For example, GradleTask implementations hold onto every task for every project in the build
    List<TaskExecutionRequest> requests = new ArrayList<TaskExecutionRequest>(launchables.size());
    for (InternalLaunchable launchable : launchables) {
        if (launchable instanceof TaskExecutionRequest) {
            TaskExecutionRequest originalLaunchable = (TaskExecutionRequest) launchable;
            TaskExecutionRequest launchableImpl = new DefaultTaskExecutionRequest(originalLaunchable.getArgs(), originalLaunchable.getProjectPath(), originalLaunchable.getRootDir());
            requests.add(launchableImpl);
        } else {
            throw new InternalUnsupportedBuildArgumentException("Problem with provided launchable arguments: " + launchables + ". " + "\nOnly objects from this provider can be built.");
        }
    }
    return requests;
}
Also used : DefaultTaskExecutionRequest(org.gradle.internal.DefaultTaskExecutionRequest) TaskExecutionRequest(org.gradle.TaskExecutionRequest) DefaultTaskExecutionRequest(org.gradle.internal.DefaultTaskExecutionRequest) ArrayList(java.util.ArrayList) InternalUnsupportedBuildArgumentException(org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException) InternalLaunchable(org.gradle.tooling.internal.protocol.InternalLaunchable)

Example 3 with InternalLaunchable

use of org.gradle.tooling.internal.protocol.InternalLaunchable in project gradle by gradle.

the class ProviderStartParameterConverter method toStartParameter.

public StartParameterInternal toStartParameter(ProviderOperationParameters parameters, Map<String, String> properties) {
    // Important that this is constructed on the client so that it has the right gradleHomeDir and other state internally
    StartParameterInternal startParameter = new StartParameterInternal();
    startParameter.setProjectDir(parameters.getProjectDir());
    if (parameters.getGradleUserHomeDir() != null) {
        startParameter.setGradleUserHomeDir(parameters.getGradleUserHomeDir());
    }
    List<InternalLaunchable> launchables = parameters.getLaunchables(null);
    if (launchables != null) {
        startParameter.setTaskRequests(unpack(launchables, parameters.getProjectDir()));
    } else if (parameters.getTasks() != null) {
        startParameter.setTaskNames(parameters.getTasks());
    }
    new PropertiesToStartParameterConverter().convert(properties, startParameter);
    List<String> arguments = parameters.getArguments();
    if (arguments != null) {
        DefaultCommandLineConverter converter = new DefaultCommandLineConverter();
        try {
            converter.convert(arguments, startParameter);
        } catch (CommandLineArgumentException e) {
            throw new InternalUnsupportedBuildArgumentException("Problem with provided build arguments: " + arguments + ". " + "\n" + e.getMessage() + "\nEither it is not a valid build option or it is not supported in the target Gradle version." + "\nNot all of the Gradle command line options are supported build arguments." + "\nExamples of supported build arguments: '--info', '-u', '-p'." + "\nExamples of unsupported build options: '--daemon', '-?', '-v'." + "\nPlease find more information in the javadoc for the BuildLauncher class.", e);
        }
    }
    if (parameters.isSearchUpwards() != null) {
        startParameter.setSearchUpwards(parameters.isSearchUpwards());
    }
    if (parameters.getBuildLogLevel() != null) {
        startParameter.setLogLevel(parameters.getBuildLogLevel());
    }
    if (parameters.getStandardInput() != null) {
        startParameter.setInteractive(true);
    }
    return startParameter;
}
Also used : DefaultCommandLineConverter(org.gradle.initialization.DefaultCommandLineConverter) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) PropertiesToStartParameterConverter(org.gradle.launcher.cli.converter.PropertiesToStartParameterConverter) InternalUnsupportedBuildArgumentException(org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) InternalLaunchable(org.gradle.tooling.internal.protocol.InternalLaunchable)

Example 4 with InternalLaunchable

use of org.gradle.tooling.internal.protocol.InternalLaunchable in project gradle by gradle.

the class ProviderStartParameterConverter method unpack.

private List<TaskExecutionRequest> unpack(final List<InternalLaunchable> launchables) {
    // Important that the launchables are unpacked on the client side, to avoid sending back any additional internal state that
    // the launchable may hold onto. For example, GradleTask implementations hold onto every task for every project in the build
    List<TaskExecutionRequest> requests = new ArrayList<TaskExecutionRequest>(launchables.size());
    for (InternalLaunchable launchable : launchables) {
        if (launchable instanceof TaskExecutionRequest) {
            TaskExecutionRequest originalLaunchable = (TaskExecutionRequest) launchable;
            TaskExecutionRequest launchableImpl = new DefaultTaskExecutionRequest(originalLaunchable.getArgs(), originalLaunchable.getProjectPath(), originalLaunchable.getRootDir());
            requests.add(launchableImpl);
        } else {
            throw new InternalUnsupportedBuildArgumentException("Problem with provided launchable arguments: " + launchables + ". " + "\nOnly objects from this provider can be built.");
        }
    }
    return requests;
}
Also used : DefaultTaskExecutionRequest(org.gradle.internal.DefaultTaskExecutionRequest) TaskExecutionRequest(org.gradle.TaskExecutionRequest) DefaultTaskExecutionRequest(org.gradle.internal.DefaultTaskExecutionRequest) ArrayList(java.util.ArrayList) InternalUnsupportedBuildArgumentException(org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException) InternalLaunchable(org.gradle.tooling.internal.protocol.InternalLaunchable)

Aggregations

InternalLaunchable (org.gradle.tooling.internal.protocol.InternalLaunchable)4 InternalUnsupportedBuildArgumentException (org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException)4 ArrayList (java.util.ArrayList)2 TaskExecutionRequest (org.gradle.TaskExecutionRequest)2 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)2 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)2 DefaultTaskExecutionRequest (org.gradle.internal.DefaultTaskExecutionRequest)2 CommandLineParser (org.gradle.cli.CommandLineParser)1 ParsedCommandLine (org.gradle.cli.ParsedCommandLine)1 DefaultCommandLineConverter (org.gradle.initialization.DefaultCommandLineConverter)1 BuildLayoutConverter (org.gradle.launcher.cli.converter.BuildLayoutConverter)1 InitialPropertiesConverter (org.gradle.launcher.cli.converter.InitialPropertiesConverter)1 PropertiesToStartParameterConverter (org.gradle.launcher.cli.converter.PropertiesToStartParameterConverter)1 StartParameterConverter (org.gradle.launcher.cli.converter.StartParameterConverter)1