Search in sources :

Example 26 with ModifiableRootModel

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);
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Example 27 with ModifiableRootModel

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);
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ExtIdeaCompilerOutput(org.jetbrains.plugins.gradle.model.ExtIdeaCompilerOutput) File(java.io.File)

Example 28 with ModifiableRootModel

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);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 29 with ModifiableRootModel

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);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 30 with ModifiableRootModel

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);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LanguageLevelModuleExtensionImpl(com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)101 Module (com.intellij.openapi.module.Module)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 ContentEntry (com.intellij.openapi.roots.ContentEntry)27 File (java.io.File)18 Library (com.intellij.openapi.roots.libraries.Library)15 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)14 ModuleManager (com.intellij.openapi.module.ModuleManager)8 Sdk (com.intellij.openapi.projectRoots.Sdk)8 IOException (java.io.IOException)8 NotNull (org.jetbrains.annotations.NotNull)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)7 Project (com.intellij.openapi.project.Project)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Nullable (org.jetbrains.annotations.Nullable)6 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)5 ConfigurationException (com.intellij.openapi.options.ConfigurationException)5 THashMap (gnu.trove.THashMap)5 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)4 AccessToken (com.intellij.openapi.application.AccessToken)4