leftovers

This commit is contained in:
Dmitry Jemerov
2009-09-02 15:42:15 +04:00
parent 21f4b36141
commit 41359f6a5c
17 changed files with 0 additions and 0 deletions
@@ -0,0 +1,12 @@
package com.intellij.openapi.components.impl.stores;
import com.intellij.openapi.project.impl.ProjectStoreClassProvider;
/**
* @author mike
*/
public class IdeaProjectStoreClassProvider implements ProjectStoreClassProvider {
public Class<? extends IComponentStore> getProjectStoreClass(final boolean isDefaultProject) {
return isDefaultProject ? DefaultProjectStoreImpl.class : IdeaProjectStoreImpl.class;
}
}
@@ -0,0 +1,76 @@
package com.intellij.openapi.components.impl.stores;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
import com.intellij.openapi.project.impl.convertors.Convertor01;
import com.intellij.openapi.project.impl.convertors.Convertor12;
import com.intellij.openapi.project.impl.convertors.Convertor23;
import com.intellij.openapi.project.impl.convertors.Convertor34;
import org.jdom.Element;
/**
* @author mike
*/
public class IdeaProjectStoreImpl extends ProjectWithModulesStoreImpl {
public IdeaProjectStoreImpl(final ProjectEx project) {
super(project);
}
protected StateStorageManager createStateStorageManager() {
return new ProjectStateStorageManager(PathMacroManager.getInstance(getComponentManager()).createTrackingSubstitutor(), myProject) {
public XmlElementStorage.StorageData createWsStorageData() {
return new IdeaWsStorageData(ROOT_TAG_NAME, myProject);
}
public XmlElementStorage.StorageData createIprStorageData() {
return new IdeaIprStorageData(ROOT_TAG_NAME, myProject);
}
};
}
private class IdeaWsStorageData extends WsStorageData {
public IdeaWsStorageData(final String rootElementName, final Project project) {
super(rootElementName, project);
}
public IdeaWsStorageData(final WsStorageData storageData) {
super(storageData);
}
public XmlElementStorage.StorageData clone() {
return new IdeaWsStorageData(this);
}
}
private class IdeaIprStorageData extends IprStorageData {
public IdeaIprStorageData(final String rootElementName, Project project) {
super(rootElementName, project);
}
public IdeaIprStorageData(final IprStorageData storageData) {
super(storageData);
}
public XmlElementStorage.StorageData clone() {
return new IdeaIprStorageData(this);
}
protected void convert(final Element root, final int originalVersion) {
if (originalVersion < 1) {
Convertor01.execute(root);
}
if (originalVersion < 2) {
Convertor12.execute(root);
}
if (originalVersion < 3) {
Convertor23.execute(root);
}
if (originalVersion < 4) {
Convertor34.execute(root, myFilePath, getConversionProblemsStorage());
}
}
}
}
@@ -0,0 +1,33 @@
package com.intellij.openapi.project.impl;
import com.intellij.conversion.ConversionService;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.ex.VirtualFileManagerEx;
import org.jetbrains.annotations.Nullable;
import java.io.File;
/**
* @author mike
*/
public class IdeaProjectManagerImpl extends ProjectManagerImpl {
public IdeaProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx) {
super(virtualFileManagerEx);
}
@Nullable
protected Pair<Class, Object> convertProject(final String filePath) throws ProcessCanceledException {
final String fp = canonicalize(filePath);
final File f = new File(fp);
if (fp != null && f.exists() && f.isFile() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
final boolean converted = ConversionService.getInstance().convert(fp);
if (!converted) {
throw new ProcessCanceledException();
}
}
return null;
}
}
@@ -0,0 +1,123 @@
package com.intellij.openapi.project.impl.convertors;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jdom.Element;
import java.util.List;
import java.util.Iterator;
@SuppressWarnings({"HardCodedStringLiteral"})
public class Convertor01 {
private static final String VIRTUAL_FILE_MANAGER_CLASS = "com.intellij.vfs.VirtualFileManager";
private static final String JAR_FILE_SYSTEM_CLASS = "com.intellij.vfs.jar.JarFileSystem";
private static final String PROJECT_ROOT_CONTAINER_CLASS = "com.intellij.project.ProjectRootContainer";
private static final String SOURCE_PATH_ENTRY_ATTRIBUTE = "sourcePathEntry";
private static final String CLASS_PATH_ENTRY_ATTRIBUTE = "classPathEntry";
private static final String OUTPUT_PATH_ENTRY_ATTRIBUTE = "outputPathEntry";
private static final String JAVADOC_PATH_ENTRY_ATTRIBUTE = "javadocPathEntry";
public static void execute(Element root) {
Element rootContComponent = Util.findComponent(root, PROJECT_ROOT_CONTAINER_CLASS);
if (rootContComponent != null) {
for (Iterator iterator = rootContComponent.getChildren("root").iterator(); iterator.hasNext();) {
Element element = (Element)iterator.next();
String url = element.getAttributeValue("file");
if (url != null) {
boolean isJar = url.indexOf("!/") >= 0;
if (isJar) {
url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, url);
}
else {
url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, url);
}
element.setAttribute("file", url);
}
Element propertyElement = new Element("property");
element.addContent(propertyElement);
propertyElement.setAttribute("name", "type");
propertyElement.setAttribute("value", "projectFiles");
}
}
else {
rootContComponent = new Element("component");
root.addContent(rootContComponent);
rootContComponent.setAttribute("class", PROJECT_ROOT_CONTAINER_CLASS);
}
Element vfManComponent = Util.findComponent(root, VIRTUAL_FILE_MANAGER_CLASS);
if (vfManComponent != null) {
for (Iterator iterator = vfManComponent.getChildren("fileSystem").iterator(); iterator.hasNext();) {
Element node = (Element)iterator.next();
String fileSystemClass = node.getAttributeValue("class");
boolean isJar = JAR_FILE_SYSTEM_CLASS.equals(fileSystemClass);
String path = null;
String rootType = null;
List children = node.getChildren();
for (Iterator i = children.iterator(); i.hasNext();) {
Element node1 = (Element)i.next();
if ("root".equals(node1.getName())) {
path = node1.getAttributeValue("path");
}
else if ("attribute".equals(node1.getName())) {
String name = node1.getAttributeValue("name");
if (SOURCE_PATH_ENTRY_ATTRIBUTE.equals(name)) {
rootType = "sourcePathEntry";
}
else if (CLASS_PATH_ENTRY_ATTRIBUTE.equals(name)) {
rootType = "classPathEntry";
}
else if (OUTPUT_PATH_ENTRY_ATTRIBUTE.equals(name)) {
rootType = "outputPath";
}
else if (JAVADOC_PATH_ENTRY_ATTRIBUTE.equals(name)) {
rootType = "javadocPathEntry";
}
/*
else if (EXTERNAL_ATTRIBUTE.equals(name)){
isExternal = true;
}
*/
}
}
String url;
if (isJar) {
path += JarFileSystem.JAR_SEPARATOR;
url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, path);
}
else {
url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, path);
}
Element element = new Element("root");
rootContComponent.addContent(element);
element.setAttribute("file", url);
Element propertyElement = new Element("property");
element.addContent(propertyElement);
propertyElement.setAttribute("name", "type");
if (rootType != null) {
propertyElement.setAttribute("value", rootType);
}
/*
if (isExternal){
propertyElement = document.createElement("property");
element.appendChild(propertyElement);
propertyElement.setAttribute("name", ProjectRoot.PROP_EXTERNAL);
}
*/
}
root.removeContent(vfManComponent);
}
}
}
@@ -0,0 +1,16 @@
package com.intellij.openapi.project.impl.convertors;
import org.jdom.Element;
@SuppressWarnings({"HardCodedStringLiteral"})
public class Convertor12 {
private static final String OLD_PROJECT_ROOT_CONTAINER_CLASS = "com.intellij.project.ProjectRootContainer";
private static final String NEW_PROJECT_ROOT_CONTAINER_CLASS = "com.intellij.projectRoots.ProjectRootContainer";
public static void execute(Element root) {
Element rootContComponent = Util.findComponent(root, OLD_PROJECT_ROOT_CONTAINER_CLASS);
if (rootContComponent != null) {
rootContComponent.setAttribute("class", NEW_PROJECT_ROOT_CONTAINER_CLASS);
}
}
}
@@ -0,0 +1,96 @@
package com.intellij.openapi.project.impl.convertors;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jdom.Element;
import java.util.Iterator;
/**
* @author mike
*/
@SuppressWarnings({"HardCodedStringLiteral"})
public class Convertor23 {
private static final String PROJECT_ROOT_CONTAINER_CLASS = "com.intellij.projectRoots.ProjectRootContainer";
public static void execute(Element root) {
Element rootContComponent = Util.findComponent(root, PROJECT_ROOT_CONTAINER_CLASS);
if (rootContComponent != null) {
rootContComponent.setAttribute("class", ProjectRootManager.class.getName());
}
convertCompilerConfiguration(root);
}
private static final String COMPILER_CONFIGURATION_CLASS = "com.intellij.openapi.compiler.Compiler";
private static final String COMPILER_CONFIGURATION_COMPONENT = "CompilerConfiguration";
private static final String COMPILER_WORKSPACE_CONFIGURATION_COMPONENT = "CompilerWorkspaceConfiguration";
private static final String ATTR_CLASS = "class";
private static final String ATTR_OPTION = "option";
private static final String ATTR_NAME = "name";
private static final String ATTR_VALUE = "value";
private static final String ATTR_PATH = "path";
private static final String ATTR_URL = "url";
private static final String ATTR_EXCLUDE_FROM_COMPILE = "excludeFromCompile";
public static void convertCompilerConfiguration(Element root){
String compileInBackgroundValue = null;
Element component = Util.findComponent(root, COMPILER_CONFIGURATION_CLASS);
if(component != null){
component.setAttribute(ATTR_NAME, COMPILER_CONFIGURATION_COMPONENT);
component.removeAttribute(ATTR_CLASS);
for(Iterator children = component.getChildren().iterator(); children.hasNext();){
Element element = (Element)children.next();
String elementName = element.getName();
if(ATTR_OPTION.equals(elementName)){
String name = element.getAttributeValue(ATTR_NAME);
if(name != null){
if(name.equals("COMPILE_IN_BACKGROUND")){
compileInBackgroundValue = element.getAttributeValue(ATTR_VALUE);
}
}
}
else if (ATTR_EXCLUDE_FROM_COMPILE.equals(elementName)){
for(Iterator excludeIterator = element.getChildren().iterator(); excludeIterator.hasNext();){
Element excludeElement = (Element)excludeIterator.next();
String path = excludeElement.getAttributeValue(ATTR_PATH);
if(path != null){
String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, path);
excludeElement.removeAttribute(ATTR_PATH);
excludeElement.setAttribute(ATTR_URL, url);
}
}
}
}
}
if(compileInBackgroundValue != null){
component = Util.findComponent(root, COMPILER_WORKSPACE_CONFIGURATION_COMPONENT);
if(component == null){
component = new Element("component");
component.setAttribute(ATTR_NAME, COMPILER_WORKSPACE_CONFIGURATION_COMPONENT);
root.addContent(component);
}
boolean added = false;
for(Iterator children = component.getChildren().iterator(); children.hasNext();){
Element element = (Element)children.next();
String elementName = element.getName();
if(ATTR_OPTION.equals(elementName)){
String name = element.getAttributeValue(ATTR_NAME);
if(name != null){
if(name.equals("COMPILE_IN_BACKGROUND")){
element.setAttribute(ATTR_VALUE, compileInBackgroundValue);
added = true;
}
}
}
}
if(!added){
Element compileInBackgroundElement = new Element(ATTR_OPTION);
compileInBackgroundElement.setAttribute(ATTR_NAME, "COMPILE_IN_BACKGROUND");
compileInBackgroundElement.setAttribute(ATTR_VALUE, compileInBackgroundValue);
component.addContent(compileInBackgroundElement);
}
}
}
}
@@ -0,0 +1,755 @@
package com.intellij.openapi.project.impl.convertors;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.projectRoots.impl.ProjectRootUtil;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
/**
* @author max, dsl
*/
public class Convertor34 {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.project.impl.convertors.Convertor34");
@NonNls public static final String PROJECT_ROOT_MANAGER = "ProjectRootManager";
@NonNls public static final String PROJECT_ROOT_MANAGER_CLASS = "com.intellij.openapi.projectRoots.ProjectRootManager";
private static final String SOURCE_ROOTS_NOT_UNDER_PROJECT_ROOTS = ProjectBundle.message("project.convert.source.roots.not.under.project.roots.error");
private static final String JAVA_DOC_ROOTS_CANNOT_BE_CONVERTED = ProjectBundle.message("project.convert.javadoc.paths.error");
private static final String MULTIPLE_OUTPUT_PATHS = ProjectBundle.message("project.convert.multiple.output.paths.error");
public static void execute(Element root, String filePath, ArrayList<String> conversionProblems) {
if (filePath == null) return;
if (conversionProblems == null) {
conversionProblems = new ArrayList<String>();
}
convertProjectFile(root, filePath, conversionProblems);
}
@SuppressWarnings({"HardCodedStringLiteral"})
public static String convertLibraryTable34(Element root, String filePath) {
if (filePath == null) return null;
final Element libraryTable = findNamedChild(root, "component", "ProjectLibraryTable");
if (libraryTable == null) return null;
final Element applicationLibraryTable = new Element("component");
applicationLibraryTable.setAttribute("name", "libraryTable");
final List oldLibraries = libraryTable.getChildren("library");
for (int i = 0; i < oldLibraries.size(); i++) {
Element oldLibrary = (Element)oldLibraries.get(i);
Element newLibrary = convertLibrary(oldLibrary);
applicationLibraryTable.addContent(newLibrary);
}
final String ioFilePath = filePath.replace('/', File.separatorChar);
String parentPath = new File(ioFilePath).getParent();
if (parentPath == null) parentPath = ".";
parentPath += "/applicationLibraries.xml";
final Element newRoot = new Element("application");
newRoot.addContent(applicationLibraryTable);
final Document libraryTableDocument = new Document(newRoot);
try {
JDOMUtil.writeDocument(libraryTableDocument, parentPath, "\n");
}
catch (IOException e) {
LOG.error(e);
return null;
}
return parentPath;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element convertLibrary(Element oldLibrary) {
final Element library = new Element("library");
final Element nameChild = oldLibrary.getChild("name");
LOG.assertTrue(nameChild != null);
library.setAttribute("name", nameChild.getAttributeValue("value"));
processLibraryRootContainer(oldLibrary, library, "CLASSES", "classPath");
processLibraryRootContainer(oldLibrary, library, "JAVADOC", "javadocPath");
processLibraryRootContainer(oldLibrary, library, "SOURCES", "sourcePath");
return library;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void processLibraryRootContainer(Element oldLibrary,
final Element library,
String newElementType,
String oldElementType) {
final Element elementCLASSES = new Element(newElementType);
final Element rootsElement = oldLibrary.getChild("roots");
final Element classPath = rootsElement.getChild(oldElementType);
if (classPath != null) {
processRootTypeElement(classPath, new SimpleRootProcessor(elementCLASSES));
}
library.addContent(elementCLASSES);
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void convertProjectFile(Element root, String filePath, ArrayList<String> conversionProblems) {
Element rootComponent = null;
List components = root.getChildren("component");
for (final Object component1 : components) {
Element component = (Element)component1;
if (isProjectRootManager(component)) rootComponent = component;
}
if (rootComponent == null) return;
Element module = createModule(root);
final String moduleFilePath = filePath.substring(0, filePath.lastIndexOf('.')) + ModuleFileType.DOT_DEFAULT_EXTENSION;
Element moduleRootComponent = convertProjectRootManager(rootComponent, conversionProblems);
module.addContent(moduleRootComponent);
Document moduleDoc = new Document(module);
try {
JDOMUtil.writeDocument(moduleDoc, moduleFilePath, "\n");
}
catch (IOException e) {
LOG.error(e);
}
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(moduleFilePath));
rootComponent.setAttribute("name", "ProjectRootManager");
rootComponent.setAttribute("version", "4");
Element moduleManager = new Element("component");
moduleManager.setAttribute("name", "ProjectModuleManager");
addModule(moduleFilePath, moduleManager);
String moduleFile = new File(moduleFilePath).getName();
convertWebApps(moduleManager, root, rootComponent, moduleFile.substring(0, moduleFile.lastIndexOf('.')));
root.addContent(moduleManager);
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element createModule(Element root) {
Element module = new Element("module");
module.setAttribute("version", "4");
String relativePaths = root.getAttributeValue("relativePaths");
if (relativePaths != null) {
module.setAttribute("relativePaths", relativePaths);
}
return module;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void convertWebApps(Element moduleManager, Element projectElement, Element projectRootManager, String mainModule) {
Element webRootContainer = findNamedChild(projectElement, "component", "WebRootContainer");
if(webRootContainer == null) return;
List roots = webRootContainer.getChildren("root");
for (Iterator iterator = roots.iterator(); iterator.hasNext();) {
Element root = (Element)iterator.next();
String name = root.getAttributeValue("name");
String url = root.getAttributeValue("url");
if(name == null || url == null) continue;
String filepath = VirtualFileManager.extractPath(url);
VirtualFile moduleDirectory = LocalFileSystem.getInstance().findFileByPath(filepath);
if(moduleDirectory != null) {
Element module = createModule(projectElement);
module.setAttribute("type", "J2EE_WEB_MODULE");
Element rootManager = createWebModuleRootManager(module, moduleDirectory, projectRootManager, mainModule);
module.addContent(rootManager);
Element buildComponent = createWebModuleBuildComponent();
module.addContent(buildComponent);
Element moduleProperties = createWebModuleProperties(moduleDirectory);
module.addContent(moduleProperties);
Document moduleDocument = new Document(module);
String moduleName = (!"".equals(name) ? name : moduleDirectory.getName());
if(moduleName.equals(mainModule)) moduleName = "web" + moduleName;
try {
final String modulePath = moduleDirectory.getPath() + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
JDOMUtil.writeDocument(moduleDocument, modulePath, "\n");
addModule(modulePath, moduleManager);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(modulePath));
}
});
}
catch (IOException e) {
LOG.error(e);
}
}
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void addSetting(Element parent, String name, String value){
Element option = new Element("setting");
option.setAttribute("name", name);
option.setAttribute("value", value);
parent.addContent(option);
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element createWebModuleProperties(VirtualFile moduleDirectory) {
Element component = new Element("component");
component.setAttribute("name", "WebModuleProperties");
try {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(new File(moduleDirectory.getPath(), "WEB-INF/web.xml")));
writer.write(FileTemplateManager.getInstance().getJ2eeTemplate("web.2_3.xml").getText());
}
finally {
if (writer != null) {
writer.close();
}
}
}
catch (IOException e) {
LOG.error(e);
}
Element webRoots = new Element("webroots");
component.addContent(webRoots);
Element root = new Element("root");
webRoots.addContent(root);
root.setAttribute("url", moduleDirectory.getUrl());
root.setAttribute("relative", "/");
return component;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element createWebModuleBuildComponent() {
Element component = new Element("component");
component.setAttribute("name", "WebModuleBuildComponent");
addSetting(component, "EXPLODED_URL", "file://$MODULE_DIR$");
addSetting(component, "EXPLODED_ENABLED", "true");
return component;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element createWebModuleRootManager(Element module, VirtualFile moduleDirectory, Element projectRootManager, String mainModule) {
Element newModuleRootManager = new Element("component");
newModuleRootManager.setAttribute("name", "NewModuleRootManager");
Element jdk = projectRootManager.getChild("jdk");
if(jdk != null) {
String jdkName = jdk.getAttributeValue("name");
if (jdkName != null) {
Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "jdk");
orderEntry.setAttribute("jdkName", jdkName);
newModuleRootManager.addContent(orderEntry);
}
}
Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "module");
orderEntry.setAttribute("module-name", mainModule);
newModuleRootManager.addContent(orderEntry);
Element output = new Element("output");
output.setAttribute("url", "file://" + getModulePath("classes", moduleDirectory.getPath()));
newModuleRootManager.addContent(output);
Element content = new Element("content");
content.setAttribute("url", "file://" + getModulePath("", moduleDirectory.getPath()));
newModuleRootManager.addContent(content);
VirtualFile classesDir = moduleDirectory.findFileByRelativePath("WEB-INF/classes");
if(classesDir != null) {
Element classes = createLibraryEntry(classesDir, module, moduleDirectory);
newModuleRootManager.addContent(classes);
}
VirtualFile lib = moduleDirectory.findFileByRelativePath("WEB-INF/lib");
if(lib != null) {
for (VirtualFile virtualFile : lib.getChildren()) {
Element libEntry = createLibraryEntry(virtualFile, module, moduleDirectory);
newModuleRootManager.addContent(libEntry);
}
}
return newModuleRootManager;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element createLibraryEntry(VirtualFile file, Element module, VirtualFile moduleDirectory) {
String path = file.getPath().substring(moduleDirectory.getPath().length() + 1);
if(file.getFileSystem() instanceof JarFileSystem) {
path = path + "!/";
}
Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "module-library");
Element library = new Element("library");
orderEntry.addContent(library);
Element classes = new Element("CLASSES");
library.addContent(classes);
Element root = new Element("root");
root.setAttribute("url", "file://" + getModulePath(path, moduleDirectory.getPath()));
classes.addContent(root);
return orderEntry;
}
private static String getModulePath(String path, String moduleDirectory) {
return "".equals(path) ? moduleDirectory : moduleDirectory + "/" + path;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void addModule(final String moduleFilePath, Element moduleManager) {
Element moduleEntry = new Element("module");
final String moduleVfsPath = moduleFilePath.replace(File.separatorChar, '/');
moduleEntry.setAttribute("filepath", moduleVfsPath);
moduleEntry.setAttribute("fileurl", "file://" +moduleVfsPath);
Element modulesEntry = moduleManager.getChild("modules");
if(modulesEntry == null) {
modulesEntry = new Element("modules");
moduleManager.addContent(modulesEntry);
}
modulesEntry.addContent(moduleEntry);
}
private static Element convertProjectRootManager(Element projectRootManager, ArrayList<String> conversionProblems) {
return new ProjectToModuleConverter(projectRootManager, conversionProblems).getModuleRootManager();
}
private static interface RootElementProcessor {
void processSimpleRoot(Element root);
void processJdkRoot(Element root);
void processOutputRoot(Element root);
void processExcludedOutputRoot(Element root);
void processLibraryRoot(Element root);
void processEjbRoot(Element root);
}
private static abstract class EmptyRootProcessor implements RootElementProcessor {
public void processSimpleRoot(Element root) {
cannotProcess(root);
}
public void processJdkRoot(Element root) {
cannotProcess(root);
}
public void processOutputRoot(Element root) {
cannotProcess(root);
}
public void processExcludedOutputRoot(Element root) {
cannotProcess(root);
}
public void processLibraryRoot(Element root) {
cannotProcess(root);
}
public void processEjbRoot(Element root) {
cannotProcess(root);
}
@SuppressWarnings({"HardCodedStringLiteral"})
protected void cannotProcess(Element root) {
LOG.error("Cannot process roots of type " + root.getAttributeValue("type") + " in " + classId());
}
abstract protected String classId();
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void processRoot(Element root, RootElementProcessor processor) {
LOG.assertTrue("root".equals(root.getName()));
final String type = root.getAttributeValue("type");
LOG.assertTrue(type != null);
if (ProjectRootUtil.SIMPLE_ROOT.equals(type)) {
processor.processSimpleRoot(root);
}
else if (ProjectRootUtil.OUTPUT_ROOT.equals(type)) {
processor.processOutputRoot(root);
}
else if (ProjectRootUtil.JDK_ROOT.equals(type)) {
processor.processJdkRoot(root);
}
else if (ProjectRootUtil.EXCLUDED_OUTPUT.equals(type)) {
processor.processExcludedOutputRoot(root);
}
else if (ProjectRootUtil.LIBRARY_ROOT.equals(type)) {
processor.processLibraryRoot(root);
}
else if (ProjectRootUtil.EJB_ROOT.equals(type)) {
processor.processEjbRoot(root);
}
else if (ProjectRootUtil.COMPOSITE_ROOT.equals(type)) {
final List children = root.getChildren("root");
for (int i = 0; i < children.size(); i++) {
Element element = (Element)children.get(i);
processRoot(element, processor);
}
}
else {
LOG.error("Unknown root type: " + type);
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static void processRootTypeElement(Element rootTypeElement, RootElementProcessor rootProcessor) {
if (rootTypeElement == null) return;
final List children = rootTypeElement.getChildren("root");
for (int i = 0; i < children.size(); i++) {
Element element = (Element)children.get(i);
processRoot(element, rootProcessor);
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static class ProjectToModuleConverter {
private final Element myProjectRootManager;
private final Element myModuleRootManager;
private final ArrayList<String> myProjectRoots;
private final List<String> mySourceFolders;
private final ArrayList<String> myExcludeFolders;
private final ArrayList<String> myDetectedProblems;
private ProjectToModuleConverter(Element projectRootManager, ArrayList<String> problems) {
myProjectRootManager = projectRootManager;
myModuleRootManager = new Element("component");
myModuleRootManager.setAttribute("name", "NewModuleRootManager");
myProjectRoots = new ArrayList<String>();
myDetectedProblems = problems;
final Element projectPath = projectRootManager.getChild("projectPath");
if(projectPath != null) {
processRootTypeElement(projectPath, new ProjectRootProcessor());
}
Collections.sort(myProjectRoots);
for (int i = 0; i < myProjectRoots.size(); i++) {
String path = myProjectRoots.get(i);
final int next = i + 1;
while (next < myProjectRoots.size() && myProjectRoots.get(next).startsWith(path)) {
myProjectRoots.remove(next);
}
}
final Element sourcePath = projectRootManager.getChild("sourcePath");
mySourceFolders = new ArrayList<String>();
processRootTypeElement(sourcePath, new SourceRootProcessor());
final Element excludePath = projectRootManager.getChild("excludePath");
myExcludeFolders = new ArrayList<String>();
processRootTypeElement(excludePath, new ExcludeRootsProcessor());
Element javadocPath = projectRootManager.getChild("javadocPath");
processRootTypeElement(javadocPath, new JavaDocRootProcessor());
final Element patternExcludeFolder = new Element("excludeFolder");
final Element patternSourceFolder = new Element("sourceFolder");
patternSourceFolder.setAttribute("isTestSource", "false");
Map<String, List<String>> contentToSource = dispatchFolders(myProjectRoots, mySourceFolders);
final Map<String, List<String>> contentToExclude = dispatchFolders(myProjectRoots, myExcludeFolders);
for (String root : myProjectRoots) {
final Element contentElement = new Element("content");
contentElement.setAttribute("url", root);
createFolders(contentElement, patternSourceFolder, contentToSource.get(root));
createFolders(contentElement, patternExcludeFolder, contentToExclude.get(root));
myModuleRootManager.addContent(contentElement);
}
final Element classPath = projectRootManager.getChild("classPath");
processRootTypeElement(classPath, new ClassPathRootProcessor());
final Element projectElement = (Element)myProjectRootManager.getParent();
final Element compilerConfigurationElement = findNamedChild(projectElement, "component", "CompilerConfiguration");
if (compilerConfigurationElement != null) {
final Element option = findNamedChild(compilerConfigurationElement, "option", "DEFAULT_OUTPUT_PATH");
final String path = option == null ? null : option.getAttributeValue("value");
if (path != null) {
final String url = "file://" + path;
final Element outputElement = new Element("output");
outputElement.setAttribute("url", url);
myModuleRootManager.addContent(outputElement);
final Element outputTestElement = new Element("output-test");
outputTestElement.setAttribute("url", url);
myModuleRootManager.addContent(outputTestElement);
}
// check for multiple outputs
{
final Element outputMode = findNamedChild(compilerConfigurationElement, "option", "OUTPUT_MODE");
final String attributeValue = outputMode != null ? outputMode.getAttributeValue("value") : "";
if ("multiple".equals(attributeValue)) {
addProblem(MULTIPLE_OUTPUT_PATHS);
}
}
}
final Element excludeOutput = myProjectRootManager.getChild("exclude_output");
if (excludeOutput != null) {
final String enabled = excludeOutput.getAttributeValue("enabled");
if ("yes".equals(enabled) || "true".equals(enabled)) {
myModuleRootManager.addContent(new Element("exclude-output"));
}
}
}
private static void createFolders(final Element contentElement,
final Element patternFolderElement,
final List<String> folders) {
for (String folder : folders) {
Element folderElement = (Element)patternFolderElement.clone();
folderElement.setAttribute("url", folder);
contentElement.addContent(folderElement);
}
}
private static Map<String, List<String>> dispatchFolders(ArrayList<String> projectRoots, List<String> folders) {
final Map<String, List<String>> result = new HashMap<String, List<String>>();
for (String root : projectRoots) {
final ArrayList<String> foldersForRoot = new ArrayList<String>();
result.put(root, foldersForRoot);
for (Iterator<String> iterator1 = folders.iterator(); iterator1.hasNext();) {
String folder = iterator1.next();
if (folder.startsWith(root)) {
foldersForRoot.add(folder);
}
}
Collections.sort(foldersForRoot);
}
return result;
}
public Element getModuleRootManager() { return myModuleRootManager; }
@SuppressWarnings({"HardCodedStringLiteral"})
private class JavaDocRootProcessor extends EmptyRootProcessor {
protected void cannotProcess(Element root) {
addProblem(JAVA_DOC_ROOTS_CANNOT_BE_CONVERTED);
}
protected String classId() {
return "JavaDocRootProcessor";
}
}
private class ProjectRootProcessor extends EmptyRootProcessor {
public void processSimpleRoot(Element root) {
final String value = root.getAttributeValue("url");
myProjectRoots.add(value);
}
public void processEjbRoot(Element root) {
// todo[cdr,dsl] implement conversion of EJB roots
}
protected String classId() {
return "ProjectRootProcessor";
}
}
private void addProblem(final String description) {
if (!myDetectedProblems.contains(description)) {
myDetectedProblems.add(description);
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private class SourceRootProcessor extends EmptyRootProcessor {
public void processSimpleRoot(Element root) {
final String url = root.getAttributeValue("url");
boolean found = false;
for (int i = 0; i < myProjectRoots.size(); i++) {
String projectPath = myProjectRoots.get(i);
if (url.startsWith(projectPath)) {
mySourceFolders.add(url);
found = true;
break;
}
else if (projectPath.startsWith(url)) {
myProjectRoots.remove(i);
myProjectRoots.add(i, url);
mySourceFolders.add(url);
found = true;
break;
}
}
if (!found) {
addProblem(SOURCE_ROOTS_NOT_UNDER_PROJECT_ROOTS);
}
}
public void processJdkRoot(Element root) {
}
public void processLibraryRoot(Element root) {
}
public void processEjbRoot(Element root) {
// todo[cdr,dsl] implement conversion of EJB roots
}
protected String classId() {
return "SourceRootProcessor";
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private class ExcludeRootsProcessor extends EmptyRootProcessor {
public void processSimpleRoot(Element root) {
final String url = root.getAttributeValue("url");
for (int i = 0; i < myProjectRoots.size(); i++) {
String projectRoot = myProjectRoots.get(i);
if (url.startsWith(projectRoot)) {
myExcludeFolders.add(url);
}
}
}
public void processEjbRoot(Element root) {
// todo[cdr,dsl] implement conversion of EJB roots
}
protected String classId() {
return "ExcludeRootsProcessor";
}
public void processJdkRoot(Element root) {
// [dsl]: fix for SCR24517
// [dsl]: I have no idea how such project can be configured in Ariadna,
// [dsl]: and what does it mean, but such projects do exist....
}
public void processExcludedOutputRoot(Element root) {
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private class ClassPathRootProcessor extends EmptyRootProcessor {
public void processSimpleRoot(Element root) {
final Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "module-library");
final Element libraryElement = new Element("library");
final Element classesElement = new Element("CLASSES");
final Element rootElement = new Element("root");
rootElement.setAttribute((Attribute)root.getAttribute("url").clone());
classesElement.addContent(rootElement);
libraryElement.addContent(classesElement);
orderEntry.addContent(libraryElement);
myModuleRootManager.addContent(orderEntry);
}
public void processJdkRoot(Element root) {
final Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "jdk");
orderEntry.setAttribute("jdkName", root.getAttributeValue("name"));
myModuleRootManager.addContent(orderEntry);
}
public void processLibraryRoot(Element root) {
final String libraryName = root.getAttributeValue("name");
final Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "library");
orderEntry.setAttribute("name", libraryName);
orderEntry.setAttribute("level", LibraryTablesRegistrar.APPLICATION_LEVEL);
myModuleRootManager.addContent(orderEntry);
}
public void processEjbRoot(Element root) {
// todo[cdr,dsl] implement conversion of EJB roots
}
protected String classId() {
return "ClassPathProcessor";
}
public void processOutputRoot(Element root) {
final Element orderEntry = new Element("orderEntry");
orderEntry.setAttribute("type", "sourceFolder");
myModuleRootManager.addContent(orderEntry);
}
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static boolean isProjectRootManager(Element component) {
String compName = component.getAttributeValue("name");
String compClass = component.getAttributeValue("class");
return compName != null && compName.equals(PROJECT_ROOT_MANAGER) ||
compClass != null && compClass.equals(PROJECT_ROOT_MANAGER_CLASS);
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static Element findNamedChild(Element root, String name, String nameAttributeValue) {
final List children = root.getChildren(name);
for (int i = 0; i < children.size(); i++) {
Element e = (Element)children.get(i);
if (nameAttributeValue.equals(e.getAttributeValue("name"))) {
return e;
}
}
return null;
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static class SimpleRootProcessor extends EmptyRootProcessor {
private final Element myTargetElement;
public SimpleRootProcessor(Element targetElement) {
myTargetElement = targetElement;
}
public void processSimpleRoot(Element root) {
final String url = root.getAttributeValue("url");
final Element newRoot = new Element("root");
newRoot.setAttribute("url", url);
myTargetElement.addContent(newRoot);
}
public void processEjbRoot(Element root) {
// todo[cdr,dsl] implement conversion of EJB roots
}
protected String classId() {
return "SimpleRootProcessor";
}
}
}
@@ -0,0 +1,19 @@
package com.intellij.openapi.project.impl.convertors;
import org.jdom.Element;
import java.util.Iterator;
class Util {
@SuppressWarnings({"HardCodedStringLiteral"})
static Element findComponent(Element root, String className) {
for (Iterator iterator = root.getChildren("component").iterator(); iterator.hasNext();) {
Element element = (Element)iterator.next();
String className1 = element.getAttributeValue("class");
if (className1 != null && className1.equals(className)) {
return element;
}
}
return null;
}
}
@@ -0,0 +1,15 @@
package com.intellij.openapi.keymap;
import com.intellij.openapi.keymap.impl.BundledKeymapProvider;
import java.util.Arrays;
import java.util.List;
/**
* @author yole
*/
public class JBuilderKeymapProvider implements BundledKeymapProvider {
public List<String> getKeymapFileNames() {
return Arrays.asList("JBuilderKeymap.xml");
}
}
@@ -0,0 +1,317 @@
/*
* User: anna
* Date: 27-Dec-2007
*/
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerListener;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.util.ArrayUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class CompilerModuleExtensionImpl extends CompilerModuleExtension {
@NonNls private static final String OUTPUT_TAG = "output";
@NonNls private static final String TEST_OUTPUT_TAG = "output-test";
@NonNls private static final String ATTRIBUTE_URL = "url";
@NonNls private static final String INHERIT_COMPILER_OUTPUT = "inherit-compiler-output";
@NonNls private static final String EXCLUDE_OUTPUT_TAG = "exclude-output";
private String myCompilerOutput;
private VirtualFilePointer myCompilerOutputPointer;
private String myCompilerOutputForTests;
private VirtualFilePointer myCompilerOutputPathForTestsPointer;
private boolean myInheritedCompilerOutput = true;
private boolean myExcludeOutput = true;
private final Module myModule;
private CompilerModuleExtensionImpl mySource;
private boolean myWritable;
private boolean myDisposed;
public CompilerModuleExtensionImpl(@NotNull final Module module) {
myModule = module;
}
public CompilerModuleExtensionImpl(final CompilerModuleExtensionImpl source, final boolean writable) {
this(source.myModule);
myWritable = writable;
myCompilerOutput = source.myCompilerOutput;
myCompilerOutputPointer = duplicatePointer(source.myCompilerOutputPointer);
myCompilerOutputForTests = source.myCompilerOutputForTests;
myCompilerOutputPathForTestsPointer = duplicatePointer(source.myCompilerOutputPathForTestsPointer);
myInheritedCompilerOutput = source.myInheritedCompilerOutput;
myExcludeOutput = source.myExcludeOutput;
mySource = source;
}
private VirtualFilePointer duplicatePointer(VirtualFilePointer pointer) {
if (pointer == null) return null;
final VirtualFilePointerListener listener =
((ProjectRootManagerImpl)ProjectRootManager.getInstance(myModule.getProject())).getVirtualFilePointerListener();
final VirtualFilePointerManager filePointerManager = VirtualFilePointerManager.getInstance();
return filePointerManager.duplicate(pointer, this, listener);
}
public void readExternal(final Element element) throws InvalidDataException {
assert !myDisposed;
final String value = element.getAttributeValue(INHERIT_COMPILER_OUTPUT);
myInheritedCompilerOutput = value != null && Boolean.parseBoolean(value);
myExcludeOutput = element.getChild(EXCLUDE_OUTPUT_TAG) != null;
myCompilerOutputPointer = getOutputPathValue(element, OUTPUT_TAG, !myInheritedCompilerOutput);
myCompilerOutput = getOutputPathValue(element, OUTPUT_TAG);
myCompilerOutputPathForTestsPointer = getOutputPathValue(element, TEST_OUTPUT_TAG, !myInheritedCompilerOutput);
myCompilerOutputForTests = getOutputPathValue(element, TEST_OUTPUT_TAG);
}
public void writeExternal(final Element element) throws WriteExternalException {
assert !myDisposed;
if (myCompilerOutput != null) {
final Element pathElement = new Element(OUTPUT_TAG);
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutput);
element.addContent(pathElement);
}
if (myCompilerOutputForTests != null) {
final Element pathElement = new Element(TEST_OUTPUT_TAG);
pathElement.setAttribute(ATTRIBUTE_URL, myCompilerOutputForTests);
element.addContent(pathElement);
}
element.setAttribute(INHERIT_COMPILER_OUTPUT, String.valueOf(myInheritedCompilerOutput));
if (myExcludeOutput) {
element.addContent(new Element(EXCLUDE_OUTPUT_TAG));
}
}
@Nullable
protected VirtualFilePointer getOutputPathValue(Element element, String tag, final boolean createPointer) {
final Element outputPathChild = element.getChild(tag);
VirtualFilePointer vptr = null;
if (outputPathChild != null && createPointer) {
String outputPath = outputPathChild.getAttributeValue(ATTRIBUTE_URL);
vptr = createPointer(outputPath);
}
return vptr;
}
@Nullable
protected static String getOutputPathValue(Element element, String tag) {
final Element outputPathChild = element.getChild(tag);
if (outputPathChild != null) {
return outputPathChild.getAttributeValue(ATTRIBUTE_URL);
}
return null;
}
@Nullable
public VirtualFile getCompilerOutputPath() {
if (myInheritedCompilerOutput) {
final VirtualFile projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutput();
if (projectOutputPath == null) return null;
return projectOutputPath.findFileByRelativePath(PRODUCTION + "/" + getModule().getName());
}
return myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getFile();
}
@Nullable
public VirtualFile getCompilerOutputPathForTests() {
if (myInheritedCompilerOutput) {
final VirtualFile projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutput();
if (projectOutputPath == null) return null;
return projectOutputPath.findFileByRelativePath(TEST + "/" + getModule().getName());
}
return myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getFile();
}
@Nullable
public String getCompilerOutputUrl() {
if (myInheritedCompilerOutput) {
final String projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutputUrl();
if (projectOutputPath == null) return null;
return projectOutputPath + "/" + PRODUCTION + "/" + getModule().getName();
}
return myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getUrl();
}
@Nullable
public String getCompilerOutputUrlForTests() {
if (myInheritedCompilerOutput) {
final String projectOutputPath = CompilerProjectExtension.getInstance(getProject()).getCompilerOutputUrl();
if (projectOutputPath == null) return null;
return projectOutputPath + "/" + TEST + "/" + getModule().getName();
}
return myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getUrl();
}
public void setCompilerOutputPath(final VirtualFile file) {
setCompilerOutputPath(file == null ? null : file.getUrl());
}
private VirtualFilePointer createPointer(final String url) {
final VirtualFilePointerListener listener =
((ProjectRootManagerImpl)ProjectRootManager.getInstance(myModule.getProject())).getVirtualFilePointerListener();
return VirtualFilePointerManager.getInstance().create(url, this, listener);
}
public void setCompilerOutputPath(final String url) {
assertWritable();
myCompilerOutput = url;
myCompilerOutputPointer = url == null ? null : createPointer(url);
}
public void setCompilerOutputPathForTests(final VirtualFile file) {
setCompilerOutputPathForTests(file == null ? null : file.getUrl());
}
public void setCompilerOutputPathForTests(final String url) {
assertWritable();
myCompilerOutputForTests = url;
myCompilerOutputPathForTestsPointer = url == null ? null : createPointer(url);
}
public Module getModule() {
return myModule;
}
public Project getProject() {
return myModule.getProject();
}
public void inheritCompilerOutputPath(final boolean inherit) {
assertWritable();
myInheritedCompilerOutput = inherit;
}
private void assertWritable() {
assert myWritable: "Writable model can be retrieved from writable ModifiableRootModel";
}
public boolean isCompilerOutputPathInherited() {
return myInheritedCompilerOutput;
}
public VirtualFilePointer getCompilerOutputPointer() {
return myCompilerOutputPointer;
}
public VirtualFilePointer getCompilerOutputForTestsPointer() {
return myCompilerOutputPathForTestsPointer;
}
public void setExcludeOutput(final boolean exclude) {
assertWritable();
myExcludeOutput = exclude;
}
public boolean isExcludeOutput() {
return myExcludeOutput;
}
public CompilerModuleExtension getModifiableModel(final boolean writable) {
assert !myDisposed;
return new CompilerModuleExtensionImpl(this, writable);
}
public void commit() {
if (mySource != null) {
mySource.myCompilerOutput = myCompilerOutput;
boolean old = mySource.myWritable;
mySource.myWritable = true;
mySource.setCompilerOutputPath(myCompilerOutputPointer == null ? null : myCompilerOutputPointer.getUrl());
mySource.myCompilerOutputForTests = myCompilerOutputForTests;
mySource.setCompilerOutputPathForTests(myCompilerOutputPathForTestsPointer == null ? null : myCompilerOutputPathForTestsPointer.getUrl());
mySource.myInheritedCompilerOutput = myInheritedCompilerOutput;
mySource.myExcludeOutput = myExcludeOutput;
mySource.myWritable = old;
}
}
public boolean isChanged() {
if (myInheritedCompilerOutput != mySource.myInheritedCompilerOutput) {
return true;
}
if (!myInheritedCompilerOutput) {
if (!vptrEqual(myCompilerOutputPointer, mySource.myCompilerOutputPointer)) {
return true;
}
if (!vptrEqual(myCompilerOutputPathForTestsPointer, mySource.myCompilerOutputPathForTestsPointer)) {
return true;
}
}
return myExcludeOutput != mySource.myExcludeOutput;
}
private static boolean vptrEqual(VirtualFilePointer p1, VirtualFilePointer p2) {
return Comparing.equal(p1 == null ? null : p1.getUrl(), p2 == null ? null : p2.getUrl());
}
public void dispose() {
myDisposed = true;
mySource = null;
myCompilerOutput = null;
myCompilerOutputForTests = null;
}
@Nullable
@Override
public VirtualFile[] getRootPaths(final OrderRootType type) {
if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) ||
OrderRootType.COMPILATION_CLASSES.equals(type) ||
OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) {
final ArrayList<VirtualFile> result = new ArrayList<VirtualFile>();
VirtualFile outputRoot = getCompilerOutputPath();
if (outputRoot != null) result.add(outputRoot);
if (!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) {
final VirtualFile outputPathForTests = getCompilerOutputPathForTests();
if (outputPathForTests != null && !outputPathForTests.equals(outputRoot)) {
result.add(outputPathForTests);
}
}
return result.toArray(new VirtualFile[result.size()]);
}
return null;
}
@Override
public String[] getRootUrls(final OrderRootType type) {
if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) ||
OrderRootType.COMPILATION_CLASSES.equals(type) ||
OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) {
final List<String> result = new ArrayList<String>();
String outputRoot = getCompilerOutputUrl();
if (outputRoot != null) result.add(outputRoot);
if (!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) {
final String outputPathForTests = getCompilerOutputUrlForTests();
if (outputPathForTests != null && !outputPathForTests.equals(outputRoot)) {
result.add(outputPathForTests);
}
}
return ArrayUtil.toStringArray(result);
}
return null;
}
}
@@ -0,0 +1,145 @@
/*
* User: anna
* Date: 27-Dec-2007
*/
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.roots.ProjectExtension;
import com.intellij.openapi.roots.WatchedRootsProvider;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
public class CompilerProjectExtensionImpl extends CompilerProjectExtension {
@NonNls private static final String OUTPUT_TAG = "output";
@NonNls private static final String URL = "url";
private VirtualFilePointer myCompilerOutput;
private LocalFileSystem.WatchRequest myCompilerOutputWatchRequest;
private final Project myProject;
public CompilerProjectExtensionImpl(final Project project) {
myProject = project;
}
private void readExternal(final Element element) {
final Element outputPathChild = element.getChild(OUTPUT_TAG);
if (outputPathChild != null) {
String outputPath = outputPathChild.getAttributeValue(URL);
assert myCompilerOutput == null;
myCompilerOutput = VirtualFilePointerManager.getInstance().create(outputPath, myProject, null);
}
}
private void writeExternal(final Element element) {
if (myCompilerOutput != null) {
final Element pathElement = new Element(OUTPUT_TAG);
pathElement.setAttribute(URL, myCompilerOutput.getUrl());
element.addContent(pathElement);
}
}
@Nullable
public VirtualFile getCompilerOutput() {
if (myCompilerOutput == null) return null;
return myCompilerOutput.getFile();
}
@Nullable
public String getCompilerOutputUrl() {
if (myCompilerOutput == null) return null;
return myCompilerOutput.getUrl();
}
public VirtualFilePointer getCompilerOutputPointer() {
return myCompilerOutput;
}
public void setCompilerOutputPointer(VirtualFilePointer pointer) {
myCompilerOutput = pointer;
}
public void setCompilerOutputUrl(String compilerOutputUrl) {
VirtualFilePointer pointer = VirtualFilePointerManager.getInstance()
.create(compilerOutputUrl, myProject, ProjectRootManagerImpl.getInstanceImpl(myProject).getVirtualFilePointerListener());
setCompilerOutputPointer(pointer);
final LocalFileSystem.WatchRequest watchRequest =
LocalFileSystem.getInstance().addRootToWatch(ProjectRootManagerImpl.extractLocalPath(compilerOutputUrl), true);
if (myCompilerOutputWatchRequest != null) {
LocalFileSystem.getInstance().removeWatchedRoot(myCompilerOutputWatchRequest);
}
myCompilerOutputWatchRequest = watchRequest;
}
@NotNull
private Set<String> getRootsToWatch() {
final Set<String> rootsToWatch = new HashSet<String>();
Module[] modules = ModuleManager.getInstance(myProject).getModules();
for (Module module : modules) {
final String compilerOutputPath = ProjectRootManagerImpl.extractLocalPath(CompilerModuleExtension.getInstance(module).getCompilerOutputUrl());
if (compilerOutputPath.length() > 0) {
rootsToWatch.add(compilerOutputPath);
}
final String compilerOutputPathForTests =
ProjectRootManagerImpl.extractLocalPath(CompilerModuleExtension.getInstance(module).getCompilerOutputUrlForTests());
if (compilerOutputPathForTests.length() > 0) {
rootsToWatch.add(compilerOutputPathForTests);
}
}
if (myCompilerOutput != null) {
final String url = myCompilerOutput.getUrl();
rootsToWatch.add(ProjectRootManagerImpl.extractLocalPath(url));
}
return rootsToWatch;
}
private static CompilerProjectExtensionImpl getImpl(final Project project) {
return (CompilerProjectExtensionImpl)CompilerProjectExtension.getInstance(project);
}
public static class MyProjectExtension extends ProjectExtension {
private final Project myProject;
public MyProjectExtension(final Project project) {
myProject = project;
}
public void readExternal(final Element element) throws InvalidDataException {
getImpl(myProject).readExternal(element);
}
public void writeExternal(final Element element) throws WriteExternalException {
getImpl(myProject).writeExternal(element);
}
}
public static class MyWatchedRootsProvider implements WatchedRootsProvider {
private final Project myProject;
public MyWatchedRootsProvider(final Project project) {
myProject = project;
}
@NotNull
public Set<String> getRootsToWatch() {
return getImpl(myProject).getRootsToWatch();
}
}
}
@@ -0,0 +1,78 @@
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.CompilerProjectExtension;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.openapi.util.io.FileUtil;
import java.util.ArrayList;
/**
* @author yole
*/
public class ExcludeCompilerOutputPolicy implements DirectoryIndexExcludePolicy {
private final Project myProject;
public ExcludeCompilerOutputPolicy(final Project project) {
myProject = project;
}
public boolean isExcludeRoot(final VirtualFile f) {
CompilerProjectExtension compilerProjectExtension = CompilerProjectExtension.getInstance(myProject);
if (isEqualWithFileOrUrl(f, compilerProjectExtension.getCompilerOutput(), compilerProjectExtension.getCompilerOutputUrl())) return true;
for (Module m : ModuleManager.getInstance(myProject).getModules()) {
CompilerModuleExtension rm = CompilerModuleExtension.getInstance(m);
if (isEqualWithFileOrUrl(f, rm.getCompilerOutputPath(), rm.getCompilerOutputUrl())) return true;
if (isEqualWithFileOrUrl(f, rm.getCompilerOutputPathForTests(), rm.getCompilerOutputUrlForTests())) return true;
}
return false;
}
public boolean isExcludeRootForModule(final Module module, final VirtualFile excludeRoot) {
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
return compilerModuleExtension.getCompilerOutputPath() == excludeRoot || compilerModuleExtension.getCompilerOutputPathForTests() == excludeRoot;
}
public VirtualFile[] getExcludeRootsForProject() {
VirtualFile outputPath = CompilerProjectExtension.getInstance(myProject).getCompilerOutput();
if (outputPath != null) {
return new VirtualFile[] { outputPath };
}
return VirtualFile.EMPTY_ARRAY;
}
public VirtualFilePointer[] getExcludeRootsForModule(final ModuleRootModel rootModel) {
ArrayList<VirtualFilePointer> result = new ArrayList<VirtualFilePointer>();
final CompilerModuleExtension extension = rootModel.getModuleExtension(CompilerModuleExtension.class);
if (extension == null) {
return VirtualFilePointer.EMPTY_ARRAY;
}
if (extension.isCompilerOutputPathInherited()) {
result.add(CompilerProjectExtension.getInstance(myProject).getCompilerOutputPointer());
}
else {
if (!extension.isExcludeOutput()) return VirtualFilePointer.EMPTY_ARRAY;
final VirtualFilePointer outputPath = extension.getCompilerOutputPointer();
if (outputPath != null) result.add(outputPath);
final VirtualFilePointer outputPathForTests = extension.getCompilerOutputForTestsPointer();
if (outputPathForTests != null) result.add(outputPathForTests);
}
return result.isEmpty() ? VirtualFilePointer.EMPTY_ARRAY : result.toArray(new VirtualFilePointer[result.size()]);
}
private static boolean isEqualWithFileOrUrl(VirtualFile f, VirtualFile fileToCompareWith, String url) {
if (fileToCompareWith != null) {
if (fileToCompareWith == f) return true;
}
else if (url != null) {
if (FileUtil.pathsEqual(url, f.getUrl())) return true;
}
return false;
}
}
@@ -0,0 +1,79 @@
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.LanguageLevelUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.FileAttribute;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.messages.MessageBus;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* @author Gregory.Shrago
*/
public class JavaLanguageLevelPusher implements FilePropertyPusher<LanguageLevel> {
public static void pushLanguageLevel(final Project project) {
PushedFilePropertiesUpdater.getInstance(project).pushAll(new JavaLanguageLevelPusher());
}
public void initExtra(Project project, MessageBus bus, Engine languageLevelUpdater) {
// nothing
}
public Key<LanguageLevel> getFileDataKey() {
return LanguageLevel.KEY;
}
public boolean pushDirectoriesOnly() {
return true;
}
public LanguageLevel getDefaultValue() {
return LanguageLevel.HIGHEST;
}
public LanguageLevel getImmediateValue(Project project, VirtualFile file) {
return null;
}
public LanguageLevel getImmediateValue(Module module) {
return LanguageLevelUtil.getEffectiveLanguageLevel(module);
}
public boolean acceptsFile(VirtualFile file) {
return false;
}
private static final FileAttribute PERSISTENCE = new FileAttribute("language_level_persistence", 1);
public void persistAttribute(VirtualFile fileOrDir, LanguageLevel level) throws IOException {
final DataInputStream iStream = PERSISTENCE.readAttribute(fileOrDir);
if (iStream != null) {
try {
final int oldLevelOrdinal = iStream.readInt();
if (oldLevelOrdinal == level.ordinal()) return;
}
finally {
iStream.close();
}
}
final DataOutputStream oStream = PERSISTENCE.writeAttribute(fileOrDir);
oStream.writeInt(level.ordinal());
oStream.close();
for (VirtualFile child : fileOrDir.getChildren()) {
if (!child.isDirectory() && StdFileTypes.JAVA.equals(child.getFileType())) {
FileBasedIndex.getInstance().requestReindex(child);
}
}
}
}
@@ -0,0 +1,141 @@
/*
* User: anna
* Date: 26-Dec-2007
*/
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.roots.ProjectExtension;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.pom.java.LanguageLevel;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExtension {
@Deprecated
@NonNls private static final String ASSERT_KEYWORD_ATTR = "assert-keyword";
@Deprecated
@NonNls private static final String JDK_15_ATTR = "jdk-15";
private LanguageLevel myLanguageLevel = LanguageLevel.JDK_1_5;
private LanguageLevel myOriginalLanguageLevel = myLanguageLevel;
private final Project myProject;
private volatile Runnable myReloadProjectRequest;
public LanguageLevelProjectExtensionImpl(final Project project) {
myProject = project;
}
private void readExternal(final Element element) {
if (myProject.isDefault()) {
return; // TODO[max]: hack to enforce default project always has LangLevel == 1.5. This is necessary until StubUpdatingIndex
// is able to determine correct language level for stub parsing.
}
String level = element.getAttributeValue("languageLevel");
if (level == null) {
myLanguageLevel = migrateFromIdea7(element);
}
else {
myLanguageLevel = LanguageLevel.valueOf(level);
}
myOriginalLanguageLevel = myLanguageLevel;
}
private static LanguageLevel migrateFromIdea7(Element element) {
final boolean assertKeyword = Boolean.valueOf(element.getAttributeValue(ASSERT_KEYWORD_ATTR)).booleanValue();
final boolean jdk15 = Boolean.valueOf(element.getAttributeValue(JDK_15_ATTR)).booleanValue();
if (jdk15) {
return LanguageLevel.JDK_1_5;
}
else if (assertKeyword) {
return LanguageLevel.JDK_1_4;
}
else {
return LanguageLevel.JDK_1_3;
}
}
private void writeExternal(final Element element) {
element.setAttribute("languageLevel", myLanguageLevel.name());
writeAttributesForIdea7(element);
}
private void writeAttributesForIdea7(Element element) {
final boolean is14 = LanguageLevel.JDK_1_4.equals(myLanguageLevel);
final boolean is15 = myLanguageLevel.compareTo(LanguageLevel.JDK_1_5) >= 0;
element.setAttribute(ASSERT_KEYWORD_ATTR, Boolean.toString(is14 || is15));
element.setAttribute(JDK_15_ATTR, Boolean.toString(is15));
}
public LanguageLevel getLanguageLevel() {
return myLanguageLevel;
}
public void setLanguageLevel(LanguageLevel languageLevel) {
if (myLanguageLevel != languageLevel) {
reloadProjectOnLanguageLevelChange(languageLevel, false);
}
myLanguageLevel = languageLevel;
if (!willReload() && DirectoryIndex.getInstance(myProject).isInitialized()) {
JavaLanguageLevelPusher.pushLanguageLevel(myProject);
}
}
public void reloadProjectOnLanguageLevelChange(final LanguageLevel languageLevel, final boolean forceReload) {
if (willReload()) {
myReloadProjectRequest = new Runnable() {
public void run() {
if (myProject.isDisposed()) return;
if (myReloadProjectRequest != this) {
// obsolete, another request has already replaced this one
return;
}
if (!forceReload && myOriginalLanguageLevel.equals(getLanguageLevel())) {
// the question does not make sense now
return;
}
final String _message = ProjectBundle.message("project.language.level.reload.prompt", myProject.getName());
if (Messages.showYesNoDialog(myProject, _message, ProjectBundle.message("project.language.level.reload.title"), Messages.getQuestionIcon()) == 0) {
ProjectManager.getInstance().reloadProject(myProject);
}
myReloadProjectRequest = null;
}
};
ApplicationManager.getApplication().invokeLater(myReloadProjectRequest, ModalityState.NON_MODAL);
}
else {
// if the project is not open, reset the original level to the same value as mylanguageLevel has
myOriginalLanguageLevel = languageLevel;
}
}
private boolean willReload() {
return myProject.isOpen() && !ApplicationManager.getApplication().isUnitTestMode();
}
public static class MyProjectExtension extends ProjectExtension {
private final Project myProject;
public MyProjectExtension(final Project project) {
myProject = project;
}
public void readExternal(final Element element) throws InvalidDataException {
((LanguageLevelProjectExtensionImpl)getInstance(myProject)).readExternal(element);
}
public void writeExternal(final Element element) throws WriteExternalException {
((LanguageLevelProjectExtensionImpl)getInstance(myProject)).writeExternal(element);
}
}
}
@@ -0,0 +1,34 @@
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.roots.ModuleFileIndex;
import com.intellij.openapi.roots.ModulePackageIndex;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.FilteredQuery;
import com.intellij.util.Query;
import org.jetbrains.annotations.NotNull;
public class ModulePackageIndexImpl extends ModulePackageIndex {
private final ModuleFileIndex myModuleFileIndex;
private final DirectoryIndex myDirectoryIndex;
public ModulePackageIndexImpl(ModuleRootManager moduleRootManager, DirectoryIndex directoryIndex) {
myModuleFileIndex = moduleRootManager.getFileIndex();
myDirectoryIndex = directoryIndex;
}
private final Condition<VirtualFile> myDirCondition = new Condition<VirtualFile>() {
public boolean value(final VirtualFile dir) {
return dir.isValid() && myModuleFileIndex.getOrderEntryForFile(dir) != null;
}
};
public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return new FilteredQuery<VirtualFile>(myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources), myDirCondition);
}
public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY);
}
}
@@ -0,0 +1,60 @@
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleComponent;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import org.jdom.Element;
import java.util.Iterator;
import java.util.List;
/**
* @author dsl
*/
public class OldModuleRootsKeeper implements ModuleComponent, JDOMExternalizable {
private Element myElement;
public static OldModuleRootsKeeper getInstance(Module module) {
return module.getComponent(OldModuleRootsKeeper.class);
}
public OldModuleRootsKeeper(Module module) {
}
public String getComponentName() {
return "ModuleRootManager";
}
public void initComponent() { }
public void disposeComponent() {
}
public void readExternal(Element element) throws InvalidDataException {
myElement = (Element)element.clone();
}
public void writeExternal(Element element) throws WriteExternalException {
if (myElement != null) {
final List children = myElement.getChildren();
for (final Object aChildren : children) {
Element child = (Element)aChildren;
element.addContent((Element)child.clone());
}
}
}
public void projectOpened() {
}
public void projectClosed() {
}
public void moduleAdded() {
}
}
@@ -0,0 +1,23 @@
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.roots.PackageIndex;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Query;
import org.jetbrains.annotations.NotNull;
public class ProjectPackageIndexImpl extends PackageIndex {
private final DirectoryIndex myDirectoryIndex;
public ProjectPackageIndexImpl(DirectoryIndex directoryIndex) {
myDirectoryIndex = directoryIndex;
}
public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY);
}
public Query<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
return myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources);
}
}