use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidApplicationArtifactProperties method onBuildFinished.
@Override
public void onBuildFinished(@NotNull Artifact artifact, @NotNull CompileContext context) {
if (!(artifact.getArtifactType() instanceof AndroidApplicationArtifactType)) {
return;
}
if (mySigningMode != AndroidArtifactSigningMode.RELEASE_SIGNED && mySigningMode != AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
return;
}
final AndroidFacet facet = AndroidArtifactUtil.getPackagedFacet(context.getProject(), artifact);
if (facet == null) {
return;
}
final String artifactName = artifact.getName();
final String messagePrefix = "[Artifact '" + artifactName + "'] ";
final Module module = facet.getModule();
final AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform == null) {
context.addMessage(CompilerMessageCategory.ERROR, messagePrefix + AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
return;
}
final String sdkLocation = platform.getSdkData().getPath();
final String artifactFilePath = artifact.getOutputFilePath();
final String keyStorePath = myKeyStoreUrl != null ? VfsUtilCore.urlToPath(myKeyStoreUrl) : "";
final String keyStorePassword = myKeyStorePassword != null && myKeyStorePassword.length() > 0 ? getPlainKeystorePassword() : null;
final String keyPassword = myKeyPassword != null && myKeyPassword.length() > 0 ? getPlainKeyPassword() : null;
try {
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidCommonUtils.buildArtifact(artifactName, messagePrefix, sdkLocation, platform.getTarget(), artifactFilePath, keyStorePath, myKeyAlias, keyStorePassword, keyPassword);
AndroidCompileUtil.addMessages(context, AndroidCompileUtil.toCompilerMessageCategoryKeys(messages), null);
} catch (GeneralSecurityException e) {
AndroidCompileUtil.reportException(context, messagePrefix, e);
} catch (IOException e) {
AndroidCompileUtil.reportException(context, messagePrefix, e);
}
}
use of org.jetbrains.android.sdk.AndroidPlatform 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 org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class ModuleClassLoader method create.
@Nullable
public static ClassLoader create(IAndroidTarget target, Module module) throws Exception {
AndroidPlatform androidPlatform = AndroidPlatform.getInstance(module);
if (androidPlatform == null) {
return null;
}
AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(target);
LayoutLibrary library = targetData.getLayoutLibrary(module.getProject());
if (library == null) {
return null;
}
return get(library, module);
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidToolWindowFactory method checkFacetAndSdk.
private static void checkFacetAndSdk(Project project, @NotNull final ConsoleView console) {
final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (facets.size() == 0) {
console.clear();
console.print(AndroidBundle.message("android.logcat.no.android.facets.error"), ConsoleViewContentType.ERROR_OUTPUT);
return;
}
final AndroidFacet facet = facets.get(0);
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
console.clear();
final Module module = facet.getModule();
if (!AndroidMavenUtil.isMavenizedModule(module)) {
console.print("Please ", ConsoleViewContentType.ERROR_OUTPUT);
console.printHyperlink("configure", new HyperlinkInfo() {
@Override
public void navigate(Project project) {
AndroidSdkUtils.openModuleDependenciesConfigurable(module);
}
});
console.print(" Android SDK\n", ConsoleViewContentType.ERROR_OUTPUT);
} else {
console.print(AndroidBundle.message("android.maven.cannot.parse.android.sdk.error", module.getName()) + '\n', ConsoleViewContentType.ERROR_OUTPUT);
}
}
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidModuleConverter1 method process.
@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
assert confElement != null;
Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
if (platformName == null)
return;
removeOldDependencies(moduleSettings, platformName);
confElement.removeContent(platformNameElement);
Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName);
if (androidLibrary != null) {
AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null);
if (androidPlatform != null) {
IAndroidTarget target = androidPlatform.getTarget();
Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
if (androidSdk == null) {
androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
if (androidSdk != null) {
final SdkModificator modificator = androidSdk.getSdkModificator();
for (OrderRootType type : OrderRootType.getAllTypes()) {
for (VirtualFile root : androidLibrary.getFiles(type)) {
modificator.addRoot(root, type);
}
}
modificator.commitChanges();
}
}
if (androidSdk != null) {
addNewDependency(moduleSettings, androidSdk.getName());
}
}
}
}
Aggregations