public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable StartupProgress progress) {
    if (ClassUtilCore.isLoadingOfExternalPluginsDisabled()) {
      return IdeaPluginDescriptorImpl.EMPTY_ARRAY;
    }

    final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>();

    int pluginsCount =
        countPlugins(PathManager.getPluginsPath())
            + countPlugins(PathManager.getPreinstalledPluginsPath());
    loadDescriptors(PathManager.getPluginsPath(), result, progress, pluginsCount);
    Application application = ApplicationManager.getApplication();
    boolean fromSources = false;
    if (application == null || !application.isUnitTestMode()) {
      int size = result.size();
      loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress, pluginsCount);
      fromSources = size == result.size();
    }

    loadDescriptorsFromProperty(result);

    loadDescriptorsFromClassPath(result, fromSources ? progress : null);

    IdeaPluginDescriptorImpl[] pluginDescriptors =
        result.toArray(new IdeaPluginDescriptorImpl[result.size()]);
    try {
      Arrays.sort(pluginDescriptors, new PluginDescriptorComparator(pluginDescriptors));
    } catch (Exception e) {
      prepareLoadingPluginsErrorMessage(
          IdeBundle.message("error.plugins.were.not.loaded", e.getMessage()));
      getLogger().info(e);
      return findCorePlugin(pluginDescriptors);
    }
    return pluginDescriptors;
  }
  @Override
  public boolean isBundled() {
    if (PluginManagerCore.CORE_PLUGIN_ID.equals(myId.getIdString())) {
      return true;
    }

    String path;
    try {
      // to avoid paths like this /home/kb/IDEA/bin/../config/plugins/APlugin
      path = getPath().getCanonicalPath();
    } catch (IOException e) {
      path = getPath().getAbsolutePath();
    }
    Application app = ApplicationManager.getApplication();
    if (app != null && app.isInternal()) {
      if (path.startsWith(
          PathManager.getHomePath() + File.separator + "out" + File.separator + "classes")) {
        return true;
      }
      if (app.isUnitTestMode()
          && !path.startsWith(PathManager.getPluginsPath() + File.separatorChar)) {
        return true;
      }
    }

    return path.startsWith(PathManager.getPreInstalledPluginsPath());
  }
 private static File getJettyLauncherFile() {
   final String binDir =
       PathManager.getPluginsPath()
           + File.separator
           + JettyManager.PLUGIN_NAME
           + File.separator
           + BIN_DIR;
   return new File(binDir, getDefaultJettyLauncherFileName());
 }
Exemplo n.º 4
0
 @NotNull
 private static InputStream retrieveSourceKeymapStream() throws IOException {
   String keymapPath =
       PATH_JOINER.join(
           PathManager.getPluginsPath(), VimPlugin.IDEAVIM_NOTIFICATION_TITLE, VIM_XML);
   try {
     return new FileInputStream(keymapPath);
   } catch (FileNotFoundException e) {
     if (ApplicationManager.getApplication().isInternal()) {
       LOG.debug("Development mode on. Trying to retrieve source keymap from resources");
       return Resources.getResource(VimKeyMapUtil.class, "/" + VIM_XML).openStream();
     }
     throw e;
   }
 }
Exemplo n.º 5
0
 public static String pluginsRootPath() {
   return FileUtilRt.toSystemIndependentName(PathManager.getPluginsPath() + "/live-plugins");
 }
Exemplo n.º 6
0
public class LivePluginAppComponent implements ApplicationComponent { // TODO implement DumbAware?
  public static final String PLUGIN_EXAMPLES_PATH = "/liveplugin/pluginexamples";
  public static final String LIVEPLUGIN_LIBS_PATH =
      PathManager.getPluginsPath() + "/LivePlugin/lib/";
  public static final NotificationGroup livePluginNotificationGroup =
      NotificationGroup.balloonGroup("Live Plugin");

  private static final Logger LOG = Logger.getInstance(LivePluginAppComponent.class);
  private static final String DEFAULT_PLUGIN_PATH = PLUGIN_EXAMPLES_PATH;
  private static final String DEFAULT_PLUGIN_SCRIPT = "default-plugin.groovy";
  private static final String DEFAULT_PLUGIN_TEST_SCRIPT = "default-plugin-test.groovy";

  private static final String DEFAULT_IDEA_OUTPUT_FOLDER = "out";
  private static final String COMPONENT_NAME = "LivePluginComponent";

  public static String pluginsRootPath() {
    return FileUtilRt.toSystemIndependentName(PathManager.getPluginsPath() + "/live-plugins");
  }

  public static Map<String, String> pluginIdToPathMap() {
    final boolean containsIdeaProjectFolder =
        new File(pluginsRootPath() + "/" + DIRECTORY_STORE_FOLDER).exists();

    File[] files =
        new File(pluginsRootPath())
            .listFiles(
                new FileFilter() {
                  @SuppressWarnings("SimplifiableIfStatement")
                  @Override
                  public boolean accept(@NotNull File file) {
                    if (containsIdeaProjectFolder
                        && file.getName().equals(DEFAULT_IDEA_OUTPUT_FOLDER)) return false;
                    if (file.getName().equals(DIRECTORY_STORE_FOLDER)) return false;
                    return file.isDirectory();
                  }
                });
    if (files == null) return new HashMap<String, String>();

    HashMap<String, String> result = new HashMap<String, String>();
    for (File file : files) {
      result.put(file.getName(), FileUtilRt.toSystemIndependentName(file.getAbsolutePath()));
    }
    return result;
  }

  public static boolean isInvalidPluginFolder(VirtualFile virtualFile) {
    File file = new File(virtualFile.getPath());
    if (!file.isDirectory()) return false;
    String[] files =
        file.list(
            new FilenameFilter() {
              @Override
              public boolean accept(@NotNull File dir, @NotNull String name) {
                return name.equals(GroovyPluginRunner.MAIN_SCRIPT);
              }
            });
    return files.length < 1;
  }

  public static String defaultPluginScript() {
    return readSampleScriptFile(DEFAULT_PLUGIN_PATH, DEFAULT_PLUGIN_SCRIPT);
  }

  public static String defaultPluginTestScript() {
    return readSampleScriptFile(DEFAULT_PLUGIN_PATH, DEFAULT_PLUGIN_TEST_SCRIPT);
  }

  public static String readSampleScriptFile(String pluginPath, String file) {
    try {
      String path = pluginPath + "/" + file;
      return FileUtil.loadTextAndClose(
          LivePluginAppComponent.class.getClassLoader().getResourceAsStream(path));
    } catch (IOException e) {
      LOG.error(e);
      return "";
    }
  }

  public static boolean pluginExists(String pluginId) {
    return pluginIdToPathMap().keySet().contains(pluginId);
  }

  private static boolean isGroovyOnClasspath() {
    return IDEUtil.isOnClasspath("org.codehaus.groovy.runtime.DefaultGroovyMethods");
  }

  public static boolean scalaIsOnClassPath() {
    return IDEUtil.isOnClasspath("scala.Some");
  }

  public static boolean clojureIsOnClassPath() {
    return IDEUtil.isOnClasspath("clojure.core.Vec");
  }

  private static void runAllPlugins() {
    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                AnActionEvent event =
                    new AnActionEvent(
                        null,
                        IDEUtil.DUMMY_DATA_CONTEXT,
                        PluginRunner.IDE_STARTUP,
                        new Presentation(),
                        ActionManager.getInstance(),
                        0);
                final ErrorReporter errorReporter = new ErrorReporter();
                RunPluginAction.runPlugins(
                    pluginIdToPathMap().keySet(),
                    event,
                    errorReporter,
                    RunPluginAction.createPluginRunners(errorReporter));
              }
            });
  }

  private static void installHelloWorldPlugin() {
    ExamplePluginInstaller pluginInstaller =
        new ExamplePluginInstaller(PLUGIN_EXAMPLES_PATH + "/helloWorld", asList("plugin.groovy"));
    pluginInstaller.installPlugin(
        new ExamplePluginInstaller.Listener() {
          @Override
          public void onException(Exception e, String pluginPath) {
            LOG.warn("Failed to install plugin: " + pluginPath, e);
          }
        });
  }

  public static void checkThatGroovyIsOnClasspath() {
    final File oldGroovyLibrary =
        new File(LIVEPLUGIN_LIBS_PATH + File.separator + "groovy-all-2.0.6.jar");

    NotificationListener listener =
        new NotificationListener() {
          @Override
          public void hyperlinkUpdate(
              @NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (oldGroovyLibrary.exists()) {
              FileUtil.delete(oldGroovyLibrary);
            }

            boolean downloaded =
                downloadFile(
                    "http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.2.1/",
                    "groovy-all-2.2.1.jar",
                    LIVEPLUGIN_LIBS_PATH);
            if (downloaded) {
              notification.expire();
              askIsUserWantsToRestartIde(
                  "For Groovy libraries to be loaded IDE restart is required. Restart now?");
            } else {
              livePluginNotificationGroup.createNotification(
                  "Failed to download Groovy libraries", NotificationType.WARNING);
            }
          }
        };

    if (oldGroovyLibrary.exists()) {
      livePluginNotificationGroup
          .createNotification(
              "There is old version of groovy library on LivePlugin classpath",
              "It might work incorrectly. <a href=\"\">Click here to update groovy to 2.2.1</a> (~6Mb)",
              NotificationType.ERROR,
              listener)
          .notify(null);
    }

    if (isGroovyOnClasspath()) return;

    livePluginNotificationGroup
        .createNotification(
            "LivePlugin didn't find Groovy libraries on classpath",
            "Without it plugins won't work. <a href=\"\">Download Groovy libraries</a> (~6Mb)",
            NotificationType.ERROR,
            listener)
        .notify(null);
  }

  @Override
  public void initComponent() {
    IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(getId("IntelliJEval"));
    if (pluginDescriptor != null && pluginDescriptor.isEnabled()) {
      livePluginNotificationGroup
          .createNotification(
              "It seems that you have IntelliJEval plugin enabled.<br/>Please disable it to use LivePlugin.",
              NotificationType.ERROR)
          .notify(null);
      return;
    }
    checkThatGroovyIsOnClasspath();

    Settings settings = Settings.getInstance();
    if (settings.justInstalled) {
      installHelloWorldPlugin();
      settings.justInstalled = false;
    }
    if (settings.runAllPluginsOnIDEStartup) {
      runAllPlugins();
    }

    new PluginToolWindowManager().init();
  }

  @Override
  public void disposeComponent() {}

  @Override
  @NotNull
  public String getComponentName() {
    return COMPONENT_NAME;
  }
}