use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidActivityAliasCompletionContributor method collectActivityAliases.
@NotNull
private static Set<String> collectActivityAliases(@NotNull AndroidFacet facet) {
final Set<String> result = new HashSet<String>();
doCollectActivityAliases(facet, result);
for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(facet.getModule(), true)) {
doCollectActivityAliases(depFacet, result);
}
return result;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidUtils method getDepLibsPackages.
@NotNull
public static Set<String> getDepLibsPackages(Module module) {
final Set<String> result = new HashSet<>();
final HashSet<Module> visited = new HashSet<>();
if (visited.add(module)) {
for (AndroidFacet depFacet : getAllAndroidDependencies(module, true)) {
final Manifest manifest = depFacet.getManifest();
if (manifest != null) {
String aPackage = manifest.getPackage().getValue();
if (aPackage != null) {
result.add(aPackage);
}
}
}
}
return result;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class ThemeEditorStyle method removeAttribute.
/**
* Deletes an attribute of that particular style from all the relevant xml files
*/
public void removeAttribute(@NotNull final String attribute) {
if (!isProjectStyle()) {
throw new UnsupportedOperationException("Non project styles can not be modified");
}
final Project project = myManager.getProject();
Collection<PsiFile> toBeEdited = new HashSet<PsiFile>();
final Collection<XmlTag> toBeRemoved = new HashSet<XmlTag>();
for (ResourceItem resourceItem : getStyleResourceItems()) {
final XmlTag sourceXml = LocalResourceRepository.getItemTag(project, resourceItem);
assert sourceXml != null;
final XmlTag tag = getValueTag(sourceXml, attribute);
if (tag != null) {
toBeEdited.add(tag.getContainingFile());
toBeRemoved.add(tag);
}
}
new WriteCommandAction.Simple(project, "Removing " + attribute, toBeEdited.toArray(new PsiFile[toBeEdited.size()])) {
@Override
protected void run() {
// Makes the command global even if only one xml file is modified
// That way, the Undo is always available from the theme editor
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
for (XmlTag tag : toBeRemoved) {
tag.delete();
}
}
}.execute();
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidAutogenerator method runAapt.
private static void runAapt(@NotNull final AndroidFacet facet, @NotNull final CompileContext context, boolean force) {
final Module module = facet.getModule();
final AptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<AptAutogenerationItem>() {
@Nullable
@Override
public AptAutogenerationItem compute() {
if (module.isDisposed() || module.getProject().isDisposed()) {
return null;
}
final VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
if (manifestFile == null) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.manifest.not.found", module.getName()), null, -1, -1);
return null;
}
final Manifest manifest = AndroidUtils.loadDomElement(module, manifestFile, Manifest.class);
if (manifest == null) {
context.addMessage(CompilerMessageCategory.ERROR, "Cannot parse file", manifestFile.getUrl(), -1, -1);
return null;
}
String packageName = manifest.getPackage().getValue();
if (packageName != null) {
packageName = packageName.trim();
}
if (packageName == null || packageName.length() <= 0) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("package.not.found.error"), manifestFile.getUrl(), -1, -1);
return null;
}
if (!AndroidUtils.isValidAndroidPackageName(packageName)) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("not.valid.package.name.error", packageName), manifestFile.getUrl(), -1, -1);
return null;
}
final String sourceRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
if (sourceRootPath == null) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.apt.gen.not.specified", module.getName()), null, -1, -1);
return null;
}
final Map<String, String> genFilePath2Package = new HashMap<String, String>();
final String packageDir = packageName.replace('.', '/') + '/';
genFilePath2Package.put(packageDir + AndroidCommonUtils.MANIFEST_JAVA_FILE_NAME, packageName);
genFilePath2Package.put(packageDir + AndroidCommonUtils.R_JAVA_FILENAME, packageName);
return new AptAutogenerationItem(packageName, sourceRootPath, genFilePath2Package);
}
});
if (item == null) {
return;
}
if (force) {
final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
for (String genFileRelPath : item.myGenFileRelPath2package.keySet()) {
final String genFileFullPath = item.myOutputDirOsPath + '/' + genFileRelPath;
if (new File(genFileFullPath).exists()) {
final VirtualFile genFile = LocalFileSystem.getInstance().findFileByPath(genFileFullPath);
if (genFile != null) {
filesToCheck.add(genFile);
}
}
}
if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
return;
}
}
File tempOutDir = null;
try {
// Aapt generation can be very long, so we generate it in temp directory first
tempOutDir = FileUtil.createTempDirectory("android_apt_autogeneration", "tmp");
generateStubClasses(item.myPackage, tempOutDir, AndroidUtils.R_CLASS_NAME, AndroidUtils.MANIFEST_CLASS_NAME);
for (String genFileRelPath : item.myGenFileRelPath2package.keySet()) {
final File srcFile = new File(tempOutDir.getPath() + '/' + genFileRelPath);
if (srcFile.isFile()) {
final File dstFile = new File(item.myOutputDirOsPath + '/' + genFileRelPath);
if (dstFile.exists()) {
if (!force) {
continue;
}
if (!FileUtil.delete(dstFile)) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (module.isDisposed() || module.getProject().isDisposed()) {
return;
}
context.addMessage(CompilerMessageCategory.ERROR, "Cannot delete " + FileUtil.toSystemDependentName(dstFile.getPath()), null, -1, -1);
}
});
}
}
FileUtil.rename(srcFile, dstFile);
}
}
for (Map.Entry<String, String> entry : item.myGenFileRelPath2package.entrySet()) {
final String path = item.myOutputDirOsPath + '/' + entry.getKey();
final String aPackage = entry.getValue();
final File file = new File(path);
CompilerUtil.refreshIOFile(file);
removeAllFilesWithSameName(module, file, item.myOutputDirOsPath);
removeDuplicateClasses(module, aPackage, file, item.myOutputDirOsPath);
}
final VirtualFile genSourceRoot = LocalFileSystem.getInstance().findFileByPath(item.myOutputDirOsPath);
if (genSourceRoot != null) {
genSourceRoot.refresh(false, true);
}
facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AAPT);
for (String relPath : item.myGenFileRelPath2package.keySet()) {
final VirtualFile genFile = LocalFileSystem.getInstance().findFileByPath(item.myOutputDirOsPath + '/' + relPath);
if (genFile != null && genFile.exists()) {
facet.markFileAutogenerated(AndroidAutogeneratorMode.AAPT, genFile);
}
}
} catch (final IOException e) {
LOG.info(e);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (module.getProject().isDisposed())
return;
context.addMessage(CompilerMessageCategory.ERROR, "I/O error: " + e.getMessage(), null, -1, -1);
}
});
} finally {
if (tempOutDir != null) {
FileUtil.delete(tempOutDir);
}
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidCompileUtil method excludeAllBuildConfigsFromCompilation.
private static void excludeAllBuildConfigsFromCompilation(AndroidFacet facet, VirtualFile sourceRoot) {
final Module module = facet.getModule();
final Project project = module.getProject();
final Set<String> packages = new HashSet<String>();
final Manifest manifest = facet.getManifest();
final String aPackage = manifest != null ? manifest.getPackage().getStringValue() : null;
if (aPackage != null) {
packages.add(aPackage);
}
packages.addAll(AndroidUtils.getDepLibsPackages(module));
for (String p : packages) {
excludeFromCompilation(project, sourceRoot, p);
}
}
Aggregations