Search in sources :

Example 6 with FacetManager

use of com.intellij.facet.FacetManager in project intellij by bazelbuild.

the class BlazePythonSyncPlugin method getOrCreatePythonFacet.

@Nullable
private static LibraryContributingFacet<?> getOrCreatePythonFacet(BlazeContext context, Module module) {
    LibraryContributingFacet<?> facet = findPythonFacet(module);
    if (facet != null && facetHasSdk(facet)) {
        return facet;
    }
    FacetManager manager = FacetManager.getInstance(module);
    ModifiableFacetModel facetModel = manager.createModifiableModel();
    if (facet != null) {
        // we can't modify in place, IntelliJ has no hook to trigger change events. Instead we create
        // a new facet.
        facetModel.removeFacet(facet);
    }
    Sdk sdk = getOrCreatePythonSdk();
    if (sdk == null) {
        String msg = "Unable to find a Python SDK installed.\n" + "After configuring a suitable SDK in the \"Project Structure\" dialog, " + "sync the project again.";
        IssueOutput.error(msg).submit(context);
        return null;
    }
    facet = manager.createFacet(PythonFacetUtil.getFacetType(), "Python", null);
    facetModel.addFacet(facet);
    facetModel.commit();
    return facet;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Sdk(com.intellij.openapi.projectRoots.Sdk) FacetManager(com.intellij.facet.FacetManager) Nullable(javax.annotation.Nullable)

Example 7 with FacetManager

use of com.intellij.facet.FacetManager in project intellij by bazelbuild.

the class AndroidFacetModuleCustomizer method createAndroidFacet.

public static void createAndroidFacet(Module module) {
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet != null) {
        configureFacet(facet);
    } else {
        // Module does not have Android facet. Create one and add it.
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel model = facetManager.createModifiableModel();
        try {
            facet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
            model.addFacet(facet);
            configureFacet(facet);
        } finally {
            model.commit();
        }
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with FacetManager

use of com.intellij.facet.FacetManager in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineUtil method createArtifactDeploymentSources.

/**
 * Creates a list of artifact deployment sources available for deployment to App Engine.
 *
 * <p>Artifacts either target the standard or the flexible environment. All standard artifacts are
 * added. Flexible artifacts are only added if there are no other standard artifacts associated
 * with the same module.
 *
 * @return a list of {@link AppEngineArtifactDeploymentSource}
 */
public static List<AppEngineArtifactDeploymentSource> createArtifactDeploymentSources(@NotNull final Project project) {
    List<AppEngineArtifactDeploymentSource> sources = Lists.newArrayList();
    AppEngineProjectService projectService = AppEngineProjectService.getInstance();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        FacetManager facetManager = FacetManager.getInstance(module);
        if (facetManager.getFacetByType(AppEngineStandardFacetType.ID) != null || facetManager.getFacetByType(AppEngineFlexibleFacetType.ID) != null) {
            final AppEngineEnvironment environment = projectService.getModuleAppEngineEnvironment(module).orElseThrow(() -> new RuntimeException("No environment."));
            Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
            sources.addAll(artifacts.stream().filter(artifact -> doesArtifactMatchEnvironment(artifact, environment)).map(artifact -> AppEngineUtil.createArtifactDeploymentSource(project, artifact, environment)).collect(toList()));
        }
    }
    return sources;
}
Also used : ModulePointer(com.intellij.openapi.module.ModulePointer) AppEngineStandardFacetType(com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacetType) ModuleManager(com.intellij.openapi.module.ModuleManager) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) Artifact(com.intellij.packaging.artifacts.Artifact) Lists(com.google.common.collect.Lists) ModuleDeploymentSource(com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource) Project(com.intellij.openapi.project.Project) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) AppEngineFlexibleFacetType(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) AppEngineArtifactDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.AppEngineArtifactDeploymentSource) Collection(java.util.Collection) FacetManager(com.intellij.facet.FacetManager) ArtifactPointerManager(com.intellij.packaging.artifacts.ArtifactPointerManager) ModulePointerManager(com.intellij.openapi.module.ModulePointerManager) Nullable(org.jetbrains.annotations.Nullable) Collectors.toList(java.util.stream.Collectors.toList) UserSpecifiedPathDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource) List(java.util.List) ArtifactUtil(com.intellij.packaging.impl.artifacts.ArtifactUtil) MavenBuildDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.MavenBuildDeploymentSource) NotNull(org.jetbrains.annotations.NotNull) AppEngineEnvironment(com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) AppEngineArtifactDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.AppEngineArtifactDeploymentSource) AppEngineEnvironment(com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment) Module(com.intellij.openapi.module.Module) FacetManager(com.intellij.facet.FacetManager) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 9 with FacetManager

use of com.intellij.facet.FacetManager in project android by JetBrains.

the class AndroidTestCase method addAndroidFacet.

private static AndroidFacet addAndroidFacet(Module module, boolean attachSdk) {
    FacetManager facetManager = FacetManager.getInstance(module);
    AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
    if (attachSdk) {
        addLatestAndroidSdk(module);
    }
    ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    facetModel.addFacet(facet);
    ApplicationManager.getApplication().runWriteAction(facetModel::commit);
    return facet;
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 10 with FacetManager

use of com.intellij.facet.FacetManager in project android by JetBrains.

the class NewProjectImportGradleSyncListener method createTopLevelModule.

@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    File projectRootDir = getBaseDirPath(project);
    VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
    if (contentRoot != null) {
        File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
        Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
        // This prevents the balloon "Unsupported Modules detected".
        ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        model.addContentEntry(contentRoot);
        if (IdeInfo.getInstance().isAndroidStudio()) {
            // If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
            // users will update build.gradle files to fix Gradle sync.)
            // See: https://code.google.com/p/android/issues/detail?id=194621
            Sdk jdk = IdeSdks.getInstance().getJdk();
            if (jdk != null) {
                model.setSdk(jdk);
            }
        }
        model.commit();
        FacetManager facetManager = FacetManager.getInstance(module);
        ModifiableFacetModel facetModel = facetManager.createModifiableModel();
        try {
            GradleFacet gradleFacet = GradleFacet.getInstance(module);
            if (gradleFacet == null) {
                // Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
                gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
                facetModel.addFacet(gradleFacet);
            }
            gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
            // Add "android" facet to avoid the balloon "Android Framework detected".
            AndroidFacet androidFacet = AndroidFacet.getInstance(module);
            if (androidFacet == null) {
                androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
                facetModel.addFacet(androidFacet);
            }
            // This is what actually stops Studio from showing the balloon.
            androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
        } finally {
            facetModel.commit();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.android.annotations.VisibleForTesting)

Aggregations

FacetManager (com.intellij.facet.FacetManager)20 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)18 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)9 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)3 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)3 Module (com.intellij.openapi.module.Module)3 NotNull (org.jetbrains.annotations.NotNull)3 AppEngineEnvironment (com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment)2 AppEngineProjectService (com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService)2 Result (com.intellij.openapi.application.Result)2 WriteAction (com.intellij.openapi.application.WriteAction)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ModuleDeploymentSource (com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1