Search in sources :

Example 36 with THashSet

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

the class EclipseImportBuilder method validate.

@Override
public boolean validate(final Project currentProject, final Project dstProject) {
    final Ref<Exception> refEx = new Ref<>();
    final Set<String> variables = new THashSet<>();
    final Map<String, String> naturesNames = new THashMap<>();
    final List<String> projectsToConvert = getParameters().projectsToConvert;
    final boolean oneProjectToConvert = projectsToConvert.size() == 1;
    final String separator = oneProjectToConvert ? "<br>" : ", ";
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        try {
            for (String path : projectsToConvert) {
                File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
                if (classPathFile.exists()) {
                    EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
                }
                collectUnknownNatures(path, naturesNames, separator);
            }
        } catch (IOException | JDOMException e) {
            refEx.set(e);
        }
    }, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
    if (!refEx.isNull()) {
        Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
        return false;
    }
    if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
        return false;
    }
    if (!naturesNames.isEmpty()) {
        final String title = "Unknown Natures Detected";
        final String naturesByProject;
        if (oneProjectToConvert) {
            naturesByProject = naturesNames.values().iterator().next();
        } else {
            naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
        }
        Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
    }
    return true;
}
Also used : ClassPathStorageUtil(com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) IdeaXml(org.jetbrains.idea.eclipse.IdeaXml) ClasspathStorage(com.intellij.openapi.roots.impl.storage.ClasspathStorage) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) EclipseIcons(icons.EclipseIcons) Library(com.intellij.openapi.roots.libraries.Library) ProjectImportBuilder(com.intellij.projectImport.ProjectImportBuilder) Task(com.intellij.openapi.progress.Task) JDOMException(org.jdom.JDOMException) EclipseUserLibrariesHelper(org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) ModuleManagerImpl(com.intellij.openapi.module.impl.ModuleManagerImpl) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryTablesRegistrar(com.intellij.openapi.roots.libraries.LibraryTablesRegistrar) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) Comparing(com.intellij.openapi.util.Comparing) StartupManager(com.intellij.openapi.startup.StartupManager) JDOMUtil(com.intellij.openapi.util.JDOMUtil) EclipseXml(org.jetbrains.idea.eclipse.EclipseXml) Project(com.intellij.openapi.project.Project) JpsEclipseClasspathSerializer(org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) File(java.io.File) EclipseProjectFinder(org.jetbrains.idea.eclipse.EclipseProjectFinder) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectMacrosUtil(com.intellij.openapi.project.impl.ProjectMacrosUtil) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) EclipseBundle(org.jetbrains.idea.eclipse.EclipseBundle) javax.swing(javax.swing) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) Notification(com.intellij.notification.Notification) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 37 with THashSet

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

the class EclipseClasspathReader method readClasspath.

public void readClasspath(@NotNull ModifiableRootModel model, @NotNull Collection<String> unknownLibraries, @NotNull Collection<String> unknownJdks, Set<String> refsToModules, final String testPattern, Element classpathElement) throws IOException, ConversionException {
    for (OrderEntry orderEntry : model.getOrderEntries()) {
        if (!(orderEntry instanceof ModuleSourceOrderEntry)) {
            model.removeOrderEntry(orderEntry);
        }
    }
    int idx = 0;
    EclipseModuleManagerImpl eclipseModuleManager = EclipseModuleManagerImpl.getInstance(model.getModule());
    Set<String> libs = new THashSet<>();
    for (Element o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) {
        try {
            readClasspathEntry(model, unknownLibraries, unknownJdks, refsToModules, testPattern, o, idx++, eclipseModuleManager, ((BasePathMacroManager) PathMacroManager.getInstance(model.getModule())).getExpandMacroMap(), libs);
        } catch (ConversionException e) {
            ErrorLog.rethrow(ErrorLog.Level.Warning, null, EclipseXml.CLASSPATH_FILE, e);
        }
    }
    if (!model.isSdkInherited() && model.getSdkName() == null) {
        eclipseModuleManager.setForceConfigureJDK();
        model.inheritSdk();
    }
}
Also used : EclipseModuleManagerImpl(org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl) Element(org.jdom.Element) THashSet(gnu.trove.THashSet)

Example 38 with THashSet

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

the class UnInjectLanguageAction method defaultFunctionalityWorked.

private static boolean defaultFunctionalityWorked(final PsiLanguageInjectionHost host) {
    final THashSet<String> languages = new THashSet<>();
    final List<Pair<PsiElement, TextRange>> files = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
    if (files == null)
        return false;
    for (Pair<PsiElement, TextRange> pair : files) {
        for (Language lang = pair.first.getLanguage(); lang != null; lang = lang.getBaseLanguage()) {
            languages.add(lang.getID());
        }
    }
    // todo therefore this part doesn't work for java
    return Configuration.getProjectInstance(host.getProject()).setHostInjectionEnabled(host, languages, false);
}
Also used : Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair)

Example 39 with THashSet

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

the class BuildOperations method initTargetFSState.

private static void initTargetFSState(CompileContext context, BuildTarget<?> target, final boolean forceMarkDirty) throws IOException {
    final ProjectDescriptor pd = context.getProjectDescriptor();
    final Timestamps timestamps = pd.timestamps.getStorage();
    final THashSet<File> currentFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    FSOperations.markDirtyFiles(context, target, CompilationRound.CURRENT, timestamps, forceMarkDirty, currentFiles, null);
    // handle deleted paths
    final BuildFSState fsState = pd.fsState;
    fsState.clearDeletedPaths(target);
    final SourceToOutputMapping sourceToOutputMap = pd.dataManager.getSourceToOutputMap(target);
    for (final Iterator<String> it = sourceToOutputMap.getSourcesIterator(); it.hasNext(); ) {
        final String path = it.next();
        // can check if the file exists
        final File file = new File(path);
        if (!currentFiles.contains(file)) {
            fsState.registerDeleted(context, target, file, timestamps);
        }
    }
    pd.fsState.markInitialScanPerformed(target);
}
Also used : Timestamps(org.jetbrains.jps.incremental.storage.Timestamps) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 40 with THashSet

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

the class BuildOperations method cleanOutputsCorrespondingToChangedFiles.

public static <R extends BuildRootDescriptor, T extends BuildTarget<R>> Map<T, Set<File>> cleanOutputsCorrespondingToChangedFiles(final CompileContext context, DirtyFilesHolder<R, T> dirtyFilesHolder) throws ProjectBuildException {
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    try {
        final Map<T, Set<File>> cleanedSources = new HashMap<>();
        final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        final Collection<String> deletedPaths = new ArrayList<>();
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<R, T>() {

            // cache the mapping locally
            private final Map<T, SourceToOutputMapping> mappingsCache = new HashMap<>();

            private final TObjectIntHashMap<T> idsCache = new TObjectIntHashMap<>();

            @Override
            public boolean apply(T target, File file, R sourceRoot) throws IOException {
                SourceToOutputMapping srcToOut = mappingsCache.get(target);
                if (srcToOut == null) {
                    srcToOut = dataManager.getSourceToOutputMap(target);
                    mappingsCache.put(target, srcToOut);
                }
                final int targetId;
                if (!idsCache.containsKey(target)) {
                    targetId = dataManager.getTargetsState().getBuildTargetId(target);
                    idsCache.put(target, targetId);
                } else {
                    targetId = idsCache.get(target);
                }
                final String srcPath = file.getPath();
                final Collection<String> outputs = srcToOut.getOutputs(srcPath);
                if (outputs != null) {
                    final boolean shouldPruneOutputDirs = target instanceof ModuleBasedTarget;
                    final List<String> deletedForThisSource = new ArrayList<>(outputs.size());
                    for (String output : outputs) {
                        deleteRecursively(output, deletedForThisSource, shouldPruneOutputDirs ? dirsToDelete : null);
                    }
                    deletedPaths.addAll(deletedForThisSource);
                    dataManager.getOutputToTargetRegistry().removeMapping(deletedForThisSource, targetId);
                    Set<File> cleaned = cleanedSources.get(target);
                    if (cleaned == null) {
                        cleaned = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                        cleanedSources.put(target, cleaned);
                    }
                    cleaned.add(file);
                }
                return true;
            }
        });
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled()) {
                logger.logDeletedFiles(deletedPaths);
            }
        }
        if (!deletedPaths.isEmpty()) {
            context.processMessage(new FileDeletedEvent(deletedPaths));
        }
        // attempting to delete potentially empty directories
        FSOperations.pruneEmptyDirs(context, dirsToDelete);
        return cleanedSources;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileDeletedEvent(org.jetbrains.jps.incremental.messages.FileDeletedEvent) File(java.io.File)

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