Search in sources :

Example 1 with XsltRunConfiguration

use of org.intellij.lang.xpath.xslt.run.XsltRunConfiguration 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)

Aggregations

CantRunException (com.intellij.execution.CantRunException)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 PluginId (com.intellij.openapi.extensions.PluginId)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiManager (com.intellij.psi.PsiManager)1 File (java.io.File)1 IOException (java.io.IOException)1 XsltChecker (org.intellij.lang.xpath.xslt.impl.XsltChecker)1 XsltRunConfiguration (org.intellij.lang.xpath.xslt.run.XsltRunConfiguration)1