Search in sources :

Example 66 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class TestLocationDataRule method collectRelativeLocations.

@NotNull
protected static List<Location> collectRelativeLocations(Project project, VirtualFile file) {
    if (DumbService.isDumb(project))
        return Collections.emptyList();
    final List<Location> locations = new ArrayList<>();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    if (fileIndex.isInContent(file) && !fileIndex.isInSource(file) && !fileIndex.isInLibraryClasses(file)) {
        final VirtualFile parent = file.getParent();
        final VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
        if (contentRoot != null && parent != null) {
            final String relativePath = VfsUtilCore.getRelativePath(parent, contentRoot, '/');
            if (relativePath != null) {
                final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(project);
                final List<String> words = StringUtil.getWordsIn(relativePath);
                // put longer strings first
                Collections.sort(words, (o1, o2) -> o2.length() - o1.length());
                final GlobalSearchScope testScope = GlobalSearchScopesCore.projectTestScope(project);
                Set<PsiFile> resultFiles = null;
                for (String word : words) {
                    if (word.length() < 5) {
                        continue;
                    }
                    final Set<PsiFile> files = new THashSet<>();
                    searchHelper.processAllFilesWithWordInLiterals(word, testScope, new CommonProcessors.CollectProcessor<>(files));
                    if (resultFiles == null) {
                        resultFiles = files;
                    } else {
                        resultFiles.retainAll(files);
                    }
                    if (resultFiles.isEmpty())
                        break;
                }
                if (resultFiles != null) {
                    for (Iterator<PsiFile> iterator = resultFiles.iterator(); iterator.hasNext(); ) {
                        if (!VfsUtilCore.isAncestor(contentRoot, iterator.next().getVirtualFile(), true)) {
                            iterator.remove();
                        }
                    }
                    final String fileName = file.getName();
                    final String nameWithoutExtension = file.getNameWithoutExtension();
                    for (PsiFile resultFile : resultFiles) {
                        if (resultFile instanceof PsiClassOwner) {
                            final PsiClass[] classes = ((PsiClassOwner) resultFile).getClasses();
                            if (classes.length > 0) {
                                ContainerUtil.addIfNotNull(locations, getLocation(project, fileName, nameWithoutExtension, classes[0]));
                            }
                        }
                    }
                }
            }
        }
    }
    return locations;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CommonProcessors(com.intellij.util.CommonProcessors) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) PsiLocation(com.intellij.execution.PsiLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class AppEngineEnhancerBuilder method processModule.

private static boolean processModule(final CompileContext context, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException {
    final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (String path : extension.getFilesToEnhance()) {
        roots.add(new File(FileUtil.toSystemDependentName(path)));
    }
    final List<String> pathsToProcess = new ArrayList<>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
            if (JpsPathUtil.isUnder(roots, file)) {
                Collection<String> outputs = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target).getOutputs(file.getAbsolutePath());
                if (outputs != null) {
                    pathsToProcess.addAll(outputs);
                }
            }
            return true;
        }
    });
    if (pathsToProcess.isEmpty()) {
        return false;
    }
    JpsModule module = extension.getModule();
    JpsSdk<JpsDummyElement> sdk = JavaBuilderUtil.ensureModuleHasJdk(module, context, NAME);
    context.processMessage(new ProgressMessage("Enhancing classes in module '" + module.getName() + "'..."));
    List<String> vmParams = Collections.singletonList("-Xmx256m");
    List<String> classpath = new ArrayList<>();
    classpath.add(extension.getToolsApiJarPath());
    classpath.add(PathManager.getJarPathForClass(EnhancerRunner.class));
    boolean removeOrmJars = Boolean.parseBoolean(System.getProperty("jps.appengine.enhancer.remove.orm.jars", "true"));
    for (File file : JpsJavaExtensionService.dependencies(module).recursively().compileOnly().productionOnly().classes().getRoots()) {
        if (removeOrmJars && FileUtil.isAncestor(new File(extension.getOrmLibPath()), file, true)) {
            continue;
        }
        classpath.add(file.getAbsolutePath());
    }
    List<String> programParams = new ArrayList<>();
    final File argsFile = FileUtil.createTempFile("appEngineEnhanceFiles", ".txt");
    PrintWriter writer = new PrintWriter(argsFile);
    try {
        for (String path : pathsToProcess) {
            writer.println(FileUtil.toSystemDependentName(path));
        }
    } finally {
        writer.close();
    }
    programParams.add(argsFile.getAbsolutePath());
    programParams.add("com.google.appengine.tools.enhancer.Enhance");
    programParams.add("-api");
    PersistenceApi api = extension.getPersistenceApi();
    programParams.add(api.getEnhancerApiName());
    if (api.getEnhancerVersion() == 2) {
        programParams.add("-enhancerVersion");
        programParams.add("v2");
    }
    programParams.add("-v");
    List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(JpsJavaSdkType.getJavaExecutable(sdk), EnhancerRunner.class.getName(), Collections.<String>emptyList(), classpath, vmParams, programParams);
    Process process = new ProcessBuilder(commandLine).start();
    ExternalEnhancerProcessHandler handler = new ExternalEnhancerProcessHandler(process, commandLine, context);
    handler.startNotify();
    handler.waitFor();
    ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
    if (logger.isEnabled()) {
        logger.logCompiledPaths(pathsToProcess, NAME, "Enhancing classes:");
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) EnhancerRunner(com.intellij.appengine.rt.EnhancerRunner) JpsModule(org.jetbrains.jps.model.module.JpsModule) PersistenceApi(org.jetbrains.jps.appengine.model.PersistenceApi) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 68 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class AppEngineSdkUtil method computeWhiteList.

public static Map<String, Set<String>> computeWhiteList(final File toolsApiJarFile) {
    try {
        final THashMap<String, Set<String>> map = new THashMap<>();
        final ClassLoader loader = UrlClassLoader.build().urls(toolsApiJarFile.toURI().toURL()).parent(AppEngineSdkUtil.class.getClassLoader()).get();
        final Class<?> whiteListClass = Class.forName("com.google.apphosting.runtime.security.WhiteList", true, loader);
        final Set<String> classes = (Set<String>) whiteListClass.getMethod("getWhiteList").invoke(null);
        for (String qualifiedName : classes) {
            final String packageName = StringUtil.getPackageName(qualifiedName);
            Set<String> classNames = map.get(packageName);
            if (classNames == null) {
                classNames = new THashSet<>();
                map.put(packageName, classNames);
            }
            classNames.add(StringUtil.getShortName(qualifiedName));
        }
        return map;
    } catch (UnsupportedClassVersionError e) {
        LOG.warn(e);
        return Collections.emptyMap();
    } catch (Exception e) {
        LOG.error(e);
        return Collections.emptyMap();
    }
}
Also used : Set(java.util.Set) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) UrlClassLoader(com.intellij.util.lang.UrlClassLoader)

Example 69 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class GradleResourcesTarget method getOutputRoots.

@NotNull
@Override
public Collection<File> getOutputRoots(CompileContext context) {
    GradleModuleResourceConfiguration configuration = getModuleResourcesConfiguration(context.getProjectDescriptor().dataManager.getDataPaths());
    final Set<File> result = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    final File moduleOutput = getModuleOutputDir();
    for (ResourceRootConfiguration resConfig : getRootConfigurations(configuration)) {
        final File output = getOutputDir(moduleOutput, resConfig, configuration.outputDirectory);
        if (output != null) {
            result.add(output);
        }
    }
    return result;
}
Also used : File(java.io.File) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with THashSet

use of gnu.trove.THashSet in project intellij-community by JetBrains.

the class ExternalProjectSerializer method configureKryo.

private void configureKryo() {
    myKryo.setAutoReset(true);
    myKryo.setRegistrationRequired(true);
    Log.set(Log.LEVEL_WARN);
    myKryo.register(ArrayList.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new ArrayList();
        }
    });
    myKryo.register(HashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new HashMap();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(File.class, new FileSerializer());
    myKryo.register(DefaultExternalProject.class, new FieldSerializer<DefaultExternalProject>(myKryo, DefaultExternalProject.class) {

        @Override
        protected DefaultExternalProject create(Kryo kryo, Input input, Class<DefaultExternalProject> type) {
            return new DefaultExternalProject();
        }
    });
    myKryo.register(DefaultExternalTask.class, new FieldSerializer<DefaultExternalTask>(myKryo, DefaultExternalTask.class) {

        @Override
        protected DefaultExternalTask create(Kryo kryo, Input input, Class<DefaultExternalTask> type) {
            return new DefaultExternalTask();
        }
    });
    myKryo.register(DefaultExternalPlugin.class, new FieldSerializer<DefaultExternalPlugin>(myKryo, DefaultExternalPlugin.class) {

        @Override
        protected DefaultExternalPlugin create(Kryo kryo, Input input, Class<DefaultExternalPlugin> type) {
            return new DefaultExternalPlugin();
        }
    });
    myKryo.register(DefaultExternalSourceSet.class, new FieldSerializer<DefaultExternalSourceSet>(myKryo, DefaultExternalSourceSet.class) {

        @Override
        protected DefaultExternalSourceSet create(Kryo kryo, Input input, Class<DefaultExternalSourceSet> type) {
            return new DefaultExternalSourceSet();
        }
    });
    myKryo.register(DefaultExternalSourceDirectorySet.class, new FieldSerializer<DefaultExternalSourceDirectorySet>(myKryo, DefaultExternalSourceDirectorySet.class) {

        @Override
        protected DefaultExternalSourceDirectorySet create(Kryo kryo, Input input, Class<DefaultExternalSourceDirectorySet> type) {
            return new DefaultExternalSourceDirectorySet();
        }
    });
    myKryo.register(DefaultExternalFilter.class, new FieldSerializer<DefaultExternalFilter>(myKryo, DefaultExternalFilter.class) {

        @Override
        protected DefaultExternalFilter create(Kryo kryo, Input input, Class<DefaultExternalFilter> type) {
            return new DefaultExternalFilter();
        }
    });
    myKryo.register(ExternalSystemSourceType.class, new DefaultSerializers.EnumSerializer(ExternalSystemSourceType.class));
    myKryo.register(DefaultExternalProjectDependency.class, new FieldSerializer<DefaultExternalProjectDependency>(myKryo, DefaultExternalProjectDependency.class) {

        @Override
        protected DefaultExternalProjectDependency create(Kryo kryo, Input input, Class<DefaultExternalProjectDependency> type) {
            return new DefaultExternalProjectDependency();
        }
    });
    myKryo.register(DefaultFileCollectionDependency.class, new FieldSerializer<DefaultFileCollectionDependency>(myKryo, DefaultFileCollectionDependency.class) {

        @Override
        protected DefaultFileCollectionDependency create(Kryo kryo, Input input, Class<DefaultFileCollectionDependency> type) {
            return new DefaultFileCollectionDependency();
        }
    });
    myKryo.register(DefaultExternalLibraryDependency.class, new FieldSerializer<DefaultExternalLibraryDependency>(myKryo, DefaultExternalLibraryDependency.class) {

        @Override
        protected DefaultExternalLibraryDependency create(Kryo kryo, Input input, Class<DefaultExternalLibraryDependency> type) {
            return new DefaultExternalLibraryDependency();
        }
    });
    myKryo.register(DefaultUnresolvedExternalDependency.class, new FieldSerializer<DefaultUnresolvedExternalDependency>(myKryo, DefaultUnresolvedExternalDependency.class) {

        @Override
        protected DefaultUnresolvedExternalDependency create(Kryo kryo, Input input, Class<DefaultUnresolvedExternalDependency> type) {
            return new DefaultUnresolvedExternalDependency();
        }
    });
    myKryo.register(DefaultExternalDependencyId.class, new FieldSerializer<DefaultExternalDependencyId>(myKryo, DefaultExternalDependencyId.class) {

        @Override
        protected DefaultExternalDependencyId create(Kryo kryo, Input input, Class<DefaultExternalDependencyId> type) {
            return new DefaultExternalDependencyId();
        }
    });
    myKryo.register(LinkedHashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new LinkedHashSet();
        }
    });
    myKryo.register(HashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashSet.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new THashSet();
        }
    });
    myKryo.register(Set.class, new CollectionSerializer() {

        @Override
        protected Collection create(Kryo kryo, Input input, Class<Collection> type) {
            return new HashSet();
        }
    });
    myKryo.register(THashMap.class, new MapSerializer() {

        @Override
        protected Map create(Kryo kryo, Input input, Class<Map> type) {
            return new THashMap();
        }
    });
}
Also used : THashMap(gnu.trove.THashMap) DefaultExternalDependencyId(org.jetbrains.plugins.gradle.DefaultExternalDependencyId) Input(com.esotericsoftware.kryo.io.Input) MapSerializer(com.esotericsoftware.kryo.serializers.MapSerializer) THashSet(gnu.trove.THashSet) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ExternalSystemSourceType(com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType) THashMap(gnu.trove.THashMap) DefaultSerializers(com.esotericsoftware.kryo.serializers.DefaultSerializers) CollectionSerializer(com.esotericsoftware.kryo.serializers.CollectionSerializer) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10