don't index bundled gdsl files, we know very well how to retrieve them (EA-26440, IDEA-66597)

This commit is contained in:
peter
2011-04-20 19:17:00 +02:00
parent 9e3d10c77d
commit 6db0dbcebb
6 changed files with 87 additions and 135 deletions
-2
View File
@@ -311,8 +311,6 @@
<renameInputValidator implementation="org.jetbrains.plugins.groovy.GroovyRenameInputValidator"/>
<lang.namesValidator implementationClass="org.jetbrains.plugins.groovy.lang.GroovyNamesValidator" language="Groovy"/>
<!-- Groovy DSL support -->
<indexedRootsProvider implementation="org.jetbrains.plugins.groovy.dsl.StandardDslIndexedRootsProvider"/>
<fileBasedIndex implementation="org.jetbrains.plugins.groovy.dsl.GroovyDslFileIndex"/>
<patterns.patternClass className="org.jetbrains.plugins.groovy.lang.psi.patterns.GroovyPatterns" alias="groovy"/>
@@ -1,54 +0,0 @@
/*
* Copyright 2000-2010 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 org.jetbrains.plugins.groovy.dsl;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PathUtil;
import com.intellij.util.indexing.IndexableSetContributor;
import java.io.File;
import java.util.Collections;
import java.util.Set;
public class AbstractDslIndexedRootsProvider extends IndexableSetContributor implements GroovyDslIndexedRootProvider{
private final Set<VirtualFile> ourDslsDirs;
public AbstractDslIndexedRootsProvider() {
final File jarPath = new File(PathUtil.getJarPathForClass(getClass()));
String dirPath;
if (jarPath.isFile()) { //jar
dirPath = new File(jarPath.getParentFile(), getScriptFolderName()).getAbsolutePath();
} else {
dirPath = new File(jarPath, getScriptFolderName()).getAbsolutePath();
}
final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByPath(dirPath);
assert parent != null : dirPath;
parent.getChildren();
ourDslsDirs = Collections.singleton(parent);
parent.refresh(true, true);
}
protected String getScriptFolderName() {
return "standardDsls";
}
@Override
public Set<VirtualFile> getAdditionalRootsToIndex() {
return ourDslsDirs;
}
}
@@ -30,6 +30,7 @@ import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileAdapter;
import com.intellij.openapi.vfs.VirtualFileEvent;
@@ -40,10 +41,13 @@ import com.intellij.psi.impl.PsiModificationTrackerImpl;
import com.intellij.psi.scope.DelegatingScopeProcessor;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.*;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.unscramble.UnscrambleDialog;
import com.intellij.util.PathUtil;
import com.intellij.util.containers.ConcurrentMultiMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.indexing.*;
import com.intellij.util.io.EnumeratorStringDescriptor;
@@ -51,17 +55,16 @@ import com.intellij.util.io.KeyDescriptor;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.annotator.GroovyFrameworkConfigNotification;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
import javax.swing.event.HyperlinkEvent;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
@@ -220,29 +223,83 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
return false;
}
private static volatile List<Pair<File, GroovyDslExecutor>> ourStandardScripts;
private static List<Pair<File, GroovyDslExecutor>> getStandardScripts() {
if (ourStandardScripts == null) {
synchronized (SCRIPTS_CACHE) {
if (ourStandardScripts == null) {
Set<File> scriptFolders = new LinkedHashSet<File>();
// perhaps a separate extension for that?
for (GroovyFrameworkConfigNotification extension : GroovyFrameworkConfigNotification.EP_NAME.getExtensions()) {
File jarPath = new File(PathUtil.getJarPathForClass(extension.getClass()));
if (jarPath.isFile()) {
jarPath = jarPath.getParentFile();
}
scriptFolders.add(new File(jarPath, "standardDsls"));
}
List<Pair<File, GroovyDslExecutor>> executors = new ArrayList<Pair<File, GroovyDslExecutor>>();
for (File file : scriptFolders) {
if (file.exists()) {
for (File child : file.listFiles()) {
final String fileName = child.getName();
if (fileName.endsWith(".gdsl")) {
try {
final String text = new String(FileUtil.loadFileText(child));
executors.add(Pair.create(child, new GroovyDslExecutor(text, fileName)));
}
catch (IOException e) {
LOG.error(e);
}
}
}
}
}
ourStandardScripts = executors;
}
}
}
return ourStandardScripts;
}
private static final Key<CachedValue<List<GroovyDslScript>>> SCRIPTS_CACHE = Key.create("GdslScriptCache");
private static List<GroovyDslScript> getDslScripts(final Project project) {
return CachedValuesManager.getManager(project).getCachedValue(project, SCRIPTS_CACHE, new CachedValueProvider<List<GroovyDslScript>>() {
@Override
public Result<List<GroovyDslScript>> compute() {
if (stopGdsl) {
return Result.create(Collections.<GroovyDslScript>emptyList());
}
int count = 0;
List<GroovyDslScript> result = new ArrayList<GroovyDslScript>();
final LinkedBlockingQueue<Pair<VirtualFile, GroovyDslExecutor>> queue = new LinkedBlockingQueue<Pair<VirtualFile, GroovyDslExecutor>>();
try {
for (Pair<File, GroovyDslExecutor> pair : getStandardScripts()) {
result.add(new GroovyDslScript(project, null, pair.second, pair.first.getPath()));
}
}
catch (OutOfMemoryError e) {
stopGdsl = true;
throw e;
}
catch (NoClassDefFoundError e) {
stopGdsl = true;
throw e;
}
final LinkedBlockingQueue<Pair<VirtualFile, GroovyDslExecutor>> queue =
new LinkedBlockingQueue<Pair<VirtualFile, GroovyDslExecutor>>();
final GroovyDslIndexedRootProvider[] indexedRootProviders =
ContainerUtil.findAllAsArray(IndexableSetContributor.EP_NAME.getExtensions(), GroovyDslIndexedRootProvider.class);
final AdditionalIndexableFileSet standardSet = new AdditionalIndexableFileSet(indexedRootProviders);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final AdditionalIndexedRootsScope scope = new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project), standardSet);
for (VirtualFile vfile : FileBasedIndex.getInstance().getContainingFiles(NAME, OUR_KEY, scope)) {
for (VirtualFile vfile : FileBasedIndex.getInstance().getContainingFiles(NAME, OUR_KEY, GlobalSearchScope.allScope(project))) {
if (!vfile.isValid()) {
continue;
}
if (!standardSet.isInSet(vfile) && !fileIndex.isInLibraryClasses(vfile) && !fileIndex.isInLibrarySource(vfile)) {
if (!fileIndex.isInLibraryClasses(vfile) && !fileIndex.isInLibrarySource(vfile)) {
if (!fileIndex.isInSourceContent(vfile) || !isActivated(vfile)) {
continue;
}
@@ -255,7 +312,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
count++;
}
else {
result.add(new GroovyDslScript(project, vfile, cached));
result.add(new GroovyDslScript(project, vfile, cached, vfile.getPath()));
}
}
@@ -266,7 +323,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
if (pair != null) {
count--;
if (pair.second != null) {
result.add(new GroovyDslScript(project, pair.first, pair.second));
result.add(new GroovyDslScript(project, pair.first, pair.second, pair.first.getPath()));
}
}
}
@@ -371,7 +428,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
return null;
}
}
static void invokeDslErrorPopup(Throwable e, final Project project, VirtualFile vfile) {
static void invokeDslErrorPopup(Throwable e, final Project project, @NotNull VirtualFile vfile) {
if (!isActivated(vfile)) {
return;
}
@@ -1,22 +0,0 @@
/*
* Copyright 2000-2010 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 org.jetbrains.plugins.groovy.dsl;
import com.intellij.util.indexing.IndexedRootsProvider;
public interface GroovyDslIndexedRootProvider extends IndexedRootsProvider {
}
@@ -19,6 +19,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ProcessingContext;
import groovy.lang.Closure;
import org.codehaus.groovy.runtime.InvokerInvocationException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.dsl.holders.CustomMembersHolder;
import org.jetbrains.plugins.groovy.dsl.toplevel.ClassContextFilter;
import org.jetbrains.plugins.groovy.dsl.toplevel.ContextFilter;
@@ -29,15 +30,17 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
*/
public class GroovyDslScript {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.dsl.GroovyDslScript");
public final Project project;
public final VirtualFile file;
public final GroovyDslExecutor executor;
private final Project project;
@Nullable private final VirtualFile file;
private final GroovyDslExecutor executor;
private final String myPath;
private final CachedValue<FactorTree> myMaps;
public GroovyDslScript(final Project project, VirtualFile file, GroovyDslExecutor executor) {
public GroovyDslScript(final Project project, @Nullable VirtualFile file, GroovyDslExecutor executor, String path) {
this.project = project;
this.file = file;
this.executor = executor;
myPath = path;
myMaps = CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider<FactorTree>() {
@Override
public Result<FactorTree> compute() {
@@ -65,7 +68,7 @@ public class GroovyDslScript {
return holder.processMembers(descriptor, processor, state);
}
catch (IncorrectOperationException e) {
LOG.error("Error while processing dsl script '" + file.getUrl()+ "'", e);
LOG.error("Error while processing dsl script '" + myPath + "'", e);
return false;
}
}
@@ -118,12 +121,14 @@ public class GroovyDslScript {
if (project.isDisposed() || ApplicationManager.getApplication().isUnitTestMode()) {
return true;
}
GroovyDslFileIndex.invokeDslErrorPopup(e, project, file);
if (file != null) {
GroovyDslFileIndex.invokeDslErrorPopup(e, project, file);
}
return false;
}
@Override
public String toString() {
return "GroovyDslScript: " + file.getPath();
return "GroovyDslScript: " + myPath;
}
}
@@ -1,32 +0,0 @@
/*
* 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.
*/
package org.jetbrains.plugins.groovy.dsl;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PathUtil;
import com.intellij.util.indexing.IndexedRootsProvider;
import java.io.File;
import java.util.Collections;
import java.util.Set;
/**
* @author peter
*/
public class StandardDslIndexedRootsProvider extends AbstractDslIndexedRootsProvider {
}