use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class ExternalAnnotationsSupport method addAnnotations.
public static void addAnnotations(@NotNull Sdk sdk) {
SdkModificator modifier = sdk.getSdkModificator();
attachJdkAnnotations(modifier);
modifier.commitChanges();
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class GradleSpecificInitializer method checkAndSetSources.
private static void checkAndSetSources(@NotNull Sdk sdk) {
VirtualFile[] storedSources = sdk.getRootProvider().getFiles(OrderRootType.SOURCES);
if (storedSources.length > 0) {
return;
}
AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
if (platform != null) {
SdkModificator sdkModificator = sdk.getSdkModificator();
IAndroidTarget target = platform.getTarget();
AndroidSdks.getInstance().findAndSetPlatformSources(target, sdkModificator);
sdkModificator.commitChanges();
}
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class GradleSpecificInitializer method setupSdks.
private static void setupSdks() {
IdeSdks ideSdks = IdeSdks.getInstance();
File androidHome = ideSdks.getAndroidSdkPath();
if (androidHome != null) {
String androidHomePath = androidHome.getAbsolutePath();
ValidationResult result = validateLocation(androidHomePath, "Android SDK location", false, WritableCheckMode.DO_NOT_CHECK);
if (result.isError()) {
notifyInvalidSdk();
}
// Do not prompt user to select SDK path (we have one already.) Instead, check SDK compatibility when a project is opened.
return;
}
// If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
if (AndroidPlugin.isGuiTestingMode()) {
// This is good enough. Later on in the GUI test we'll validate the given SDK path.
return;
}
Sdk sdk = findFirstCompatibleAndroidSdk();
if (sdk != null) {
String sdkHomePath = sdk.getHomePath();
assert sdkHomePath != null;
ideSdks.createAndroidSdkPerAndroidTarget(new File(toSystemDependentName(sdkHomePath)));
return;
}
// Called in a 'invokeLater' block, otherwise file chooser will hang forever.
ApplicationManager.getApplication().invokeLater(() -> {
File androidSdkPath = getAndroidSdkPath();
if (androidSdkPath == null) {
return;
}
FirstRunWizardMode wizardMode = AndroidStudioWelcomeScreenProvider.getWizardMode();
// Only show "Select SDK" dialog if the "First Run" wizard is not displayed.
boolean promptSdkSelection = wizardMode == null;
Sdk sdk1 = createNewAndroidPlatform(androidSdkPath.getPath(), promptSdkSelection);
if (sdk1 != null) {
// Rename the SDK to fit our default naming convention.
String sdkNamePrefix = AndroidSdks.SDK_NAME_PREFIX;
if (sdk1.getName().startsWith(sdkNamePrefix)) {
SdkModificator sdkModificator = sdk1.getSdkModificator();
sdkModificator.setName(sdkNamePrefix + sdk1.getName().substring(sdkNamePrefix.length()));
sdkModificator.commitChanges();
// Rename the JDK that goes along with this SDK.
AndroidSdkAdditionalData additionalData = AndroidSdks.getInstance().getAndroidSdkAdditionalData(sdk1);
if (additionalData != null) {
Sdk jdk = additionalData.getJavaSdk();
if (jdk != null) {
sdkModificator = jdk.getSdkModificator();
sdkModificator.setName(DEFAULT_JDK_NAME);
sdkModificator.commitChanges();
}
}
// Fill out any missing build APIs for this new SDK.
ideSdks.createAndroidSdkPerAndroidTarget(androidSdkPath);
}
}
});
}
use of com.intellij.openapi.projectRoots.SdkModificator in project android by JetBrains.
the class AndroidSdkSourcesBrowsingTest method initializeDummyProject.
/**
* This method prepares a simple project which can be used by tests to confirm that the project
* was hooked up in expected ways. When finished, it returns the full path to the source
* directory under the project, which can be useful for finding source files in the project.
*
* <p>If a test only cares about a single source file that references the SDK directly, then this
* method is not needed.
*/
private String initializeDummyProject() {
VirtualFile sourcesDir = myFixture.copyDirectoryToProject('/' + DUMMY_PROJECT_PATH, "/src");
VirtualFile classesJar = JarFileSystem.getInstance().findFileByPath(sourcesDir.getPath() + "/" + DUMMY_CLASSES_JAR + "!/");
Sdk sdk = ModuleRootManager.getInstance(myFixture.getModule()).getSdk();
SdkModificator modificator = sdk.getSdkModificator();
modificator.addRoot(sourcesDir, OrderRootType.SOURCES);
modificator.addRoot(classesJar, OrderRootType.CLASSES);
modificator.commitChanges();
return sourcesDir.getPath();
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-plugins by JetBrains.
the class BndProjectImporter method addEntry.
private void addEntry(ModifiableModuleModel moduleModel, LibraryTable.ModifiableModel libraryModel, ModifiableRootModel rootModel, Container dependency, DependencyScope scope) throws IllegalArgumentException {
File file = dependency.getFile();
String bsn = dependency.getBundleSymbolicName();
String version = dependency.getVersion();
String path = file.getPath();
if (path.contains(": ")) {
throw new IllegalArgumentException("Cannot resolve " + bsn + ":" + version + ": " + path);
}
if (JDK_DEPENDENCY.equals(bsn)) {
String name = BND_LIB_PREFIX + bsn + ":" + version;
if (FileUtil.isAncestor(myWorkspace.getBase(), file, true)) {
name += "-" + myProject.getName();
}
ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
Sdk jdk = jdkTable.findJdk(name);
if (jdk == null) {
jdk = jdkTable.createSdk(name, JavaSdk.getInstance());
SdkModificator jdkModel = jdk.getSdkModificator();
jdkModel.setHomePath(file.getParent());
jdkModel.setVersionString(version);
VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(url(file));
assert root != null : file + " " + file.exists();
jdkModel.addRoot(root, OrderRootType.CLASSES);
VirtualFile srcRoot = VirtualFileManager.getInstance().findFileByUrl(url(file) + SRC_ROOT);
if (srcRoot != null)
jdkModel.addRoot(srcRoot, OrderRootType.SOURCES);
jdkModel.commitChanges();
jdkTable.addJdk(jdk);
}
rootModel.setSdk(jdk);
return;
}
ExportableOrderEntry entry;
switch(dependency.getType()) {
case PROJECT:
{
String name = dependency.getProject().getName();
Module module = moduleModel.findModuleByName(name);
if (module == null) {
throw new IllegalArgumentException("Unknown module '" + name + "'");
}
entry = (ModuleOrderEntry) ContainerUtil.find(rootModel.getOrderEntries(), e -> e instanceof ModuleOrderEntry && ((ModuleOrderEntry) e).getModule() == module);
if (entry == null) {
entry = rootModel.addModuleOrderEntry(module);
}
break;
}
case REPO:
{
String name = BND_LIB_PREFIX + bsn + ":" + version;
Library library = libraryModel.getLibraryByName(name);
if (library == null) {
library = libraryModel.createLibrary(name);
}
Library.ModifiableModel model = library.getModifiableModel();
for (String url : model.getUrls(OrderRootType.CLASSES)) model.removeRoot(url, OrderRootType.CLASSES);
for (String url : model.getUrls(OrderRootType.SOURCES)) model.removeRoot(url, OrderRootType.SOURCES);
model.addRoot(url(file), OrderRootType.CLASSES);
String srcRoot = mySourcesMap.get(path);
if (srcRoot != null) {
model.addRoot(url(file) + srcRoot, OrderRootType.SOURCES);
}
model.commit();
entry = rootModel.addLibraryEntry(library);
break;
}
case EXTERNAL:
{
Library library = rootModel.getModuleLibraryTable().createLibrary(file.getName());
Library.ModifiableModel model = library.getModifiableModel();
model.addRoot(url(file), OrderRootType.CLASSES);
String srcRoot = mySourcesMap.get(path);
if (srcRoot != null) {
model.addRoot(url(file) + srcRoot, OrderRootType.SOURCES);
}
model.commit();
entry = rootModel.findLibraryOrderEntry(library);
assert entry != null : library;
break;
}
default:
throw new IllegalArgumentException("Unknown dependency '" + dependency + "' of type " + dependency.getType());
}
entry.setScope(scope);
}
Aggregations