mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'upsource-master'
This commit is contained in:
Generated
+1
@@ -56,6 +56,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/java/compiler/instrumentation-util/instrumentation-util.iml" filepath="$PROJECT_DIR$/java/compiler/instrumentation-util/instrumentation-util.iml" group="java/compiler" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/java-i18n/java-i18n.iml" filepath="$PROJECT_DIR$/plugins/java-i18n/java-i18n.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/java-impl/java-impl.iml" filepath="$PROJECT_DIR$/java/java-impl/java-impl.iml" group="java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/java-indexing-impl/java-indexing-impl.iml" filepath="$PROJECT_DIR$/java/java-indexing-impl/java-indexing-impl.iml" group="java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/java-psi-api/java-psi-api.iml" filepath="$PROJECT_DIR$/java/java-psi-api/java-psi-api.iml" group="java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/java-psi-impl/java-psi-impl.iml" filepath="$PROJECT_DIR$/java/java-psi-impl/java-psi-impl.iml" group="java" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java/java-runtime/java-runtime.iml" filepath="$PROJECT_DIR$/java/java-runtime/java-runtime.iml" group="java" />
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
<dirname property="build.dir" file="${ant.file}"/>
|
||||
<property name="project.home" value="${build.dir}/.."/>
|
||||
<property name="gant.home" value="${project.home}/build/lib/gant"/>
|
||||
<property name="gant.target" value="default"/>
|
||||
|
||||
<path id="gant.classpath">
|
||||
<fileset dir="${gant.home}/lib">
|
||||
@@ -14,6 +15,6 @@
|
||||
</taskdef>
|
||||
|
||||
<target name="doGant">
|
||||
<gant file="${gant.script}"/>
|
||||
<gant file="${gant.script}" target="${gant.target}"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
<macrodef name="run">
|
||||
<attribute name="script"/>
|
||||
<attribute name="target" default="default"/>
|
||||
<attribute name="deploy"/>
|
||||
|
||||
<sequential>
|
||||
@@ -29,6 +30,7 @@
|
||||
<jvmarg line=""-Ddeploy=@{deploy}""/>
|
||||
<jvmarg line=""-Dmodules.output=${modules.output}""/>
|
||||
<jvmarg line=""-Dgant.script=@{script}""/>
|
||||
<jvmarg line=""-Dgant.target=@{target}""/>
|
||||
|
||||
<classpath>
|
||||
<fileset dir="${project.home}/lib/ant/lib">
|
||||
@@ -62,4 +64,10 @@
|
||||
<run script="${project.home}/build/scripts/layouts.gant"
|
||||
deploy="${project.home}/out/deploy"/>
|
||||
</target>
|
||||
|
||||
<target name="build-jars">
|
||||
<run script="${project.home}/build/scripts/dist.gant"
|
||||
target="build-dist-jars"
|
||||
deploy="${project.home}/out/deploy"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -31,6 +31,8 @@
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="java-psi-impl" exported="" />
|
||||
<orderEntry type="module" module-name="RegExpSupport" />
|
||||
<orderEntry type="module" module-name="java-indexing-impl" exported="" />
|
||||
<orderEntry type="module" module-name="idea" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="java-psi-api" exported="" />
|
||||
<orderEntry type="module" module-name="java-psi-impl" exported="" />
|
||||
<orderEntry type="module" module-name="indexing-api" exported="" />
|
||||
<orderEntry type="module" module-name="indexing-impl" exported="" />
|
||||
<orderEntry type="module" module-name="projectModel-api" />
|
||||
<orderEntry type="module" module-name="projectModel-impl" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<File> myClasspath = new ArrayList<File>();
|
||||
private VirtualFile[] myClasspathRoots = null;
|
||||
private final List<VirtualFile> myClasspath = new ArrayList<VirtualFile>();
|
||||
|
||||
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<VirtualFile> answerList = new ArrayList<VirtualFile>(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<VirtualFile> 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<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
|
||||
return new CollectionQuery<VirtualFile>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<VirtualFile> myClasspath = new ArrayList<VirtualFile>();
|
||||
|
||||
public CorePackageIndex() {
|
||||
}
|
||||
|
||||
private List<VirtualFile> roots() {
|
||||
return myClasspath;
|
||||
}
|
||||
|
||||
private List<VirtualFile> findDirectoriesByPackageName(String packageName) {
|
||||
List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
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<VirtualFile> getDirsByPackageName(@NotNull String packageName, boolean includeLibrarySources) {
|
||||
return new CollectionQuery<VirtualFile>(findDirectoriesByPackageName(packageName));
|
||||
}
|
||||
|
||||
public void addToClasspath(VirtualFile root) {
|
||||
myClasspath.add(root);
|
||||
}
|
||||
}
|
||||
+2
-40
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<? extends ZipEntry> entries();
|
||||
|
||||
@Nullable ZipFile getZipFile();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<StubSerializer<? extends StubElement>> myIdToSerializer = new TIntObjectHashMap<StubSerializer<? extends StubElement>>();
|
||||
protected final TObjectIntHashMap<StubSerializer<? extends StubElement>> mySerializerToId = new TObjectIntHashMap<StubSerializer<? extends StubElement>>();
|
||||
|
||||
public StubSerializationHelper(AbstractStringEnumerator nameStorage) {
|
||||
myNameStorage = nameStorage;
|
||||
}
|
||||
public void assignId(@NotNull final StubSerializer<? extends StubElement> 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<? extends StubElement> 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<StubElement> 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
+22
-68
@@ -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<FileTypeRegistry>(myFileTypeRegistry),
|
||||
new StaticGetter<EncodingRegistry>(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<CharSequence, Document>() {
|
||||
@@ -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 <T> void registerProjectComponent(final Class<T> 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 <T> void addExplicitExtension(final LanguageExtension<T> 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 <T> void addExplicitExtension(final FileTypeExtension<T> 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 <T> void addExtension(ExtensionPointName<T> name, final T extension) {
|
||||
final ExtensionPoint<T> 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 <T> void registerProjectExtensionPoint(final ExtensionPointName<T> extensionPointName,
|
||||
final Class<? extends T> 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);
|
||||
}
|
||||
}
|
||||
@@ -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 <T> void registerProjectExtensionPoint(final ExtensionPointName<T> extensionPointName,
|
||||
final Class<? extends T> aClass) {
|
||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(myProject), extensionPointName, aClass);
|
||||
}
|
||||
|
||||
public <T> void registerProjectComponent(final Class<T> 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<ZipFile> myZipFile = new TimedReference<ZipFile>(null);
|
||||
protected final TimedReference<JarFile> myJarFile = new TimedReference<JarFile>(null);
|
||||
protected SoftReference<Map<String, EntryInfo>> myRelPathsToEntries = new SoftReference<Map<String, EntryInfo>>(null);
|
||||
protected final Object lock = new Object();
|
||||
protected final String myBasePath;
|
||||
@@ -63,7 +64,7 @@ public class JarHandlerBase {
|
||||
synchronized (lock) {
|
||||
Map<String, EntryInfo> map = myRelPathsToEntries.get();
|
||||
if (map == null) {
|
||||
final ZipFile zip = getZip();
|
||||
final JarFile zip = getJar();
|
||||
|
||||
map = new THashMap<String, EntryInfo>();
|
||||
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<? extends ZipEntry> 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;
|
||||
|
||||
@@ -84,11 +84,15 @@ public class CoreLocalVirtualFile extends VirtualFile {
|
||||
if (answer == null) {
|
||||
List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
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;
|
||||
|
||||
@@ -65,13 +65,12 @@ public class StubTree {
|
||||
|
||||
@NotNull
|
||||
public Map<StubIndexKey, Map<Object, int[]>> 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();
|
||||
|
||||
@@ -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<StubSerializer<? extends StubElement>> myAllSerializers = new ArrayList<StubSerializer<? extends StubElement>>();
|
||||
private volatile boolean mySerializersLoaded = false;
|
||||
|
||||
public static SerializationManager getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(SerializationManager.class);
|
||||
}
|
||||
|
||||
public void registerSerializer(StubSerializer<? extends StubElement> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
+1
-1
@@ -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.
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+8
-15
@@ -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<? extends StubElement> 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();
|
||||
}
|
||||
}
|
||||
@@ -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<StubSerializer<? extends StubElement>> myIdToSerializer = new TIntObjectHashMap<StubSerializer<? extends StubElement>>();
|
||||
private final TObjectIntHashMap<StubSerializer<? extends StubElement>> mySerializerToId = new TObjectIntHashMap<StubSerializer<? extends StubElement>>();
|
||||
private final List<StubSerializer<? extends StubElement>> myAllSerializers = new ArrayList<StubSerializer<? extends StubElement>>();
|
||||
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<? extends StubElement> 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<? extends StubElement> serializer) {
|
||||
myAllSerializers.add(serializer);
|
||||
try {
|
||||
assignId(serializer);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
myNameStorageCrashed.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void assignId(@NotNull final StubSerializer<? extends StubElement> 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<? extends StubElement> 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<StubElement> 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<? extends StubElement> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<exportable serviceInterface="com.intellij.openapi.projectRoots.ProjectJdkTable"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.openapi.roots.FileIndexFacade"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.ProjectFileIndexFacade"/>
|
||||
serviceImplementation="com.intellij.openapi.roots.impl.ProjectFileIndexFacade"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.vcs.impl.DefaultVcsRootPolicy"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.ModuleDefaultVcsRootPolicy"/>
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Sdk> mySdks = new ArrayList<Sdk>();
|
||||
|
||||
@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<Sdk> getSdksOfType(SdkTypeId type) {
|
||||
return Collections.emptyList();
|
||||
List<Sdk> result = new ArrayList<Sdk>();
|
||||
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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()));
|
||||
|
||||
+10
-10
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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));
|
||||
|
||||
+1
-2
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
public class PersistentStringEnumerator extends PersistentEnumeratorDelegate<String>{
|
||||
public class PersistentStringEnumerator extends PersistentEnumeratorDelegate<String> 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -203,7 +203,7 @@
|
||||
<projectService serviceInterface="com.intellij.openapi.vcs.impl.DefaultVcsRootPolicy"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.ModuleDefaultVcsRootPolicy"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.roots.FileIndexFacade"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.ProjectFileIndexFacade"/>
|
||||
serviceImplementation="com.intellij.openapi.roots.impl.ProjectFileIndexFacade"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.vcs.impl.VcsPathPresenter"
|
||||
serviceImplementation="com.intellij.openapi.vcs.impl.ModuleVcsPathPresenter"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user