本文整理汇总了Java中org.gradle.tooling.BuildLauncher.withArguments方法的典型用法代码示例。如果您正苦于以下问题:Java BuildLauncher.withArguments方法的具体用法?Java BuildLauncher.withArguments怎么用?Java BuildLauncher.withArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.gradle.tooling.BuildLauncher
的用法示例。
在下文中一共展示了BuildLauncher.withArguments方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compile
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public void compile() throws Exception {
ProjectConnection connection = getConnector().connect();
try {
// Configure the build
BuildLauncher launcher = connection.newBuild();
if (flavor != null) {
launcher.forTasks(task + StringUtils.capitalize(flavor));
} else {
launcher.forTasks(task);
}
if (buildFile != null) {
launcher.withArguments("-b", buildFile.getAbsolutePath());
}
launcher.setStandardOutput(System.out);
launcher.setStandardError(System.err);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
示例2: setBuildLoggingOptions
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
static void setBuildLoggingOptions(BuildLauncher build, IPreferenceStore prefs, String[] additionalArguments) {
ArrayList<String> buildArgs = new ArrayList<String>();
buildArgs.addAll(Arrays.asList(additionalArguments));
String logLevel = prefs.getString(WorkbenchPreferencePage.GRADLE_LOG_LEVEL_ID);
if (!logLevel.isEmpty()) {
buildArgs.add(logLevel);
}
if (prefs.getBoolean(WorkbenchPreferencePage.GRADLE_PRINT_STACKTRACES_ID)) {
buildArgs.add(GradlePluginConstants.ENABLE_STACKTRACE_FLAG);
}
if(buildArgs.isEmpty()) {
//do not modify the build.
return;
}
build.withArguments(buildArgs.toArray(new String[0]));
}
示例3: runTask
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
@Override
public InputStream runTask(final List<String> args) throws IOException {
try {
final List<String> tasks = new ArrayList<>(4);
final List<String> taskArgs = new ArrayList<>(4);
for (final String temp : args) {
for (final String arg : temp.split(" ")) {
if (arg.startsWith("-")) {
taskArgs.add(arg.trim());
} else {
tasks.add(arg.trim());
}
}
}
log.debug("task:{}:{} args:{}:{}", tasks, tasks.size(), taskArgs, taskArgs.size());
final ProjectConnection projectConnection = getProjectConnection();
final BuildLauncher build = projectConnection.newBuild();
this.setBuildJVMArgs(build);
build.forTasks(tasks.toArray(new String[tasks.size()]));
if (taskArgs.size() > 0) {
build.withArguments(taskArgs.toArray(new String[taskArgs.size()]));
}
final PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(outputStream);
build.setStandardError(outputStream);
build.setStandardOutput(outputStream);
final VoidResultHandler handler =
new VoidResultHandler(outputStream, inputStream, projectConnection);
build.run(handler);
return inputStream;
} finally {
Config.setProjectRoot(this.projectRoot.getCanonicalPath());
}
}
示例4: run
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
/**
* Starts the progress handler and executes the gradle task.
*/
@Override
public void run() {
if (gradleTask != null && gradleTask.isValid()) {
progressHandler = ProgressHandle.createHandle(gradleTask.getDescription(), this);
progressHandler.start();
ProjectConnection connection = null;
try {
connection = getGradleConnection();
BuildLauncher buildLauncher = connection.newBuild();
buildLauncher.forTasks(gradleTask.getName());
String[] executionParameters = gradleTask.getExecutionParameters();
buildLauncher.withArguments(executionParameters);
LOG.info(EXECUTE_A_GRADLE_TASK);
LOG.log(Level.INFO, "{0} {1} on folder: {2}", new Object[]{gradleTask.getName(),
Arrays.toString(executionParameters),
gradleTask.getFolder()});
GradleResultHandler resultHandler = gradleTask.getResultHandler();
if (resultHandler != null) {
buildLauncher.setStandardError(resultHandler.getErrorOutputStream());
buildLauncher.setStandardOutput(resultHandler.getOutputStream());
buildLauncher.run(resultHandler);
} else {
buildLauncher.run();
}
} catch(GradleConnectionException | IllegalStateException ex) {
Exceptions.printStackTrace(ex);
} finally {
if (connection != null) {
connection.close();
}
}
}
}
示例5: start
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public GradleHandle start(File directory, List<String> arguments) {
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(directory);
ProjectConnection connection = connector.connect();
BuildLauncher launcher = connection.newBuild();
String[] argumentArray = new String[arguments.size()];
arguments.toArray(argumentArray);
launcher.withArguments(argumentArray);
return new BuildLauncherBackedGradleHandle(launcher);
}
示例6: getDepsCoordinates
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public List<String> getDepsCoordinates(ProjectConnection connection, File buildFile) {
BuildLauncher launcher = connection.newBuild();
if (buildFile != null) {
launcher.withArguments("-b", buildFile.getAbsolutePath());
}
launcher.forTasks("dependencies");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
launcher.setStandardOutput(bos);
launcher.setStandardError(System.err);
launcher.run();
String content = bos.toString();
String[] lines = content.split("\\n");
List<String> coordinates = new LinkedList<String>();
for (int i = 0; i < lines.length; i++) {
if (lines[i].startsWith("compile") || lines[i].startsWith("provided")) {
if (i + 1 < lines.length && !lines[i + 1].startsWith("No dependencies")) {
int j = i + 1;
String prefix = null;
String nextGoal = "debugApk";
if (lines[i].startsWith("provided")) {
nextGoal = "releaseApk";
}
while (j < lines.length && !lines[j].startsWith(nextGoal)) {
int index = lines[j].lastIndexOf("--");
if (index != -1) {
prefix = lines[j].substring(0, index + 2);
if (lines[j].length() > prefix.length()) {
String artifact = lines[j].substring(prefix.length()).trim();
if (!artifact.endsWith("(*)")) {
int dynamicVersionIndex = artifact.indexOf("->");
if (dynamicVersionIndex != -1) {
String artifactName = artifact.substring(0, artifact.lastIndexOf(":")).trim();
String version = artifact.substring(dynamicVersionIndex + 2).trim();
artifact = artifactName + ":" + version;
}
coordinates.add(artifact);
}
}
}
j++;
}
}
}
}
return coordinates;
}