use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class DependenciesModuleSetupStep method addExtraSdkLibrariesAsDependencies.
/**
* Sets the 'useLibrary' libraries or SDK add-ons as library dependencies.
* <p>
* These libraries are set at the project level, which makes it impossible to add them to a IDE SDK definition because the IDE SDK is
* global to the whole IDE. To work around this limitation, we set these libraries as module dependencies instead.
* </p>
*/
private void addExtraSdkLibrariesAsDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull AndroidProject androidProject) {
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
Sdk sdk = moduleModel.getSdk();
// If we got here, SDK will *NOT* be null.
assert sdk != null;
String suffix = null;
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
if (sdkData != null) {
SdkAdditionalData data = sdk.getSdkAdditionalData();
if (data instanceof AndroidSdkAdditionalData) {
AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
suffix = androidSdkData.getBuildTargetHashString();
}
}
if (suffix == null) {
// In practice, we won't get here. A proper Android SDK has been already configured by now, and the suffix won't be null.
suffix = androidProject.getCompileTarget();
}
Set<String> currentIdeSdkFilePaths = Sets.newHashSetWithExpectedSize(5);
for (VirtualFile sdkFile : sdk.getRootProvider().getFiles(CLASSES)) {
// We need to convert the VirtualFile to java.io.File, because the path of the VirtualPath is using 'jar' protocol and it won't match
// the path returned by AndroidProject#getBootClasspath().
File sdkFilePath = virtualToIoFile(sdkFile);
currentIdeSdkFilePaths.add(sdkFilePath.getPath());
}
Collection<String> bootClasspath = androidProject.getBootClasspath();
for (String library : bootClasspath) {
if (isNotEmpty(library) && !currentIdeSdkFilePaths.contains(library)) {
// Library is not in the SDK IDE definition. Add it as library and make the module depend on it.
File binaryPath = new File(library);
String name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(library);
// Include compile target as part of the name, to ensure the library name is unique to this Android platform.
// e.g. maps-android-23, effects-android-23 (it follows the library naming convention: library-version
name = name + "-" + suffix;
myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, COMPILE, binaryPath);
}
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class CompilerOutputModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
File mainClassesFolder = null;
File testClassesFolder = null;
ExtIdeaCompilerOutput compilerOutput = javaModuleModel.getCompilerOutput();
if (compilerOutput == null) {
File buildFolderPath = javaModuleModel.getBuildFolderPath();
if (buildFolderPath != null) {
mainClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "main"));
testClassesFolder = new File(buildFolderPath, join(CLASSES_FOLDER_NAME, "test"));
}
} else {
mainClassesFolder = compilerOutput.getMainClassesDir();
testClassesFolder = compilerOutput.getTestClassesDir();
}
if (mainClassesFolder != null) {
// This folder is null for modules that are just folders containing other modules. This type of modules are later on removed by
// PostProjectSyncTaskExecutor.
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
myCompilerSettingsSetup.setOutputPaths(moduleModel, mainClassesFolder, testClassesFolder);
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class ContentRootsModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
JavaContentEntriesSetup setup = new JavaContentEntriesSetup(javaModuleModel, moduleModel);
List<ContentEntry> contentEntries = findContentEntries(moduleModel, javaModuleModel);
setup.execute(contentEntries);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class DependenciesModuleSetupStep method updateDependency.
private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
String moduleName = dependency.getModuleName();
Module found = null;
for (Module m : modelsProvider.getModules()) {
if (moduleName.equals(m.getName())) {
found = m;
}
}
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
if (found != null) {
AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
if (androidFacet == null) {
ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
entry.setExported(true);
} else {
// If it depends on an android module, we should skip that.
setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
}
return;
}
setupErrors.addMissingModule(moduleName, module.getName(), null);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class JavaLanguageLevelModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
LanguageLevel languageLevel = javaModuleModel.getJavaLanguageLevel();
if (languageLevel == null) {
// Java language is still not correct. Most likely this module does not have dependents.
// Get minimum language level from all Android modules.
languageLevel = getMinimumLanguageLevelForAndroidModules(ideModelsProvider);
}
if (languageLevel == null) {
// The minimum safe Java language level.
languageLevel = JDK_1_6;
}
ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
LanguageLevelModuleExtensionImpl moduleExtension = rootModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class);
moduleExtension.setLanguageLevel(languageLevel);
}
Aggregations