use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidSdksTest method testCreateSdk.
public void testCreateSdk() {
IAndroidTarget target = findAndroidTarget();
String name = "testSdk";
Sdk sdk = myAndroidSdks.create(target, mySdkPath, name, myJdk, true);
assertNotNull(sdk);
assertEquals(name, sdk.getName());
verifyCorrectPath(sdk);
AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
assertSame(myJdk, androidData.getJavaSdk());
AndroidPlatform androidPlatform = androidData.getAndroidPlatform();
assertNotNull(androidPlatform);
assertSame(target, androidPlatform.getTarget());
File platformPath = new File(mySdkPath, join("platforms", androidData.getBuildTargetHashString()));
// Check roots added to SDK
Map<String, VirtualFile> classRootsByName = getSdkRootsByName(sdk, CLASSES);
// android.jar and res folder
assertThat(classRootsByName).hasSize(2);
VirtualFile androidJar = classRootsByName.get("android.jar");
File expectedAndroidJarPath = new File(platformPath, androidJar.getName());
assertAbout(file()).that(virtualToIoFile(androidJar)).isEquivalentAccordingToCompareTo(expectedAndroidJarPath);
VirtualFile resFolder = classRootsByName.get("res");
File expectedResFolderPath = new File(platformPath, join("data", resFolder.getName()));
assertAbout(file()).that(virtualToIoFile(resFolder)).isEquivalentAccordingToCompareTo(expectedResFolderPath);
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class IdeSdksTest method assertOneSdkPerAvailableTarget.
private void assertOneSdkPerAvailableTarget(@NotNull List<Sdk> sdks) {
List<IAndroidTarget> platformTargets = Lists.newArrayList();
AndroidSdkData sdkData = AndroidSdkData.getSdkData(myAndroidSdkPath);
assertNotNull(sdkData);
for (IAndroidTarget target : sdkData.getTargets()) {
if (target.isPlatform()) {
platformTargets.add(target);
}
}
assertEquals(platformTargets.size(), sdks.size());
for (Sdk sdk : sdks) {
AndroidPlatform androidPlatform = AndroidPlatform.getInstance(sdk);
assertNotNull(androidPlatform);
IAndroidTarget target = androidPlatform.getTarget();
platformTargets.remove(target);
}
assertEquals(0, platformTargets.size());
}
use of org.jetbrains.android.sdk.AndroidPlatform in project android by JetBrains.
the class AndroidPreviewPanelTest method testSimpleRender.
public void testSimpleRender() throws ParserConfigurationException, IOException, SAXException, InterruptedException {
VirtualFile layout = myFixture.copyFileToProject("themeEditor/theme_preview_layout.xml", "res/layout/theme_preview_layout.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(layout);
AtomicBoolean executorCalled = new AtomicBoolean(false);
ExecutorService threadPool = Executors.newFixedThreadPool(1);
Executor executor = (r) -> {
// Run in a separate thread and wait for the result
try {
threadPool.submit(r).get(60, TimeUnit.SECONDS);
executorCalled.set(true);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new AssertionError("Unexpected exception", e);
}
};
AndroidPreviewPanel.GraphicsLayoutRendererFactory graphicsFactory = (configuration1, parser, background) -> {
Module module = configuration.getModule();
AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
assertNotNull(facet);
AndroidPlatform platform = AndroidPlatform.getInstance(module);
assertNotNull(platform);
return GraphicsLayoutRenderer.create(facet, platform, getProject(), configuration, parser, background, SessionParams.RenderingMode.V_SCROLL, false);
};
AndroidPreviewPanel panel = new AndroidPreviewPanel(configuration, executor, graphicsFactory) {
@Override
public void invalidateGraphicsRenderer() {
myInvalidateRunnable.run();
}
};
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader("<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"" + " android:layout_width=\"match_parent\"" + " android:layout_height=\"match_parent\"" + " android:background=\"#0F0\">" + " <TextView" + " android:layout_width=\"wrap_content\"" + " android:layout_height=\"wrap_content\"" + " android:text=\"Hello world\"" + " android:background=\"#F00\"/>" + "</LinearLayout>")));
panel.setDocument(document);
panel.setBounds(0, 0, 400, 100);
//noinspection UndesirableClassUsage (we don't want to use HDPI images here)
BufferedImage output = new BufferedImage(400, 100, BufferedImage.TYPE_INT_ARGB);
panel.paintComponent(output.getGraphics());
// Make sure that the executor got called since we were trying to render on the UI thread.
assertTrue(executorCalled.get());
BufferedImage goldenImage = ImageIO.read(new File(getTestDataPath() + "/themeEditor/previewPanel/golden.png"));
assertImageSimilar("layout", goldenImage, output, 3);
ViewInfo textView = panel.findViewAtPoint(new Point(0, 0));
assertEquals("android.widget.TextView", textView.getClassName());
threadPool.shutdownNow();
threadPool.awaitTermination(30, TimeUnit.SECONDS);
Disposer.dispose(panel);
}
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