diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 1692c19ad1b7..53900076825f 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -311,8 +311,6 @@ - - diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java deleted file mode 100644 index de632f999bdb..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/AbstractDslIndexedRootsProvider.java +++ /dev/null @@ -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 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 getAdditionalRootsToIndex() { - return ourDslsDirs; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index 55affb34b8ee..dd46a2cc8c83 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -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 { return false; } + private static volatile List> ourStandardScripts; + + private static List> getStandardScripts() { + if (ourStandardScripts == null) { + synchronized (SCRIPTS_CACHE) { + if (ourStandardScripts == null) { + Set scriptFolders = new LinkedHashSet(); + // 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> executors = new ArrayList>(); + 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>> SCRIPTS_CACHE = Key.create("GdslScriptCache"); private static List getDslScripts(final Project project) { return CachedValuesManager.getManager(project).getCachedValue(project, SCRIPTS_CACHE, new CachedValueProvider>() { @Override public Result> compute() { + if (stopGdsl) { + return Result.create(Collections.emptyList()); + } + int count = 0; List result = new ArrayList(); - final LinkedBlockingQueue> queue = new LinkedBlockingQueue>(); + try { + for (Pair 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> queue = + new LinkedBlockingQueue>(); - 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 { 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 { 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 { 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; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslIndexedRootProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslIndexedRootProvider.java deleted file mode 100644 index f179445d292a..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslIndexedRootProvider.java +++ /dev/null @@ -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 { - -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java index baf382c9b06b..db95e36a8aa2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslScript.java @@ -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 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() { @Override public Result 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; } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/StandardDslIndexedRootsProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/StandardDslIndexedRootsProvider.java deleted file mode 100644 index 624e8a4e7aa1..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/StandardDslIndexedRootsProvider.java +++ /dev/null @@ -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 { - -}