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());
}
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;
}
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;
}
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();
}
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;
}
Aggregations