use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.
the class AndroidSdkUtils method findAppropriateAndroidPlatform.
@Nullable
public static Sdk findAppropriateAndroidPlatform(@NotNull IAndroidTarget target, @NotNull AndroidSdkData sdkData, boolean forMaven) {
for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
String homePath = sdk.getHomePath();
AndroidSdks androidSdks = AndroidSdks.getInstance();
if (homePath != null && androidSdks.isAndroidSdk(sdk)) {
AndroidSdkData currentSdkData = getSdkData(homePath);
if (sdkData.equals(currentSdkData)) {
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
IAndroidTarget currentTarget = data.getBuildTarget(currentSdkData);
if (currentTarget != null && target.hashString().equals(currentTarget.hashString()) && checkSdkRoots(sdk, target, forMaven)) {
return sdk;
}
}
}
}
}
return null;
}
use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.
the class AndroidSdkUtils method checkSdkRoots.
public static boolean checkSdkRoots(@NotNull Sdk sdk, @NotNull IAndroidTarget target, boolean forMaven) {
String homePath = sdk.getHomePath();
if (homePath == null) {
return false;
}
AndroidSdks androidSdks = AndroidSdks.getInstance();
AndroidSdkAdditionalData sdkAdditionalData = androidSdks.getAndroidSdkAdditionalData(sdk);
Sdk javaSdk = sdkAdditionalData != null ? sdkAdditionalData.getJavaSdk() : null;
if (javaSdk == null) {
return false;
}
Set<VirtualFile> filesInSdk = Sets.newHashSet(sdk.getRootProvider().getFiles(CLASSES));
List<VirtualFile> platformAndAddOnJars = androidSdks.getPlatformAndAddOnJars(target);
for (VirtualFile file : platformAndAddOnJars) {
if (filesInSdk.contains(file) == forMaven) {
return false;
}
}
boolean containsJarFromJdk = false;
for (VirtualFile file : javaSdk.getRootProvider().getFiles(CLASSES)) {
if (file.getFileType() instanceof ArchiveFileType && filesInSdk.contains(file)) {
containsJarFromJdk = true;
}
}
return containsJarFromJdk == forMaven;
}
use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.
the class AndroidTestBase method ensureSdkManagerAvailable.
protected void ensureSdkManagerAvailable() {
AndroidSdks androidSdks = AndroidSdks.getInstance();
AndroidSdkData sdkData = androidSdks.tryToChooseAndroidSdk();
if (sdkData == null) {
sdkData = createTestSdkManager();
if (sdkData != null) {
androidSdks.setSdkData(sdkData);
}
}
assertNotNull(sdkData);
}
use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.
the class VfsInstallListener method doRefresh.
private static void doRefresh(@NonNull PackageOperation op, @NonNull ProgressIndicator progress) {
VirtualFile file = VfsUtil.findFileByIoFile(op.getLocation(progress), false);
if (file != null) {
file.refresh(false, true);
}
// Note that this must be done asynchronously, and must be done separately from the refresh above:
// The above refresh may note that jar files are added or deleted, which then kicks off an asynchronous
// refresh of jar-rooted filesystems. We queue a dummy refresh to run afterward, with our desired logic
// as the finishRunnable.
RefreshQueue.getInstance().refresh(true, false, () -> {
AndroidSdks androidSdks = AndroidSdks.getInstance();
for (Sdk sdk : androidSdks.getAllAndroidSdks()) {
androidSdks.refreshLibrariesIn(sdk);
}
});
}
use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.
the class AndroidFacetImporterBase method createNewAndroidSdkForMaven.
@Nullable
private static Sdk createNewAndroidSdkForMaven(File sdkPath, IAndroidTarget target) {
AndroidSdks androidSdks = AndroidSdks.getInstance();
Sdk sdk = null;
Sdk jdk = Jdks.getInstance().chooseOrCreateJavaSdk();
if (jdk != null) {
String sdkName = "Maven " + androidSdks.chooseNameForNewLibrary(target);
sdk = androidSdks.create(target, sdkPath, sdkName, jdk, false);
}
if (sdk == null) {
return null;
}
SdkModificator modificator = sdk.getSdkModificator();
for (OrderRoot root : androidSdks.getLibraryRootsForTarget(target, sdkPath, false)) {
modificator.addRoot(root.getFile(), root.getType());
}
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
final Sdk javaSdk = data.getJavaSdk();
if (javaSdk != null) {
for (VirtualFile file : javaSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
modificator.addRoot(file, OrderRootType.CLASSES);
}
} else {
LOG.error("AndroidSdkUtils.createNewAndroidPlatform should return Android SDK with a valid JDK reference, or return null");
}
}
modificator.commitChanges();
return sdk;
}
Aggregations