Search in sources :

Example 76 with HashSet

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

the class NewModuleWizardTest method testBuildChooseModuleStep.

public void testBuildChooseModuleStep() throws Exception {
    File otherTemplateDir = new File(TemplateManager.getTemplateRootFolder(), Template.CATEGORY_PROJECTS);
    List<String> templateDirFiles = Arrays.asList(otherTemplateDir.list((file, name) -> !name.startsWith(".")));
    int expectedCount = templateDirFiles.size() - 3 + 3;
    WrapArchiveWizardPath wrapArchiveWizardPath = new WrapArchiveWizardPath(new NewModuleWizardState(), getProject(), () -> {
    }, null);
    expectedCount += wrapArchiveWizardPath.getBuiltInTemplates().size();
    ArrayList<ModuleWizardStep> steps = Lists.newArrayList();
    TemplateWizardModuleBuilder myModuleBuilder = new TemplateWizardModuleBuilder(null, myModule.getProject(), AndroidIcons.Wizards.NewModuleSidePanel, steps, getTestRootDisposable(), false) {

        @Override
        public void update() {
        // Do nothing
        }
    };
    assertInstanceOf(steps.get(0), ChooseTemplateStep.class);
    ChooseTemplateStep chooseTemplateStep = (ChooseTemplateStep) steps.get(0);
    // Make sure we've got an actual object
    assertNotNull(chooseTemplateStep);
    DefaultListModel templateMetadatas = (DefaultListModel) chooseTemplateStep.myTemplateList.getModel();
    Set<String> templateNames = new HashSet<>(templateMetadatas.getSize());
    for (Object o : templateMetadatas.toArray()) {
        templateNames.add(o.toString());
    }
    // Make sure we have the right number of choices
    assertEquals(expectedCount, templateMetadatas.getSize());
    // Ensure we're not offering duplicate elements in the list
    assertEquals(templateNames.size(), templateMetadatas.getSize());
}
Also used : Arrays(java.util.Arrays) HashSet(com.intellij.util.containers.HashSet) Set(java.util.Set) IOException(java.io.IOException) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) SystemProperties(com.intellij.util.SystemProperties) AndroidIcons(icons.AndroidIcons) Template(com.android.tools.idea.templates.Template) TemplateManager(com.android.tools.idea.templates.TemplateManager) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) WrapArchiveWizardPath(com.android.tools.idea.npw.deprecated.WrapArchiveWizardPath) FileUtil(com.intellij.openapi.util.io.FileUtil) AndroidTestCase(org.jetbrains.android.AndroidTestCase) javax.swing(javax.swing) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) File(java.io.File) WrapArchiveWizardPath(com.android.tools.idea.npw.deprecated.WrapArchiveWizardPath) HashSet(com.intellij.util.containers.HashSet)

Example 77 with HashSet

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

the class AndroidApt method doCompile.

private static Map<AndroidCompilerMessageKind, List<String>> doCompile(@NotNull IAndroidTarget target, @NotNull String manifestFileOsPath, @NotNull String outDirOsPath, @NotNull String[] resourceDirsOsPaths, @NotNull List<Pair<String, String>> libRTxtFilesAndPackages, @Nullable String customPackage, boolean nonConstantIds, @Nullable String proguardCfgOutputFileOsPath, @Nullable String rTxtOutDirOsPath, boolean optimizeRFile) throws IOException {
    final List<String> args = new ArrayList<String>();
    BuildToolInfo buildToolInfo = target.getBuildToolInfo();
    if (buildToolInfo == null) {
        return Collections.singletonMap(AndroidCompilerMessageKind.ERROR, Collections.singletonList("No Build Tools in the Android SDK."));
    }
    args.add(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
    args.add("package");
    args.add("-m");
    if (nonConstantIds) {
        args.add("--non-constant-id");
    }
    if (resourceDirsOsPaths.length > 1) {
        args.add("--auto-add-overlay");
    }
    final Set<String> extraPackages = new HashSet<String>();
    for (Pair<String, String> pair : libRTxtFilesAndPackages) {
        extraPackages.add(pair.getSecond());
    }
    if (extraPackages.size() > 0) {
        args.add("--extra-packages");
        args.add(toPackagesString(ArrayUtil.toStringArray(extraPackages)));
    }
    if (customPackage != null) {
        args.add("--custom-package");
        args.add(customPackage);
    }
    if (rTxtOutDirOsPath != null) {
        args.add("--output-text-symbols");
        args.add(rTxtOutDirOsPath);
    }
    args.add("-J");
    args.add(outDirOsPath);
    args.add("-M");
    args.add(manifestFileOsPath);
    for (String libResFolderOsPath : resourceDirsOsPaths) {
        args.add("-S");
        args.add(libResFolderOsPath);
    }
    args.add("-I");
    args.add(target.getPath(IAndroidTarget.ANDROID_JAR));
    if (proguardCfgOutputFileOsPath != null) {
        args.add("-G");
        args.add(proguardCfgOutputFileOsPath);
    }
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidExecutionUtil.doExecute(ArrayUtil.toStringArray(args));
    LOG.info(AndroidCommonUtils.command2string(args));
    if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
        return messages;
    }
    if (optimizeRFile && !libRTxtFilesAndPackages.isEmpty() && rTxtOutDirOsPath != null) {
        final File rFile = new File(rTxtOutDirOsPath, SdkConstants.FN_RESOURCE_TEXT);
        // if the project has no resources the file could not exist.
        if (rFile.isFile()) {
            final SymbolLoader fullSymbolValues = new SymbolLoader(rFile);
            fullSymbolValues.load();
            final MultiMap<String, SymbolLoader> libMap = new MultiMap<String, SymbolLoader>();
            for (Pair<String, String> pair : libRTxtFilesAndPackages) {
                final File rTextFile = new File(pair.getFirst());
                final String libPackage = pair.getSecond();
                if (rTextFile.isFile()) {
                    final SymbolLoader libSymbols = new SymbolLoader(rTextFile);
                    libSymbols.load();
                    libMap.putValue(libPackage, libSymbols);
                }
            }
            for (Map.Entry<String, Collection<SymbolLoader>> entry : libMap.entrySet()) {
                final String libPackage = entry.getKey();
                final Collection<SymbolLoader> symbols = entry.getValue();
                final SymbolWriter writer = new SymbolWriter(outDirOsPath, libPackage, fullSymbolValues);
                for (SymbolLoader symbolLoader : symbols) {
                    writer.addSymbolsToWrite(symbolLoader);
                }
                writer.write();
            }
        }
    }
    return messages;
}
Also used : BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) SymbolLoader(com.android.sdklib.internal.build.SymbolLoader) MultiMap(com.intellij.util.containers.MultiMap) SymbolWriter(com.android.sdklib.internal.build.SymbolWriter) File(java.io.File) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) HashSet(com.intellij.util.containers.HashSet)

Example 78 with HashSet

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

the class AndroidPreDexBuildTarget method computeRootDescriptors.

@NotNull
@Override
public List<AndroidPreDexBuildTarget.MyRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final List<AndroidPreDexBuildTarget.MyRootDescriptor> result = new ArrayList<AndroidPreDexBuildTarget.MyRootDescriptor>();
    final Set<JpsModule> libModules = new HashSet<JpsModule>();
    final Set<String> externalJars = new HashSet<String>();
    for (JpsModule module : myProject.getModules()) {
        final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
        if (extension != null && !extension.isLibrary() && extension.isPreDexingEnabled()) {
            final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, null, null);
            if (platform != null) {
                fillDepsRecursively(module, libModules, externalJars, dataPaths, platform);
            }
        }
    }
    for (JpsModule libModule : libModules) {
        final File classesJarFile = new AndroidLibraryPackagingTarget(libModule).getOutputFile(dataPaths);
        result.add(new MyRootDescriptor(this, classesJarFile, libModule.getName()));
    }
    for (String externalJarPath : externalJars) {
        result.add(new MyRootDescriptor(this, new File(externalJarPath), null));
    }
    return result;
}
Also used : AndroidPlatform(org.jetbrains.jps.android.AndroidPlatform) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with HashSet

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

the class AndroidResourceCachingBuildTarget method doComputeRootDescriptors.

@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
    if (extension != null) {
        final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
        for (File resOverlayDir : extension.getResourceOverlayDirs()) {
            result.add(new BuildRootDescriptorImpl(this, resOverlayDir));
        }
        final File resourceDir = AndroidJpsUtil.getResourceDirForCompilationPath(extension);
        if (resourceDir != null) {
            result.add(new BuildRootDescriptorImpl(this, resourceDir));
        }
        if (!extension.isLibrary()) {
            final Set<String> aarResDirPaths = new HashSet<String>();
            AndroidJpsUtil.collectResDirectoriesFromAarDeps(myModule, aarResDirPaths);
            for (JpsAndroidModuleExtension depExtension : AndroidJpsUtil.getAllAndroidDependencies(myModule, true)) {
                AndroidJpsUtil.collectResDirectoriesFromAarDeps(depExtension.getModule(), aarResDirPaths);
            }
            for (String path : aarResDirPaths) {
                result.add(new BuildRootDescriptorImpl(this, new File(path)));
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with HashSet

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

the class ApkDiffParser method createTreeNode.

@VisibleForTesting
@NotNull
static DefaultMutableTreeNode createTreeNode(@Nullable VirtualFile oldFile, @Nullable VirtualFile newFile) {
    if (oldFile == null && newFile == null) {
        throw new IllegalArgumentException("Both old and new files are null");
    }
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    long oldSize = 0;
    long newSize = 0;
    HashSet<String> childrenInOldFile = new HashSet<>();
    final String name = oldFile == null ? newFile.getName() : oldFile.getName();
    if (oldFile != null) {
        if (StringUtil.equals(oldFile.getExtension(), SdkConstants.EXT_ZIP)) {
            VirtualFile zipRoot = ApkFileSystem.getInstance().extractAndGetContentRoot(oldFile);
            if (zipRoot != null) {
                oldFile = zipRoot;
            }
        }
        if (oldFile.isDirectory()) {
            //noinspection UnsafeVfsRecursion (no symlinks inside an APK)
            for (VirtualFile oldChild : oldFile.getChildren()) {
                VirtualFile newChild = newFile == null ? null : newFile.findChild(oldChild.getName());
                childrenInOldFile.add(oldChild.getName());
                DefaultMutableTreeNode childNode = createTreeNode(oldChild, newChild);
                node.add(childNode);
                ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
                oldSize += entry.getOldSize();
                newSize += entry.getNewSize();
            }
            if (oldFile.getLength() > 0) {
                // This is probably a zip inside the apk, and we should use it's size
                oldSize = oldFile.getLength();
            }
        } else {
            oldSize += oldFile.getLength();
        }
    }
    if (newFile != null) {
        if (StringUtil.equals(newFile.getExtension(), SdkConstants.EXT_ZIP)) {
            VirtualFile zipRoot = ApkFileSystem.getInstance().extractAndGetContentRoot(newFile);
            if (zipRoot != null) {
                newFile = zipRoot;
            }
        }
        if (newFile.isDirectory()) {
            //noinspection UnsafeVfsRecursion (no symlinks inside an APK)
            for (VirtualFile newChild : newFile.getChildren()) {
                if (childrenInOldFile.contains(newChild.getName())) {
                    continue;
                }
                DefaultMutableTreeNode childNode = createTreeNode(null, newChild);
                node.add(childNode);
                ApkDiffEntry entry = (ApkDiffEntry) childNode.getUserObject();
                oldSize += entry.getOldSize();
                newSize += entry.getNewSize();
            }
            if (newFile.getLength() > 0) {
                // This is probably a zip inside the apk, and we should use it's size
                newSize = newFile.getLength();
            }
        } else {
            newSize += newFile.getLength();
        }
    }
    node.setUserObject(new ApkDiffEntry(name, oldFile, newFile, oldSize, newSize));
    ApkParser.sort(node);
    return node;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashSet(com.intellij.util.containers.HashSet) VisibleForTesting(com.android.annotations.VisibleForTesting) 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