From fde91d0cd179f0f76275a93cc56ad7d1c9404e15 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 20 Jul 2012 12:10:08 +0400 Subject: [PATCH] improved adding plugin libraries to external compiler classpath --- .../compiler/server/CompileServerPlugin.java | 19 +++--- .../impl/CompileServerClasspathManager.java | 62 ++++++++++++++----- plugins/android/src/META-INF/plugin.xml | 21 +------ plugins/devkit/resources/META-INF/plugin.xml | 2 +- plugins/groovy/src/META-INF/plugin.xml | 2 +- 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPlugin.java b/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPlugin.java index fe6c98ad65de..7f6c2ae4535c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPlugin.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/CompileServerPlugin.java @@ -11,19 +11,22 @@ import com.intellij.util.xmlb.annotations.Attribute; public class CompileServerPlugin implements PluginAware { public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.compileServer.plugin"); private PluginDescriptor myPluginDescriptor; - private String myJarPath; + private String myClasspath; /** - * Specifies path to a jar file which should be added to the classpath of the compile server. The path is relative to the plugin 'lib' directory. - * In the development mode the name of this file without extension is treated as a module name and the output directory of the module is added to the classpath. + * Specifies semicolon-separated list of paths which should be added to the classpath of the compile server. The paths are relative to the plugin 'lib' directory. + *

+ * In the development mode the name of each file without extension is treated as a module name and the output directory of the module + * is added to the classpath. If such file doesn't exists the jar is searched under 'lib' directory of the plugin sources home directory. + *

*/ - @Attribute("jar-path") - public String getJarPath() { - return myJarPath; + @Attribute("classpath") + public String getClasspath() { + return myClasspath; } - public void setJarPath(String jarPath) { - myJarPath = jarPath; + public void setClasspath(String classpath) { + myClasspath = classpath; } @Override diff --git a/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java b/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java index 32cfe65d6cd4..868df114637e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/impl/CompileServerClasspathManager.java @@ -18,10 +18,13 @@ package com.intellij.compiler.server.impl; import com.intellij.compiler.server.CompileServerPlugin; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.PathUtil; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.ArrayList; @@ -52,26 +55,53 @@ public class CompileServerClasspathManager { classpath.add(baseFile); } else if (baseFile.isDirectory()) { - final String relativePath = serverPlugin.getJarPath(); - - final File jarFile = relativePath.startsWith("../") - ? new File(baseFile, relativePath.substring(3)) - : new File(new File(baseFile, "lib"), relativePath); - if (jarFile.exists()) { - classpath.add(jarFile); - } - else { - //development mode: add directory out/classes/production/ to classpath, assuming that jar-name is equal to module name - final String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(relativePath)); - final File dir = new File(baseFile.getParentFile(), moduleName); - if (!dir.exists()) { - LOG.warn("Cannot add plugin " + pluginId + " to compile server classpath: " + jarFile.getAbsolutePath() + " and " + - dir.getAbsolutePath() + " don't exist"); + for (String relativePath : StringUtil.split(serverPlugin.getClasspath(), ";")) { + final File jarFile = new File(new File(baseFile, "lib"), relativePath); + if (jarFile.exists()) { + classpath.add(jarFile); + } + else { + //development mode: add directory out/classes/production/ to classpath, assuming that jar-name is equal to module name + final String moduleName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(relativePath)); + final File dir = new File(baseFile.getParentFile(), moduleName); + if (dir.exists()) { + classpath.add(dir); + } + else { + //looks like refers to a library, try to find it under /lib + File pluginDir = getPluginDir(plugin); + if (pluginDir != null) { + File libraryFile = new File(pluginDir, "lib" + File.separator + PathUtil.getFileName(relativePath)); + if (libraryFile.exists()) { + classpath.add(libraryFile); + } + else { + LOG.error("Cannot add plugin '" + plugin.getName() + "' to external compiler classpath: library " + + libraryFile.getAbsolutePath() + " not found"); + } + } + else { + LOG.error("Cannot add plugin '" + plugin.getName() + "' to external compiler classpath: home directory of plugin not found"); + } + } } - classpath.add(dir); } + } } return classpath; } + + @Nullable + private static File getPluginDir(IdeaPluginDescriptor plugin) { + String pluginDirName = StringUtil.getShortName(plugin.getPluginId().getIdString()); + String[] roots = {PathManager.getHomePath(), PathManager.getHomePath() + File.separator + "community"}; + for (String root : roots) { + File pluginDir = new File(root, "plugins" + File.separator + pluginDirName); + if (pluginDir.isDirectory()) { + return pluginDir; + } + } + return null; + } } diff --git a/plugins/android/src/META-INF/plugin.xml b/plugins/android/src/META-INF/plugin.xml index 5131f5775455..dfade9b013a2 100644 --- a/plugins/android/src/META-INF/plugin.xml +++ b/plugins/android/src/META-INF/plugin.xml @@ -229,25 +229,8 @@ - - - - - - - - - - - - - - - - - - - + + diff --git a/plugins/devkit/resources/META-INF/plugin.xml b/plugins/devkit/resources/META-INF/plugin.xml index 9726864787d7..90d9b27798b4 100644 --- a/plugins/devkit/resources/META-INF/plugin.xml +++ b/plugins/devkit/resources/META-INF/plugin.xml @@ -31,7 +31,7 @@ - + - +