Search in sources :

Example 51 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class ContentRootModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull NdkModuleModel ndkModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    NdkContentEntriesSetup setup = new NdkContentEntriesSetup(ndkModuleModel, moduleModel);
    List<ContentEntry> contentEntries = findContentEntries(moduleModel, ndkModuleModel);
    setup.execute(contentEntries);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 52 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class SdkModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    File androidSdkHomePath = IdeSdks.getInstance().getAndroidSdkPath();
    // Android SDK may be not configured in IntelliJ
    if (androidSdkHomePath == null) {
        assert !IdeInfo.getInstance().isAndroidStudio();
        logAndroidSdkHomeNotFound();
        return;
    }
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    LanguageLevel languageLevel = androidModel.getJavaLanguageLevel();
    if (languageLevel != null) {
        moduleModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class).setLanguageLevel(languageLevel);
    }
    AndroidProject androidProject = androidModel.getAndroidProject();
    String compileTarget = androidProject.getCompileTarget();
    Sdk sdk = myAndroidSdks.findSuitableAndroidSdk(compileTarget);
    if (sdk == null) {
        sdk = myAndroidSdks.tryToCreate(androidSdkHomePath, compileTarget);
        if (sdk == null) {
            // If SDK was not created, this might be an add-on.
            sdk = findMatchingSdkForAddon(androidProject);
        }
    }
    if (sdk == null) {
        showPlatformNotFoundError(module, compileTarget);
        return;
    }
    moduleModel.setSdk(sdk);
    String sdkPath = sdk.getHomePath();
    if (sdkPath == null) {
        sdkPath = "<path not set>";
    }
    getLog().info(String.format("Set Android SDK '%1$s' (%2$s) to module '%3$s'", sdk.getName(), sdkPath, module.getName()));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LanguageLevelModuleExtensionImpl(com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel) AndroidProject(com.android.builder.model.AndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 53 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 AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    GradleVersion modelVersion = androidModel.getModelVersion();
    if (modelVersion == null) {
        // We are dealing with old model that does not have the 'class' folder.
        return;
    }
    Variant selectedVariant = androidModel.getSelectedVariant();
    File mainClassesFolder = selectedVariant.getMainArtifact().getClassesFolder();
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    File testClassesFolder = testArtifact == null ? null : testArtifact.getClassesFolder();
    ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
    myCompilerSettingsSetup.setOutputPaths(rootModel, mainClassesFolder, testClassesFolder);
}
Also used : Variant(com.android.builder.model.Variant) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) JavaArtifact(com.android.builder.model.JavaArtifact) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File)

Example 54 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStep 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);
    for (Map.Entry<String, Set<File>> entry : javaModuleModel.getArtifactsByConfiguration().entrySet()) {
        Set<File> artifacts = entry.getValue();
        if (artifacts != null && !artifacts.isEmpty()) {
            for (File artifact : artifacts) {
                if (!artifact.isFile() || !endsWithIgnoreCase(artifact.getName(), DOT_JAR)) {
                    // We only expose artifacts that are jar files.
                    continue;
                }
                File buildFolderPath = javaModuleModel.getBuildFolderPath();
                String artifactName = getNameWithoutExtension(artifact);
                if (buildFolderPath != null && buildFolderPath.isDirectory() && isAncestor(buildFolderPath, artifact, true) && module.getName().equals(artifactName)) {
                    // This is the jar obtained by compiling the module, no need to add it as dependency.
                    continue;
                }
                String libraryName = module.getName() + "." + artifactName;
                Library library = ideModelsProvider.getLibraryByName(libraryName);
                if (library == null) {
                    // Create library.
                    library = ideModelsProvider.createLibrary(libraryName);
                    Library.ModifiableModel libraryModel = ideModelsProvider.getModifiableLibraryModel(library);
                    String url = pathToIdeaUrl(artifact);
                    libraryModel.addRoot(url, CLASSES);
                } else {
                    SyncLibraryRegistry.getInstance(module.getProject()).markAsUsed(library, artifact);
                }
                LibraryOrderEntry orderEntry = moduleModel.addLibraryEntry(library);
                orderEntry.setScope(COMPILE);
                orderEntry.setExported(true);
            }
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Set(java.util.Set) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Map(java.util.Map) File(java.io.File)

Example 55 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class JavaModuleSetup method cleanUpAndroidModuleWithoutVariants.

private static void cleanUpAndroidModuleWithoutVariants(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    // Remove Android facet, otherwise the IDE will try to build the module, and fail. The facet may have been added in a previous
    // successful commit.
    removeAllFacets(ideModelsProvider.getModifiableFacetModel(module), AndroidFacet.ID);
    // Clear all source and exclude folders.
    ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
    for (ContentEntry contentEntry : rootModel.getContentEntries()) {
        contentEntry.clearSourceFolders();
        contentEntry.clearExcludeFolders();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)102 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