private static void addMessages( @NotNull final CompileContext context, @NotNull final Map<CompilerMessageCategory, List<String>> messages, @NotNull final String url) { for (final CompilerMessageCategory category : messages.keySet()) { final List<String> messageList = messages.get(category); for (final String message : messageList) { context.addMessage(category, message, url, -1, -1); } } }
@Nullable private static Module getModule( @NotNull CompileContext context, @NotNull Chunk<Module> moduleChunk) { if (moduleChunk.getNodes().size() != 1) { context.addMessage( CompilerMessageCategory.ERROR, "K2JSCompiler does not support multiple modules.", null, -1, -1); return null; } return moduleChunk.getNodes().iterator().next(); }
private boolean reportProblems( CompileContext context, Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap) { if (problemsMap.isEmpty()) { return false; } boolean errorsReported = false; for (Map.Entry<ProblemDescriptor, HighlightDisplayLevel> entry : problemsMap.entrySet()) { ProblemDescriptor problemDescriptor = entry.getKey(); final PsiElement element = problemDescriptor.getPsiElement(); final PsiFile psiFile = element.getContainingFile(); if (psiFile == null) continue; final VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) continue; final CompilerMessageCategory category = myValidator.getCategoryByHighlightDisplayLevel(entry.getValue(), virtualFile, context); final Document document = myPsiDocumentManager.getDocument(psiFile); final int offset = problemDescriptor.getStartElement().getTextOffset(); assert document != null; final int line = document.getLineNumber(offset); final int column = offset - document.getLineStartOffset(line); context.addMessage( category, problemDescriptor.getDescriptionTemplate(), virtualFile.getUrl(), line + 1, column + 1); if (CompilerMessageCategory.ERROR == category) { errorsReported = true; } } return errorsReported; }
private static GenerationItem[] doGenerate( @NotNull final CompileContext context, @NotNull final GenerationItem[] items, VirtualFile outputRootDirectory) { if (context.getProject().isDisposed()) { return EMPTY_GENERATION_ITEM_ARRAY; } // we have one item per module there, so clear output directory final String genRootPath = FileUtil.toSystemDependentName(outputRootDirectory.getPath()); final File genRootDir = new File(genRootPath); if (genRootDir.exists()) { if (!FileUtil.delete(genRootDir)) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot delete directory " + genRootPath, null, -1, -1); return EMPTY_GENERATION_ITEM_ARRAY; } if (!genRootDir.mkdir()) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + genRootPath, null, -1, -1); return EMPTY_GENERATION_ITEM_ARRAY; } } final List<GenerationItem> results = new ArrayList<GenerationItem>(items.length); for (final GenerationItem item : items) { if (item instanceof MyGenerationItem) { final MyGenerationItem genItem = (MyGenerationItem) item; if (!AndroidCompileUtil.isModuleAffected(context, genItem.myModule)) { continue; } boolean success = true; for (final VirtualFile sourceFile : genItem.myFiles) { final String depFolderOsPath = getDependencyFolder(context.getProject(), sourceFile, outputRootDirectory); try { final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys( AndroidRenderscript.execute( genItem.mySdkLocation, genItem.myAndroidTarget, sourceFile.getPath(), genRootPath, depFolderOsPath, genItem.myRawDirPath)); ApplicationManager.getApplication() .runReadAction( new Runnable() { public void run() { if (context.getProject().isDisposed()) { return; } addMessages(context, messages, sourceFile.getUrl()); } }); if (messages.get(CompilerMessageCategory.ERROR).size() > 0) { success = false; } } catch (final IOException e) { ApplicationManager.getApplication() .runReadAction( new Runnable() { public void run() { if (context.getProject().isDisposed()) return; context.addMessage( CompilerMessageCategory.ERROR, e.getMessage(), sourceFile.getUrl(), -1, -1); } }); success = false; } } if (success) { results.add(genItem); } } } outputRootDirectory.refresh(false, true); return results.toArray(new GenerationItem[results.size()]); }
@Nullable public static String findResourcesCacheDirectory( @NotNull Module module, boolean createIfNotFound, @Nullable CompileContext context) { final Project project = module.getProject(); final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project); if (extension == null) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot get compiler settings for project " + project.getName(), null, -1, -1); } return null; } final String projectOutputDirUrl = extension.getCompilerOutputUrl(); if (projectOutputDirUrl == null) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot find output directory for project " + project.getName(), null, -1, -1); } return null; } final String pngCacheDirPath = VfsUtil.urlToPath(projectOutputDirUrl) + '/' + RESOURCES_CACHE_DIR_NAME + '/' + module.getName(); final String pngCacheDirOsPath = FileUtil.toSystemDependentName(pngCacheDirPath); final File pngCacheDir = new File(pngCacheDirOsPath); if (pngCacheDir.exists()) { if (pngCacheDir.isDirectory()) { return pngCacheDirOsPath; } else { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + pngCacheDirOsPath + " because file already exists", null, -1, -1); } return null; } } if (!createIfNotFound) { return null; } if (!pngCacheDir.mkdirs()) { if (context != null) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + pngCacheDirOsPath, null, -1, -1); } return null; } return pngCacheDirOsPath; }