use of org.gradle.cli.CommandLineParser in project gradle by gradle.
the class GradleWrapperMain method main.
public static void main(String[] args) throws Exception {
File wrapperJar = wrapperJar();
File propertiesFile = wrapperProperties(wrapperJar);
File rootDir = rootDir(wrapperJar);
CommandLineParser parser = new CommandLineParser();
parser.allowUnknownOptions();
parser.option(GRADLE_USER_HOME_OPTION, GRADLE_USER_HOME_DETAILED_OPTION).hasArgument();
parser.option(GRADLE_QUIET_OPTION, GRADLE_QUIET_DETAILED_OPTION);
SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
converter.configure(parser);
ParsedCommandLine options = parser.parse(args);
Properties systemProperties = System.getProperties();
systemProperties.putAll(converter.convert(options, new HashMap<String, String>()));
File gradleUserHome = gradleUserHome(options);
addSystemProperties(gradleUserHome, rootDir);
Logger logger = logger(options);
WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
wrapperExecutor.execute(args, new Install(logger, new Download(logger, "gradlew", wrapperVersion()), new PathAssembler(gradleUserHome)), new BootstrapMainStarter());
}
use of org.gradle.cli.CommandLineParser in project intellij-community by JetBrains.
the class GradleExecuteTaskAction method buildTaskInfo.
private static ExternalTaskExecutionInfo buildTaskInfo(@NotNull String projectPath, @NotNull String fullCommandLine) throws CommandLineArgumentException {
CommandLineParser gradleCmdParser = new CommandLineParser();
GradleCommandLineOptionsConverter commandLineConverter = new GradleCommandLineOptionsConverter();
commandLineConverter.configure(gradleCmdParser);
ParsedCommandLine parsedCommandLine = gradleCmdParser.parse(ParametersListUtil.parse(fullCommandLine, true));
final Map<String, List<String>> optionsMap = commandLineConverter.convert(parsedCommandLine, new HashMap<>());
final List<String> systemProperties = optionsMap.remove("system-prop");
final String vmOptions = systemProperties == null ? "" : StringUtil.join(systemProperties, entry -> "-D" + entry, " ");
final String scriptParameters = StringUtil.join(optionsMap.entrySet(), entry -> {
final List<String> values = entry.getValue();
final String longOptionName = entry.getKey();
if (values != null && !values.isEmpty()) {
return StringUtil.join(values, entry1 -> "--" + longOptionName + ' ' + entry1, " ");
} else {
return "--" + longOptionName;
}
}, " ");
final List<String> tasks = parsedCommandLine.getExtraArguments();
ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
settings.setExternalProjectPath(projectPath);
settings.setTaskNames(tasks);
settings.setScriptParameters(scriptParameters);
settings.setVmOptions(vmOptions);
settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.toString());
return new ExternalTaskExecutionInfo(settings, DefaultRunExecutor.EXECUTOR_ID);
}
use of org.gradle.cli.CommandLineParser in project gradle by gradle.
the class BuildLogLevelMixIn method getBuildLogLevel.
public LogLevel getBuildLogLevel() {
LoggingCommandLineConverter converter = new LoggingCommandLineConverter();
CommandLineParser parser = new CommandLineParser().allowUnknownOptions().allowMixedSubcommandsAndOptions();
converter.configure(parser);
List<String> arguments = parameters.getArguments();
ParsedCommandLine parsedCommandLine = parser.parse(arguments == null ? Collections.<String>emptyList() : arguments);
//configure verbosely only if arguments do not specify any log level.
if (parameters.getVerboseLogging() && !parsedCommandLine.hasAnyOption(converter.getLogLevelOptions())) {
return LogLevel.DEBUG;
}
LoggingConfiguration loggingConfiguration = converter.convert(parsedCommandLine, new DefaultLoggingConfiguration());
return loggingConfiguration.getLogLevel();
}
use of org.gradle.cli.CommandLineParser in project gradle by gradle.
the class CommandLineTaskConfigurer method configureTasksNow.
private List<String> configureTasksNow(Collection<Task> tasks, List<String> arguments) {
List<String> remainingArguments = null;
for (Task task : tasks) {
CommandLineParser parser = new CommandLineParser();
final List<OptionDescriptor> commandLineOptions = optionReader.getOptions(task);
for (OptionDescriptor optionDescriptor : commandLineOptions) {
String optionName = optionDescriptor.getName();
org.gradle.cli.CommandLineOption option = parser.option(optionName);
option.hasDescription(optionDescriptor.getDescription());
option.hasArgument(optionDescriptor.getArgumentType());
}
ParsedCommandLine parsed;
try {
parsed = parser.parse(arguments);
} catch (CommandLineArgumentException e) {
//we expect that all options must be applicable for each task
throw new TaskConfigurationException(task.getPath(), "Problem configuring task " + task.getPath() + " from command line.", e);
}
for (OptionDescriptor commandLineOptionDescriptor : commandLineOptions) {
final String name = commandLineOptionDescriptor.getName();
if (parsed.hasOption(name)) {
ParsedCommandLineOption o = parsed.option(name);
try {
commandLineOptionDescriptor.apply(task, o.getValues());
} catch (TypeConversionException ex) {
throw new TaskConfigurationException(task.getPath(), String.format("Problem configuring option '%s' on task '%s' from command line.", name, task.getPath()), ex);
}
}
}
assert remainingArguments == null || remainingArguments.equals(parsed.getExtraArguments()) : "we expect all options to be consumed by each task so remainingArguments should be the same for each task";
remainingArguments = parsed.getExtraArguments();
}
return remainingArguments;
}
use of org.gradle.cli.CommandLineParser in project gradle by gradle.
the class InProcessGradleExecuter method executeBuild.
private BuildResult executeBuild(GradleInvocation invocation, StandardOutputListener outputListener, StandardOutputListener errorListener, BuildListenerImpl listener) {
// Augment the environment for the execution
System.setIn(connectStdIn());
processEnvironment.maybeSetProcessDir(getWorkingDir());
for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) {
processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
}
Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
System.getProperties().putAll(implicitJvmSystemProperties);
resetTempDirLocation();
// TODO: Fix tests that rely on this being set before we process arguments like this...
StartParameter startParameter = new StartParameter();
startParameter.setCurrentDir(getWorkingDir());
startParameter.setShowStacktrace(ShowStacktrace.ALWAYS);
CommandLineParser parser = new CommandLineParser();
ParametersConverter parametersConverter = new ParametersConverter();
parametersConverter.configure(parser);
final Parameters parameters = new Parameters(startParameter);
parametersConverter.convert(parser.parse(getAllArgs()), parameters);
BuildActionExecuter<BuildActionParameters> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
listenerManager.addListener(listener);
try {
// TODO: Reuse more of BuildActionsFactory
BuildAction action = new ExecuteBuildAction(startParameter);
BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
BuildRequestContext buildRequestContext = createBuildRequestContext(outputListener, errorListener);
startMeasurement();
actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
return new BuildResult(null, null);
} catch (ReportedException e) {
return new BuildResult(null, e.getCause());
} finally {
stopMeasurement();
listenerManager.removeListener(listener);
}
}
Aggregations