diff --git a/.idea/modules.xml b/.idea/modules.xml index f31fa8d873f9..7dd2c78681b2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -56,6 +56,7 @@ + diff --git a/build/gant.xml b/build/gant.xml index 5e8ca1dfac5b..cf349b7ef3af 100644 --- a/build/gant.xml +++ b/build/gant.xml @@ -2,6 +2,7 @@ + @@ -14,6 +15,6 @@ - + diff --git a/build/scripts/dist.gant b/build/scripts/dist.gant index c7ce4335d956..677c4ba74dfc 100644 --- a/build/scripts/dist.gant +++ b/build/scripts/dist.gant @@ -82,6 +82,17 @@ target('default': 'The default target') { home, null, paths) } +target('build-dist-jars' : 'Target to build jars from locally compiled classes') { + loadProject() + // load ApplicationInfo.xml properties + ant.xmlproperty(file: appInfoFile(), collapseAttributes: "true") + + layoutAll([buildNumber: "IC-$snapshot", + system_selector: "IdeaIC${p("component.version.major")}", + tools_jar: true], + home, null, paths) +} + def layoutAll(Map args, String home, String out, Paths _paths = null) { Paths paths = _paths != null ? _paths : new Paths(out) diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 923a39ebf639..1790ca85e78d 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -59,6 +59,7 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir "instrumentation-util", "platform-main", "java-psi-impl", + "java-indexing-impl", "java-impl", "compiler-impl", "debugger-impl", @@ -530,6 +531,7 @@ def layout_core_upsource(String home, String target) { module("java-psi-impl") module("projectModel-api") module("projectModel-impl") + module("java-indexing-impl") } jar("annotations.jar") { diff --git a/build/update.xml b/build/update.xml index 5372bd479360..d8398ea75dfb 100644 --- a/build/update.xml +++ b/build/update.xml @@ -21,6 +21,7 @@ + @@ -29,6 +30,7 @@ + @@ -62,4 +64,10 @@ + + + + \ No newline at end of file diff --git a/java/java-impl/java-impl.iml b/java/java-impl/java-impl.iml index 8f8444f32442..d19011b3e584 100644 --- a/java/java-impl/java-impl.iml +++ b/java/java-impl/java-impl.iml @@ -31,6 +31,8 @@ + + diff --git a/java/java-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java index 9dbb441d7b71..ceb77e3d0587 100644 --- a/java/java-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/file/impl/JavaFileManagerImpl.java @@ -34,7 +34,7 @@ import com.intellij.psi.impl.PsiManagerEx; import com.intellij.psi.impl.file.PsiPackageImpl; import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiUtilBase; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Query; import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.containers.ContainerUtil; @@ -186,7 +186,7 @@ public class JavaFileManagerImpl implements JavaFileManager, Disposable { private static boolean notClass(final PsiElement found) { if (found instanceof PsiClass) return false; - VirtualFile faultyContainer = PsiUtilBase.getVirtualFile(found); + VirtualFile faultyContainer = PsiUtilCore.getVirtualFile(found); LOG.error("Non class in class list: " + faultyContainer + ". found: " + found); if (faultyContainer != null && faultyContainer.isValid()) { FileBasedIndex.getInstance().requestReindex(faultyContainer); diff --git a/java/java-indexing-impl/java-indexing-impl.iml b/java/java-indexing-impl/java-indexing-impl.iml new file mode 100644 index 000000000000..94f91bbb0a10 --- /dev/null +++ b/java/java-indexing-impl/java-indexing-impl.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/java/java-impl/src/com/intellij/psi/impl/java/stubs/index/JavaFullClassNameIndex.java b/java/java-indexing-impl/src/com/intellij/psi/impl/java/stubs/index/JavaFullClassNameIndex.java similarity index 100% rename from java/java-impl/src/com/intellij/psi/impl/java/stubs/index/JavaFullClassNameIndex.java rename to java/java-indexing-impl/src/com/intellij/psi/impl/java/stubs/index/JavaFullClassNameIndex.java diff --git a/java/java-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java similarity index 92% rename from java/java-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java rename to java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java index a0178fb407de..086a20eabcf7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaSourceFilterScope.java @@ -19,7 +19,7 @@ */ package com.intellij.psi.impl.search; -import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.ide.highlighter.JavaClassFileType; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.vfs.VirtualFile; @@ -41,7 +41,7 @@ public class JavaSourceFilterScope extends DelegatingGlobalSearchScope { return false; } - if (StdFileTypes.CLASS == file.getFileType()) { + if (JavaClassFileType.INSTANCE == file.getFileType()) { return myIndex.isInLibraryClasses(file); } diff --git a/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java b/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java index a4a26f9f3f5e..b6fcf28e23c9 100644 --- a/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java +++ b/java/java-psi-impl/src/com/intellij/core/CoreJavaFileManager.java @@ -16,69 +16,37 @@ package com.intellij.core; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.roots.PackageIndex; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem; -import com.intellij.openapi.vfs.local.CoreLocalFileSystem; import com.intellij.psi.*; import com.intellij.psi.impl.file.PsiPackageImpl; import com.intellij.psi.impl.file.impl.JavaFileManager; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.util.CollectionQuery; -import com.intellij.util.Query; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * @author yole */ -public class CoreJavaFileManager extends PackageIndex implements JavaFileManager { +public class CoreJavaFileManager implements JavaFileManager { private static final Logger LOG = Logger.getInstance("#com.intellij.core.CoreJavaFileManager"); - private final CoreLocalFileSystem myLocalFileSystem; - private final CoreJarFileSystem myJarFileSystem; - private final List myClasspath = new ArrayList(); - private VirtualFile[] myClasspathRoots = null; + private final List myClasspath = new ArrayList(); private final PsiManager myPsiManager; - public CoreJavaFileManager(PsiManager psiManager, CoreLocalFileSystem localFileSystem, CoreJarFileSystem jarFileSystem) { + public CoreJavaFileManager(PsiManager psiManager) { myPsiManager = psiManager; - myLocalFileSystem = localFileSystem; - myJarFileSystem = jarFileSystem; } - private VirtualFile[] roots() { - VirtualFile[] answer = myClasspathRoots; - - if (answer == null) { - ArrayList answerList = new ArrayList(myClasspath.size()); - for (File root : myClasspath) { - VirtualFile rootVfs = calcRoot(root); - if (rootVfs != null) { - answerList.add(rootVfs); - } - } - - answer = answerList.toArray(new VirtualFile[answerList.size()]); - myClasspathRoots = answer; - } - - return answer; - } - - @Nullable - private VirtualFile calcRoot(File root) { - if (root.isFile()) { - return myJarFileSystem.findFileByPath(root.getPath() + "!/"); - } - else { - return myLocalFileSystem.findFileByPath(root.getPath()); - } + private List roots() { + return myClasspath; } @Override @@ -104,26 +72,16 @@ public class CoreJavaFileManager extends PackageIndex implements JavaFileManager @Nullable public PsiPackage getPackage(PsiDirectory dir) { - final File ioFile = new File(dir.getVirtualFile().getPath()); - for (File root : myClasspath) { - if (FileUtil.isAncestor(root, ioFile, false)) { - final String relativePath = FileUtil.getRelativePath(root.getPath(), ioFile.getPath(), '.'); + final VirtualFile file = dir.getVirtualFile(); + for (VirtualFile root : myClasspath) { + if (VfsUtilCore.isAncestor(root, file, false)) { + final String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '.'); return new PsiPackageImpl(myPsiManager, relativePath); } } return null; } - @Override - public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { - return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY); - } - - @Override - public Query getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) { - return new CollectionQuery(findDirectoriesByPackageName(packageName)); - } - @Override public PsiClass findClass(@NotNull String qName, @NotNull GlobalSearchScope scope) { for (VirtualFile root : roots()) { @@ -223,8 +181,7 @@ public class CoreJavaFileManager extends PackageIndex implements JavaFileManager public void initialize() { } - public void addToClasspath(File path) { - myClasspath.add(path); - myClasspathRoots = null; + public void addToClasspath(VirtualFile root) { + myClasspath.add(root); } } diff --git a/java/java-psi-impl/src/com/intellij/core/CorePackageIndex.java b/java/java-psi-impl/src/com/intellij/core/CorePackageIndex.java new file mode 100644 index 000000000000..c20f234073e6 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/core/CorePackageIndex.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.core; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.roots.PackageIndex; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.CollectionQuery; +import com.intellij.util.Query; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class CorePackageIndex extends PackageIndex { + private static final Logger LOG = Logger.getInstance("#com.intellij.core.CorePackageIndex"); + + private final List myClasspath = new ArrayList(); + + public CorePackageIndex() { + } + + private List roots() { + return myClasspath; + } + + private List findDirectoriesByPackageName(String packageName) { + List result = new ArrayList(); + String dirName = packageName.replace(".", "/"); + for (VirtualFile root : roots()) { + VirtualFile classDir = root.findFileByRelativePath(dirName); + if (classDir != null) { + result.add(classDir); + } + } + return result; + } + + @Override + public VirtualFile[] getDirectoriesByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + return getDirsByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY); + } + + @Override + public Query getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) { + return new CollectionQuery(findDirectoriesByPackageName(packageName)); + } + + public void addToClasspath(VirtualFile root) { + myClasspath.add(root); + } +} diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java similarity index 63% rename from java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java rename to java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java index bd47461fcaa6..3bc4c3d7d287 100644 --- a/java/java-psi-impl/src/com/intellij/core/JavaCoreEnvironment.java +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreApplicationEnvironment.java @@ -47,10 +47,8 @@ import java.io.File; /** * @author yole */ -public class JavaCoreEnvironment extends CoreEnvironment { - private final CoreJavaFileManager myFileManager; - - public JavaCoreEnvironment(Disposable parentDisposable) { +public class JavaCoreApplicationEnvironment extends CoreApplicationEnvironment { + public JavaCoreApplicationEnvironment(Disposable parentDisposable) { super(parentDisposable); registerFileType(JavaClassFileType.INSTANCE, "class"); @@ -62,7 +60,6 @@ public class JavaCoreEnvironment extends CoreEnvironment { addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition()); addExplicitExtension(LanguageConstantExpressionEvaluator.INSTANCE, JavaLanguage.INSTANCE, new PsiExpressionEvaluator()); - registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class); registerExtensionPoint(Extensions.getRootArea(), ClsStubBuilderFactory.EP_NAME, ClsStubBuilderFactory.class); registerExtensionPoint(Extensions.getRootArea(), PsiAugmentProvider.EP_NAME, PsiAugmentProvider.class); registerExtensionPoint(Extensions.getRootArea(), JavaMainMethodProvider.EP_NAME, JavaMainMethodProvider.class); @@ -70,43 +67,8 @@ public class JavaCoreEnvironment extends CoreEnvironment { myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper()); - myFileManager = createCoreFileManager(); - myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); - myProject.registerService(JavaPsiImplementationHelper.class, new CoreJavaPsiImplementationHelper()); - myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); - myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); - myProject.registerService(PackageIndex.class, myFileManager); - myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); - myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); - myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); - - JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus); - myProject.registerService(CoreJavaFileManager.class, myFileManager); - registerComponentInstance(myProject.getPicoContainer(), - JavaPsiFacade.class, - javaPsiFacade); - myProject.registerService(JavaPsiFacade.class, javaPsiFacade); - myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl()); myApplication.registerService(JavaDirectoryService.class, new CoreJavaDirectoryService()); myApplication.registerService(JavaVersionService.class, new JavaVersionService()); } - - protected CoreJavaFileManager createCoreFileManager() { - return new CoreJavaFileManager(myPsiManager, getLocalFileSystem(), myJarFileSystem); - } - - public void addToClasspath(File path) { - final VirtualFile root = path.isFile() - ? myJarFileSystem.findFileByPath(path + "!/") - : getLocalFileSystem().findFileByPath(path.getPath()); - - if (root != null) { - myFileManager.addToClasspath(path); - myFileIndexFacade.addLibraryRoot(root); - } - else { - throw new IllegalArgumentException("trying to add non-existing file to classpath: " + path); - } - } } diff --git a/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java new file mode 100644 index 000000000000..25e840058e08 --- /dev/null +++ b/java/java-psi-impl/src/com/intellij/core/JavaCoreProjectEnvironment.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.core; + +import com.intellij.mock.MockFileIndexFacade; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.roots.FileIndexFacade; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.openapi.roots.PackageIndex; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiElementFactory; +import com.intellij.psi.PsiElementFinder; +import com.intellij.psi.PsiResolveHelper; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.codeStyle.JavaCodeStyleSettingsFacade; +import com.intellij.psi.impl.JavaPsiFacadeImpl; +import com.intellij.psi.impl.JavaPsiImplementationHelper; +import com.intellij.psi.impl.PsiElementFactoryImpl; +import com.intellij.psi.impl.file.impl.JavaFileManager; +import com.intellij.psi.impl.source.resolve.JavaResolveCache; +import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class JavaCoreProjectEnvironment extends CoreProjectEnvironment { + private final JavaFileManager myFileManager; + private final PackageIndex myPackageIndex; + + public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { + super(parentDisposable, applicationEnvironment); + + myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager)); + myProject.registerService(JavaPsiImplementationHelper.class, new CoreJavaPsiImplementationHelper()); + myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager)); + myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension()); + myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus)); + myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade()); + myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager()); + registerProjectExtensionPoint(PsiElementFinder.EP_NAME, PsiElementFinder.class); + + myPackageIndex = createCorePackageIndex(); + myProject.registerService(PackageIndex.class, myPackageIndex); + + myFileManager = createCoreFileManager(); + myProject.registerService(JavaFileManager.class, myFileManager); + + JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus); + registerProjectComponent(JavaPsiFacade.class, javaPsiFacade); + myProject.registerService(JavaPsiFacade.class, javaPsiFacade); + } + + protected JavaFileManager createCoreFileManager() { + return new CoreJavaFileManager(myPsiManager); + } + + protected PackageIndex createCorePackageIndex() { + return new CorePackageIndex(); + } + + public void addJarToClassPath (File path) { + assert path.isFile(); + + final VirtualFile root = getEnvironment().getJarFileSystem().findFileByPath(path + "!/"); + if (root == null) { + throw new IllegalArgumentException("trying to add non-existing file to classpath: " + path); + } + + addSourcesToClasspath(root); + } + + public void addSourcesToClasspath(@NotNull VirtualFile root) { + assert root.isDirectory(); + ((CoreJavaFileManager)myFileManager).addToClasspath(root); + ((CorePackageIndex)myPackageIndex).addToClasspath(root); + ((MockFileIndexFacade)myFileIndexFacade).addLibraryRoot(root); + } +} diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java index d51c377556a3..2d8c0be99a17 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java @@ -62,7 +62,7 @@ public class JavaResolveCache { private static final Object NULL = Key.create("NULL"); - public JavaResolveCache(@Nullable("can be null in com.intellij.core.JavaCoreEnvironment.JavaCoreEnvironment") MessageBus messageBus) { + public JavaResolveCache(@Nullable("can be null in com.intellij.core.JavaCoreApplicationEnvironment.JavaCoreApplicationEnvironment") MessageBus messageBus) { if (messageBus != null) { messageBus.connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener() { @Override diff --git a/java/openapi/src/com/intellij/openapi/roots/libraries/JarVersionDetectionUtil.java b/java/openapi/src/com/intellij/openapi/roots/libraries/JarVersionDetectionUtil.java index 2a36e16685c6..7937bec6bc8f 100644 --- a/java/openapi/src/com/intellij/openapi/roots/libraries/JarVersionDetectionUtil.java +++ b/java/openapi/src/com/intellij/openapi/roots/libraries/JarVersionDetectionUtil.java @@ -33,7 +33,6 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; public class JarVersionDetectionUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.libraries.JarVersionDetectionUtil"); @@ -76,7 +75,7 @@ public class JarVersionDetectionUtil { } @Nullable - public static String detectJarVersion(ZipFile zipFile) { + public static String detectJarVersion(com.intellij.openapi.vfs.JarFile zipFile) { if (zipFile == null) { return null; } @@ -96,7 +95,7 @@ public class JarVersionDetectionUtil { } @Nullable - private static ZipFile getDetectionJar(final String detectionClass, Module module) throws IOException { + private static com.intellij.openapi.vfs.JarFile getDetectionJar(final String detectionClass, Module module) throws IOException { for (OrderEntry library : ModuleRootManager.getInstance(module).getOrderEntries()) { if (library instanceof LibraryOrderEntry) { VirtualFile file = LibrariesHelper.getInstance().findJarByClass(((LibraryOrderEntry)library).getLibrary(), detectionClass); diff --git a/platform/core-api/src/com/intellij/openapi/vfs/JarFile.java b/platform/core-api/src/com/intellij/openapi/vfs/JarFile.java new file mode 100644 index 000000000000..33f2e1c17b81 --- /dev/null +++ b/platform/core-api/src/com/intellij/openapi/vfs/JarFile.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs; + +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * Encapsulates operations with .jar file + */ +public interface JarFile { + ZipEntry getEntry(String name); + InputStream getInputStream(ZipEntry entry) throws IOException; + Enumeration entries(); + + @Nullable ZipFile getZipFile(); +} diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubInputStream.java b/platform/core-api/src/com/intellij/psi/stubs/StubInputStream.java index bcc02d6ef197..8f2d96eb330d 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/StubInputStream.java +++ b/platform/core-api/src/com/intellij/psi/stubs/StubInputStream.java @@ -16,10 +16,7 @@ package com.intellij.psi.stubs; -import com.intellij.util.io.DataInputOutputUtil; -import com.intellij.util.io.IOUtil; -import com.intellij.util.io.PersistentStringEnumerator; -import com.intellij.util.io.StringRef; +import com.intellij.util.io.*; import java.io.DataInputStream; import java.io.IOException; @@ -29,10 +26,10 @@ import java.io.InputStream; * @author yole */ public class StubInputStream extends DataInputStream { - private final PersistentStringEnumerator myNameStorage; + private final AbstractStringEnumerator myNameStorage; private final byte[] myStringIOBuffer = IOUtil.allocReadWriteUTFBuffer(); - public StubInputStream(InputStream in, PersistentStringEnumerator nameStorage) { + public StubInputStream(InputStream in, AbstractStringEnumerator nameStorage) { super(in); myNameStorage = nameStorage; } diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubOutputStream.java b/platform/core-api/src/com/intellij/psi/stubs/StubOutputStream.java index 46696d6c1cc0..d1f61c634e0e 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/StubOutputStream.java +++ b/platform/core-api/src/com/intellij/psi/stubs/StubOutputStream.java @@ -16,10 +16,7 @@ package com.intellij.psi.stubs; -import com.intellij.util.io.DataInputOutputUtil; -import com.intellij.util.io.DataOutputStream; -import com.intellij.util.io.IOUtil; -import com.intellij.util.io.PersistentStringEnumerator; +import com.intellij.util.io.*; import java.io.IOException; import java.io.OutputStream; @@ -28,10 +25,10 @@ import java.io.OutputStream; * @author yole */ public class StubOutputStream extends DataOutputStream { - private final PersistentStringEnumerator myNameStorage; + private final AbstractStringEnumerator myNameStorage; private final byte[] myStringIOBuffer = IOUtil.allocReadWriteUTFBuffer(); - public StubOutputStream(OutputStream out, PersistentStringEnumerator nameStorage) { + public StubOutputStream(OutputStream out, AbstractStringEnumerator nameStorage) { super(out); myNameStorage = nameStorage; } diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java new file mode 100644 index 000000000000..358847d16e92 --- /dev/null +++ b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java @@ -0,0 +1,109 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.stubs; + +import com.intellij.openapi.diagnostic.LogUtil; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.io.AbstractStringEnumerator; +import com.intellij.util.io.DataInputOutputUtil; +import gnu.trove.TIntObjectHashMap; +import gnu.trove.TObjectIntHashMap; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; + +/** + * Author: dmitrylomov + */ +public class StubSerializationHelper { + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubs.StubSerializationHelper"); + + private AbstractStringEnumerator myNameStorage; + + protected final TIntObjectHashMap> myIdToSerializer = new TIntObjectHashMap>(); + protected final TObjectIntHashMap> mySerializerToId = new TObjectIntHashMap>(); + + public StubSerializationHelper(AbstractStringEnumerator nameStorage) { + myNameStorage = nameStorage; + } + public void assignId(@NotNull final StubSerializer serializer) throws IOException { + final int id = persistentId(serializer); + final StubSerializer old = myIdToSerializer.put(id, serializer); + assert old == null : "ID: " + serializer.getExternalId() + " is not unique; Already registered serializer with this ID: " + old.getClass().getName(); + + final int oldId = mySerializerToId.put(serializer, id); + assert oldId == 0 : "Serializer " + serializer + " is already registered; Old ID:" + oldId; + } + + private int persistentId(@NotNull final StubSerializer serializer) throws IOException { + if (myNameStorage == null) { + throw new IOException("SerializationManager's name storage failed to initialize"); + } + return myNameStorage.enumerate(serializer.getExternalId()); + } + + private void doSerialize(final StubElement rootStub, final StubOutputStream stream) throws IOException { + final StubSerializer serializer = StubSerializationUtil.getSerializer(rootStub); + + DataInputOutputUtil.writeINT(stream, getClassId(serializer)); + serializer.serialize(rootStub, stream); + + final List children = rootStub.getChildrenStubs(); + final int childrenSize = children.size(); + DataInputOutputUtil.writeINT(stream, childrenSize); + for (int i = 0; i < childrenSize; ++i) { + doSerialize(children.get(i), stream); + } + } + + public void serialize(StubElement rootStub, OutputStream stream) throws IOException { + StubOutputStream stubOutputStream = new StubOutputStream(stream, myNameStorage); + doSerialize(rootStub, stubOutputStream); + } + + private int getClassId(final StubSerializer serializer) { + final int idValue = mySerializerToId.get(serializer); + assert idValue != 0: "No ID found for serializer " + LogUtil.objectAndClass(serializer); + return idValue; + } + + public StubElement deserialize(InputStream stream) throws IOException { + StubInputStream inputStream = new StubInputStream(stream, myNameStorage); + return deserialize(inputStream, null); + } + + private StubElement deserialize(StubInputStream stream, StubElement parentStub) throws IOException { + final int id = DataInputOutputUtil.readINT(stream); + final StubSerializer serializer = getClassById(id); + + assert serializer != null : "No serializer registered for stub: ID=" + id + "; parent stub class=" + (parentStub != null? parentStub.getClass().getName() : "null"); + + StubElement stub = serializer.deserialize(stream, parentStub); + int childCount = DataInputOutputUtil.readINT(stream); + for (int i = 0; i < childCount; i++) { + deserialize(stream, stub); + } + return stub; + } + + + private StubSerializer getClassById(int id) { + return myIdToSerializer.get(id); + } +} diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubSerializationUtil.java b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationUtil.java new file mode 100644 index 000000000000..45f610676d80 --- /dev/null +++ b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationUtil.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.stubs; + +/** + * Author: dmitrylomov + */ +public abstract class StubSerializationUtil { + private StubSerializationUtil() {} + + public static StubSerializer getSerializer(StubElement rootStub) { + if (rootStub instanceof PsiFileStub) { + final PsiFileStub fileStub = (PsiFileStub)rootStub; + return fileStub.getType(); + } + + return rootStub.getStubType(); + } +} diff --git a/platform/core-impl/src/com/intellij/core/CoreEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java similarity index 71% rename from platform/core-impl/src/com/intellij/core/CoreEnvironment.java rename to platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java index dc2f5f2859da..9581a190a341 100644 --- a/platform/core-impl/src/com/intellij/core/CoreEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreApplicationEnvironment.java @@ -17,7 +17,9 @@ package com.intellij.core; import com.intellij.lang.*; import com.intellij.lang.impl.PsiBuilderFactoryImpl; -import com.intellij.mock.*; +import com.intellij.mock.MockApplication; +import com.intellij.mock.MockFileDocumentManagerImpl; +import com.intellij.mock.MockReferenceProvidersRegistry; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -31,11 +33,8 @@ import com.intellij.openapi.extensions.ExtensionsArea; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.progress.*; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.StaticGetter; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.openapi.vfs.encoding.EncodingRegistry; @@ -45,25 +44,13 @@ import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem; import com.intellij.openapi.vfs.local.CoreLocalFileSystem; import com.intellij.openapi.vfs.newvfs.FileSystemPersistence; import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; -import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReferenceService; import com.intellij.psi.PsiReferenceServiceImpl; -import com.intellij.psi.impl.*; -import com.intellij.psi.impl.file.PsiDirectoryFactory; -import com.intellij.psi.impl.file.PsiDirectoryFactoryImpl; -import com.intellij.psi.impl.file.impl.FileManagerImpl; -import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; -import com.intellij.psi.search.ProjectScopeBuilder; import com.intellij.psi.stubs.BinaryFileStubBuilders; import com.intellij.psi.stubs.CoreStubTreeLoader; import com.intellij.psi.stubs.StubTreeLoader; -import com.intellij.psi.util.CachedValuesManager; -import com.intellij.psi.util.PsiModificationTracker; -import com.intellij.util.CachedValuesManagerImpl; import com.intellij.util.Function; -import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.impl.MessageBusImpl; import org.jetbrains.annotations.NotNull; import org.picocontainer.MutablePicoContainer; @@ -73,19 +60,15 @@ import java.lang.reflect.Modifier; /** * @author yole */ -public class CoreEnvironment { +public class CoreApplicationEnvironment { private final CoreFileTypeRegistry myFileTypeRegistry; private final CoreEncodingRegistry myEncodingRegistry; protected final MockApplication myApplication; - protected MockProject myProject; private final CoreLocalFileSystem myLocalFileSystem; - protected final CoreJarFileSystem myJarFileSystem; - protected final MockFileIndexFacade myFileIndexFacade; - protected final PsiManagerImpl myPsiManager; + protected final VirtualFileSystem myJarFileSystem; private final Disposable myParentDisposable; - protected final MessageBusImpl myMessageBus; - public CoreEnvironment(Disposable parentDisposable) { + public CoreApplicationEnvironment(Disposable parentDisposable) { myParentDisposable = parentDisposable; Extensions.cleanRootArea(myParentDisposable); @@ -97,11 +80,10 @@ public class CoreEnvironment { new StaticGetter(myFileTypeRegistry), new StaticGetter(myEncodingRegistry), myParentDisposable); - myLocalFileSystem = new CoreLocalFileSystem(); - myJarFileSystem = new CoreJarFileSystem(); + myLocalFileSystem = createLocalFileSystem(); + myJarFileSystem = createJarFileSystem(); Extensions.registerAreaClass(ExtensionAreas.IDEA_PROJECT, null); - myProject = new MockProject(myApplication.getPicoContainer(), myParentDisposable); final MutablePicoContainer appContainer = myApplication.getPicoContainer(); registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(new Function() { @@ -126,7 +108,8 @@ public class CoreEnvironment { } ) ); - registerApplicationComponent(VirtualFilePointerManager.class, new CoreVirtualFilePointerManager()); + //registerApplicationComponent(VirtualFilePointerManager.class, new CoreVirtualFilePointerManager()); + myApplication.registerService(VirtualFilePointerManager.class, new CoreVirtualFilePointerManager()); myApplication.registerService(DefaultASTFactory.class, new CoreASTFactory()); myApplication.registerService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl()); @@ -137,26 +120,6 @@ public class CoreEnvironment { registerApplicationExtensionPoint(ContentBasedFileSubstitutor.EP_NAME, ContentBasedFileSubstitutor.class); registerExtensionPoint(Extensions.getRootArea(), BinaryFileStubBuilders.EP_NAME, FileTypeExtensionPoint.class); - myFileIndexFacade = new MockFileIndexFacade(myProject); - myMessageBus = new MessageBusImpl(); - - PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(myProject); - myProject.registerService(PsiModificationTracker.class, modificationTracker); - myProject.registerService(FileIndexFacade.class, myFileIndexFacade); - myProject.registerService(ResolveScopeManager.class, new MockResolveScopeManager(myProject)); - myProject.registerService(ResolveCache.class, new ResolveCache(myMessageBus)); - - registerProjectExtensionPoint(PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor.class); - myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, myMessageBus, modificationTracker); - ((FileManagerImpl) myPsiManager.getFileManager()).markInitialized(); - registerProjectComponent(PsiManager.class, myPsiManager); - - myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); - myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); - myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myPsiManager)); - myProject.registerService(ProjectScopeBuilder.class, new CoreProjectScopeBuilder(myProject, myFileIndexFacade)); - myProject.registerService(DumbService.class, new MockDumbService(myProject)); - ProgressIndicatorProvider.ourInstance = new ProgressIndicatorProvider() { @Override public ProgressIndicator getProgressIndicator() { @@ -178,6 +141,14 @@ public class CoreEnvironment { }; } + protected VirtualFileSystem createJarFileSystem() { + return new CoreJarFileSystem(); + } + + protected CoreLocalFileSystem createLocalFileSystem() { + return new CoreLocalFileSystem(); + } + public MockApplication getApplication() { return myApplication; } @@ -190,14 +161,6 @@ public class CoreEnvironment { registerComponentInstance(myApplication.getPicoContainer(), interfaceClass, implementation); } - public void registerProjectComponent(final Class interfaceClass, final T implementation) { - registerComponentInstance(myProject.getPicoContainer(), interfaceClass, implementation); - } - - public MockProject getProject() { - return myProject; - } - public void registerFileType(FileType fileType, String extension) { myFileTypeRegistry.registerFileType(fileType, extension); } @@ -213,7 +176,7 @@ public class CoreEnvironment { protected void addExplicitExtension(final LanguageExtension instance, final Language language, final T object) { instance.addExplicitExtension(language, object); - Disposer.register(myProject, new Disposable() { + Disposer.register(myParentDisposable, new Disposable() { @Override public void dispose() { instance.removeExplicitExtension(language, object); @@ -223,7 +186,7 @@ public class CoreEnvironment { protected void addExplicitExtension(final FileTypeExtension instance, final FileType fileType, final T object) { instance.addExplicitExtension(fileType, object); - Disposer.register(myProject, new Disposable() { + Disposer.register(myParentDisposable, new Disposable() { @Override public void dispose() { instance.removeExplicitExtension(fileType, object); @@ -234,7 +197,7 @@ public class CoreEnvironment { protected void addExtension(ExtensionPointName name, final T extension) { final ExtensionPoint extensionPoint = Extensions.getRootArea().getExtensionPoint(name); extensionPoint.registerExtension(extension); - Disposer.register(myProject, new Disposable() { + Disposer.register(myParentDisposable, new Disposable() { @Override public void dispose() { extensionPoint.unregisterExtension(extension); @@ -260,20 +223,11 @@ public class CoreEnvironment { registerExtensionPoint(Extensions.getRootArea(), name, aClass); } - public void registerProjectExtensionPoint(final ExtensionPointName extensionPointName, - final Class aClass) { - registerExtensionPoint(Extensions.getArea(myProject), extensionPointName, aClass); - } - public CoreLocalFileSystem getLocalFileSystem() { return myLocalFileSystem; } - public CoreJarFileSystem getJarFileSystem() { + public VirtualFileSystem getJarFileSystem() { return myJarFileSystem; } - - public void addLibraryRoot(VirtualFile file) { - myFileIndexFacade.addLibraryRoot(file); - } } diff --git a/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java new file mode 100644 index 000000000000..8f841215f271 --- /dev/null +++ b/platform/core-impl/src/com/intellij/core/CoreProjectEnvironment.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.core; + +import com.intellij.mock.MockDumbService; +import com.intellij.mock.MockFileIndexFacade; +import com.intellij.mock.MockProject; +import com.intellij.mock.MockResolveScopeManager; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.project.DumbService; +import com.intellij.openapi.roots.FileIndexFacade; +import com.intellij.psi.PsiFileFactory; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.*; +import com.intellij.psi.impl.file.PsiDirectoryFactory; +import com.intellij.psi.impl.file.PsiDirectoryFactoryImpl; +import com.intellij.psi.impl.file.impl.FileManagerImpl; +import com.intellij.psi.impl.source.resolve.ResolveCache; +import com.intellij.psi.search.ProjectScopeBuilder; +import com.intellij.psi.util.CachedValuesManager; +import com.intellij.psi.util.PsiModificationTracker; +import com.intellij.util.CachedValuesManagerImpl; +import com.intellij.util.messages.impl.MessageBusImpl; + +public class CoreProjectEnvironment { + private final Disposable myParentDisposable; + private final CoreApplicationEnvironment myEnvironment; + + protected final FileIndexFacade myFileIndexFacade; + protected final PsiManagerImpl myPsiManager; + protected final MockProject myProject; + protected final MessageBusImpl myMessageBus; + + public CoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { + myParentDisposable = parentDisposable; + myEnvironment = applicationEnvironment; + myProject = new MockProject(myEnvironment.getApplication().getPicoContainer(), myParentDisposable); + + myFileIndexFacade = createFileIndexFacade(); + myMessageBus = new MessageBusImpl(); + + PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(myProject); + myProject.registerService(PsiModificationTracker.class, modificationTracker); + myProject.registerService(FileIndexFacade.class, myFileIndexFacade); + myProject.registerService(ResolveScopeManager.class, new MockResolveScopeManager(myProject)); + myProject.registerService(ResolveCache.class, new ResolveCache(myMessageBus)); + + registerProjectExtensionPoint(PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor.class); + myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, myMessageBus, modificationTracker); + ((FileManagerImpl) myPsiManager.getFileManager()).markInitialized(); + registerProjectComponent(PsiManager.class, myPsiManager); + + myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); + myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); + myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myPsiManager)); + myProject.registerService(ProjectScopeBuilder.class, new CoreProjectScopeBuilder(myProject, myFileIndexFacade)); + myProject.registerService(DumbService.class, new MockDumbService(myProject)); + } + + protected FileIndexFacade createFileIndexFacade() { + return new MockFileIndexFacade(myProject); + } + + public void registerProjectExtensionPoint(final ExtensionPointName extensionPointName, + final Class aClass) { + CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(myProject), extensionPointName, aClass); + } + + public void registerProjectComponent(final Class interfaceClass, final T implementation) { + CoreApplicationEnvironment.registerComponentInstance(myProject.getPicoContainer(), interfaceClass, implementation); + } + + public Disposable getParentDisposable() { + return myParentDisposable; + } + + public CoreApplicationEnvironment getEnvironment() { + return myEnvironment; + } + + public MockProject getProject() { + return myProject; + } +} diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java index eeb8e1474ad2..0d34db51b4e9 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/CoreJarFileSystem.java @@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.HashMap; @@ -46,10 +47,13 @@ public class CoreJarFileSystem extends DeprecatedVirtualFileSystem { String localPath = path.substring(0, separatorIndex); String pathInJar = path.substring(separatorIndex+2); CoreJarHandler handler = getHandler(localPath); + if (handler == null) + return null; return handler.findFileByPath(pathInJar); } - private CoreJarHandler getHandler(String localPath) { + @Nullable + protected CoreJarHandler getHandler(String localPath) { CoreJarHandler handler = myHandlers.get(localPath); if (handler == null) { handler = new CoreJarHandler(this, localPath); diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java index dfb2685e2d1e..433fc1f55c77 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandlerBase.java @@ -18,6 +18,7 @@ package com.intellij.openapi.vfs.impl.jar; import com.intellij.openapi.util.io.BufferExposingByteArrayInputStream; import com.intellij.openapi.util.io.FileAttributes; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.JarFile; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.reference.SoftReference; import com.intellij.util.ArrayUtil; @@ -37,7 +38,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class JarHandlerBase { - protected final TimedReference myZipFile = new TimedReference(null); + protected final TimedReference myJarFile = new TimedReference(null); protected SoftReference> myRelPathsToEntries = new SoftReference>(null); protected final Object lock = new Object(); protected final String myBasePath; @@ -63,7 +64,7 @@ public class JarHandlerBase { synchronized (lock) { Map map = myRelPathsToEntries.get(); if (map == null) { - final ZipFile zip = getZip(); + final JarFile zip = getJar(); map = new THashMap(); if (zip != null) { @@ -88,19 +89,46 @@ public class JarHandlerBase { } @Nullable - public ZipFile getZip() { - ZipFile zip = myZipFile.get(); - if (zip == null) { - try { - zip = new ZipFile(getMirrorFile(getOriginalFile())); - myZipFile.set(zip); - } - catch (IOException e) { - return null; - } + public JarFile getJar() { + JarFile jar = myJarFile.get(); + if (jar == null) { + jar = createJarFile(); + if (jar != null) + myJarFile.set(jar); } - return zip; + return jar; + } + + @Nullable + protected JarFile createJarFile() { + try { + final ZipFile zipFile = new ZipFile(getMirrorFile(getOriginalFile())); + return new JarFile() { + @Override + public ZipEntry getEntry(String name) { + return zipFile.getEntry(name); + } + + @Override + public InputStream getInputStream(ZipEntry entry) throws IOException { + return zipFile.getInputStream(entry); + } + + @Override + public Enumeration entries() { + return zipFile.entries(); + } + + @Override + public ZipFile getZipFile() { + return zipFile; + } + }; + } + catch (IOException e) { + return null; + } } protected File getOriginalFile() { @@ -161,8 +189,8 @@ public class JarHandlerBase { @Nullable private ZipEntry convertToEntry(VirtualFile file) { String path = getRelativePath(file); - final ZipFile zip = getZip(); - return zip != null ? zip.getEntry(path) : null; + final JarFile jar = getJar(); + return jar != null ? jar.getEntry(path) : null; } public long getLength(@NotNull final VirtualFile file) { @@ -185,10 +213,10 @@ public class JarHandlerBase { return new byte[0]; } - final ZipFile zip = getZip(); - assert zip != null : file; + final JarFile jar = getJar(); + assert jar != null : file; - final InputStream stream = zip.getInputStream(entry); + final InputStream stream = jar.getInputStream(entry); assert stream != null : file; try { @@ -220,7 +248,7 @@ public class JarHandlerBase { public boolean exists(@NotNull final VirtualFile fileOrDirectory) { if (fileOrDirectory.getParent() == null) { // Optimization. Do not build entries if asked for jar root existence. - return myZipFile.get() != null || getOriginalFile().exists(); + return myJarFile.get() != null || getOriginalFile().exists(); } return getEntryInfo(fileOrDirectory) != null; diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java index f7c8749da965..3b575138a972 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/local/CoreLocalVirtualFile.java @@ -84,11 +84,15 @@ public class CoreLocalVirtualFile extends VirtualFile { if (answer == null) { List result = new ArrayList(); final File[] files = myIoFile.listFiles(); - for (File file : files) { - result.add(new CoreLocalVirtualFile(myFileSystem, file)); + if (files == null) { + answer = EMPTY_ARRAY; + } + else { + for (File file : files) { + result.add(new CoreLocalVirtualFile(myFileSystem, file)); + } + answer = result.toArray(new VirtualFile[result.size()]); } - answer = result.toArray(new VirtualFile[result.size()]); - myChildren = answer; } return answer; @@ -130,7 +134,6 @@ public class CoreLocalVirtualFile extends VirtualFile { return 0; } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/platform/core-impl/src/com/intellij/psi/stubs/StubTree.java b/platform/core-impl/src/com/intellij/psi/stubs/StubTree.java index 34aa9ee3a48e..ec9a76b40444 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/StubTree.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/StubTree.java @@ -65,13 +65,12 @@ public class StubTree { @NotNull public Map> indexStubTree() { - SerializationManager serializationManager = SerializationManager.getInstance(); StubIndexSink sink = new StubIndexSink(); for (int i = 0, plainListSize = myPlainList.size(); i < plainListSize; i++) { final StubElement stub = myPlainList.get(i); sink.myStubIdx = i; - serializationManager.getSerializer(stub).indexStub(stub, sink); + StubSerializationUtil.getSerializer(stub).indexStub(stub, sink); } return sink.getResult(); diff --git a/platform/lang-api/src/com/intellij/psi/stubs/AbstractStubIndex.java b/platform/indexing-api/src/com/intellij/psi/stubs/AbstractStubIndex.java similarity index 100% rename from platform/lang-api/src/com/intellij/psi/stubs/AbstractStubIndex.java rename to platform/indexing-api/src/com/intellij/psi/stubs/AbstractStubIndex.java diff --git a/platform/lang-api/src/com/intellij/psi/stubs/IntStubIndexExtension.java b/platform/indexing-api/src/com/intellij/psi/stubs/IntStubIndexExtension.java similarity index 100% rename from platform/lang-api/src/com/intellij/psi/stubs/IntStubIndexExtension.java rename to platform/indexing-api/src/com/intellij/psi/stubs/IntStubIndexExtension.java diff --git a/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java b/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java new file mode 100644 index 000000000000..4426bd038967 --- /dev/null +++ b/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java @@ -0,0 +1,70 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @author max + */ +package com.intellij.psi.stubs; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.IStubFileElementType; + +import java.util.ArrayList; +import java.util.List; + +public abstract class SerializationManager { + + protected final List> myAllSerializers = new ArrayList>(); + private volatile boolean mySerializersLoaded = false; + + public static SerializationManager getInstance() { + return ApplicationManager.getApplication().getComponent(SerializationManager.class); + } + + public void registerSerializer(StubSerializer serializer) { + myAllSerializers.add(serializer); + } + + protected void initSerializers() { + if (mySerializersLoaded) return; + synchronized (this) { + if (mySerializersLoaded) return; + for (StubElementTypeHolderEP holderEP : Extensions.getExtensions(StubElementTypeHolderEP.EP_NAME)) { + holderEP.initialize(); + } + final IElementType[] stubElementTypes = IElementType.enumerate(new IElementType.Predicate() { + public boolean matches(final IElementType type) { + return type instanceof StubSerializer; + } + }); + for (IElementType type : stubElementTypes) { + if (type instanceof IStubFileElementType && + ((IStubFileElementType)type).getExternalId().equals(PsiFileStubImpl.TYPE.getExternalId())) { + continue; + } + StubSerializer stubSerializer = (StubSerializer)type; + + if (!myAllSerializers.contains(stubSerializer)) { + registerSerializer(stubSerializer); + } + } + mySerializersLoaded = true; + } + } + +} \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java b/platform/indexing-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java similarity index 96% rename from platform/lang-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java rename to platform/indexing-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java index 4d17ab028629..8aacbce5f45d 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java +++ b/platform/indexing-api/src/com/intellij/psi/stubs/StringStubIndexExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/lang-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java b/platform/indexing-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java similarity index 100% rename from platform/lang-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java rename to platform/indexing-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java diff --git a/platform/lang-api/src/com/intellij/psi/stubs/StubIndex.java b/platform/indexing-api/src/com/intellij/psi/stubs/StubIndex.java similarity index 98% rename from platform/lang-api/src/com/intellij/psi/stubs/StubIndex.java rename to platform/indexing-api/src/com/intellij/psi/stubs/StubIndex.java index 2c28767eab44..1aca7059ab7e 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/StubIndex.java +++ b/platform/indexing-api/src/com/intellij/psi/stubs/StubIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/lang-api/src/com/intellij/psi/stubs/StubIndexExtension.java b/platform/indexing-api/src/com/intellij/psi/stubs/StubIndexExtension.java similarity index 100% rename from platform/lang-api/src/com/intellij/psi/stubs/StubIndexExtension.java rename to platform/indexing-api/src/com/intellij/psi/stubs/StubIndexExtension.java diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java index 3694101ae83c..fdf5d8044391 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java @@ -45,7 +45,6 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; public class JdkUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.projectRoots.JdkUtil"); @@ -86,7 +85,7 @@ public class JdkUtil { if (rtJarFileContent == null) { return null; } - ZipFile manifestJarFile; + com.intellij.openapi.vfs.JarFile manifestJarFile; try { manifestJarFile = JarFileSystem.getInstance().getJarFile(rtJarFileContent); } diff --git a/platform/core-api/src/com/intellij/psi/stubs/SerializationManager.java b/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerEx.java similarity index 66% rename from platform/core-api/src/com/intellij/psi/stubs/SerializationManager.java rename to platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerEx.java index b41a9d41306d..55f72005403d 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/SerializationManager.java +++ b/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,34 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * @author max - */ package com.intellij.psi.stubs; -import com.intellij.openapi.application.ApplicationManager; - import java.io.InputStream; import java.io.OutputStream; -public abstract class SerializationManager { +/** + * Author: dmitrylomov + */ +public abstract class SerializationManagerEx extends SerializationManager { - public static SerializationManager getInstance() { - return ApplicationManager.getApplication().getComponent(SerializationManager.class); + public static SerializationManagerEx getInstanceEx() { + return (SerializationManagerEx) SerializationManager.getInstance(); } - public abstract void registerSerializer(StubSerializer serializer); - public abstract void serialize(StubElement rootStub, OutputStream stream); public abstract StubElement deserialize(InputStream stream); - public abstract StubSerializer getSerializer(StubElement rootStub); - public abstract boolean isNameStorageCorrupted(); public abstract void repairNameStorage(); public abstract void flushNameStorage(); -} \ No newline at end of file +} diff --git a/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerImpl.java b/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerImpl.java index a7ed63f25059..e438e9d38b59 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerImpl.java +++ b/platform/lang-api/src/com/intellij/psi/stubs/SerializationManagerImpl.java @@ -17,42 +17,30 @@ package com.intellij.psi.stubs; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.ApplicationComponent; -import com.intellij.openapi.diagnostic.LogUtil; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.IStubFileElementType; -import com.intellij.util.io.DataInputOutputUtil; +import com.intellij.util.io.AbstractStringEnumerator; import com.intellij.util.io.PersistentStringEnumerator; -import gnu.trove.TIntObjectHashMap; -import gnu.trove.TObjectIntHashMap; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; /* * @author max */ -public class SerializationManagerImpl extends SerializationManager implements ApplicationComponent { +public class SerializationManagerImpl extends SerializationManagerEx implements ApplicationComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubs.SerializationManagerImpl"); - private PersistentStringEnumerator myNameStorage; - - private final TIntObjectHashMap> myIdToSerializer = new TIntObjectHashMap>(); - private final TObjectIntHashMap> mySerializerToId = new TObjectIntHashMap>(); - private final List> myAllSerializers = new ArrayList>(); private final AtomicBoolean myNameStorageCrashed = new AtomicBoolean(false); private final File myFile = new File(PathManager.getIndexRoot(), "rep.names"); - private volatile boolean mySerializersLoaded = false; private final AtomicBoolean myShutdownPerformed = new AtomicBoolean(false); + private AbstractStringEnumerator myNameStorage; + private StubSerializationHelper myStubSerializationHelper; public SerializationManagerImpl() { myFile.getParentFile().mkdirs(); @@ -60,12 +48,13 @@ public class SerializationManagerImpl extends SerializationManager implements Ap // we need to cache last id -> String mappings due to StringRefs and stubs indexing that initially creates stubs (doing enumerate on String) // and then index them (valueOf), also similar string items are expected to be enumerated during stubs processing myNameStorage = new PersistentStringEnumerator(myFile, true); + myStubSerializationHelper = new StubSerializationHelper(myNameStorage); } catch (IOException e) { - myNameStorageCrashed.set(true); + nameStorageCrashed(); LOG.info(e); repairNameStorage(); // need this in order for myNameStorage not to be null - myNameStorageCrashed.set(true); + nameStorageCrashed(); } finally { registerSerializer(PsiFileStubImpl.TYPE); @@ -97,16 +86,14 @@ public class SerializationManagerImpl extends SerializationManager implements Ap } } myNameStorage = new PersistentStringEnumerator(myFile, true); - - mySerializerToId.clear(); - myIdToSerializer.clear(); + myStubSerializationHelper = new StubSerializationHelper(myNameStorage); for (StubSerializer serializer : myAllSerializers) { - assignId(serializer); + myStubSerializationHelper.assignId(serializer); } } catch (IOException e) { LOG.info(e); - myNameStorageCrashed.set(true); + nameStorageCrashed(); } } } @@ -116,126 +103,8 @@ public class SerializationManagerImpl extends SerializationManager implements Ap myNameStorage.force(); } - public void registerSerializer(@NotNull StubSerializer serializer) { - myAllSerializers.add(serializer); - try { - assignId(serializer); - } - catch (IOException e) { - LOG.info(e); - myNameStorageCrashed.set(true); - } - } - - private void assignId(@NotNull final StubSerializer serializer) throws IOException { - final int id = persistentId(serializer); - final StubSerializer old = myIdToSerializer.put(id, serializer); - assert old == null : "ID: " + serializer.getExternalId() + " is not unique; Already registered serializer with this ID: " + old.getClass().getName(); - - final int oldId = mySerializerToId.put(serializer, id); - assert oldId == 0 : "Serializer " + serializer + " is already registered; Old ID:" + oldId; - } - - private int persistentId(@NotNull final StubSerializer serializer) throws IOException { - if (myNameStorage == null) { - throw new IOException("SerializationManager's name storage failed to initialize"); - } - return myNameStorage.enumerate(serializer.getExternalId()); - } - - private synchronized void initSerializers() { - if (mySerializersLoaded) return; - for(StubElementTypeHolderEP holderEP: Extensions.getExtensions(StubElementTypeHolderEP.EP_NAME)) { - holderEP.initialize(); - } - final IElementType[] stubElementTypes = IElementType.enumerate(new IElementType.Predicate() { - public boolean matches(final IElementType type) { - return type instanceof StubSerializer; - } - }); - for(IElementType type: stubElementTypes) { - if (type instanceof IStubFileElementType && ((IStubFileElementType) type).getExternalId().equals(PsiFileStubImpl.TYPE.getExternalId())) { - continue; - } - StubSerializer stubSerializer = (StubSerializer) type; - - if (!myAllSerializers.contains(stubSerializer)) { - registerSerializer(stubSerializer); - } - } - mySerializersLoaded = true; - } - - public void serialize(StubElement rootStub, OutputStream stream) { - if (!mySerializersLoaded) initSerializers(); - StubOutputStream stubOutputStream = new StubOutputStream(stream, myNameStorage); - doSerialize(rootStub, stubOutputStream); - } - - private void doSerialize(final StubElement rootStub, final StubOutputStream stream) { - try { - final StubSerializer serializer = getSerializer(rootStub); - - DataInputOutputUtil.writeINT(stream, getClassId(serializer)); - serializer.serialize(rootStub, stream); - - final List children = rootStub.getChildrenStubs(); - final int childrenSize = children.size(); - DataInputOutputUtil.writeINT(stream, childrenSize); - for (int i = 0; i < childrenSize; ++i) { - doSerialize(children.get(i), stream); - } - } - catch (IOException e) { - LOG.info(e); - myNameStorageCrashed.set(true); - } - } - - public StubSerializer getSerializer(final StubElement rootStub) { - if (rootStub instanceof PsiFileStub) { - final PsiFileStub fileStub = (PsiFileStub)rootStub; - return fileStub.getType(); - } - - return rootStub.getStubType(); - } - - public StubElement deserialize(InputStream stream) { - StubInputStream inputStream = new StubInputStream(stream, myNameStorage); - if (!mySerializersLoaded) initSerializers(); - try { - return deserialize(inputStream, null); - } - catch (IOException e) { - myNameStorageCrashed.set(true); - LOG.info(e); - throw new RuntimeException(e); - } - } - - private StubElement deserialize(StubInputStream stream, StubElement parentStub) throws IOException { - final int id = DataInputOutputUtil.readINT(stream); - final StubSerializer serializer = getClassById(id); - - assert serializer != null : "No serializer registered for stub: ID=" + id + "; parent stub class=" + (parentStub != null? parentStub.getClass().getName() : "null"); - - StubElement stub = serializer.deserialize(stream, parentStub); - int childCount = DataInputOutputUtil.readINT(stream); - for (int i = 0; i < childCount; i++) { - deserialize(stream, stub); - } - return stub; - } - - private int getClassId(final StubSerializer serializer) { - final int idValue = mySerializerToId.get(serializer); - assert idValue != 0: "No ID found for serializer " + LogUtil.objectAndClass(serializer); - return idValue; - } - - private StubSerializer getClassById(int id) { - return myIdToSerializer.get(id); + protected void nameStorageCrashed() { + myNameStorageCrashed.set(true); } @NotNull @@ -263,4 +132,42 @@ public class SerializationManagerImpl extends SerializationManager implements Ap LOG.error(e); } } + + public void registerSerializer(@NotNull StubSerializer serializer) { + super.registerSerializer(serializer); + try { + myStubSerializationHelper.assignId(serializer); + } + catch (IOException e) { + LOG.info(e); + nameStorageCrashed(); + } + } + + + + public void serialize(StubElement rootStub, OutputStream stream) { + initSerializers(); + try { + myStubSerializationHelper.serialize(rootStub, stream); + } + catch (IOException e) { + LOG.info(e); + nameStorageCrashed(); + } + } + + + public StubElement deserialize(InputStream stream) { + initSerializers(); + + try { + return myStubSerializationHelper.deserialize(stream); + } + catch (IOException e) { + nameStorageCrashed(); + LOG.info(e); + throw new RuntimeException(e); + } + } } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java index ddfd11b99314..47a07ed76341 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java @@ -58,7 +58,7 @@ public class SerializedStubTree { myStubElement = null; if (willIndexStub) return stubElement; } - return SerializationManager.getInstance().deserialize(new UnsyncByteArrayInputStream(myBytes)); + return SerializationManagerEx.getInstanceEx().deserialize(new UnsyncByteArrayInputStream(myBytes)); } public boolean equals(final Object that) { diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 8bc874d04202..b4e6a7182b55 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -122,7 +122,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi if (rootStub == null) return; final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(); - SerializationManager.getInstance().serialize(rootStub, bytes); + SerializationManagerEx.getInstanceEx().serialize(rootStub, bytes); final int key = Math.abs(FileBasedIndex.getFileId(inputData.getFile())); result.put(key, new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub)); @@ -293,7 +293,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi } private static void checkNameStorage() throws StorageException { - final SerializationManager serializationManager = SerializationManager.getInstance(); + final SerializationManagerEx serializationManager = SerializationManagerEx.getInstanceEx(); if (serializationManager.isNameStorageCorrupted()) { serializationManager.repairNameStorage(); //noinspection ThrowFromFinallyBlock diff --git a/platform/lang-impl/src/com/intellij/util/indexing/CustomImplementationFileBasedIndexExtension.java b/platform/lang-impl/src/com/intellij/util/indexing/CustomImplementationFileBasedIndexExtension.java index 16a0a4a43860..32b22274dced 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/CustomImplementationFileBasedIndexExtension.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/CustomImplementationFileBasedIndexExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index b3b1728b3914..a8349053520a 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -58,6 +58,7 @@ import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.search.EverythingGlobalScope; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.stubs.SerializationManager; +import com.intellij.psi.stubs.SerializationManagerEx; import com.intellij.util.*; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.containers.ConcurrentHashSet; @@ -670,7 +671,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { } if (!HeavyProcessLatch.INSTANCE.isRunning() && modCount == myLocalModCount) { // do not interfere with 'main' jobs - SerializationManager.getInstance().flushNameStorage(); + SerializationManagerEx.getInstanceEx().flushNameStorage(); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexStorage.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexStorage.java index 5b0f2aa3f447..a268c0c12f27 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexStorage.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UpdatableIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/UpdatableIndex.java index 07411af9cfdf..35c51999fce6 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UpdatableIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UpdatableIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index efca09d692a7..7f346cef4956 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -29,10 +29,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.JarFileSystem; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.openapi.vfs.*; import com.intellij.ui.GuiUtils; import com.intellij.util.io.ZipUtil; import com.intellij.util.ui.OptionsDialog; @@ -333,10 +330,11 @@ public class BrowserUtil { if (!extract.get()) return null; - final ZipFile jarFile = jarFileSystem.getJarFile(file); - ZipEntry entry = jarFile.getEntry(targetFileRelativePath); + final ZipFile zipFile = jarFileSystem.getJarFile(file).getZipFile(); + if (zipFile == null) return null; + ZipEntry entry = zipFile.getEntry(targetFileRelativePath); if (entry == null) return null; - InputStream is = jarFile.getInputStream(entry); + InputStream is = zipFile.getInputStream(entry); try { ZipUtil.extractEntry(entry, is, outputDir); } @@ -348,7 +346,7 @@ public class BrowserUtil { public void run() { new Task.Backgroundable(null, "Extracting files...", true) { public void run(@NotNull final ProgressIndicator indicator) { - final int size = jarFile.size(); + final int size = zipFile.size(); final int[] counter = new int[]{0}; class MyFilter implements FilenameFilter { @@ -372,8 +370,8 @@ public class BrowserUtil { } try { - ZipUtil.extract(jarFile, outputDir, new MyFilter(true)); - ZipUtil.extract(jarFile, outputDir, new MyFilter(false)); + ZipUtil.extract(zipFile, outputDir, new MyFilter(true)); + ZipUtil.extract(zipFile, outputDir, new MyFilter(false)); FileUtil.writeToFile(timestampFile, currentTimestamp.getBytes()); } catch (IOException ignore) { diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java index 4eb914886771..cf066b254337 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/JarFileSystem.java @@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.zip.ZipFile; public abstract class JarFileSystem extends NewVirtualFileSystem implements JarCopyingFileSystem { @NonNls public static final String PROTOCOL = StandardFileSystems.JAR_PROTOCOL; @@ -34,7 +33,8 @@ public abstract class JarFileSystem extends NewVirtualFileSystem implements JarC @Nullable public abstract VirtualFile getVirtualFileForJar(@Nullable VirtualFile entryVFile); - public abstract ZipFile getJarFile(VirtualFile entryVFile) throws IOException; + @Nullable + public abstract JarFile getJarFile(VirtualFile entryVFile) throws IOException; @SuppressWarnings("MethodMayBeStatic") @Nullable diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java index 165de86755c8..1ab273622a04 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.*; -import java.util.zip.ZipFile; public class JarFileSystemImpl extends JarFileSystem implements ApplicationComponent { private final Set myNoCopyJarPaths = SystemInfo.isFileSystemCaseSensitive ? @@ -173,10 +172,10 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo } @Override - public ZipFile getJarFile(VirtualFile entryVFile) throws IOException { + public JarFile getJarFile(VirtualFile entryVFile) throws IOException { JarHandler handler = getHandler(entryVFile); - return handler.getZip(); + return handler.getJar(); } @Nullable diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandler.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandler.java index 276fbafcad5a..126a25a0d74e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandler.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarHandler.java @@ -64,7 +64,7 @@ public class JarHandler extends JarHandlerBase implements FileSystemInterface { public VirtualFile markDirty() { synchronized (lock) { myRelPathsToEntries = null; - myZipFile.set(null); + myJarFile.set(null); final NewVirtualFile root = (NewVirtualFile) JarFileSystem.getInstance().findFileByPath(myBasePath + JarFileSystem.JAR_SEPARATOR); diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 63b695c72159..54be17c8badf 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -35,7 +35,7 @@ + serviceImplementation="com.intellij.openapi.roots.impl.ProjectFileIndexFacade"/> diff --git a/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java b/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java index 69950d9b08e4..553326185600 100644 --- a/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java @@ -32,16 +32,20 @@ import java.io.IOException; */ public class CoreModuleManagerTest extends UsefulTestCase { public void _testLoadingModules() throws IOException, JDOMException, InvalidDataException { - CoreEnvironment env = new CoreEnvironment(getTestRootDisposable()); - ProjectModelEnvironment.register(env); + CoreApplicationEnvironment appEnv = new CoreApplicationEnvironment(getTestRootDisposable()); + ProjectModelEnvironment.registerApplicationEnvironment(appEnv); + + CoreProjectEnvironment prjEnv = new CoreProjectEnvironment(getTestRootDisposable(), appEnv); + ProjectModelEnvironment.registerProjectEnvironment(prjEnv); + final String projectPath = PathManagerEx.getTestDataPath("/core/loadingTest"); VirtualFile vFile = StandardFileSystems.local().findFileByPath(projectPath); - CoreProjectLoader.loadProject(env.getProject(), vFile); - final ModuleManager moduleManager = ModuleManager.getInstance(env.getProject()); + CoreProjectLoader.loadProject(prjEnv.getProject(), vFile); + final ModuleManager moduleManager = ModuleManager.getInstance(prjEnv.getProject()); final Module[] modules = moduleManager.getModules(); assertEquals(1, modules.length); - ProjectRootManager projectRootManager = ProjectRootManager.getInstance(env.getProject()); + ProjectRootManager projectRootManager = ProjectRootManager.getInstance(prjEnv.getProject()); assertEquals("1.6", projectRootManager.getProjectSdkName()); ModuleRootManager rootManager = ModuleRootManager.getInstance(modules[0]); diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java index 1b5e7bac4bda..e4d607ee7113 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java @@ -35,6 +35,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.PathUtil; import org.jetbrains.annotations.NotNull; /** @@ -50,7 +51,7 @@ public class CoreModule extends MockComponentManager implements ModuleEx { myPath = moduleFilePath; Extensions.instantiateArea(ExtensionAreas.IDEA_MODULE, this, null); - CoreEnvironment.registerExtensionPoint(Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class); + CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class); Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { @@ -110,7 +111,7 @@ public class CoreModule extends MockComponentManager implements ModuleEx { @NotNull @Override public String getName() { - return StringUtil.trimEnd(myPath, ModuleFileType.DOT_DEFAULT_EXTENSION); + return StringUtil.trimEnd(PathUtil.getFileName(myPath), ModuleFileType.DOT_DEFAULT_EXTENSION); } @Override diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreProjectJdkTable.java b/platform/projectModel-impl/src/com/intellij/core/CoreProjectJdkTable.java index 864f4183cae6..ef055c0bfc14 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreProjectJdkTable.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreProjectJdkTable.java @@ -18,42 +18,66 @@ package com.intellij.core; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkTypeId; +import com.intellij.openapi.util.Comparing; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; /** * @author yole */ public class CoreProjectJdkTable extends ProjectJdkTable { + private final List mySdks = new ArrayList(); + @Override public Sdk findJdk(String name) { + synchronized (mySdks) { + for (Sdk jdk : mySdks) { + if (Comparing.strEqual(name, jdk.getName())) { + return jdk; + } + } + } return null; } @Override public Sdk findJdk(String name, String type) { - return null; + return findJdk(name); } @Override public Sdk[] getAllJdks() { - return new Sdk[0]; + synchronized (mySdks) { + return mySdks.toArray(new Sdk[mySdks.size()]); + } } @Override public List getSdksOfType(SdkTypeId type) { - return Collections.emptyList(); + List result = new ArrayList(); + synchronized (mySdks) { + for (Sdk sdk : mySdks) { + if (sdk.getSdkType() == type) { + result.add(sdk); + } + } + } + return result; } @Override public void addJdk(Sdk jdk) { - throw new UnsupportedOperationException(); + synchronized (mySdks) { + mySdks.add(jdk); + } } @Override public void removeJdk(Sdk jdk) { - throw new UnsupportedOperationException(); + synchronized (mySdks) { + mySdks.remove(jdk); + } } @Override diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java index 635f9fa27352..3e0319b3522a 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java @@ -23,8 +23,6 @@ import com.intellij.openapi.components.impl.stores.StorageData; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.roots.impl.DirectoryIndex; -import com.intellij.openapi.roots.impl.DirectoryIndexImpl; import com.intellij.openapi.roots.impl.ProjectRootManagerImpl; import com.intellij.openapi.roots.impl.libraries.LibraryTableBase; import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable; @@ -86,7 +84,7 @@ public class CoreProjectLoader { } moduleManager.loadModules(); - ((DirectoryIndexImpl) DirectoryIndex.getInstance(project)).initialize(); + //((DirectoryIndexImpl) DirectoryIndex.getInstance(project)).initialize(); } public static StorageData loadStorageFile(ComponentManager componentManager, VirtualFile modulesXml) throws JDOMException, IOException { diff --git a/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java b/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java index ea05242bea81..e08d13d298c9 100644 --- a/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java +++ b/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java @@ -40,24 +40,27 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; * @author yole */ public class ProjectModelEnvironment { - public static void register(CoreEnvironment env) { + public static void registerApplicationEnvironment(CoreApplicationEnvironment env) { Extensions.registerAreaClass(ExtensionAreas.IDEA_MODULE, null); PathMacrosImpl pathMacros = new PathMacrosImpl(); env.registerApplicationComponent(PathMacros.class, pathMacros); - CoreEnvironment.registerApplicationExtensionPoint(OrderRootType.EP_NAME, OrderRootType.class); - CoreEnvironment.registerApplicationExtensionPoint(SdkFinder.EP_NAME, SdkFinder.class); - CoreEnvironment.registerApplicationExtensionPoint(PathMacroFilter.EP_NAME, PathMacroFilter.class); + CoreApplicationEnvironment.registerApplicationExtensionPoint(OrderRootType.EP_NAME, OrderRootType.class); + CoreApplicationEnvironment.registerApplicationExtensionPoint(SdkFinder.EP_NAME, SdkFinder.class); + CoreApplicationEnvironment.registerApplicationExtensionPoint(PathMacroFilter.EP_NAME, PathMacroFilter.class); env.getApplication().registerService(ProjectJdkTable.class, new CoreProjectJdkTable()); env.getApplication().registerService(ApplicationLibraryTable.class, new ApplicationLibraryTable()); env.getApplication().registerService(LibraryTablesRegistrar.class, new LibraryTablesRegistrarImpl()); + } + public static void registerProjectEnvironment(CoreProjectEnvironment env) { final MockProject project = env.getProject(); env.registerProjectComponent(ModuleManager.class, new CoreModuleManager(project, env.getParentDisposable())); - env.registerProjectComponent(PathMacroManager.class, new ProjectPathMacroManager(pathMacros, project)); + env.registerProjectComponent(PathMacroManager.class, new ProjectPathMacroManager(PathMacros.getInstance(), project)); env.registerProjectExtensionPoint(DirectoryIndexExcludePolicy.EP_NAME, DirectoryIndexExcludePolicy.class); env.registerProjectExtensionPoint(ProjectExtension.EP_NAME, ProjectExtension.class); DirectoryIndex index = new DirectoryIndexImpl(project); - env.registerProjectComponent(DirectoryIndex.class, index); + //env.registerProjectComponent(DirectoryIndex.class, index); + project.registerService(DirectoryIndex.class, index); env.registerProjectComponent(ProjectRootManager.class, new ProjectRootManagerImpl(project, index)); project.registerService(ProjectLibraryTable.class, new ProjectLibraryTable()); project.registerService(ProjectFileIndex.class, new ProjectFileIndexImpl(project, index, FileTypeRegistry.getInstance())); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java index 20106e0e327d..0ef62c27ae24 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/BasePathMacroManager.java @@ -24,12 +24,13 @@ import com.intellij.openapi.components.TrackingPathMacroSubstitutor; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.StandardFileSystems; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.FactoryMap; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; -import java.io.File; import java.util.*; public class BasePathMacroManager extends PathMacroManager { @@ -41,15 +42,14 @@ public class BasePathMacroManager extends PathMacroManager { protected static void addFileHierarchyReplacements(ExpandMacroToPathMap result, String macroName, @Nullable String path) { if (path == null) return; - final File f = new File(FileUtil.toSystemDependentName(path)); - addFileHierarchyReplacements(result, f, "$" + macroName + "$"); + addFileHierarchyReplacements(result, StandardFileSystems.local().findFileByPath(path), "$" + macroName + "$"); } - protected static void addFileHierarchyReplacements(ExpandMacroToPathMap result, @Nullable File f, String macro) { + private static void addFileHierarchyReplacements(ExpandMacroToPathMap result, @Nullable VirtualFile f, String macro) { if (f == null) return; - addFileHierarchyReplacements(result, f.getParentFile(), macro + "/.."); + addFileHierarchyReplacements(result, f.getParent(), macro + "/.."); - final String path = FileUtil.toSystemIndependentName(f.getAbsolutePath()); + final String path = FileUtil.toSystemIndependentName(f.getCanonicalPath()); String s = macro; if (StringUtil.endsWithChar(path, '/')) s += "/"; result.put(s, path); @@ -59,10 +59,10 @@ public class BasePathMacroManager extends PathMacroManager { if (path == null) return; String macro = "$" + macroName + "$"; - File dir = new File(FileUtil.toSystemDependentName(path)); + VirtualFile dir = StandardFileSystems.local().findFileByPath(path); boolean check = false; - while (dir != null && dir.getParentFile() != null) { - path = FileUtil.toSystemIndependentName(dir.getAbsolutePath()); + while (dir != null && dir.getParent() != null) { + path = FileUtil.toSystemIndependentName(dir.getCanonicalPath()); String s = macro; if (StringUtil.endsWithChar(path, '/')) s += "/"; @@ -83,7 +83,7 @@ public class BasePathMacroManager extends PathMacroManager { macro += "/.."; check = true; - dir = dir.getParentFile(); + dir = dir.getParent(); } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 510b837457ba..7ebe49401d5e 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -652,9 +652,13 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project private Module loadModuleInternal(String filePath, @Nullable ProgressIndicator progressIndicator) throws ModuleWithNameAlreadyExists, IOException, StateStorageException { - final File moduleFile = new File(filePath); - filePath = resolveShortWindowsName(filePath); + final VirtualFile moduleFile = StandardFileSystems.local().findFileByPath(filePath); + if (moduleFile == null) { + throw new IOException(ProjectBundle.message("module.file.does.not.exist.error", filePath)); + } + + filePath = resolveShortWindowsName(filePath); final String name = moduleFile.getName(); if (progressIndicator != null) { progressIndicator.setText2(FileUtil.getNameWithoutExtension(name)); diff --git a/platform/lang-impl/src/com/intellij/openapi/vcs/impl/ProjectFileIndexFacade.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java similarity index 96% rename from platform/lang-impl/src/com/intellij/openapi/vcs/impl/ProjectFileIndexFacade.java rename to platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java index 466ed9c7a8a8..476fc854f862 100644 --- a/platform/lang-impl/src/com/intellij/openapi/vcs/impl/ProjectFileIndexFacade.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ProjectFileIndexFacade.java @@ -14,14 +14,13 @@ * limitations under the License. */ -package com.intellij.openapi.vcs.impl; +package com.intellij.openapi.roots.impl; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.roots.impl.DirectoryIndex; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.Nullable; diff --git a/platform/util/src/com/intellij/util/io/AbstractStringEnumerator.java b/platform/util/src/com/intellij/util/io/AbstractStringEnumerator.java new file mode 100644 index 000000000000..589fa0add6fe --- /dev/null +++ b/platform/util/src/com/intellij/util/io/AbstractStringEnumerator.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.io; + +import com.intellij.openapi.Forceable; +import org.jetbrains.annotations.Nullable; + +import java.io.Closeable; +import java.io.IOException; + +/** + * Author: dmitrylomov + */ +public interface AbstractStringEnumerator extends Closeable, Forceable { + int enumerate(@Nullable String value) throws IOException; + + @Nullable + String valueOf(int idx) throws IOException; + + void markCorrupted(); +} diff --git a/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java b/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java index ed0c8218a6f9..f19ee9881643 100644 --- a/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java +++ b/platform/util/src/com/intellij/util/io/DataInputOutputUtil.java @@ -32,11 +32,11 @@ public class DataInputOutputUtil { record.skipBytes(record.readUnsignedShort()); } - public static StringRef readNAME(DataInput record, PersistentStringEnumerator nameStore) throws IOException { + public static StringRef readNAME(DataInput record, AbstractStringEnumerator nameStore) throws IOException { return StringRef.fromStream(record, nameStore); } - public static void writeNAME(DataOutput record, final String name, PersistentStringEnumerator nameStore) throws IOException { + public static void writeNAME(DataOutput record, final String name, AbstractStringEnumerator nameStore) throws IOException { final int nameId = name != null ? nameStore.enumerate(name) : 0; record.writeByte(nameId & 0xFF); writeINT(record, (nameId >> 8)); diff --git a/platform/util/src/com/intellij/util/io/PersistentStringEnumerator.java b/platform/util/src/com/intellij/util/io/PersistentStringEnumerator.java index e7b46210c319..f19ce0b85f82 100644 --- a/platform/util/src/com/intellij/util/io/PersistentStringEnumerator.java +++ b/platform/util/src/com/intellij/util/io/PersistentStringEnumerator.java @@ -24,7 +24,7 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.locks.Lock; -public class PersistentStringEnumerator extends PersistentEnumeratorDelegate{ +public class PersistentStringEnumerator extends PersistentEnumeratorDelegate implements AbstractStringEnumerator { private static final int STRIPE_POWER = 4; private static final int STRIPE_COUNT = 1 << STRIPE_POWER; private static final int STRIPE_MASK = STRIPE_COUNT - 1; diff --git a/platform/util/src/com/intellij/util/io/StringRef.java b/platform/util/src/com/intellij/util/io/StringRef.java index 2e4679cd4ad1..a45c08e93bba 100644 --- a/platform/util/src/com/intellij/util/io/StringRef.java +++ b/platform/util/src/com/intellij/util/io/StringRef.java @@ -28,7 +28,7 @@ public class StringRef { private int id; private String name; - private final PersistentStringEnumerator store; + private final AbstractStringEnumerator store; private StringRef(final String name) { this.name = name; @@ -36,7 +36,7 @@ public class StringRef { store = null; } - private StringRef(final int id, final PersistentStringEnumerator store) { + private StringRef(final int id, final AbstractStringEnumerator store) { this.id = id; this.store = store; name = null; @@ -56,13 +56,13 @@ public class StringRef { return name; } - public void writeTo(DataOutput out, PersistentStringEnumerator store) throws IOException { + public void writeTo(DataOutput out, AbstractStringEnumerator store) throws IOException { int nameId = getId(store); out.writeByte(nameId & 0xFF); DataInputOutputUtil.writeINT(out, nameId >> 8); } - public int getId(PersistentStringEnumerator store) { + public int getId(AbstractStringEnumerator store) { if (id == -1) { try { id = store.enumerate(name); @@ -98,7 +98,7 @@ public class StringRef { return source == null ? null : new StringRef(source); } - public static StringRef fromStream(DataInput in, PersistentStringEnumerator store) throws IOException { + public static StringRef fromStream(DataInput in, AbstractStringEnumerator store) throws IOException { final int low = in.readUnsignedByte(); final int nameId = (DataInputOutputUtil.readINT(in) << 8) | low; diff --git a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java index 13d17f44dfcf..f43b32dc7bc0 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java +++ b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java @@ -57,7 +57,6 @@ import java.io.IOException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.ZipFile; /** * @author Hani Suleiman Date: Jul 20, 2005 Time: 1:37:36 PM @@ -77,7 +76,7 @@ public class TestNGUtil try { final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(testngjar); if (jarRoot != null) { - final ZipFile zipFile = JarFileSystem.getInstance().getJarFile(jarRoot); + final JarFile zipFile = JarFileSystem.getInstance().getJarFile(jarRoot); final String version = JarVersionDetectionUtil.detectJarVersion(zipFile); if (version != null && version.compareTo("5.12") > 0) { return false; diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index 6f614bddea9a..621a2c0d8808 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -203,7 +203,7 @@ + serviceImplementation="com.intellij.openapi.roots.impl.ProjectFileIndexFacade"/>