Search in sources :

Example 1 with CantRunException

use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.

the class TestNGTestPackage method fillTestObjects.

@Override
public void fillTestObjects(Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
    final String packageName = myConfig.getPersistantData().getPackageName();
    PsiPackage psiPackage = ApplicationManager.getApplication().runReadAction(new Computable<PsiPackage>() {

        @Nullable
        public PsiPackage compute() {
            return JavaPsiFacade.getInstance(myConfig.getProject()).findPackage(packageName);
        }
    });
    if (psiPackage == null) {
        throw CantRunException.packageNotFound(packageName);
    } else {
        TestSearchScope scope = myConfig.getPersistantData().getScope();
        //TODO we should narrow this down by module really, if that's what's specified
        SourceScope sourceScope = scope.getSourceScope(myConfig);
        TestClassFilter projectFilter = new TestClassFilter(sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.projectScope(myConfig.getProject()), myConfig.getProject(), true, true);
        TestClassFilter filter = projectFilter.intersectionWith(PackageScope.packageScope(psiPackage, true));
        calculateDependencies(null, classes, getSearchScope(), TestNGUtil.getAllTestClasses(filter, false));
        if (classes.size() == 0) {
            throw new CantRunException("No tests found in the package \"" + packageName + '\"');
        }
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) SourceScope(com.intellij.execution.testframework.SourceScope) TestSearchScope(com.intellij.execution.testframework.TestSearchScope) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CantRunException

use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.

the class XsltDebuggerExtension method patchParameters.

public void patchParameters(final SimpleJavaParameters parameters, XsltRunConfiguration configuration, UserDataHolder extensionData) throws CantRunException {
    final XsltRunConfiguration.OutputType outputType = configuration.getOutputType();
    final Sdk jdk = configuration.getEffectiveJDK();
    assert jdk != null;
    final String ver = jdk.getVersionString();
    if (ver == null || (ver.contains("1.0") || ver.contains("1.1") || ver.contains("1.2") || ver.contains("1.3") || ver.contains("1.4"))) {
        throw new CantRunException("The XSLT Debugger can only be used with JDK 1.5+");
    }
    // TODO: fix and remove
    if (outputType != XsltRunConfiguration.OutputType.CONSOLE) {
        throw new CantRunException("XSLT Debugger requires Output Type == CONSOLE");
    }
    try {
        final int port = NetUtils.findAvailableSocketPort();
        parameters.getVMParametersList().defineProperty("xslt.debugger.port", String.valueOf(port));
        extensionData.putUserData(PORT, port);
    } catch (IOException e) {
        LOG.info(e);
        throw new CantRunException("Unable to find a free network port");
    }
    final char c = File.separatorChar;
    final PluginId pluginId = PluginManagerCore.getPluginByClassName(getClass().getName());
    assert pluginId != null || System.getProperty("xslt-debugger.plugin.path") != null;
    final File pluginPath;
    if (pluginId != null) {
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
        assert descriptor != null;
        pluginPath = descriptor.getPath();
    } else {
        // -Dxslt-debugger.plugin.path=C:\work\java\intellij/ultimate\out\classes\production\xslt-debugger-engine
        pluginPath = new File(System.getProperty("xslt-debugger.plugin.path"));
    }
    File rtClasspath = new File(pluginPath, "lib" + c + "xslt-debugger-engine.jar");
    if (rtClasspath.exists()) {
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(pluginPath, "lib" + c + "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
        final File engineImpl = new File(pluginPath, "lib" + c + "rt" + c + "xslt-debugger-engine-impl.jar");
        assert engineImpl.exists() : engineImpl.getAbsolutePath();
        parameters.getClassPath().addTail(engineImpl.getAbsolutePath());
    } else {
        if (!(rtClasspath = new File(pluginPath, "classes")).exists()) {
            if (ApplicationManagerEx.getApplicationEx().isInternal() && new File(pluginPath, "org").exists()) {
                rtClasspath = pluginPath;
                final File engineImplInternal = new File(pluginPath, ".." + c + "xslt-debugger-engine-impl");
                assert engineImplInternal.exists() : engineImplInternal.getAbsolutePath();
                parameters.getClassPath().addTail(engineImplInternal.getAbsolutePath());
            } else {
                throw new CantRunException("Runtime classes not found");
            }
        }
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(rtClasspath, "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
    }
    File trove4j = new File(PathManager.getLibPath() + c + "trove4j.jar");
    if (!trove4j.exists()) {
        trove4j = new File(PathManager.getHomePath() + c + "community" + c + "lib" + c + "trove4j.jar");
        assert trove4j.exists() : trove4j.getAbsolutePath();
    }
    parameters.getClassPath().addTail(trove4j.getAbsolutePath());
    final String type = parameters.getVMParametersList().getPropertyValue("xslt.transformer.type");
    if ("saxon".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_6_JAR);
    } else if ("saxon9".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_9_JAR);
    } else if ("xalan".equalsIgnoreCase(type)) {
        final Boolean xalanPresent = isValidXalanPresent(parameters);
        if (xalanPresent == null) {
            addXalan(parameters, pluginPath);
        } else if (!xalanPresent) {
            throw new CantRunException("Unsupported Xalan version is present in classpath.");
        }
    } else if (type != null) {
        throw new CantRunException("Unsupported Transformer type '" + type + "'");
    } else if (parameters.getClassPath().getPathsString().toLowerCase().contains("xalan")) {
        if (isValidXalanPresent(parameters) == Boolean.TRUE) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "xalan");
        }
    }
    final VirtualFile xsltFile = configuration.findXsltFile();
    final PsiManager psiManager = PsiManager.getInstance(configuration.getProject());
    final XsltChecker.LanguageLevel level;
    if (xsltFile != null) {
        level = XsltSupport.getXsltLanguageLevel(psiManager.findFile(xsltFile));
    } else {
        level = XsltChecker.LanguageLevel.V1;
    }
    extensionData.putUserData(VERSION, level);
    if (!parameters.getVMParametersList().hasProperty("xslt.transformer.type")) {
        // add saxon for backward-compatibility
        if (level == XsltChecker.LanguageLevel.V2) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon9");
            addSaxon(parameters, pluginPath, SAXON_9_JAR);
        } else {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon");
            addSaxon(parameters, pluginPath, SAXON_6_JAR);
        }
    }
    parameters.getVMParametersList().defineProperty("xslt.main", "org.intellij.plugins.xsltDebugger.rt.XSLTDebuggerMain");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XsltRunConfiguration(org.intellij.lang.xpath.xslt.run.XsltRunConfiguration) PsiManager(com.intellij.psi.PsiManager) IOException(java.io.IOException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) XsltChecker(org.intellij.lang.xpath.xslt.impl.XsltChecker) PluginId(com.intellij.openapi.extensions.PluginId) CantRunException(com.intellij.execution.CantRunException) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with CantRunException

use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.

the class XsltCommandLineState method createJavaParameters.

protected SimpleJavaParameters createJavaParameters() throws ExecutionException {
    final Sdk jdk = myXsltRunConfiguration.getEffectiveJDK();
    if (jdk == null) {
        throw CantRunException.noJdkConfigured();
    }
    final SimpleJavaParameters parameters = new SimpleJavaParameters();
    parameters.setJdk(jdk);
    if (myXsltRunConfiguration.getJdkChoice() == XsltRunConfiguration.JdkChoice.FROM_MODULE) {
        final Module module = myXsltRunConfiguration.getEffectiveModule();
        // OK to run as if just a JDK has been selected (a missing JDK would already have been complained about above)
        if (module != null) {
            OrderEnumerator.orderEntries(module).productionOnly().recursively().classes().collectPaths(parameters.getClassPath());
        }
    }
    final ParametersList vmParameters = parameters.getVMParametersList();
    vmParameters.addParametersString(myXsltRunConfiguration.myVmArguments);
    if (isEmpty(myXsltRunConfiguration.getXsltFile())) {
        throw new CantRunException("No XSLT file selected");
    }
    vmParameters.defineProperty("xslt.file", myXsltRunConfiguration.getXsltFile());
    if (isEmpty(myXsltRunConfiguration.getXmlInputFile())) {
        throw new CantRunException("No XML input file selected");
    }
    vmParameters.defineProperty("xslt.input", myXsltRunConfiguration.getXmlInputFile());
    final XsltRunConfiguration.OutputType outputType = myXsltRunConfiguration.getOutputType();
    if (outputType == XsltRunConfiguration.OutputType.CONSOLE) {
        //noinspection deprecation
        myPort = NetUtils.tryToFindAvailableSocketPort(myXsltRunConfiguration.myRunnerPort);
        vmParameters.defineProperty("xslt.listen-port", String.valueOf(myPort));
    }
    if (myXsltRunConfiguration.isSaveToFile()) {
        vmParameters.defineProperty("xslt.output", myXsltRunConfiguration.myOutputFile);
    }
    for (Pair<String, String> pair : myXsltRunConfiguration.getParameters()) {
        final String name = pair.getFirst();
        final String value = pair.getSecond();
        if (isEmpty(name) || value == null)
            continue;
        vmParameters.defineProperty("xslt.param." + name, value);
    }
    vmParameters.defineProperty("xslt.smart-error-handling", String.valueOf(myXsltRunConfiguration.mySmartErrorHandling));
    final PluginId pluginId = PluginManagerCore.getPluginByClassName(getClass().getName());
    assert pluginId != null || System.getProperty("xslt.plugin.path") != null : "PluginId not found - development builds need to specify -Dxslt.plugin.path=../out/classes/production/xslt-rt";
    final File pluginPath;
    if (pluginId != null) {
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
        assert descriptor != null;
        pluginPath = descriptor.getPath();
    } else {
        // -Dxslt.plugin.path=C:\work\java\intellij/ultimate\out\classes\production\xslt-rt
        pluginPath = new File(System.getProperty("xslt.plugin.path"));
    }
    LOG.debug("Plugin Path = " + pluginPath.getAbsolutePath());
    final char c = File.separatorChar;
    File rtClasspath = new File(pluginPath, "lib" + c + "rt" + c + "xslt-rt.jar");
    //        File rtClasspath = new File("C:/Demetra/plugins/xpath/lib/rt/xslt-rt.jar");
    if (!rtClasspath.exists()) {
        LOG.warn("Plugin's Runtime classes not found in " + rtClasspath.getAbsolutePath());
        if (!(rtClasspath = new File(pluginPath, "classes")).exists()) {
            if (ApplicationManagerEx.getApplicationEx().isInternal() && new File(pluginPath, "org").exists()) {
                rtClasspath = pluginPath;
            } else {
                throw new CantRunException("Runtime classes not found");
            }
        }
        parameters.getVMParametersList().prepend("-ea");
    }
    parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
    parameters.setMainClass("org.intellij.plugins.xslt.run.rt.XSLTRunner");
    if (isEmpty(myXsltRunConfiguration.myWorkingDirectory)) {
        parameters.setWorkingDirectory(new File(myXsltRunConfiguration.getXsltFile()).getParentFile().getAbsolutePath());
    } else {
        parameters.setWorkingDirectory(expandPath(myXsltRunConfiguration.myWorkingDirectory, myXsltRunConfiguration.getEffectiveModule(), myXsltRunConfiguration.getProject()));
    }
    myExtensionData = new UserDataHolderBase();
    final List<XsltRunnerExtension> extensions = XsltRunnerExtension.getExtensions(myXsltRunConfiguration, myIsDebugger);
    for (XsltRunnerExtension extension : extensions) {
        extension.patchParameters(parameters, myXsltRunConfiguration, myExtensionData);
    }
    parameters.setUseDynamicClasspath(JdkUtil.useDynamicClasspath(myXsltRunConfiguration.getProject()));
    return parameters;
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) CantRunException(com.intellij.execution.CantRunException) ParametersList(com.intellij.execution.configurations.ParametersList) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 with CantRunException

use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.

the class GrabDependencies method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
    assert vfile != null;
    if (JavaPsiFacade.getInstance(project).findClass("org.apache.ivy.core.report.ResolveReport", file.getResolveScope()) == null) {
        Messages.showErrorDialog("Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.", "Ivy Missing");
        return;
    }
    Map<String, String> queries = prepareQueries(file);
    final Map<String, GeneralCommandLine> lines = new HashMap<>();
    for (String grabText : queries.keySet()) {
        final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
        try {
            DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, GRAPE_RUNNER, false, true);
            javaParameters.getClassPath().add(PathUtil.getJarPathForClass(GrapeRunner.class));
            javaParameters.getProgramParametersList().add(queries.get(grabText));
            javaParameters.setUseDynamicClasspath(true);
            lines.put(grabText, javaParameters.toCommandLine());
        } catch (CantRunException e) {
            String title = "Can't run @Grab: " + ExceptionUtil.getMessage(e);
            NOTIFICATION_GROUP.createNotification(title, ExceptionUtil.getThrowableText(e), NotificationType.ERROR, null).notify(project);
            return;
        }
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab Annotations") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            int jarCount = 0;
            String messages = "";
            for (Map.Entry<String, GeneralCommandLine> entry : lines.entrySet()) {
                String grabText = entry.getKey();
                indicator.setText2(grabText);
                try {
                    final GrapeProcessHandler handler = new GrapeProcessHandler(entry.getValue(), module);
                    handler.startNotify();
                    handler.waitFor();
                    jarCount += handler.jarCount;
                    messages += "<b>" + grabText + "</b>: " + handler.messages + "<p>";
                } catch (ExecutionException e) {
                    LOG.error(e);
                }
            }
            final String finalMessages = messages;
            final String title = jarCount + " Grape dependency jar" + (jarCount == 1 ? "" : "s") + " added";
            NOTIFICATION_GROUP.createNotification(title, finalMessages, NotificationType.INFORMATION, null).notify(project);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) CantRunException(com.intellij.execution.CantRunException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with CantRunException

use of com.intellij.execution.CantRunException in project intellij-community by JetBrains.

the class DebugProcessImpl method createVirtualMachineInt.

private VirtualMachine createVirtualMachineInt() throws ExecutionException {
    try {
        if (myArguments != null) {
            throw new IOException(DebuggerBundle.message("error.debugger.already.listening"));
        }
        final String address = myConnection.getAddress();
        if (myConnection.isServerMode()) {
            ListeningConnector connector = (ListeningConnector) findConnector(myConnection.isUseSockets() ? SOCKET_LISTENING_CONNECTOR_NAME : SHMEM_LISTENING_CONNECTOR_NAME);
            if (connector == null) {
                throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
            }
            myArguments = connector.defaultArguments();
            if (myArguments == null) {
                throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
            }
            if (address == null) {
                throw new CantRunException(DebuggerBundle.message("error.no.debug.listen.port"));
            }
            // zero port number means the caller leaves to debugger to decide at which port to listen
            //noinspection HardCodedStringLiteral
            final Connector.Argument portArg = myConnection.isUseSockets() ? myArguments.get("port") : myArguments.get("name");
            if (portArg != null) {
                portArg.setValue(address);
            }
            //noinspection HardCodedStringLiteral
            final Connector.Argument timeoutArg = myArguments.get("timeout");
            if (timeoutArg != null) {
                // wait forever
                timeoutArg.setValue("0");
            }
            String listeningAddress = connector.startListening(myArguments);
            String port = StringUtil.substringAfter(listeningAddress, ":");
            if (port != null) {
                listeningAddress = port;
            }
            myConnection.setAddress(listeningAddress);
            myDebugProcessDispatcher.getMulticaster().connectorIsReady();
            try {
                return connector.accept(myArguments);
            } finally {
                if (myArguments != null) {
                    try {
                        connector.stopListening(myArguments);
                    } catch (IllegalArgumentException | IllegalConnectorArgumentsException ignored) {
                    // ignored
                    }
                }
            }
        } else {
            // is client mode, should attach to already running process
            AttachingConnector connector = (AttachingConnector) findConnector(myConnection.isUseSockets() ? SOCKET_ATTACHING_CONNECTOR_NAME : SHMEM_ATTACHING_CONNECTOR_NAME);
            if (connector == null) {
                throw new CantRunException(DebuggerBundle.message("error.debug.connector.not.found", DebuggerBundle.getTransportName(myConnection)));
            }
            myArguments = connector.defaultArguments();
            if (myConnection.isUseSockets()) {
                //noinspection HardCodedStringLiteral
                final Connector.Argument hostnameArg = myArguments.get("hostname");
                if (hostnameArg != null && myConnection.getHostName() != null) {
                    hostnameArg.setValue(myConnection.getHostName());
                }
                if (address == null) {
                    throw new CantRunException(DebuggerBundle.message("error.no.debug.attach.port"));
                }
                //noinspection HardCodedStringLiteral
                final Connector.Argument portArg = myArguments.get("port");
                if (portArg != null) {
                    portArg.setValue(address);
                }
            } else {
                if (address == null) {
                    throw new CantRunException(DebuggerBundle.message("error.no.shmem.address"));
                }
                //noinspection HardCodedStringLiteral
                final Connector.Argument nameArg = myArguments.get("name");
                if (nameArg != null) {
                    nameArg.setValue(address);
                }
            }
            //noinspection HardCodedStringLiteral
            final Connector.Argument timeoutArg = myArguments.get("timeout");
            if (timeoutArg != null) {
                // wait forever
                timeoutArg.setValue("0");
            }
            myDebugProcessDispatcher.getMulticaster().connectorIsReady();
            try {
                return connector.attach(myArguments);
            } catch (IllegalArgumentException e) {
                throw new CantRunException(e.getLocalizedMessage());
            }
        }
    } catch (IOException e) {
        throw new ExecutionException(processIOException(e, DebuggerBundle.getAddressDisplayName(myConnection)), e);
    } catch (IllegalConnectorArgumentsException e) {
        throw new ExecutionException(processError(e), e);
    } finally {
        myArguments = null;
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

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