use of com.intellij.compiler.impl.ModuleCompileScope in project android by JetBrains.
the class AndroidGradleBuildTargetScopeProvider method getBuildTargetScopes.
@Override
@NotNull
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull CompileScope baseScope, @NotNull CompilerFilter filter, @NotNull Project project, boolean forceBuild) {
if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
return Collections.emptyList();
}
BuildSettings buildSettings = BuildSettings.getInstance(project);
String runConfigurationTypeId = baseScope.getUserData(CompilerManager.RUN_CONFIGURATION_TYPE_ID_KEY);
buildSettings.setRunConfigurationTypeId(runConfigurationTypeId);
if (baseScope instanceof ProjectCompileScope) {
// Make or Rebuild project
BuildMode buildMode = forceBuild ? BuildMode.REBUILD : BuildMode.ASSEMBLE;
if (buildSettings.getBuildMode() == null) {
buildSettings.setBuildMode(buildMode);
}
Module[] modulesToBuild = ModuleManager.getInstance(project).getModules();
buildSettings.setModulesToBuild(modulesToBuild);
} else if (baseScope instanceof ModuleCompileScope) {
String userDataString = ((ModuleCompileScope) baseScope).getUserDataString();
Module[] modulesToBuild;
if (userDataString.contains("RUN_CONFIGURATION")) {
// Triggered by a "Run Configuration"
modulesToBuild = baseScope.getAffectedModules();
} else {
// Triggered by menu item.
// Make selected modules
modulesToBuild = Projects.getModulesToBuildFromSelection(project, null);
}
buildSettings.setModulesToBuild(modulesToBuild);
buildSettings.setBuildMode(BuildMode.ASSEMBLE);
} else if (baseScope instanceof CompositeScope) {
// Compile selected modules
buildSettings.setModulesToBuild(Projects.getModulesToBuildFromSelection(project, null));
buildSettings.setBuildMode(BuildMode.COMPILE_JAVA);
}
TargetTypeBuildScope scope = CmdlineProtoUtil.createTargetsScope(AndroidGradleBuildTargetConstants.TARGET_TYPE_ID, Collections.singletonList(AndroidGradleBuildTargetConstants.TARGET_ID), forceBuild);
return Collections.singletonList(scope);
}
use of com.intellij.compiler.impl.ModuleCompileScope in project android by JetBrains.
the class AndroidAutogenerator method runRenderscript.
private static void runRenderscript(@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(AndroidRenderscriptFileType.INSTANCE, true);
facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.RENDERSCRIPT);
for (final VirtualFile file : files) {
final RenderscriptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<RenderscriptAutogenerationItem>() {
@Nullable
@Override
public RenderscriptAutogenerationItem compute() {
final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
return null;
}
final IAndroidTarget target = platform.getTarget();
final String sdkLocation = platform.getSdkData().getPath();
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 resourceDirPath = AndroidRootUtil.getResourceDirPath(facet);
assert resourceDirPath != null;
final String sourceRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
if (sourceRootPath == null) {
return null;
}
final String rawDirPath = resourceDirPath + '/' + SdkConstants.FD_RES_RAW;
return new RenderscriptAutogenerationItem(sdkLocation, target, sourceRootPath, rawDirPath);
}
});
if (item == null) {
continue;
}
File tempOutDir = null;
try {
tempOutDir = FileUtil.createTempDirectory("android_renderscript_autogeneration", "tmp");
final VirtualFile vTempOutDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempOutDir);
final String depFolderPath = vTempOutDir != null ? getDependencyFolder(context.getProject(), file, vTempOutDir) : null;
final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidRenderscript.execute(item.mySdkLocation, item.myTarget, file.getPath(), tempOutDir.getPath(), depFolderPath, item.myRawDirPath));
if (messages.get(CompilerMessageCategory.ERROR).size() == 0) {
final List<File> newFiles = new ArrayList<File>();
AndroidCommonUtils.moveAllFiles(tempOutDir, new File(item.myGenDirPath), newFiles);
for (File newFile : newFiles) {
final VirtualFile newVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(newFile);
if (newVFile != null) {
patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.RENDERSCRIPT, newVFile);
}
}
final File bcFile = new File(item.myRawDirPath, FileUtil.getNameWithoutExtension(file.getName()) + ".bc");
final VirtualFile vBcFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(bcFile);
if (vBcFile != null) {
facet.markFileAutogenerated(AndroidAutogeneratorMode.RENDERSCRIPT, vBcFile);
}
}
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (module.getProject().isDisposed()) {
return;
}
for (final CompilerMessageCategory category : messages.keySet()) {
final List<String> messageList = messages.get(category);
for (final String message : messageList) {
context.addMessage(category, message, file.getUrl(), -1, -1);
}
}
}
});
final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myGenDirPath);
if (genDir != null) {
genDir.refresh(false, true);
}
} 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);
}
});
} finally {
if (tempOutDir != null) {
FileUtil.delete(tempOutDir);
}
}
}
}
use of com.intellij.compiler.impl.ModuleCompileScope 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.compiler.impl.ModuleCompileScope in project android by JetBrains.
the class AndroidCompileUtil method doGenerate.
public static boolean doGenerate(AndroidFacet facet, final AndroidAutogeneratorMode mode) {
assert !ApplicationManager.getApplication().isDispatchThread();
final CompileContext[] contextWrapper = new CompileContext[1];
final Module module = facet.getModule();
final Project project = module.getProject();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
if (project.isDisposed())
return;
CompilerTask task = new CompilerTask(project, "Android auto-generation", true, false, true, true);
CompileScope scope = new ModuleCompileScope(module, false);
contextWrapper[0] = new CompileContextImpl(project, task, scope, false, false);
}
});
CompileContext context = contextWrapper[0];
if (context == null) {
return false;
}
generate(facet, mode, context, false);
return context.getMessages(CompilerMessageCategory.ERROR).length == 0;
}
Aggregations