use of com.intellij.openapi.projectRoots.ProjectJdkTable in project android by JetBrains.
the class AndroidSdks method create.
@Nullable
public Sdk create(@NotNull IAndroidTarget target, @NotNull File sdkPath, @NotNull String sdkName, @NotNull Sdk jdk, boolean addRoots) {
if (!target.getAdditionalLibraries().isEmpty()) {
// Do not create an IntelliJ SDK for add-ons. Add-ons should be handled as module-level library dependencies.
return null;
}
ProjectJdkTable table = ProjectJdkTable.getInstance();
String tempName = createUniqueSdkName(SDK_NAME, Arrays.asList(table.getAllJdks()));
Sdk sdk = table.createSdk(tempName, AndroidSdkType.getInstance());
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.setHomePath(sdkPath.getPath());
setUpSdk(sdk, sdkModificator, target, sdkName, Arrays.asList(table.getAllJdks()), jdk, addRoots);
sdkModificator.commitChanges();
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(sdk));
return sdk;
}
use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.
the class AppTestBase method doSetupFlexSdk.
private void doSetupFlexSdk(final Module module, final String flexSdkRootPath, final TargetPlatform targetPlatform, final String sdkVersion) {
final String sdkName = generateSdkName(sdkVersion);
Sdk sdk = ProjectJdkTable.getInstance().findJdk(sdkName);
if (sdk == null) {
ApplicationManager.getApplication().runWriteAction(() -> {
FlexSdkType2 sdkType = FlexSdkType2.getInstance();
Sdk sdk1 = new ProjectJdkImpl(sdkName, sdkType, flexSdkRootPath, "");
ProjectJdkTable.getInstance().addJdk(sdk1);
Disposer.register(getSdkParentDisposable(), new Disposable() {
@Override
public void dispose() {
ApplicationManager.getApplication().runWriteAction(() -> {
ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
sdkTable.removeJdk(sdkTable.findJdk(sdkName));
});
}
});
final SdkModificator modificator = sdk1.getSdkModificator();
modificator.setVersionString(FlexSdkType2.getInstance().getVersionString(sdk1.getHomePath()));
modifySdk(sdk1, modificator);
modificator.commitChanges();
});
}
FlexTestUtils.modifyBuildConfiguration(module, bc -> {
bc.setNature(new BuildConfigurationNature(targetPlatform, false, getOutputType()));
bc.getDependencies().setSdkEntry(Factory.createSdkEntry(sdkName));
});
}
use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.
the class ConversionParams method convertFlexSdks.
// keep old Flex SDKs for now, after IDEA 11.1 release we may decide to delete them
public static void convertFlexSdks() {
final ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
final Sdk[] allSdks = sdkTable.getAllJdks();
final FlexSdkType2 newSdkType = FlexSdkType2.getInstance();
Map<String, Sdk> homePathToNewSdk = new HashMap<>();
Collection<Sdk> sdksToAdd = new ArrayList<>();
for (Sdk sdk : allSdks) {
if (sdk.getSdkType() == newSdkType && sdk.getHomePath() != null) {
homePathToNewSdk.put(sdk.getHomePath(), sdk);
}
}
for (Sdk sdk : allSdks) {
if (!ArrayUtil.contains(sdk.getSdkType().getName(), OLD_SDKS_TYPES)) {
continue;
}
final String version = sdk.getVersionString();
if (version == null || (!version.startsWith("3.") && !version.startsWith("4."))) {
// ignore corrupt SDK
continue;
}
final String homePath = sdk.getHomePath();
if (homePath == null) {
continue;
}
if (homePathToNewSdk.containsKey(homePath)) {
continue;
}
String newSdkName = SdkConfigurationUtil.createUniqueSdkName(newSdkType, homePath, Arrays.asList(allSdks));
Sdk newSdk = new ProjectJdkImpl(newSdkName, newSdkType, homePath, "");
newSdkType.setupSdkPaths(newSdk);
sdksToAdd.add(newSdk);
homePathToNewSdk.put(homePath, newSdk);
}
WriteAction.run(() -> {
for (Sdk sdk : sdksToAdd) {
sdkTable.addJdk(sdk);
}
});
}
use of com.intellij.openapi.projectRoots.ProjectJdkTable in project android by JetBrains.
the class AndroidSdksTest method tearDown.
@Override
protected void tearDown() throws Exception {
ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
List<Sdk> sdks = sdkTable.getSdksOfType(AndroidSdkType.getInstance());
try {
ApplicationManager.getApplication().runWriteAction(() -> {
for (Sdk sdk : sdks) {
sdkTable.removeJdk(sdk);
}
sdkTable.removeJdk(myJdk);
});
} finally {
super.tearDown();
}
}
use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.
the class FlexTestUtils method createSdk.
public static Sdk createSdk(final String flexSdkRootPath, @Nullable String sdkVersion, final boolean removeExisting) {
Sdk sdk = WriteCommandAction.runWriteCommandAction(null, (Computable<Sdk>) () -> {
final ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
if (removeExisting) {
final List<Sdk> existingFlexSdks = projectJdkTable.getSdksOfType(FlexSdkType2.getInstance());
for (Sdk existingFlexSdk : existingFlexSdks) {
projectJdkTable.removeJdk(existingFlexSdk);
}
}
final FlexSdkType2 sdkType = FlexSdkType2.getInstance();
final Sdk sdk1 = new ProjectJdkImpl(sdkType.suggestSdkName(null, flexSdkRootPath), sdkType, flexSdkRootPath, "");
sdkType.setupSdkPaths(sdk1);
projectJdkTable.addJdk(sdk1);
return sdk1;
});
final SdkModificator modificator = sdk.getSdkModificator();
if (sdkVersion != null) {
modificator.setVersionString(sdkVersion);
}
if (sdk.getHomeDirectory() == null) {
throw new IllegalArgumentException("Could not find a Flex SDK at " + flexSdkRootPath);
}
modificator.addRoot(sdk.getHomeDirectory(), OrderRootType.CLASSES);
modificator.commitChanges();
return sdk;
}
Aggregations