Search in sources :

Example 56 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class ImportDependenciesUtil method doImportDependencies.

public static void doImportDependencies(@NotNull Project project, @NotNull List<Module> modules, boolean updateBackwardDependencies) {
    final List<ImportDependenciesTask> tasks = new OrderedSet<ImportDependenciesTask>();
    final List<MyUnresolvedDependency> unresolvedDependencies = new ArrayList<MyUnresolvedDependency>();
    for (Module module : modules) {
        importDependencies(module, updateBackwardDependencies, tasks, unresolvedDependencies);
    }
    final Map<VirtualFile, ModuleProvidingTask> libDir2ModuleProvidingTask = new HashMap<VirtualFile, ModuleProvidingTask>();
    for (ImportDependenciesTask task : tasks) {
        if (task instanceof ModuleProvidingTask) {
            final ModuleProvidingTask moduleProvidingTask = (ModuleProvidingTask) task;
            libDir2ModuleProvidingTask.put(moduleProvidingTask.getContentRoot(), moduleProvidingTask);
        }
    }
    for (MyUnresolvedDependency unresolvedDependency : unresolvedDependencies) {
        final ModuleProvidingTask taskProvidingDepModule = libDir2ModuleProvidingTask.get(unresolvedDependency.myLibDir);
        if (taskProvidingDepModule != null) {
            tasks.add(new AddModuleDependencyTask(unresolvedDependency.myModuleProvider, ModuleProvider.create(taskProvidingDepModule)));
        }
    }
    if (tasks.size() > 0) {
        doImportDependencies(project, tasks);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderedSet(com.intellij.util.containers.OrderedSet) HashMap(com.intellij.util.containers.HashMap) Module(com.intellij.openapi.module.Module)

Example 57 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class AndroidApkBuilder method execute.

public static Map<AndroidCompilerMessageKind, List<String>> execute(@NotNull String resPackagePath, @NotNull String dexPath, @NotNull String[] resourceRoots, @NotNull String[] externalJars, @NotNull String[] nativeLibsFolders, @NotNull Collection<AndroidNativeLibData> additionalNativeLibs, @NotNull String finalApk, boolean unsigned, @NotNull String sdkPath, @NotNull IAndroidTarget target, @Nullable String customKeystorePath, @NotNull Condition<File> resourceFilter) throws IOException {
    final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
    if (testingManager != null) {
        testingManager.getCommandExecutor().log(StringUtil.join(new String[] { "apk_builder", resPackagePath, dexPath, AndroidBuildTestingManager.arrayToString(resourceRoots), AndroidBuildTestingManager.arrayToString(externalJars), AndroidBuildTestingManager.arrayToString(nativeLibsFolders), additionalNativeLibs.toString(), finalApk, Boolean.toString(unsigned), sdkPath, customKeystorePath }, "\n"));
    }
    final Map<AndroidCompilerMessageKind, List<String>> map = new HashMap<AndroidCompilerMessageKind, List<String>>();
    map.put(ERROR, new ArrayList<String>());
    map.put(WARNING, new ArrayList<String>());
    final File outputDir = new File(finalApk).getParentFile();
    if (!outputDir.exists() && !outputDir.mkdirs()) {
        map.get(ERROR).add("Cannot create directory " + outputDir.getPath());
        return map;
    }
    File additionalLibsDir = null;
    try {
        if (additionalNativeLibs.size() > 0) {
            additionalLibsDir = FileUtil.createTempDirectory("android_additional_libs", "tmp");
            if (!copyNativeLibs(additionalNativeLibs, additionalLibsDir, map)) {
                return map;
            }
            nativeLibsFolders = ArrayUtil.append(nativeLibsFolders, additionalLibsDir.getPath());
        }
        if (unsigned) {
            return filterUsingKeystoreMessages(finalPackage(dexPath, resourceRoots, externalJars, nativeLibsFolders, finalApk, resPackagePath, customKeystorePath, false, resourceFilter));
        }
        final String zipAlignPath = AndroidCommonUtils.getZipAlign(sdkPath, target);
        boolean withAlignment = new File(zipAlignPath).exists();
        String unalignedApk = AndroidCommonUtils.addSuffixToFileName(finalApk, UNALIGNED_SUFFIX);
        Map<AndroidCompilerMessageKind, List<String>> map2 = filterUsingKeystoreMessages(finalPackage(dexPath, resourceRoots, externalJars, nativeLibsFolders, withAlignment ? unalignedApk : finalApk, resPackagePath, customKeystorePath, true, resourceFilter));
        map.putAll(map2);
        if (withAlignment && map.get(ERROR).size() == 0) {
            map2 = AndroidExecutionUtil.doExecute(zipAlignPath, "-f", "4", unalignedApk, finalApk);
            map.putAll(map2);
        }
        return map;
    } finally {
        if (additionalLibsDir != null) {
            FileUtil.delete(additionalLibsDir);
        }
    }
}
Also used : HashMap(com.intellij.util.containers.HashMap) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) File(java.io.File)

Example 58 with HashMap

use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.

the class CompileDriver method compileInExternalProcess.

@Nullable
private TaskFuture compileInExternalProcess(@NotNull final CompileContextImpl compileContext, final boolean onlyCheckUpToDate) throws Exception {
    final CompileScope scope = compileContext.getCompileScope();
    final Collection<String> paths = CompileScopeUtil.fetchFiles(compileContext);
    List<TargetTypeBuildScope> scopes = getBuildScopes(compileContext, scope, paths);
    // need to pass scope's user data to server
    final Map<String, String> builderParams;
    if (onlyCheckUpToDate) {
        builderParams = Collections.emptyMap();
    } else {
        final Map<Key, Object> exported = scope.exportUserData();
        if (!exported.isEmpty()) {
            builderParams = new HashMap<>();
            for (Map.Entry<Key, Object> entry : exported.entrySet()) {
                final String _key = entry.getKey().toString();
                final String _value = entry.getValue().toString();
                builderParams.put(_key, _value);
            }
        } else {
            builderParams = Collections.emptyMap();
        }
    }
    final MessageBus messageBus = myProject.getMessageBus();
    final MultiMap<String, Artifact> outputToArtifact = ArtifactCompilerUtil.containsArtifacts(scopes) ? ArtifactCompilerUtil.createOutputToArtifactMap(myProject) : null;
    final BuildManager buildManager = BuildManager.getInstance();
    buildManager.cancelAutoMakeTasks(myProject);
    return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), onlyCheckUpToDate, scopes, paths, builderParams, new DefaultMessageHandler(myProject) {

        @Override
        public void sessionTerminated(final UUID sessionId) {
            if (compileContext.shouldUpdateProblemsView()) {
                final ProblemsView view = ProblemsView.SERVICE.getInstance(myProject);
                view.clearProgress();
                view.clearOldMessages(compileContext.getCompileScope(), compileContext.getSessionId());
            }
        }

        @Override
        public void handleFailure(UUID sessionId, CmdlineRemoteProto.Message.Failure failure) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, failure.hasDescription() ? failure.getDescription() : "", null, -1, -1);
            final String trace = failure.hasStacktrace() ? failure.getStacktrace() : null;
            if (trace != null) {
                LOG.info(trace);
            }
            compileContext.putUserData(COMPILE_SERVER_BUILD_STATUS, ExitStatus.ERRORS);
        }

        @Override
        protected void handleCompileMessage(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
            final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
            //System.out.println(compilerMessage.getText());
            final String messageText = message.getText();
            if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.PROGRESS) {
                final ProgressIndicator indicator = compileContext.getProgressIndicator();
                indicator.setText(messageText);
                if (message.hasDone()) {
                    indicator.setFraction(message.getDone());
                }
            } else {
                final CompilerMessageCategory category = kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR ? CompilerMessageCategory.ERROR : kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.WARNING ? CompilerMessageCategory.WARNING : CompilerMessageCategory.INFORMATION;
                String sourceFilePath = message.hasSourceFilePath() ? message.getSourceFilePath() : null;
                if (sourceFilePath != null) {
                    sourceFilePath = FileUtil.toSystemIndependentName(sourceFilePath);
                }
                final long line = message.hasLine() ? message.getLine() : -1;
                final long column = message.hasColumn() ? message.getColumn() : -1;
                final String srcUrl = sourceFilePath != null ? VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, sourceFilePath) : null;
                compileContext.addMessage(category, messageText, srcUrl, (int) line, (int) column);
                if (compileContext.shouldUpdateProblemsView() && kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.JPS_INFO) {
                    // treat JPS_INFO messages in a special way: add them as info messages to the problems view
                    final Project project = compileContext.getProject();
                    ProblemsView.SERVICE.getInstance(project).addMessage(new CompilerMessageImpl(project, category, messageText), compileContext.getSessionId());
                }
            }
        }

        @Override
        protected void handleBuildEvent(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
            final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Type eventType = event.getEventType();
            switch(eventType) {
                case FILES_GENERATED:
                    final List<CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile> generated = event.getGeneratedFilesList();
                    final CompilationStatusListener publisher = !myProject.isDisposed() ? messageBus.syncPublisher(CompilerTopics.COMPILATION_STATUS) : null;
                    Set<String> writtenArtifactOutputPaths = outputToArtifact != null ? new THashSet<>(FileUtil.PATH_HASHING_STRATEGY) : null;
                    for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : generated) {
                        final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
                        final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
                        if (publisher != null) {
                            publisher.fileGenerated(root, relativePath);
                        }
                        if (outputToArtifact != null) {
                            Collection<Artifact> artifacts = outputToArtifact.get(root);
                            if (!artifacts.isEmpty()) {
                                for (Artifact artifact : artifacts) {
                                    ArtifactsCompiler.addChangedArtifact(compileContext, artifact);
                                }
                                writtenArtifactOutputPaths.add(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(root, relativePath)));
                            }
                        }
                    }
                    if (writtenArtifactOutputPaths != null && !writtenArtifactOutputPaths.isEmpty()) {
                        ArtifactsCompiler.addWrittenPaths(compileContext, writtenArtifactOutputPaths);
                    }
                    break;
                case BUILD_COMPLETED:
                    ExitStatus status = ExitStatus.SUCCESS;
                    if (event.hasCompletionStatus()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status completionStatus = event.getCompletionStatus();
                        switch(completionStatus) {
                            case CANCELED:
                                status = ExitStatus.CANCELLED;
                                break;
                            case ERRORS:
                                status = ExitStatus.ERRORS;
                                break;
                            case SUCCESS:
                                status = ExitStatus.SUCCESS;
                                break;
                            case UP_TO_DATE:
                                status = ExitStatus.UP_TO_DATE;
                                break;
                        }
                    }
                    compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, status);
                    break;
                case CUSTOM_BUILDER_MESSAGE:
                    if (event.hasCustomBuilderMessage()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.CustomBuilderMessage message = event.getCustomBuilderMessage();
                        if (GlobalOptions.JPS_SYSTEM_BUILDER_ID.equals(message.getBuilderId()) && GlobalOptions.JPS_UNPROCESSED_FS_CHANGES_MESSAGE_ID.equals(message.getMessageType())) {
                            final String text = message.getMessageText();
                            if (!StringUtil.isEmpty(text)) {
                                compileContext.addMessage(CompilerMessageCategory.INFORMATION, text, null, -1, -1);
                            }
                        }
                    }
                    break;
            }
        }
    });
}
Also used : THashSet(gnu.trove.THashSet) MessageBus(com.intellij.util.messages.MessageBus) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) DefaultMessageHandler(com.intellij.compiler.server.DefaultMessageHandler) CmdlineRemoteProto(org.jetbrains.jps.api.CmdlineRemoteProto) Artifact(com.intellij.packaging.artifacts.Artifact) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) MessageType(com.intellij.openapi.ui.MessageType) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) BuildManager(com.intellij.compiler.server.BuildManager) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class ResourceManager method getValueResourceEntries.

@NotNull
public Collection<ResourceEntry> getValueResourceEntries(@NotNull final ResourceType resourceType) {
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName());
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final Map<VirtualFile, Set<ResourceEntry>> file2resourceSet = new HashMap<VirtualFile, Set<ResourceEntry>>();
    index.processValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, null, new FileBasedIndex.ValueProcessor<ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo> infos) {
            for (AndroidValueResourcesIndex.MyResourceInfo info : infos) {
                Set<ResourceEntry> resourcesInFile = file2resourceSet.get(file);
                if (resourcesInFile == null) {
                    resourcesInFile = new HashSet<ResourceEntry>();
                    file2resourceSet.put(file, resourcesInFile);
                }
                resourcesInFile.add(info.getResourceEntry());
            }
            return true;
        }
    }, scope);
    final List<ResourceEntry> result = new ArrayList<ResourceEntry>();
    for (VirtualFile file : getAllValueResourceFiles()) {
        final Set<ResourceEntry> entries = file2resourceSet.get(file);
        if (entries != null) {
            for (ResourceEntry entry : entries) {
                if (isResourcePublic(entry.getType(), entry.getName())) {
                    result.add(entry);
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(com.intellij.util.containers.HashMap) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceEntry(org.jetbrains.android.util.ResourceEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AndroidValueResourcesIndex(org.jetbrains.android.AndroidValueResourcesIndex) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 60 with HashMap

use of com.intellij.util.containers.HashMap in project android by JetBrains.

the class ResourceManager method getIds.

@NotNull
public Collection<String> getIds(boolean declarationsOnly) {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final Map<VirtualFile, Set<String>> file2idEntries = new HashMap<VirtualFile, Set<String>>();
    index.processValues(AndroidIdIndex.INDEX_ID, AndroidIdIndex.MARKER, null, new FileBasedIndex.ValueProcessor<Set<String>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, Set<String> value) {
            file2idEntries.put(file, value);
            return true;
        }
    }, scope);
    final Set<String> result = new HashSet<String>();
    for (VirtualFile resSubdir : getResourceSubdirsToSearchIds()) {
        for (VirtualFile resFile : resSubdir.getChildren()) {
            final Set<String> idEntries = file2idEntries.get(resFile);
            if (idEntries != null) {
                for (String idEntry : idEntries) {
                    if (idEntry.startsWith("+")) {
                        idEntry = idEntry.substring(1);
                    } else if (declarationsOnly) {
                        continue;
                    }
                    if (isResourcePublic(ResourceType.ID.getName(), idEntry)) {
                        result.add(idEntry);
                    }
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashMap(com.intellij.util.containers.HashMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashMap (com.intellij.util.containers.HashMap)118 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 File (java.io.File)22 Nullable (org.jetbrains.annotations.Nullable)18 Map (java.util.Map)17 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)15 ArrayList (java.util.ArrayList)14 PsiElement (com.intellij.psi.PsiElement)11 HashSet (com.intellij.util.containers.HashSet)10 List (java.util.List)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 IOException (java.io.IOException)8 Pair (com.intellij.openapi.util.Pair)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 SearchScope (com.intellij.psi.search.SearchScope)6 Logger (com.intellij.openapi.diagnostic.Logger)5 PsiFile (com.intellij.psi.PsiFile)5 UsageInfo (com.intellij.usageView.UsageInfo)5