use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class StudySmartChecker method smartCheck.
public static void smartCheck(@NotNull final AnswerPlaceholder placeholder, @NotNull final Project project, @NotNull final VirtualFile answerFile, @NotNull final TaskFile answerTaskFile, @NotNull final TaskFile usersTaskFile, @NotNull final StudyTestRunner testRunner, @NotNull final VirtualFile virtualFile, @NotNull final Document usersDocument) {
VirtualFile fileWindows = null;
File resourceFile = null;
VirtualFile windowCopy = null;
try {
final int index = placeholder.getIndex();
String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document windowDocument = documentManager.getDocument(windowCopy);
if (windowDocument != null) {
resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
if (windowTaskFile == null) {
return;
}
EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
windowDocument.addDocumentListener(listener);
int start = placeholder.getOffset();
int end = start + placeholder.getRealLength();
final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
int userStart = userAnswerPlaceholder.getOffset();
int userEnd = userStart + userAnswerPlaceholder.getRealLength();
String text = usersDocument.getText(new TextRange(userStart, userEnd));
windowDocument.replaceString(start, end, text);
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
final ProcessOutput output = handler.runProcess();
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null) {
boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
}
}
} catch (ExecutionException | IOException e) {
LOG.error(e);
} finally {
StudyUtils.deleteFile(windowCopy);
StudyUtils.deleteFile(fileWindows);
if (resourceFile != null && resourceFile.exists() && !resourceFile.delete()) {
LOG.error("failed to delete", resourceFile.getPath());
}
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class PyPackageManagerImpl method install.
@Override
public void install(@NotNull List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws ExecutionException {
final List<String> args = new ArrayList<>();
args.add(INSTALL);
final File buildDir;
try {
buildDir = FileUtil.createTempDirectory("pycharm-packaging", null);
} catch (IOException e) {
throw new ExecutionException("Cannot create temporary build directory");
}
if (!extraArgs.contains(BUILD_DIR_OPTION)) {
args.addAll(Arrays.asList(BUILD_DIR_OPTION, buildDir.getAbsolutePath()));
}
final boolean useUserSite = extraArgs.contains(USE_USER_SITE);
final String proxyString = getProxyString();
if (proxyString != null) {
args.add("--proxy");
args.add(proxyString);
}
args.addAll(extraArgs);
for (PyRequirement req : requirements) {
args.addAll(req.getInstallOptions());
}
try {
getHelperResult(PACKAGING_TOOL, args, !useUserSite, true, null);
} catch (PyExecutionException e) {
final List<String> simplifiedArgs = new ArrayList<>();
simplifiedArgs.add("install");
if (proxyString != null) {
simplifiedArgs.add("--proxy");
simplifiedArgs.add(proxyString);
}
simplifiedArgs.addAll(extraArgs);
for (PyRequirement req : requirements) {
simplifiedArgs.addAll(req.getInstallOptions());
}
throw new PyExecutionException(e.getMessage(), "pip", simplifiedArgs, e.getStdout(), e.getStderr(), e.getExitCode(), e.getFixes());
} finally {
LOG.debug("Packages cache is about to be refreshed because these requirements were installed: " + requirements);
refreshPackagesSynchronously();
FileUtil.delete(buildDir);
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class PyRemotePackageManagerImpl method getPythonProcessOutput.
@NotNull
@Override
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, boolean showProgress, @Nullable final String workingDir) throws ExecutionException {
final Sdk sdk = getSdk();
final String homePath = sdk.getHomePath();
if (homePath == null) {
throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
}
final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
//remote interpreter
final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
RemoteSdkCredentials remoteSdkCredentials;
if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
try {
remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
} catch (InterruptedException e) {
LOG.error(e);
remoteSdkCredentials = null;
} catch (ExecutionException e) {
throw analyzeException(e, helperPath, args);
}
if (manager != null && remoteSdkCredentials != null) {
if (askForSudo) {
askForSudo = !manager.ensureCanWrite(null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
}
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
}
if (manager != null) {
final List<String> cmdline = new ArrayList<>();
cmdline.add(homePath);
cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
cmdline.addAll(Collections2.transform(args, new Function<String, String>() {
@Override
public String apply(@Nullable String input) {
return quoteIfNeeded(input);
}
}));
ProcessOutput processOutput;
do {
final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData = (PyRemoteSdkAdditionalDataBase) sdkData;
final PyRemotePathMapper pathMapper = manager.setupMappings(null, remoteSdkAdditionalData, null);
try {
processOutput = PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData).executeRemoteProcess(null, ArrayUtil.toStringArray(cmdline), workingDir, manager, remoteSdkAdditionalData, pathMapper, askForSudo, true);
} catch (InterruptedException e) {
throw new ExecutionException(e);
}
if (askForSudo && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
continue;
}
break;
} while (true);
return processOutput;
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
} else {
throw new PyExecutionException("Invalid remote SDK", helperPath, args);
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class PyCondaManagementService method addRepository.
@Override
public void addRepository(String repositoryUrl) {
final String conda = PyCondaPackageService.getCondaExecutable(mySdk.getHomeDirectory());
final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--add", "channels", repositoryUrl, "--force");
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
try {
final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
final ProcessOutput result = handler.runProcess();
final int exitCode = result.getExitCode();
if (exitCode != 0) {
final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? "Permission denied" : "Non-zero exit code";
LOG.warn("Failed to add repository " + message);
}
PyCondaPackageService.getInstance().addChannel(repositoryUrl);
} catch (ExecutionException e) {
LOG.warn("Failed to add repository");
}
}
use of com.intellij.execution.ExecutionException in project intellij-community by JetBrains.
the class PyPackageManagementService method uninstallPackages.
@Override
public void uninstallPackages(@NotNull List<InstalledPackage> installedPackages, @NotNull Listener listener) {
final String packageName = installedPackages.size() == 1 ? installedPackages.get(0).getName() : null;
final PyPackageManagerUI ui = new PyPackageManagerUI(myProject, mySdk, new PyPackageManagerUI.Listener() {
@Override
public void started() {
listener.operationStarted(packageName);
}
@Override
public void finished(List<ExecutionException> exceptions) {
listener.operationFinished(packageName, toErrorDescription(exceptions, mySdk));
}
});
final List<PyPackage> pyPackages = new ArrayList<>();
for (InstalledPackage aPackage : installedPackages) {
if (aPackage instanceof PyPackage) {
pyPackages.add((PyPackage) aPackage);
}
}
ui.uninstall(pyPackages);
}
Aggregations