Search in sources :

Example 6 with CantRunException

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;
}
Also used : CantRunException(com.intellij.execution.CantRunException) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 7 with CantRunException

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);
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 8 with CantRunException

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;
}
Also used : CantRunException(com.intellij.execution.CantRunException) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 9 with CantRunException

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;
}
Also used : Task(com.intellij.openapi.progress.Task) Macro(com.intellij.ide.macro.Macro) Project(com.intellij.openapi.project.Project) CantRunException(com.intellij.execution.CantRunException) FutureResult(com.intellij.util.concurrency.FutureResult) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with CantRunException

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) IdeaInputHandler(com.intellij.rt.ant.execution.IdeaInputHandler) AntMain2(com.intellij.rt.ant.execution.AntMain2) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) IdeaAntLogger2(com.intellij.rt.ant.execution.IdeaAntLogger2) ParametersList(com.intellij.execution.configurations.ParametersList) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId)

Aggregations

CantRunException (com.intellij.execution.CantRunException)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Sdk (com.intellij.openapi.projectRoots.Sdk)7 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 Nullable (org.jetbrains.annotations.Nullable)5 ExecutionException (com.intellij.execution.ExecutionException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)4 JavaParameters (com.intellij.execution.configurations.JavaParameters)4 IOException (java.io.IOException)4 ParametersList (com.intellij.execution.configurations.ParametersList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 SourceScope (com.intellij.execution.testframework.SourceScope)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)2 PluginId (com.intellij.openapi.extensions.PluginId)2 Project (com.intellij.openapi.project.Project)2 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)2 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)2 PsiClass (com.intellij.psi.PsiClass)2