Search in sources :

Example 1 with IdeaPluginDescriptor

use of com.intellij.ide.plugins.IdeaPluginDescriptor in project go-lang-idea-plugin by go-lang-plugin-org.

the class UpdateComponent method checkForUpdates.

private static void checkForUpdates() {
    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
    long lastUpdate = propertiesComponent.getOrInitLong(KEY, 0);
    if (lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1)) {
        ApplicationManager.getApplication().executeOnPooledThread(() -> {
            try {
                String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                IdeaPluginDescriptor plugin = getPlugin();
                String pluginVersion = plugin.getVersion();
                String pluginId = plugin.getPluginId().getIdString();
                String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                String uid = PermanentInstallationID.get();
                String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + pluginVersion + "&os=" + os + "&uuid=" + uid;
                PropertiesComponent.getInstance().setValue(KEY, String.valueOf(System.currentTimeMillis()));
                HttpRequests.request(url).connect(request -> {
                    try {
                        JDOMUtil.load(request.getReader());
                        LOG.info((request.isSuccessful() ? "Successful" : "Unsuccessful") + " update: " + url);
                    } catch (JDOMException e) {
                        LOG.warn(e);
                    }
                    return null;
                });
            } catch (UnknownHostException ignored) {
            } catch (IOException e) {
                LOG.warn(e);
            }
        });
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 2 with IdeaPluginDescriptor

use of com.intellij.ide.plugins.IdeaPluginDescriptor in project Main by SpartanRefactoring.

the class LogFileUtils method getPath.

/**
     * When running tests through intellij, the path seems to be:
     * <IDEA_PROJECTS_DIR>/<PROJECT_DIR>/build/resources/...
     * NOTE: there is no need to put logs in tests.
     * When running idea instance through gradle, the path seems to be:
     * <IDEA_PROJECTS_DIR>/<PROJECT_DIR>/build/idea-sandbox/plugins/<PLUGIN_NAME>/...
     *
     * @return The path of the logfile to be used.
     */
private static String getPath() {
    PluginId ourPluginId = PluginId.getId(PluginDescriptorReader.getPluginId());
    IdeaPluginDescriptor ourPlugin = PluginManager.getPlugin(ourPluginId);
    if (ourPlugin == null)
        throw new RuntimeException("Cannot retrieve plugin descriptor");
    return ourPlugin.getPath().getPath() + SLASH + RELATIVE_LOG_PATH + BASE_LOG_NAME + DOT + LOG_EXT;
}
Also used : IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId)

Example 3 with IdeaPluginDescriptor

use of com.intellij.ide.plugins.IdeaPluginDescriptor 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 4 with IdeaPluginDescriptor

use of com.intellij.ide.plugins.IdeaPluginDescriptor 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 5 with IdeaPluginDescriptor

use of com.intellij.ide.plugins.IdeaPluginDescriptor in project smali by JesusFreke.

the class ErrorReporter method submit.

@Override
public boolean submit(IdeaLoggingEvent[] events, String additionalInfo, Component parentComponent, final Consumer<SubmittedReportInfo> consumer) {
    IdeaLoggingEvent event = events[0];
    ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    bean.setDescription(additionalInfo);
    bean.setMessage(event.getMessage());
    Throwable throwable = event.getThrowable();
    if (throwable != null) {
        final PluginId pluginId = IdeErrorsDialog.findPluginId(throwable);
        if (pluginId != null) {
            final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
            if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
                bean.setPluginName(ideaPluginDescriptor.getName());
                bean.setPluginVersion(ideaPluginDescriptor.getVersion());
            }
        }
    }
    Object data = event.getData();
    if (data instanceof LogMessageEx) {
        bean.setAttachments(((LogMessageEx) data).getAttachments());
    }
    Map<String, String> reportValues = ITNProxy.createParameters(bean);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    Consumer<String> successCallback = new Consumer<String>() {

        @Override
        public void consume(String token) {
            final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
            consumer.consume(reportInfo);
            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
        }
    };
    Consumer<Exception> errorCallback = new Consumer<Exception>() {

        @Override
        public void consume(Exception e) {
            String message = String.format("<html>There was an error while creating a GitHub issue: %s<br>" + "Please consider manually creating an issue on the " + "<a href=\"https://github.com/JesusFreke/smali/issues\">Smali Issue Tracker</a></html>", e.getMessage());
            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
        }
    };
    GithubFeedbackTask task = new GithubFeedbackTask(project, "Submitting error report", true, reportValues, successCallback, errorCallback);
    if (project == null) {
        task.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(task);
    }
    return true;
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) LogMessageEx(com.intellij.diagnostic.LogMessageEx) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) Consumer(com.intellij.util.Consumer) ErrorBean(com.intellij.errorreport.bean.ErrorBean) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo)

Aggregations

IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)40 PluginId (com.intellij.openapi.extensions.PluginId)19 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ErrorBean (com.intellij.errorreport.bean.ErrorBean)3 ApplicationInfoEx (com.intellij.openapi.application.ex.ApplicationInfoEx)3 IdeaLoggingEvent (com.intellij.openapi.diagnostic.IdeaLoggingEvent)3 URL (java.net.URL)3 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 CantRunException (com.intellij.execution.CantRunException)2 PluginClassLoader (com.intellij.ide.plugins.cl.PluginClassLoader)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 SubmittedReportInfo (com.intellij.openapi.diagnostic.SubmittedReportInfo)2 PluginDescriptor (com.intellij.openapi.extensions.PluginDescriptor)2 ShowSettingsUtil (com.intellij.openapi.options.ShowSettingsUtil)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2