Search in sources :

Example 11 with THashMap

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

the class MavenArtifactDownloader method collectArtifactsToDownload.

private Map<MavenId, DownloadData> collectArtifactsToDownload(List<MavenExtraArtifactType> types) {
    Map<MavenId, DownloadData> result = new THashMap<>();
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myProject.isDisposed())
            return result;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myProject).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenProject eachProject : myMavenProjects) {
        List<MavenRemoteRepository> repositories = eachProject.getRemoteRepositories();
        for (MavenArtifact eachDependency : eachProject.getDependencies()) {
            if (myArtifacts != null && !myArtifacts.contains(eachDependency))
                continue;
            if (MavenConstants.SCOPE_SYSTEM.equalsIgnoreCase(eachDependency.getScope()))
                continue;
            if (myProjectsTree.findProject(eachDependency.getMavenId()) != null)
                continue;
            String dependencyType = eachDependency.getType();
            if (!dependencyTypesFromSettings.contains(dependencyType) && !eachProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
                continue;
            }
            MavenId id = eachDependency.getMavenId();
            DownloadData data = result.get(id);
            if (data == null) {
                data = new DownloadData();
                result.put(id, data);
            }
            data.repositories.addAll(repositories);
            for (MavenExtraArtifactType eachType : types) {
                Pair<String, String> classifierAndExtension = eachProject.getClassifierAndExtension(eachDependency, eachType);
                String classifier = eachDependency.getFullClassifier(classifierAndExtension.first);
                String extension = classifierAndExtension.second;
                data.classifiersWithExtensions.add(new DownloadElement(classifier, extension, eachType));
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) AccessToken(com.intellij.openapi.application.AccessToken) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType)

Example 12 with THashMap

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

the class MavenPluginConfigurationDomExtender method collectParameters.

private static Collection<ParameterData> collectParameters(MavenDomPluginModel pluginModel, MavenDomConfiguration config) {
    List<String> selectedGoals = null;
    MavenDomPluginExecution executionElement = config.getParentOfType(MavenDomPluginExecution.class, false);
    if (executionElement != null) {
        selectedGoals = new ArrayList<>();
        String id = executionElement.getId().getStringValue();
        String defaultPrefix = "default-";
        if (id != null && id.startsWith(defaultPrefix)) {
            String goal = id.substring(defaultPrefix.length());
            if (!StringUtil.isEmptyOrSpaces(goal))
                selectedGoals.add(goal);
        }
        for (GenericDomValue<String> goal : executionElement.getGoals().getGoals()) {
            selectedGoals.add(goal.getStringValue());
        }
    }
    Map<String, ParameterData> namesWithParameters = new THashMap<>();
    for (MavenDomMojo eachMojo : pluginModel.getMojos().getMojos()) {
        String goal = eachMojo.getGoal().getStringValue();
        if (goal == null)
            continue;
        if (selectedGoals == null || selectedGoals.contains(goal)) {
            for (MavenDomParameter eachParameter : eachMojo.getParameters().getParameters()) {
                if (eachParameter.getEditable().getValue() == Boolean.FALSE)
                    continue;
                String name = eachParameter.getName().getStringValue();
                if (name == null)
                    continue;
                ParameterData data = new ParameterData(eachParameter);
                fillParameterData(name, data, eachMojo);
                ParameterData oldParameter = namesWithParameters.get(name);
                if (oldParameter == null || hasMorePriority(data, oldParameter, executionElement != null)) {
                    namesWithParameters.put(name, data);
                }
            }
        }
    }
    return namesWithParameters.values();
}
Also used : MavenDomPluginExecution(org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution) THashMap(gnu.trove.THashMap) MavenDomMojo(org.jetbrains.idea.maven.dom.plugin.MavenDomMojo) MavenDomParameter(org.jetbrains.idea.maven.dom.plugin.MavenDomParameter)

Example 13 with THashMap

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

the class DependencyResolvingBuilder method syncPaths.

private static void syncPaths(final Collection<File> required, @NotNull Collection<File> resolved) throws Exception {
    final THashSet<File> libFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    libFiles.addAll(required);
    libFiles.removeAll(resolved);
    if (!libFiles.isEmpty()) {
        final Map<String, File> nameToArtifactMap = new THashMap<>(FileUtil.PATH_HASHING_STRATEGY);
        for (File f : resolved) {
            final File prev = nameToArtifactMap.put(f.getName(), f);
            if (prev != null) {
                throw new Exception("Ambiguous artifacts with the same name: " + prev.getPath() + " and " + f.getPath());
            }
        }
        for (File file : libFiles) {
            final File resolvedArtifact = nameToArtifactMap.get(file.getName());
            if (resolvedArtifact != null) {
                FileUtil.copy(resolvedArtifact, file);
            }
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) File(java.io.File) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 14 with THashMap

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

the class MicrodataUtil method findScopesWithItemRef.

private static Map<String, XmlTag> findScopesWithItemRef(@Nullable final PsiFile file) {
    if (!(file instanceof XmlFile))
        return Collections.emptyMap();
    return CachedValuesManager.getCachedValue(file, new CachedValueProvider<Map<String, XmlTag>>() {

        @Nullable
        @Override
        public Result<Map<String, XmlTag>> compute() {
            final Map<String, XmlTag> result = new THashMap<>();
            file.accept(new XmlRecursiveElementVisitor() {

                @Override
                public void visitXmlTag(final XmlTag tag) {
                    super.visitXmlTag(tag);
                    XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
                    if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) {
                        getReferencesForAttributeValue(refAttr.getValueElement(), (t, v) -> {
                            result.put(t, tag);
                            return null;
                        });
                    }
                }
            });
            return Result.create(result, file);
        }
    });
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) THashMap(gnu.trove.THashMap) Nullable(org.jetbrains.annotations.Nullable) XmlTag(com.intellij.psi.xml.XmlTag)

Example 15 with THashMap

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

the class FormsInstrumenter method instrumentForms.

private Map<File, Collection<File>> instrumentForms(CompileContext context, ModuleChunk chunk, final Map<File, String> chunkSourcePath, final InstrumentationClassFinder finder, Collection<File> forms, OutputConsumer outConsumer) throws ProjectBuildException {
    final Map<File, Collection<File>> instrumented = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    final Map<String, File> class2form = new HashMap<>();
    final MyNestedFormLoader nestedFormsLoader = new MyNestedFormLoader(chunkSourcePath, ProjectPaths.getOutputPathsWithDependents(chunk), finder);
    for (File formFile : forms) {
        final LwRootContainer rootContainer;
        try {
            rootContainer = Utils.getRootContainer(formFile.toURI().toURL(), new CompiledClassPropertiesProvider(finder.getLoader()));
        } catch (AlienFormFileException e) {
            // ignore non-IDEA forms
            continue;
        } catch (UnexpectedFormElementException e) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, e.getMessage(), formFile.getPath()));
            LOG.info(e);
            continue;
        } catch (UIDesignerException e) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, e.getMessage(), formFile.getPath()));
            LOG.info(e);
            continue;
        } catch (Exception e) {
            throw new ProjectBuildException("Cannot process form file " + formFile.getAbsolutePath(), e);
        }
        final String classToBind = rootContainer.getClassToBind();
        if (classToBind == null) {
            continue;
        }
        final CompiledClass compiled = findClassFile(outConsumer, classToBind);
        if (compiled == null) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, "Class to bind does not exist: " + classToBind, formFile.getAbsolutePath()));
            continue;
        }
        final File alreadyProcessedForm = class2form.get(classToBind);
        if (alreadyProcessedForm != null) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, formFile.getAbsolutePath() + ": The form is bound to the class " + classToBind + ".\nAnother form " + alreadyProcessedForm.getAbsolutePath() + " is also bound to this class", formFile.getAbsolutePath()));
            continue;
        }
        class2form.put(classToBind, formFile);
        for (File file : compiled.getSourceFiles()) {
            addBinding(file, formFile, instrumented);
        }
        try {
            context.processMessage(new ProgressMessage("Instrumenting forms... [" + chunk.getPresentableShortName() + "]"));
            final BinaryContent originalContent = compiled.getContent();
            final ClassReader classReader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength());
            final int version = ClassProcessingBuilder.getClassFileVersion(classReader);
            final InstrumenterClassWriter classWriter = new InstrumenterClassWriter(classReader, ClassProcessingBuilder.getAsmClassWriterFlags(version), finder);
            final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, finder, nestedFormsLoader, false, classWriter);
            final byte[] patchedBytes = codeGenerator.patchClass(classReader);
            if (patchedBytes != null) {
                compiled.setContent(new BinaryContent(patchedBytes));
            }
            final FormErrorInfo[] warnings = codeGenerator.getWarnings();
            for (final FormErrorInfo warning : warnings) {
                context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.WARNING, warning.getErrorMessage(), formFile.getAbsolutePath()));
            }
            final FormErrorInfo[] errors = codeGenerator.getErrors();
            if (errors.length > 0) {
                StringBuilder message = new StringBuilder();
                for (final FormErrorInfo error : errors) {
                    if (message.length() > 0) {
                        message.append("\n");
                    }
                    message.append(formFile.getAbsolutePath()).append(": ").append(error.getErrorMessage());
                }
                context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message.toString()));
            }
        } catch (Exception e) {
            context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Forms instrumentation failed" + e.getMessage(), formFile.getAbsolutePath()));
        }
    }
    return instrumented;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashMap(gnu.trove.THashMap) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) THashMap(gnu.trove.THashMap) InstrumenterClassWriter(com.intellij.compiler.instrumentation.InstrumenterClassWriter) CompiledClassPropertiesProvider(com.intellij.uiDesigner.lw.CompiledClassPropertiesProvider) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader)

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