Search in sources :

Example 1 with InitialPropertiesConverter

use of org.gradle.launcher.cli.converter.InitialPropertiesConverter in project gradle by gradle.

the class ProviderConnection method initParams.

private Parameters initParams(ProviderOperationParameters operationParameters) {
    CommandLineParser commandLineParser = new CommandLineParser();
    commandLineParser.allowUnknownOptions();
    commandLineParser.allowMixedSubcommandsAndOptions();
    InitialPropertiesConverter initialPropertiesConverter = new InitialPropertiesConverter();
    BuildLayoutConverter buildLayoutConverter = new BuildLayoutConverter();
    initialPropertiesConverter.configure(commandLineParser);
    buildLayoutConverter.configure(commandLineParser);
    ParsedCommandLine parsedCommandLine = commandLineParser.parse(operationParameters.getArguments() == null ? Collections.emptyList() : operationParameters.getArguments());
    InitialProperties initialProperties = initialPropertiesConverter.convert(parsedCommandLine);
    BuildLayoutResult buildLayoutResult = buildLayoutConverter.convert(initialProperties, parsedCommandLine, operationParameters.getProjectDir(), layout -> {
        if (operationParameters.getGradleUserHomeDir() != null) {
            layout.setGradleUserHomeDir(operationParameters.getGradleUserHomeDir());
        }
        layout.setProjectDir(operationParameters.getProjectDir());
    });
    AllProperties properties = new LayoutToPropertiesConverter(buildLayoutFactory).convert(initialProperties, buildLayoutResult);
    DaemonParameters daemonParams = new DaemonParameters(buildLayoutResult, fileCollectionFactory);
    new DaemonBuildOptions().propertiesConverter().convert(properties.getProperties(), daemonParams);
    if (operationParameters.getDaemonBaseDir() != null) {
        daemonParams.setBaseDir(operationParameters.getDaemonBaseDir());
    }
    // override the params with the explicit settings provided by the tooling api
    List<String> jvmArguments = operationParameters.getJvmArguments();
    if (jvmArguments != null) {
        daemonParams.setJvmArgs(jvmArguments);
    }
    // Include the system properties that are defined in the daemon JVM args
    properties = properties.merge(daemonParams.getSystemProperties());
    Map<String, String> envVariables = operationParameters.getEnvironmentVariables(null);
    if (envVariables != null) {
        daemonParams.setEnvironmentVariables(envVariables);
    }
    File javaHome = operationParameters.getJavaHome();
    if (javaHome != null) {
        daemonParams.setJvm(Jvm.forHome(javaHome));
    }
    daemonParams.applyDefaultsFor(jvmVersionDetector.getJavaVersion(daemonParams.getEffectiveJvm()));
    if (operationParameters.getDaemonMaxIdleTimeValue() != null && operationParameters.getDaemonMaxIdleTimeUnits() != null) {
        int idleTimeout = (int) operationParameters.getDaemonMaxIdleTimeUnits().toMillis(operationParameters.getDaemonMaxIdleTimeValue());
        daemonParams.setIdleTimeout(idleTimeout);
    }
    return new Parameters(daemonParams, buildLayoutResult, properties);
}
Also used : ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) AllProperties(org.gradle.launcher.configuration.AllProperties) DaemonBuildOptions(org.gradle.launcher.daemon.configuration.DaemonBuildOptions) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) InitialPropertiesConverter(org.gradle.launcher.cli.converter.InitialPropertiesConverter) BuildLayoutConverter(org.gradle.launcher.cli.converter.BuildLayoutConverter) LayoutToPropertiesConverter(org.gradle.launcher.cli.converter.LayoutToPropertiesConverter) InitialProperties(org.gradle.launcher.configuration.InitialProperties) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) CommandLineParser(org.gradle.cli.CommandLineParser) File(java.io.File) BuildLayoutResult(org.gradle.launcher.configuration.BuildLayoutResult)

Example 2 with InitialPropertiesConverter

use of org.gradle.launcher.cli.converter.InitialPropertiesConverter 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)

Aggregations

CommandLineParser (org.gradle.cli.CommandLineParser)2 ParsedCommandLine (org.gradle.cli.ParsedCommandLine)2 BuildLayoutConverter (org.gradle.launcher.cli.converter.BuildLayoutConverter)2 InitialPropertiesConverter (org.gradle.launcher.cli.converter.InitialPropertiesConverter)2 File (java.io.File)1 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)1 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)1 LayoutToPropertiesConverter (org.gradle.launcher.cli.converter.LayoutToPropertiesConverter)1 StartParameterConverter (org.gradle.launcher.cli.converter.StartParameterConverter)1 AllProperties (org.gradle.launcher.configuration.AllProperties)1 BuildLayoutResult (org.gradle.launcher.configuration.BuildLayoutResult)1 InitialProperties (org.gradle.launcher.configuration.InitialProperties)1 DaemonBuildOptions (org.gradle.launcher.daemon.configuration.DaemonBuildOptions)1 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)1 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)1 InternalLaunchable (org.gradle.tooling.internal.protocol.InternalLaunchable)1 InternalUnsupportedBuildArgumentException (org.gradle.tooling.internal.protocol.exceptions.InternalUnsupportedBuildArgumentException)1 ProviderConnectionParameters (org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters)1 ProviderOperationParameters (org.gradle.tooling.internal.provider.connection.ProviderOperationParameters)1