use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidCompileUtil method createGenModulesAndSourceRoots.
public static boolean createGenModulesAndSourceRoots(@NotNull AndroidFacet facet, @NotNull ModifiableRootModel model) {
if (facet.requiresAndroidModel() || !facet.getProperties().ENABLE_SOURCES_AUTOGENERATION) {
return false;
}
final GlobalSearchScope moduleScope = facet.getModule().getModuleScope();
final Ref<Boolean> modelChangedFlag = Ref.create(false);
if (facet.isLibraryProject()) {
removeGenModule(model, modelChangedFlag);
}
final Set<String> genRootsToCreate = new HashSet<String>();
final Set<String> genRootsToInit = new HashSet<String>();
final String buildConfigGenRootPath = AndroidRootUtil.getBuildconfigGenSourceRootPath(facet);
if (buildConfigGenRootPath != null) {
genRootsToCreate.add(buildConfigGenRootPath);
}
final String renderscriptGenRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
if (renderscriptGenRootPath != null) {
final boolean createIfNotExist = FileTypeIndex.getFiles(AndroidRenderscriptFileType.INSTANCE, moduleScope).size() > 0;
(createIfNotExist ? genRootsToCreate : genRootsToInit).add(renderscriptGenRootPath);
}
final String aptGenRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
if (aptGenRootPath != null) {
genRootsToCreate.add(aptGenRootPath);
}
final String aidlGenRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
if (aidlGenRootPath != null) {
final boolean createIfNotExist = FileTypeIndex.getFiles(AidlFileType.INSTANCE, moduleScope).size() > 0;
(createIfNotExist ? genRootsToCreate : genRootsToInit).add(aidlGenRootPath);
}
genRootsToInit.addAll(genRootsToCreate);
for (String genRootPath : genRootsToInit) {
initializeGenSourceRoot(model, genRootPath, genRootsToCreate.contains(genRootPath), true, modelChangedFlag);
}
return modelChangedFlag.get();
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidAutogenerator method runAidl.
private static void runAidl(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
final Module module = facet.getModule();
final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
final VirtualFile[] files = moduleCompileScope.getFiles(AidlFileType.INSTANCE, true);
final List<IdlAutogenerationItem> items = new ArrayList<IdlAutogenerationItem>();
for (final VirtualFile file : files) {
final IdlAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<IdlAutogenerationItem>() {
@Nullable
@Override
public IdlAutogenerationItem compute() {
if (module.isDisposed() || module.getProject().isDisposed()) {
return null;
}
final IAndroidTarget target = facet.getConfiguration().getAndroidTarget();
if (target == null) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
return null;
}
final String packageName = AndroidUtils.computePackageName(module, file);
if (packageName == null) {
context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
return null;
}
final String sourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(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 VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module, false);
final String[] sourceRootOsPaths = AndroidCompileUtil.toOsPaths(sourceRoots);
final String outFileOsPath = FileUtil.toSystemDependentName(sourceRootPath + '/' + packageName.replace('.', '/') + '/' + file.getNameWithoutExtension() + ".java");
return new IdlAutogenerationItem(file, target, outFileOsPath, sourceRootOsPaths, sourceRootPath, packageName);
}
});
if (item != null) {
items.add(item);
}
}
final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
for (IdlAutogenerationItem item : items) {
if (new File(FileUtil.toSystemDependentName(item.myFile.getPath())).exists()) {
filesToCheck.add(item.myFile);
}
}
if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
return;
}
facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AIDL);
for (IdlAutogenerationItem item : items) {
final VirtualFile file = item.myFile;
final String fileOsPath = FileUtil.toSystemDependentName(file.getPath());
try {
final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidIdl.execute(item.myTarget, fileOsPath, item.myOutFileOsPath, item.mySourceRootOsPaths));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (module.getProject().isDisposed())
return;
for (CompilerMessageCategory category : messages.keySet()) {
List<String> messageList = messages.get(category);
for (String message : messageList) {
context.addMessage(category, message, file.getUrl(), -1, -1);
}
}
}
});
removeDuplicateClasses(module, item.myPackage, new File(item.myOutFileOsPath), item.myOutDirOsPath);
final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myOutDirOsPath);
if (genDir != null) {
genDir.refresh(false, true);
}
final VirtualFile outFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(item.myOutFileOsPath);
if (outFile != null && outFile.exists()) {
patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.AIDL, outFile);
}
} 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, e.getMessage(), file.getUrl(), -1, -1);
}
});
}
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidAutogenerator method run.
public static void run(@NotNull AndroidAutogeneratorMode mode, @NotNull AndroidFacet facet, @NotNull CompileContext context, boolean force) {
if (!toRun(mode, facet, force)) {
return;
}
final Set<String> obsoleteFiles = new HashSet<String>(facet.getAutogeneratedFiles(mode));
switch(mode) {
case AAPT:
runAapt(facet, context, force);
break;
case AIDL:
runAidl(facet, context);
break;
case RENDERSCRIPT:
runRenderscript(facet, context);
break;
case BUILDCONFIG:
runBuildConfigGenerator(facet, context);
break;
default:
LOG.error("Unknown mode" + mode);
}
obsoleteFiles.removeAll(facet.getAutogeneratedFiles(mode));
for (String path : obsoleteFiles) {
final File file = new File(path);
if (file.isFile()) {
FileUtil.delete(file);
CompilerUtil.refreshIOFile(file);
}
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class ResourceManager method getValueResourceEntries.
@NotNull
public Collection<ResourceEntry> getValueResourceEntries(@NotNull final ResourceType resourceType) {
final FileBasedIndex index = FileBasedIndex.getInstance();
final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName());
final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
final Map<VirtualFile, Set<ResourceEntry>> file2resourceSet = new HashMap<VirtualFile, Set<ResourceEntry>>();
index.processValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, null, new FileBasedIndex.ValueProcessor<ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo>>() {
@Override
public boolean process(@NotNull VirtualFile file, ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo> infos) {
for (AndroidValueResourcesIndex.MyResourceInfo info : infos) {
Set<ResourceEntry> resourcesInFile = file2resourceSet.get(file);
if (resourcesInFile == null) {
resourcesInFile = new HashSet<ResourceEntry>();
file2resourceSet.put(file, resourcesInFile);
}
resourcesInFile.add(info.getResourceEntry());
}
return true;
}
}, scope);
final List<ResourceEntry> result = new ArrayList<ResourceEntry>();
for (VirtualFile file : getAllValueResourceFiles()) {
final Set<ResourceEntry> entries = file2resourceSet.get(file);
if (entries != null) {
for (ResourceEntry entry : entries) {
if (isResourcePublic(entry.getType(), entry.getName())) {
result.add(entry);
}
}
}
}
return result;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class ResourceManager method getResourceNames.
@NotNull
public Collection<String> getResourceNames(@NotNull ResourceType resourceType, boolean publicOnly) {
final Set<String> result = new HashSet<String>();
result.addAll(getValueResourceNames(resourceType));
List<ResourceFolderType> folders = FolderTypeRelationship.getRelatedFolders(resourceType);
if (!folders.isEmpty()) {
for (ResourceFolderType folderType : folders) {
if (folderType != ResourceFolderType.VALUES) {
result.addAll(getFileResourcesNames(folderType.getName()));
}
}
}
if (resourceType == ResourceType.ID) {
result.addAll(getIds(true));
}
return result;
}
Aggregations