Search in sources :

Example 36 with HashSet

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

the class AndroidLayoutDomTest method doTestTagNameIcons.

private void doTestTagNameIcons(String fileName) throws IOException {
    VirtualFile file = copyFileToProject(fileName);
    myFixture.configureFromExistingVirtualFile(file);
    LookupElement[] elements = myFixture.complete(CompletionType.BASIC);
    Set<String> elementsToCheck = new HashSet<>(Arrays.asList("view", "include", "requestFocus", "fragment", "Button"));
    for (LookupElement element : elements) {
        String s = element.getLookupString();
        Object obj = element.getObject();
        if (elementsToCheck.contains(s)) {
            LookupElementPresentation presentation = new LookupElementPresentation();
            element.renderElement(presentation);
            assertNotNull("no icon for element: " + element, presentation.getIcon());
            if ("Button".equals(s)) {
                assertInstanceOf(obj, PsiClass.class);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement) HashSet(com.intellij.util.containers.HashSet)

Example 37 with HashSet

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

the class AndroidSourceGeneratingBuilder method copyGeneratedSources.

@NotNull
private static MyExitStatus copyGeneratedSources(@NotNull Map<JpsModule, MyModuleData> moduleDataMap, @NotNull BuildDataManager dataManager, @NotNull final CompileContext context) throws IOException {
    final Ref<Boolean> didSomething = Ref.create(false);
    final Ref<Boolean> success = Ref.create(true);
    for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
        final JpsModule module = entry.getKey();
        final MyModuleData data = entry.getValue();
        if (!data.getAndroidExtension().isCopyCustomGeneratedSources()) {
            continue;
        }
        final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
        final AndroidGenSourcesCopyingStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidGenSourcesCopyingStorage.PROVIDER);
        final Set<String> genDirs = AndroidJpsUtil.getGenDirs(data.getAndroidExtension());
        final List<String> filteredGenDirs = filterExcludedByOtherProviders(module, genDirs);
        final Set<String> forciblyExcludedDirs = new HashSet<String>(genDirs);
        forciblyExcludedDirs.removeAll(filteredGenDirs);
        warnUserAboutForciblyExcludedRoots(forciblyExcludedDirs, context);
        final AndroidFileSetState savedState = storage.read();
        final AndroidFileSetState currentState = new AndroidFileSetState(filteredGenDirs, new Condition<File>() {

            @Override
            public boolean value(File file) {
                try {
                    return shouldBeCopied(file);
                } catch (IOException e) {
                    return false;
                }
            }
        }, true);
        if (currentState.equalsTo(savedState)) {
            continue;
        }
        final File outDir = AndroidJpsUtil.getCopiedSourcesStorage(module, dataManager.getDataPaths());
        clearDirectoryIfNotEmpty(outDir, context, ANDROID_GENERATED_SOURCES_PROCESSOR);
        final List<Pair<String, String>> copiedFiles = new ArrayList<Pair<String, String>>();
        for (String path : filteredGenDirs) {
            final File dir = new File(path);
            if (dir.isDirectory()) {
                FileUtil.processFilesRecursively(dir, new Processor<File>() {

                    @Override
                    public boolean process(File file) {
                        try {
                            if (!shouldBeCopied(file)) {
                                return true;
                            }
                            final String relPath = FileUtil.getRelativePath(dir, file);
                            final File dstFile = new File(outDir.getPath() + "/" + relPath);
                            final File dstDir = dstFile.getParentFile();
                            if (!dstDir.exists() && !dstDir.mkdirs()) {
                                context.processMessage(new CompilerMessage(ANDROID_GENERATED_SOURCES_PROCESSOR, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", dstDir.getPath())));
                                return true;
                            }
                            FileUtil.copy(file, dstFile);
                            copiedFiles.add(Pair.create(file.getPath(), dstFile.getPath()));
                            didSomething.set(true);
                        } catch (IOException e) {
                            AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_GENERATED_SOURCES_PROCESSOR);
                            success.set(false);
                            return true;
                        }
                        return true;
                    }
                });
            }
        }
        final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager.getDataPaths());
        final List<String> deletedFiles = new ArrayList<String>();
        if (!removeCopiedFilesDuplicatingGeneratedFiles(context, outDir, generatedSourcesDir, deletedFiles)) {
            success.set(false);
            continue;
        }
        final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
        if (testingManager != null) {
            logGeneratedSourcesProcessing(testingManager, copiedFiles, deletedFiles);
        }
        markDirtyRecursively(outDir, context, ANDROID_GENERATED_SOURCES_PROCESSOR, false);
        storage.saveState(currentState);
    }
    if (didSomething.get()) {
        return success.get() ? MyExitStatus.OK : MyExitStatus.FAIL;
    } else {
        return MyExitStatus.NOTHING_CHANGED;
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsModule(org.jetbrains.jps.model.module.JpsModule) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with HashSet

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

the class AndroidSourceGeneratingBuilder method runBuildConfigGeneration.

private static MyExitStatus runBuildConfigGeneration(@NotNull CompileContext context, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) throws IOException {
    boolean success = true;
    boolean didSomething = false;
    for (Map.Entry<JpsModule, MyModuleData> entry : moduleDataMap.entrySet()) {
        final JpsModule module = entry.getKey();
        final ModuleBuildTarget moduleTarget = new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION);
        final AndroidBuildConfigStateStorage storage = context.getProjectDescriptor().dataManager.getStorage(moduleTarget, AndroidBuildConfigStateStorage.PROVIDER);
        final MyModuleData moduleData = entry.getValue();
        final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
        final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(module, context.getProjectDescriptor().dataManager);
        final File outputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.BUILD_CONFIG_GENERATED_SOURCE_ROOT_NAME);
        try {
            if (extension == null || isLibraryWithBadCircularDependency(extension)) {
                if (!clearDirectoryIfNotEmpty(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
                    success = false;
                }
                continue;
            }
            final String packageName = moduleData.getPackage();
            final boolean debug = !AndroidJpsUtil.isReleaseBuild(context);
            final Set<String> libPackages = new HashSet<String>(getDepLibPackages(module).values());
            libPackages.remove(packageName);
            final AndroidBuildConfigState newState = new AndroidBuildConfigState(packageName, libPackages, debug);
            final AndroidBuildConfigState oldState = storage.getState(module.getName());
            if (newState.equalsTo(oldState)) {
                continue;
            }
            didSomething = true;
            context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.build.config", module.getName())));
            // clear directory, because it may contain obsolete files (ex. if package name was changed)
            if (!clearDirectory(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR)) {
                success = false;
                continue;
            }
            if (doBuildConfigGeneration(packageName, libPackages, debug, outputDirectory, context)) {
                storage.update(module.getName(), newState);
                markDirtyRecursively(outputDirectory, context, ANDROID_BUILD_CONFIG_GENERATOR, true);
            } else {
                storage.update(module.getName(), null);
                success = false;
            }
        } catch (IOException e) {
            AndroidJpsUtil.reportExceptionError(context, null, e, ANDROID_BUILD_CONFIG_GENERATOR);
            success = false;
        }
    }
    if (!success) {
        return MyExitStatus.FAIL;
    } else if (didSomething) {
        return MyExitStatus.OK;
    }
    return MyExitStatus.NOTHING_CHANGED;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet)

Example 39 with HashSet

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

the class AndroidLibraryPackagingBuilder method doBuild.

private static boolean doBuild(CompileContext context, JpsModule module, BuildOutputConsumer outputConsumer) throws IOException {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    if (extension == null || !extension.isLibrary()) {
        return true;
    }
    File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
    outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
    if (outputDir == null) {
        return false;
    }
    final File classesDir = ProjectPaths.getModuleOutputDir(module, false);
    if (classesDir == null || !classesDir.isDirectory()) {
        return true;
    }
    final Set<String> subdirs = new HashSet<String>();
    AndroidJpsUtil.addSubdirectories(classesDir, subdirs);
    if (subdirs.size() > 0) {
        context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.library.packaging", module.getName())));
        final File outputJarFile = new File(outputDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME);
        final List<String> srcFiles;
        try {
            srcFiles = AndroidCommonUtils.packClassFilesIntoJar(ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.toStringArray(subdirs), outputJarFile);
        } catch (IOException e) {
            AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
            return false;
        }
        final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
        if (testingManager != null && outputJarFile.isFile()) {
            testingManager.getCommandExecutor().checkJarContent("library_package_jar", outputJarFile.getPath());
        }
        if (srcFiles.size() > 0) {
            outputConsumer.registerOutputFile(outputJarFile, srcFiles);
        }
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) AndroidBuildTestingManager(org.jetbrains.android.util.AndroidBuildTestingManager) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) IOException(java.io.IOException) File(java.io.File) HashSet(com.intellij.util.containers.HashSet)

Example 40 with HashSet

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

the class SdkUpdaterConfigPanel method getSdkLocations.

@NotNull
private static Collection<File> getSdkLocations() {
    File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
    if (androidHome != null) {
        return ImmutableList.of(androidHome);
    }
    Set<File> locations = new HashSet<>();
    // Gradle project.
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        try {
            LocalProperties localProperties = new LocalProperties(project);
            File androidSdkPath = localProperties.getAndroidSdkPath();
            if (androidSdkPath != null) {
                locations.add(androidSdkPath);
                continue;
            }
        } catch (IOException ignored) {
            Logger.getInstance(SdkUpdaterConfigPanel.class).info("Unable to read local.properties file from project: " + project.getName(), ignored);
        }
        List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
        for (AndroidFacet facet : facets) {
            AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
            if (sdkData != null) {
                locations.add(sdkData.getLocation());
            }
        }
    }
    return locations;
}
Also used : Project(com.intellij.openapi.project.Project) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IOException(java.io.IOException) File(java.io.File) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5