mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
improved adding plugin libraries to external compiler classpath
This commit is contained in:
@@ -11,19 +11,22 @@ import com.intellij.util.xmlb.annotations.Attribute;
|
||||
public class CompileServerPlugin implements PluginAware {
|
||||
public static final ExtensionPointName<CompileServerPlugin> 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
@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
|
||||
|
||||
+46
-16
@@ -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/<jar-name> 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/<jar-name> 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 <jar-name> refers to a library, try to find it under <plugin-dir>/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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,25 +229,8 @@
|
||||
<packaging.artifactPropertiesProvider implementation="org.jetbrains.android.compiler.artifact.AndroidArtifactPropertiesProvider"/>
|
||||
<packaging.artifactType implementation="org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactType"/>
|
||||
|
||||
<compileServer.plugin jar-path="jps/android-jps-plugin.jar"/>
|
||||
<compileServer.plugin jar-path="android-common.jar"/>
|
||||
<compileServer.plugin jar-path="android-rt.jar"/>
|
||||
|
||||
<compileServer.plugin jar-path="sdklib.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../community/plugins/android/lib/sdklib.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../plugins/android/lib/sdklib.jar"/>
|
||||
|
||||
<compileServer.plugin jar-path="common.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../community/plugins/android/lib/common.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../plugins/android/lib/common.jar"/>
|
||||
|
||||
<compileServer.plugin jar-path="jarutils.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../community/plugins/android/lib/jarutils.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../plugins/android/lib/jarutils.jar"/>
|
||||
|
||||
<compileServer.plugin jar-path="androidprefs.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../community/plugins/android/lib/androidprefs.jar"/>
|
||||
<compileServer.plugin jar-path="../../../../../plugins/android/lib/androidprefs.jar"/>
|
||||
<compileServer.plugin classpath="jps/android-jps-plugin.jar;android-common.jar;android-rt.jar"/>
|
||||
<compileServer.plugin classpath="sdklib.jar;common.jar;jarutils.jar;androidprefs.jar"/>
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<configurationType implementation="org.jetbrains.idea.devkit.run.PluginConfigurationType"/>
|
||||
<moduleType id="PLUGIN_MODULE" implementationClass="org.jetbrains.idea.devkit.module.PluginModuleType" classpathProvider="true"/>
|
||||
<sdkType implementation="org.jetbrains.idea.devkit.projectRoots.IdeaJdk"/>
|
||||
<compileServer.plugin jar-path="jps/devkit-jps-plugin.jar"/>
|
||||
<compileServer.plugin classpath="jps/devkit-jps-plugin.jar"/>
|
||||
<fileTemplateGroup implementation="org.jetbrains.idea.devkit.DevKitFileTemplatesFactory"/>
|
||||
|
||||
<localInspection language="XML" shortName="PluginXmlValidity" displayName="Plugin.xml Validity"
|
||||
|
||||
@@ -355,7 +355,7 @@
|
||||
|
||||
<quoteHandler fileType="Groovy" className="org.jetbrains.plugins.groovy.lang.editor.GroovyQuoteHandler"/>
|
||||
|
||||
<compileServer.plugin jar-path="groovy_rt.jar"/>
|
||||
<compileServer.plugin classpath="groovy_rt.jar"/>
|
||||
|
||||
<indexPatternBuilder implementation="org.jetbrains.plugins.groovy.util.GroovyIndexPatternBuilder"/>
|
||||
<todoIndexer filetype="Groovy" implementationClass="org.jetbrains.plugins.groovy.highlighter.GroovyTodoIndexer"/>
|
||||
|
||||
Reference in New Issue
Block a user