use of com.intellij.execution.configurations.GeneralCommandLine in project android by JetBrains.
the class GradleImportTest method assertBuildsCleanly.
public static void assertBuildsCleanly(File base, boolean allowWarnings) throws Exception {
File gradlew = new File(base, isWindows() ? FN_GRADLE_WRAPPER_WIN : FN_GRADLE_WRAPPER_UNIX);
if (!gradlew.exists()) {
// Not using a wrapper; can't easily test building (we don't have a gradle prebuilt)
return;
}
File pwd = base.getAbsoluteFile();
List<String> args = Lists.newArrayList();
args.add(gradlew.getPath());
args.add("assembleDebug");
GradleInitScripts.getInstance().addLocalMavenRepoInitScriptCommandLineArgTo(args);
GeneralCommandLine cmdLine = new GeneralCommandLine(args).withWorkDirectory(pwd);
CapturingProcessHandler process = new CapturingProcessHandler(cmdLine);
// Building currently takes about 30s, so a 5min timeout should give a safe margin.
int timeoutInMilliseconds = 5 * 60 * 1000;
ProcessOutput processOutput = process.runProcess(timeoutInMilliseconds, true);
if (processOutput.isTimeout()) {
throw new TimeoutException("\"gradlew assembleDebug\" did not terminate within test timeout value.\n" + "[stdout]\n" + processOutput.getStdout() + "\n" + "[stderr]\n" + processOutput.getStderr() + "\n");
}
String errors = processOutput.getStderr();
String output = processOutput.getStdout();
int exitCode = processOutput.getExitCode();
int expectedExitCode = 0;
if (output.contains("BUILD FAILED") && errors.contains("Could not find any version that matches com.android.tools.build:gradle:")) {
// We ignore this assertion. We got here because we are using a version of the
// Android Gradle plug-in that is not available in Maven Central yet.
expectedExitCode = 1;
} else {
assertTrue(output + "\n" + errors, output.contains("BUILD SUCCESSFUL"));
if (!allowWarnings) {
assertEquals(output + "\n" + errors, "", errors);
}
}
assertEquals(expectedExitCode, exitCode);
System.out.println("Built project successfully; output was:\n" + output);
}
use of com.intellij.execution.configurations.GeneralCommandLine in project android by JetBrains.
the class SystemInfoStatsMonitor method runEmulatorCheck.
@Nullable
private static Integer runEmulatorCheck(@NotNull String argument, @NotNull Revision lowestToolsRevisiion, @NotNull AndroidSdkHandler handler) throws ExecutionException {
LocalPackage toolsPackage = handler.getLocalPackage(SdkConstants.FD_TOOLS, new StudioLoggerProgressIndicator(AndroidSdkInitializer.class));
if (toolsPackage == null) {
throw new ExecutionException("No SDK tools package");
}
final Revision toolsRevision = toolsPackage.getVersion();
if (toolsRevision.compareTo(lowestToolsRevisiion) < 0) {
return null;
}
File checkBinary = getEmulatorCheckBinary(handler);
if (!checkBinary.isFile()) {
throw new ExecutionException("No emulator-check binary in the SDK tools package");
}
GeneralCommandLine commandLine = new GeneralCommandLine(checkBinary.getPath(), argument);
CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
ProcessOutput output = process.runProcess();
int exitCode = output.getExitCode();
if (exitCode == EMULATOR_CHECK_ERROR_EXIT_CODE) {
throw new ExecutionException(String.format("Emulator-check failed to check for '%s' with a generic error code %d", argument, EMULATOR_CHECK_ERROR_EXIT_CODE));
}
return exitCode;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project android by JetBrains.
the class AvdManagerConnection method checkAcceleration.
/**
* Run "emulator -accel-check" to check the status for emulator acceleration on this machine.
* Return a {@link AccelerationErrorCode}.
*/
public AccelerationErrorCode checkAcceleration() {
if (!initIfNecessary()) {
return AccelerationErrorCode.UNKNOWN_ERROR;
}
File emulatorBinary = getEmulatorBinary();
if (!emulatorBinary.isFile()) {
return AccelerationErrorCode.NO_EMULATOR_INSTALLED;
}
if (getMemorySize() < Storage.Unit.GiB.getNumberOfBytes()) {
// TODO: The emulator -accel-check current does not check for the available memory, do it here instead:
return AccelerationErrorCode.NOT_ENOUGH_MEMORY;
}
if (!hasQEMU2Installed()) {
return AccelerationErrorCode.TOOLS_UPDATE_REQUIRED;
}
File checkBinary = getEmulatorCheckBinary();
GeneralCommandLine commandLine = new GeneralCommandLine();
if (checkBinary.isFile()) {
commandLine.setExePath(checkBinary.getPath());
commandLine.addParameter("accel");
} else {
commandLine.setExePath(emulatorBinary.getPath());
commandLine.addParameter("-accel-check");
}
int exitValue;
try {
CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
ProcessOutput output = process.runProcess();
exitValue = output.getExitCode();
} catch (ExecutionException e) {
exitValue = AccelerationErrorCode.UNKNOWN_ERROR.getErrorCode();
}
if (exitValue != 0) {
return AccelerationErrorCode.fromExitCode(exitValue);
}
if (!hasPlatformToolsForQEMU2Installed()) {
return AccelerationErrorCode.PLATFORM_TOOLS_UPDATE_ADVISED;
}
if (!hasSystemImagesForQEMU2Installed()) {
return AccelerationErrorCode.SYSTEM_IMAGE_UPDATE_ADVISED;
}
return AccelerationErrorCode.ALREADY_INSTALLED;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project android by JetBrains.
the class AndroidMavenExecutor method generateResources.
public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
try {
JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {
@Nullable
@Override
public JavaParameters compute() {
try {
return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
} catch (ExecutionException e) {
LOG.info(e);
result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
return null;
}
}
});
if (javaParams == null) {
return result;
}
GeneralCommandLine commandLine = javaParams.toCommandLine();
final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
String message = processor.getMessage();
if (!success) {
LOG.info(message);
String lcmessage = message.toLowerCase();
int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
if (buildErrorIndex >= 0) {
result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
}
}
} catch (ExecutionException e) {
LOG.info(e);
result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
}
return result;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class GitExecutableDetector method runs.
/**
* Checks if it is possible to run the specified program.
* Made protected for tests not to start a process there.
*/
protected boolean runs(@NotNull String exec) {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath(exec);
commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
try {
CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
ProcessOutput result = handler.runProcess((int) TimeUnit.SECONDS.toMillis(5));
return !result.isTimeout();
} catch (ExecutionException e) {
return false;
}
}
Aggregations