Search in sources :

Example 6 with THashMap

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

the class InconsistentResourceBundleInspection method checkFile.

@Override
public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
    Set<ResourceBundle> visitedBundles = globalContext.getUserData(VISITED_BUNDLES_KEY);
    if (!(file instanceof PropertiesFile))
        return;
    final PropertiesFile propertiesFile = (PropertiesFile) file;
    ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
    assert visitedBundles != null;
    if (!visitedBundles.add(resourceBundle))
        return;
    List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
    if (files.size() < 2)
        return;
    BidirectionalMap<PropertiesFile, PropertiesFile> parents = new BidirectionalMap<>();
    for (PropertiesFile f : files) {
        PropertiesFile parent = PropertiesUtil.getParent(f, files);
        if (parent != null) {
            parents.put(f, parent);
        }
    }
    final FactoryMap<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = new FactoryMap<PropertiesFile, Map<String, String>>() {

        @Nullable
        @Override
        protected Map<String, String> create(PropertiesFile key) {
            return key.getNamesMap();
        }
    };
    Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
    for (PropertiesFile f : files) {
        Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
        PropertiesFile parent = parents.get(f);
        while (parent != null) {
            keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
            parent = parents.get(parent);
        }
        keysUpToParent.put(f, keys);
    }
    for (final InconsistentResourceBundleInspectionProvider provider : myInspectionProviders.getValue()) {
        if (isProviderEnabled(provider.getName())) {
            provider.check(parents, files, keysUpToParent, propertiesFilesNamesMaps, manager, globalContext.getRefManager(), problemDescriptionsProcessor);
        }
    }
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) THashSet(gnu.trove.THashSet) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) FactoryMap(com.intellij.util.containers.FactoryMap) THashMap(gnu.trove.THashMap) BidirectionalMap(com.intellij.util.containers.BidirectionalMap) BidirectionalMap(com.intellij.util.containers.BidirectionalMap)

Example 7 with THashMap

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

the class RepositoryAttachHandler method searchArtifacts.

public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
    if (coord == null || coord.length() == 0)
        return;
    final MavenArtifactInfo template;
    if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
        template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
    } else {
        template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {

        public void run(@NotNull ProgressIndicator indicator) {
            String[] urls = MavenRepositoryServicesManager.getServiceUrls();
            boolean tooManyResults = false;
            final AtomicBoolean proceedFlag = new AtomicBoolean(true);
            for (int i = 0, length = urls.length; i < length; i++) {
                if (!proceedFlag.get())
                    break;
                final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
                try {
                    String serviceUrl = urls[i];
                    final List<MavenArtifactInfo> artifacts;
                    artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
                    if (!artifacts.isEmpty()) {
                        if (!proceedFlag.get()) {
                            break;
                        }
                        List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
                        Map<String, MavenRepositoryInfo> map = new THashMap<>();
                        for (MavenRepositoryInfo repository : repositories) {
                            map.put(repository.getId(), repository);
                        }
                        for (MavenArtifactInfo artifact : artifacts) {
                            if (artifact == null) {
                                tooManyResults = true;
                            } else {
                                MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
                                // because it won't be resolved anyway
                                if (repository == null)
                                    continue;
                                resultList.add(Pair.create(artifact, repository));
                            }
                        }
                    }
                } catch (Exception e) {
                    MavenLog.LOG.error(e);
                } finally {
                    if (!proceedFlag.get())
                        break;
                    final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
                    ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
                }
            }
        }
    });
}
Also used : MavenRepositoryServicesManager(org.jetbrains.idea.maven.services.MavenRepositoryServicesManager) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PairProcessor(com.intellij.util.PairProcessor) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) Task(com.intellij.openapi.progress.Task) SmartList(com.intellij.util.SmartList) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) ProjectBundle(org.jetbrains.idea.maven.project.ProjectBundle) RepositoryAttachDialog(org.jetbrains.idea.maven.utils.RepositoryAttachDialog) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) NotificationType(com.intellij.notification.NotificationType) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) MavenDependenciesRemoteManager(org.jetbrains.idea.maven.utils.library.remote.MavenDependenciesRemoteManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SmartList(com.intellij.util.SmartList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) THashMap(gnu.trove.THashMap)

Example 8 with THashMap

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

the class JavaFxRedundantPropertyValueInspection method loadDefaultPropertyValues.

/**
   * The file format is {@code ClassName#propertyName:type=value} per line, line with leading double dash (--) is commented out
   */
@NotNull
private static Map<String, Map<String, String>> loadDefaultPropertyValues(@NotNull String resourceName) {
    final URL resource = JavaFxRedundantPropertyValueInspection.class.getResource(resourceName);
    if (resource == null) {
        LOG.warn("Resource not found: " + resourceName);
        return Collections.emptyMap();
    }
    final Map<String, Map<String, String>> result = new THashMap<>(200);
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream(), CharsetToolkit.UTF8_CHARSET))) {
        for (String line : FileUtil.loadLines(reader)) {
            if (line.isEmpty() || line.startsWith("--"))
                continue;
            boolean lineParsed = false;
            final int p1 = line.indexOf('#');
            if (p1 > 0 && p1 < line.length()) {
                final String className = line.substring(0, p1);
                final int p2 = line.indexOf('=', p1);
                if (p2 > p1 && p2 < line.length()) {
                    final String propertyName = line.substring(p1 + 1, p2);
                    final String valueText = line.substring(p2 + 1);
                    lineParsed = true;
                    final Map<String, String> properties = result.computeIfAbsent(className, ignored -> new THashMap<>());
                    if (properties.put(propertyName, valueText) != null) {
                        LOG.warn("Duplicate default property value " + line);
                    }
                }
            }
            if (!lineParsed) {
                LOG.warn("Can't parse default property value " + line);
            }
        }
    } catch (IOException e) {
        LOG.warn("Can't read resource: " + resourceName, e);
        return Collections.emptyMap();
    }
    return result;
}
Also used : THashMap(gnu.trove.THashMap) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) THashMap(gnu.trove.THashMap) Map(java.util.Map) URL(java.net.URL) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with THashMap

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

the class MavenWebArtifactConfiguration method getRootConfiguration.

@Nullable
public ResourceRootConfiguration getRootConfiguration(@NotNull File root) {
    if (myResourceRootsMap == null) {
        Map<File, ResourceRootConfiguration> map = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
        for (ResourceRootConfiguration resource : webResources) {
            map.put(new File(resource.directory), resource);
        }
        myResourceRootsMap = map;
    }
    return myResourceRootsMap.get(root);
}
Also used : THashMap(gnu.trove.THashMap) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with THashMap

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

the class MavenServerManager method createRunProfileState.

private RunProfileState createRunProfileState() {
    return new CommandLineState(null) {

        private SimpleJavaParameters createJavaParameters() {
            final SimpleJavaParameters params = new SimpleJavaParameters();
            final Sdk jdk = getJdk();
            params.setJdk(jdk);
            params.setWorkingDirectory(PathManager.getBinPath());
            params.setMainClass(MAIN_CLASS);
            Map<String, String> defs = new THashMap<>();
            defs.putAll(MavenUtil.getPropertiesFromMavenOpts());
            // pass ssl-related options
            for (Map.Entry<Object, Object> each : System.getProperties().entrySet()) {
                Object key = each.getKey();
                Object value = each.getValue();
                if (key instanceof String && value instanceof String && ((String) key).startsWith("javax.net.ssl")) {
                    defs.put((String) key, (String) value);
                }
            }
            if (SystemInfo.isMac) {
                String arch = System.getProperty("sun.arch.data.model");
                if (arch != null) {
                    params.getVMParametersList().addParametersString("-d" + arch);
                }
            }
            defs.put("java.awt.headless", "true");
            for (Map.Entry<String, String> each : defs.entrySet()) {
                params.getVMParametersList().defineProperty(each.getKey(), each.getValue());
            }
            params.getVMParametersList().addProperty("idea.version=", MavenUtil.getIdeaVersionToPassToMavenProcess());
            boolean xmxSet = false;
            boolean forceMaven2 = false;
            if (myState.vmOptions != null) {
                ParametersList mavenOptsList = new ParametersList();
                mavenOptsList.addParametersString(myState.vmOptions);
                for (String param : mavenOptsList.getParameters()) {
                    if (param.startsWith("-Xmx")) {
                        xmxSet = true;
                    }
                    if (param.equals(FORCE_MAVEN2_OPTION)) {
                        forceMaven2 = true;
                    }
                    params.getVMParametersList().add(param);
                }
            }
            final File mavenHome;
            final String mavenVersion;
            final File currentMavenHomeFile = forceMaven2 ? BundledMavenPathHolder.myBundledMaven2Home : getCurrentMavenHomeFile();
            if (currentMavenHomeFile == null) {
                mavenHome = BundledMavenPathHolder.myBundledMaven3Home;
                mavenVersion = getMavenVersion(mavenHome);
                Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
                final Project project = openProjects.length == 1 ? openProjects[0] : null;
                if (project != null) {
                    new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning.with.fix", myState.mavenHome, mavenVersion), NotificationType.WARNING, new NotificationListener() {

                        @Override
                        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                            ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME);
                        }
                    }).notify(null);
                } else {
                    new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message("external.maven.home.invalid.substitution.warning", myState.mavenHome, mavenVersion), NotificationType.WARNING).notify(null);
                }
            } else {
                mavenHome = currentMavenHomeFile;
                mavenVersion = getMavenVersion(mavenHome);
            }
            assert mavenVersion != null;
            params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_VERSION, mavenVersion);
            String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for Importer";
            verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation);
            final List<String> classPath = new ArrayList<>();
            classPath.add(PathUtil.getJarPathForClass(org.apache.log4j.Logger.class));
            if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) {
                classPath.add(PathUtil.getJarPathForClass(Logger.class));
                classPath.add(PathUtil.getJarPathForClass(Log4jLoggerFactory.class));
            }
            classPath.addAll(PathManager.getUtilClassPath());
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Query.class));
            params.getClassPath().add(PathManager.getResourceRoot(getClass(), "/messages/CommonBundle.properties"));
            params.getClassPath().addAll(classPath);
            params.getClassPath().addAllFiles(collectClassPathAndLibsFolder(mavenVersion, mavenHome));
            String embedderXmx = System.getProperty("idea.maven.embedder.xmx");
            if (embedderXmx != null) {
                params.getVMParametersList().add("-Xmx" + embedderXmx);
            } else {
                if (!xmxSet) {
                    params.getVMParametersList().add("-Xmx768m");
                }
            }
            String mavenEmbedderDebugPort = System.getProperty("idea.maven.embedder.debug.port");
            if (mavenEmbedderDebugPort != null) {
                params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + mavenEmbedderDebugPort);
            }
            String mavenEmbedderParameters = System.getProperty("idea.maven.embedder.parameters");
            if (mavenEmbedderParameters != null) {
                params.getProgramParametersList().addParametersString(mavenEmbedderParameters);
            }
            String mavenEmbedderCliOptions = System.getProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS);
            if (mavenEmbedderCliOptions != null) {
                params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_CLI_ADDITIONAL_ARGS, mavenEmbedderCliOptions);
            }
            return params;
        }

        @NotNull
        @Override
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ProcessHandler processHandler = startProcess();
            return new DefaultExecutionResult(processHandler);
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            SimpleJavaParameters params = createJavaParameters();
            GeneralCommandLine commandLine = params.toCommandLine();
            OSProcessHandler processHandler = new OSProcessHandler(commandLine);
            processHandler.setShouldDestroyProcessRecursively(false);
            return processHandler;
        }
    };
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) Query(org.apache.lucene.search.Query) Logger(org.slf4j.Logger) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) Executor(com.intellij.execution.Executor) THashMap(gnu.trove.THashMap) Log4jLoggerFactory(org.slf4j.impl.Log4jLoggerFactory) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Project(com.intellij.openapi.project.Project) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) THashMap(gnu.trove.THashMap) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

THashMap (gnu.trove.THashMap)132 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)27 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)17 IOException (java.io.IOException)17 File (java.io.File)15 Map (java.util.Map)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)9 List (java.util.List)9 Module (com.intellij.openapi.module.Module)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 ArrayList (java.util.ArrayList)7 java.util (java.util)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5