mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
devkit: avoid sporadic creation of plugin.xml file in default location
This commit is contained in:
@@ -20,7 +20,6 @@ import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleComponent;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
@@ -48,7 +47,6 @@ import java.io.File;
|
||||
public class PluginBuildConfiguration implements ModuleComponent, JDOMExternalizable {
|
||||
private final Module myModule;
|
||||
private final ConfigFileContainer myPluginXmlContainer;
|
||||
private VirtualFilePointer myPluginXmlPointer;
|
||||
private VirtualFilePointer myManifestFilePointer;
|
||||
private boolean myUseUserManifest = false;
|
||||
@NonNls private static final String URL_ATTR = "url";
|
||||
@@ -56,7 +54,6 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
@NonNls private static final String META_INF = "META-INF";
|
||||
@NonNls private static final String PLUGIN_XML = "plugin.xml";
|
||||
private final PluginBuildParticipant myBuildParticipant;
|
||||
private String myPluginXmlUrl;
|
||||
|
||||
public PluginBuildConfiguration(Module module) {
|
||||
myModule = module;
|
||||
@@ -82,16 +79,6 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
StartupManager.getInstance(myModule.getProject()).runWhenProjectIsInitialized(new Runnable() {
|
||||
public void run() {
|
||||
if (myPluginXmlUrl != null) {
|
||||
setPluginXmlUrl(myPluginXmlUrl);
|
||||
} else {
|
||||
setPluginXmlUrl(VfsUtil.pathToUrl(getDefaultLocation()));
|
||||
}
|
||||
myPluginXmlUrl = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
@@ -100,7 +87,7 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
String url = element.getAttributeValue(URL_ATTR);
|
||||
if (url != null) {
|
||||
myPluginXmlUrl = url;
|
||||
myPluginXmlContainer.getConfiguration().replaceConfigFile(PluginDescriptorConstants.META_DATA, url);
|
||||
}
|
||||
url = element.getAttributeValue(MANIFEST_ATTR);
|
||||
if (url != null) {
|
||||
@@ -109,7 +96,7 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
element.setAttribute(URL_ATTR, getPluginXmlPointer().getUrl());
|
||||
element.setAttribute(URL_ATTR, getPluginXmlUrl());
|
||||
if (myManifestFilePointer != null){
|
||||
element.setAttribute(MANIFEST_ATTR, myManifestFilePointer.getUrl());
|
||||
}
|
||||
@@ -120,13 +107,6 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
return myPluginXmlContainer.getConfigFile(PluginDescriptorConstants.META_DATA);
|
||||
}
|
||||
|
||||
public void createPluginXmlIfNotExist() {
|
||||
final ConfigFile descriptor = myPluginXmlContainer.getConfigFile(PluginDescriptorConstants.META_DATA);
|
||||
if (descriptor == null) {
|
||||
createDescriptor(getPluginXmlUrl());
|
||||
}
|
||||
}
|
||||
|
||||
private void createDescriptor(final String url) {
|
||||
final ConfigFileInfo descriptor = new ConfigFileInfo(PluginDescriptorConstants.META_DATA, url);
|
||||
myPluginXmlContainer.getConfiguration().addConfigFile(descriptor);
|
||||
@@ -135,48 +115,34 @@ public class PluginBuildConfiguration implements ModuleComponent, JDOMExternaliz
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VirtualFilePointer getStoredPluginXmlPointer() {
|
||||
return myPluginXmlPointer;
|
||||
public ConfigFile getPluginXmlConfigFile() {
|
||||
return myPluginXmlContainer.getConfigFile(PluginDescriptorConstants.META_DATA);
|
||||
}
|
||||
|
||||
public VirtualFilePointer getPluginXmlPointer() {
|
||||
if (myPluginXmlPointer == null) {
|
||||
setPluginXmlPath(getDefaultLocation());
|
||||
}
|
||||
return myPluginXmlPointer;
|
||||
}
|
||||
|
||||
public String getPluginXmlUrl() {
|
||||
if (myPluginXmlPointer == null) {
|
||||
return VfsUtil.pathToUrl(getDefaultLocation());
|
||||
}
|
||||
return myPluginXmlPointer.getUrl();
|
||||
@Nullable
|
||||
private String getPluginXmlUrl() {
|
||||
ConfigFile configFile = getPluginXmlConfigFile();
|
||||
return configFile != null ? configFile.getUrl() : null;
|
||||
}
|
||||
|
||||
private String getDefaultLocation() {
|
||||
return new File(myModule.getModuleFilePath()).getParent() + File.separator + META_INF + File.separator + PLUGIN_XML;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPluginXmlPath() {
|
||||
VirtualFile file = getPluginXmlPointer().getFile();
|
||||
if (file == null){ //e.g. file deleted
|
||||
myPluginXmlPointer = null;
|
||||
file = getPluginXmlPointer().getFile(); //to suggest default location
|
||||
String url = getPluginXmlUrl();
|
||||
if (url == null) {
|
||||
return getDefaultLocation();
|
||||
}
|
||||
assert file != null;
|
||||
return FileUtil.toSystemDependentName(file.getPath());
|
||||
return FileUtil.toSystemDependentName(VfsUtil.urlToPath(url));
|
||||
}
|
||||
|
||||
public void setPluginXmlPath(final String pluginXmlPath) {
|
||||
setPluginXmlUrl(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(pluginXmlPath)));
|
||||
}
|
||||
|
||||
private void setPluginXmlUrl(final String url) {
|
||||
public void setPluginXmlPathAndCreateDescriptorIfDoesntExist(final String pluginXmlPath) {
|
||||
myPluginXmlContainer.getConfiguration().removeConfigFiles(PluginDescriptorConstants.META_DATA);
|
||||
new WriteAction() {
|
||||
protected void run(final Result result) throws Throwable {
|
||||
createDescriptor(url);
|
||||
myPluginXmlPointer = VirtualFilePointerManager.getInstance().create(url, myModule, null);
|
||||
createDescriptor(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(pluginXmlPath)));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class PluginModuleBuildConfEditor implements ModuleConfigurationEditor {
|
||||
DevKitBundle.message("deployment.cleanup", META_INF),
|
||||
null);
|
||||
}
|
||||
myBuildProperties.setPluginXmlPath(newPluginPath);
|
||||
myBuildProperties.setPluginXmlPathAndCreateDescriptorIfDoesntExist(newPluginPath);
|
||||
myBuildProperties.setManifestPath(myManifest.getText());
|
||||
myBuildProperties.setUseUserManifest(myUseUserManifest.isSelected());
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class DevKitInspectionBase extends BaseJavaLocalInspectionTool {
|
||||
|
||||
@Nullable
|
||||
private static Set<PsiClass> checkModule(Module module, PsiClass psiClass, @Nullable Set<PsiClass> types, boolean includeActions) {
|
||||
final XmlFile pluginXml = PluginModuleType.getPluginXml(module, false);
|
||||
final XmlFile pluginXml = PluginModuleType.getPluginXml(module);
|
||||
if (!isPluginXml(pluginXml)) return types;
|
||||
assert pluginXml != null;
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.projectRoots.SdkTypeId;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.idea.devkit.build.PluginBuildConfiguration;
|
||||
import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
|
||||
@@ -40,16 +38,15 @@ public class PluginModuleBuilder extends JavaModuleBuilder{
|
||||
public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException {
|
||||
super.setupRootModel(rootModel);
|
||||
final String defaultPluginXMLLocation = getModuleFileDirectory() + '/' + META_INF + '/' + PLUGIN_XML;
|
||||
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(defaultPluginXMLLocation);
|
||||
if (file == null) {
|
||||
final Module module = rootModel.getModule();
|
||||
StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(new Runnable() {
|
||||
public void run() {
|
||||
final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module);
|
||||
buildConfiguration.createPluginXmlIfNotExist();
|
||||
final Module module = rootModel.getModule();
|
||||
StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(new Runnable() {
|
||||
public void run() {
|
||||
final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module);
|
||||
if (buildConfiguration != null) {
|
||||
buildConfiguration.setPluginXmlPathAndCreateDescriptorIfDoesntExist(defaultPluginXMLLocation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,13 +26,10 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.descriptors.ConfigFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -102,21 +99,13 @@ public class PluginModuleType extends ModuleType<PluginModuleBuilder> {
|
||||
|
||||
@Nullable
|
||||
public static XmlFile getPluginXml(Module module) {
|
||||
return getPluginXml(module, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static XmlFile getPluginXml(Module module, boolean initialize) {
|
||||
if (module == null) return null;
|
||||
if (!(get(module) instanceof PluginModuleType)) return null;
|
||||
|
||||
final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module);
|
||||
if (buildConfiguration == null) return null;
|
||||
final VirtualFilePointer pluginXMLPointer = initialize ? buildConfiguration.getPluginXmlPointer() : buildConfiguration.getStoredPluginXmlPointer();
|
||||
final VirtualFile vFile = pluginXMLPointer != null ? pluginXMLPointer.getFile() : null;
|
||||
if (vFile == null) return null;
|
||||
final PsiFile file = PsiManager.getInstance(module.getProject()).findFile(vFile);
|
||||
return file instanceof XmlFile ? (XmlFile)file : null;
|
||||
final ConfigFile configFile = buildConfiguration.getPluginXmlConfigFile();
|
||||
return configFile != null ? configFile.getXmlFile() : null;
|
||||
}
|
||||
|
||||
public static boolean isPluginModuleOrDependency(@NotNull Module module) {
|
||||
|
||||
Reference in New Issue
Block a user