use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class JdkUtil method setupJVMCommandLine.
public static GeneralCommandLine setupJVMCommandLine(@NotNull SimpleJavaParameters javaParameters) throws CantRunException {
Sdk jdk = javaParameters.getJdk();
if (jdk == null)
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
SdkTypeId type = jdk.getSdkType();
if (!(type instanceof JavaSdkType))
throw new CantRunException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
String exePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
if (exePath == null)
throw new CantRunException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
GeneralCommandLine commandLine = new GeneralCommandLine(exePath);
setupCommandLine(commandLine, javaParameters);
return commandLine;
}
use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class JdkUtil method setupJVMCommandLine.
/** @deprecated use {@link SimpleJavaParameters#toCommandLine()} (to be removed in IDEA 2018) */
public static GeneralCommandLine setupJVMCommandLine(final String exePath, final SimpleJavaParameters javaParameters, final boolean forceDynamicClasspath) {
try {
javaParameters.setUseDynamicClasspath(forceDynamicClasspath);
GeneralCommandLine commandLine = new GeneralCommandLine(exePath);
setupCommandLine(commandLine, javaParameters);
return commandLine;
} catch (CantRunException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class JavaParametersUtil method createAlternativeJdk.
private static Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException {
final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
if (configuredJdk != null) {
return configuredJdk;
}
if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) {
throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
}
final JavaSdk javaSdk = JavaSdk.getInstance();
final String versionString = javaSdk.getVersionString(jreHome);
final Sdk jdk = javaSdk.createJdk(versionString != null ? versionString : "", jreHome);
if (jdk == null)
throw CantRunException.noJdkConfigured();
return jdk;
}
use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class ExecutionHandler method runBuildImpl.
/**
* @param antBuildListener should not be null. Use {@link com.intellij.lang.ant.config.AntBuildListener#NULL}
*/
@Nullable
private static FutureResult<ProcessHandler> runBuildImpl(final AntBuildFileBase buildFile, String[] targets, @Nullable final AntBuildMessageView buildMessageViewToReuse, final DataContext dataContext, List<BuildFileProperty> additionalProperties, @NotNull final AntBuildListener antBuildListener, final boolean waitFor) {
final AntBuildMessageView messageView;
final GeneralCommandLine commandLine;
final Project project = buildFile.getProject();
try {
FileDocumentManager.getInstance().saveAllDocuments();
final AntCommandLineBuilder builder = new AntCommandLineBuilder();
builder.setBuildFile(buildFile.getAllOptions(), VfsUtilCore.virtualToIoFile(buildFile.getVirtualFile()));
builder.calculateProperties(dataContext, buildFile.getProject(), additionalProperties);
builder.addTargets(targets);
builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset());
messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets, additionalProperties);
commandLine = builder.getCommandLine().toCommandLine();
messageView.setBuildCommandLine(commandLine.getCommandLineString());
} catch (RunCanceledException e) {
e.showMessage(project, AntBundle.message("run.ant.error.dialog.title"));
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
return null;
} catch (CantRunException e) {
ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.error.dialog.title"), project);
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
return null;
} catch (Macro.ExecutionCancelledException e) {
antBuildListener.buildFinished(AntBuildListener.ABORTED, 0);
return null;
} catch (Throwable e) {
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
LOG.error(e);
return null;
}
final FutureResult<ProcessHandler> future = new FutureResult<>();
new Task.Backgroundable(buildFile.getProject(), AntBundle.message("ant.build.progress.dialog.title"), true) {
public boolean shouldStartInBackground() {
return true;
}
public void onCancel() {
antBuildListener.buildFinished(AntBuildListener.ABORTED, 0);
}
public void run(@NotNull final ProgressIndicator indicator) {
try {
ProcessHandler handler = runBuild(indicator, messageView, buildFile, antBuildListener, commandLine);
future.set(handler);
if (waitFor && handler != null) {
handler.waitFor();
}
} catch (Throwable e) {
LOG.error(e);
antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0);
}
}
}.queue();
return future;
}
use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.
the class AntCommandLineBuilder method setBuildFile.
public void setBuildFile(AbstractProperty.AbstractPropertyContainer container, File buildFile) throws CantRunException {
String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(container);
Sdk jdk;
if (jdkName != null && jdkName.length() > 0) {
jdk = GlobalAntConfiguration.findJdk(jdkName);
} else {
jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(container);
if (jdkName == null || jdkName.length() == 0) {
throw new CantRunException(AntBundle.message("project.jdk.not.specified.error.message"));
}
jdk = GlobalAntConfiguration.findJdk(jdkName);
}
if (jdk == null) {
throw new CantRunException(AntBundle.message("jdk.with.name.not.configured.error.message", jdkName));
}
VirtualFile homeDirectory = jdk.getHomeDirectory();
if (homeDirectory == null) {
throw new CantRunException(AntBundle.message("jdk.with.name.bad.configured.error.message", jdkName));
}
myCommandLine.setJdk(jdk);
final ParametersList vmParametersList = myCommandLine.getVMParametersList();
vmParametersList.add("-Xmx" + AntBuildFileImpl.MAX_HEAP_SIZE.get(container) + "m");
vmParametersList.add("-Xss" + AntBuildFileImpl.MAX_STACK_SIZE.get(container) + "m");
final AntInstallation antInstallation = AntBuildFileImpl.ANT_INSTALLATION.get(container);
if (antInstallation == null) {
throw new CantRunException(AntBundle.message("ant.installation.not.configured.error.message"));
}
final String antHome = AntInstallation.HOME_DIR.get(antInstallation.getProperties());
vmParametersList.add("-Dant.home=" + antHome);
final String libraryDir = antHome + (antHome.endsWith("/") || antHome.endsWith(File.separator) ? "" : File.separator) + "lib";
vmParametersList.add("-Dant.library.dir=" + libraryDir);
String[] urls = jdk.getRootProvider().getUrls(OrderRootType.CLASSES);
final String jdkHome = homeDirectory.getPath().replace('/', File.separatorChar);
@NonNls final String pathToJre = jdkHome + File.separator + "jre" + File.separator;
for (String url : urls) {
final String path = PathUtil.toPresentableUrl(url);
if (!path.startsWith(pathToJre)) {
myCommandLine.getClassPath().add(path);
}
}
myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.ALL_CLASS_PATH.get(container));
myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.getUserHomeLibraries());
final SdkTypeId sdkType = jdk.getSdkType();
if (sdkType instanceof JavaSdkType) {
final String toolsJar = ((JavaSdkType) sdkType).getToolsPath(jdk);
if (toolsJar != null) {
myCommandLine.getClassPath().add(toolsJar);
}
}
PathUtilEx.addRtJar(myCommandLine.getClassPath());
myCommandLine.setMainClass(AntMain2.class.getName());
final ParametersList programParameters = myCommandLine.getProgramParametersList();
final String additionalParams = AntBuildFileImpl.ANT_COMMAND_LINE_PARAMETERS.get(container);
if (additionalParams != null) {
for (String param : ParametersList.parse(additionalParams)) {
if (param.startsWith("-J")) {
final String cutParam = param.substring("-J".length());
if (cutParam.length() > 0) {
vmParametersList.add(cutParam);
}
} else {
programParameters.add(param);
}
}
}
if (!(programParameters.getList().contains(LOGGER_PARAMETER))) {
programParameters.add(LOGGER_PARAMETER, IdeaAntLogger2.class.getName());
}
if (!programParameters.getList().contains(INPUT_HANDLER_PARAMETER)) {
programParameters.add(INPUT_HANDLER_PARAMETER, IdeaInputHandler.class.getName());
}
myProperties = AntBuildFileImpl.ANT_PROPERTIES.get(container);
myBuildFilePath = buildFile.getAbsolutePath();
myCommandLine.setWorkingDirectory(buildFile.getParent());
}
Aggregations