use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class IdeSdks method getJdk.
@Nullable
private Sdk getJdk(@Nullable JavaSdkVersion preferredVersion) {
List<Sdk> androidSdks = getEligibleAndroidSdks();
if (!androidSdks.isEmpty()) {
Sdk androidSdk = androidSdks.get(0);
AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(androidSdk);
assert data != null;
Sdk jdk = data.getJavaSdk();
if (isJdkCompatible(jdk, preferredVersion)) {
return jdk;
}
}
JavaSdk javaSdk = JavaSdk.getInstance();
List<Sdk> jdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk);
if (!jdks.isEmpty()) {
for (Sdk jdk : jdks) {
if (isJdkCompatible(jdk, preferredVersion)) {
return jdk;
}
}
}
// This happens when user has a fresh installation of Android Studio, and goes through the 'First Run' Wizard.
if (myIdeInfo.isAndroidStudio()) {
Sdk jdk = myJdks.createEmbeddedJdk();
if (jdk != null) {
assert isJdkCompatible(jdk, preferredVersion);
return jdk;
}
}
List<File> jdkPaths = getPotentialJdkPaths();
for (File jdkPath : jdkPaths) {
if (checkForJdk(jdkPath)) {
Sdk jdk = createJdk(jdkPath);
return isJdkCompatible(jdk, preferredVersion) ? jdk : null;
}
// On Linux, the returned path is the folder that contains all JDKs, instead of a specific JDK.
if (SystemInfo.isLinux) {
for (File child : notNullize(jdkPath.listFiles())) {
if (child.isDirectory() && checkForJdk(child)) {
Sdk jdk = myJdks.createJdk(child.getPath());
if (isJdkCompatible(jdk, preferredVersion)) {
return jdk;
}
}
}
}
}
return null;
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class IdeSdks method doGetJdkPath.
@Nullable
private File doGetJdkPath(boolean createJdkIfNeeded) {
List<Sdk> androidSdks = getEligibleAndroidSdks();
if (androidSdks.isEmpty() && createJdkIfNeeded) {
// This happens when user has a fresh installation of Android Studio without an Android SDK, but with a JDK. Android Studio should
// populate the text field with the existing JDK.
Sdk jdk = myJdks.chooseOrCreateJavaSdk();
if (jdk != null) {
String jdkPath = jdk.getHomePath();
if (jdkPath != null) {
return new File(toSystemDependentName(jdkPath));
}
}
} else {
for (Sdk sdk : androidSdks) {
AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
assert data != null;
Sdk jdk = data.getJavaSdk();
if (jdk != null) {
String jdkHomePath = jdk.getHomePath();
if (jdkHomePath != null) {
return new File(toSystemDependentName(jdkHomePath));
}
}
}
}
return null;
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class IdeSdks method updateAndroidSdks.
/**
* Iterates through all Android SDKs and makes them point to the given JDK.
*/
private void updateAndroidSdks(@NotNull Sdk jdk) {
for (Sdk sdk : myAndroidSdks.getAllAndroidSdks()) {
AndroidSdkAdditionalData oldData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
if (oldData == null) {
continue;
}
oldData.setJavaSdk(jdk);
SdkModificator modificator = sdk.getSdkModificator();
modificator.setSdkAdditionalData(oldData);
modificator.commitChanges();
}
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdksTest method testTryToCreate.
public void testTryToCreate() {
IAndroidTarget target = findAndroidTarget();
String hash = getTargetHashString(target);
Sdk sdk = myAndroidSdks.tryToCreate(mySdkPath, hash);
assertNotNull(sdk);
verifyCorrectPath(sdk);
AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(sdk);
assertEquals(hash, data.getBuildTargetHashString());
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdksTest method testCreateSdkWithoutSpecifyingJdk.
public void testCreateSdkWithoutSpecifyingJdk() {
Sdk sdk = myAndroidSdks.create(findAndroidTarget(), mySdkPath, true);
assertNotNull(sdk);
verifyCorrectPath(sdk);
AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
Sdk jdk = androidData.getJavaSdk();
assertNotNull(jdk);
assertEquals(myJdk.getHomePath(), jdk.getHomePath());
}
Aggregations