com.intellij.facet.FacetManager Java Examples

The following examples show how to use com.intellij.facet.FacetManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlazeKotlinSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static KotlinFacet getOrCreateKotlinFacet(Module module) {
  KotlinFacet facet = KotlinFacet.Companion.get(module);
  if (facet != null) {
    return facet;
  }
  FacetManager facetManager = FacetManager.getInstance(module);
  ModifiableFacetModel model = facetManager.createModifiableModel();
  try {
    facet =
        facetManager.createFacet(
            KotlinFacetType.Companion.getINSTANCE(), KotlinFacetType.NAME, null);
    model.addFacet(facet);
  } finally {
    model.commit();
  }
  return facet;
}
 
Example #2
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateAndroidModuleLibraryDependencies(Module flutterModule) {
  for (final Module module : ModuleManager.getInstance(getProject()).getModules()) {
    if (module != flutterModule) {
      if (null != FacetManager.getInstance(module).findFacet(AndroidFacet.ID, "Android")) {
        Object circularModules = CircularModuleDependenciesDetector.addingDependencyFormsCircularity(module, flutterModule);
        if (circularModules == null) {
          ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
          if (!rootManager.isDependsOn(flutterModule)) {
            JavaProjectModelModifier[] modifiers = JavaProjectModelModifier.EP_NAME.getExtensions(getProject());
            for (JavaProjectModelModifier modifier : modifiers) {
              if (modifier instanceof IdeaProjectModelModifier) {
                modifier.addModuleDependency(module, flutterModule, DependencyScope.COMPILE, false);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #3
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateAndroidModuleLibraryDependencies(Module flutterModule) {
  for (final Module module : ModuleManager.getInstance(getProject()).getModules()) {
    if (module != flutterModule) {
      if (null != FacetManager.getInstance(module).findFacet(AndroidFacet.ID, "Android")) {
        Object circularModules = CircularModuleDependenciesDetector.addingDependencyFormsCircularity(module, flutterModule);
        if (circularModules == null) {
          ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
          if (!rootManager.isDependsOn(flutterModule)) {
            JavaProjectModelModifier[] modifiers = JavaProjectModelModifier.EP_NAME.getExtensions(getProject());
            for (JavaProjectModelModifier modifier : modifiers) {
              if (modifier instanceof IdeaProjectModelModifier) {
                modifier.addModuleDependency(module, flutterModule, DependencyScope.COMPILE, false);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #4
Source File: AndroidFacetModuleCustomizer.java    From intellij with Apache License 2.0 6 votes vote down vote up
public static void createAndroidFacet(Module module, boolean isApp) {
  AndroidFacet facet = AndroidFacet.getInstance(module);
  if (facet != null) {
    configureFacet(facet, isApp);
  } 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, isApp);
    } finally {
      model.commit();
    }
  }
}
 
Example #5
Source File: DuneCompiler.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isConfigured(@NotNull Project project) {
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        DuneFacet duneFacet = FacetManager.getInstance(module).getFacetByType(DuneFacet.ID);
        if (duneFacet != null) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: DWFrameworkSupportConfigurable.java    From intellij-demandware with MIT License 5 votes vote down vote up
@Override
public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel modifiableRootModel, @Nullable Library library) {
    final FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    DWSettingsProvider dwSettingsProvider = ModuleServiceManager.getService(module, DWSettingsProvider.class);
    dwSettingsProvider.setPasswordKey(UUID.randomUUID().toString());
    dwSettingsProvider.setHostname(dwFrameworkSupportConfigurablePanel.getHostname());
    dwSettingsProvider.setUsername(dwFrameworkSupportConfigurablePanel.getUsername());
    dwSettingsProvider.setPassword(dwFrameworkSupportConfigurablePanel.getPassword());
    dwSettingsProvider.setVersion(dwFrameworkSupportConfigurablePanel.getVersion());
    dwSettingsProvider.setAutoUploadEnabled(dwFrameworkSupportConfigurablePanel.getAutoUploadEnabled());
    Facet facet = FacetManager.getInstance(modifiableRootModel.getModule()).addFacet(DWFacetType.INSTANCE, "Demandware", null);
    facetModel.addFacet(facet);
    facetModel.commit();
}
 
Example #7
Source File: BlazePythonSyncPlugin.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static LibraryContributingFacet<?> findPythonFacet(Module module) {
  final Facet<?>[] allFacets = FacetManager.getInstance(module).getAllFacets();
  for (Facet<?> facet : allFacets) {
    if ((facet instanceof LibraryContributingFacet)
        && (facet.getTypeId() == PythonFacetUtil.getFacetId())) {
      return (LibraryContributingFacet<?>) facet;
    }
  }
  return null;
}
 
Example #8
Source File: BlazePythonSyncPlugin.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void removeFacet(Module workspaceModule) {
  FacetManager manager = FacetManager.getInstance(workspaceModule);
  ModifiableFacetModel facetModel = manager.createModifiableModel();
  LibraryContributingFacet<?> facet = manager.findFacet(PythonFacetUtil.getFacetId(), "Python");
  if (facet != null) {
    facetModel.removeFacet(facet);
    facetModel.commit();
  }
}
 
Example #9
Source File: AndroidFacetModuleCustomizer.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static void removeAndroidFacet(Module module) {
  AndroidFacet facet = AndroidFacet.getInstance(module);
  if (facet != null) {
    ModifiableFacetModel facetModel = FacetManager.getInstance(module).createModifiableModel();
    facetModel.removeFacet(facet);
    facetModel.commit();
  }
}
 
Example #10
Source File: FlutterModuleUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isInFlutterAndroidModule(@NotNull Project project, @NotNull VirtualFile file) {
  final Module module = FlutterBuildActionGroup.findFlutterModule(project, file);
  if (module != null) {
    for (Facet<?> facet : FacetManager.getInstance(module).getAllFacets()) {
      if ("Android".equals(facet.getName())) {
        return declaresFlutter(project);
      }
    }
  }
  return false;
}
 
Example #11
Source File: FlutterModuleUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isInFlutterAndroidModule(@NotNull Project project, @NotNull VirtualFile file) {
  final Module module = FlutterBuildActionGroup.findFlutterModule(project, file);
  if (module != null) {
    for (Facet<?> facet : FacetManager.getInstance(module).getAllFacets()) {
      if ("Android".equals(facet.getName())) {
        return declaresFlutter(project);
      }
    }
  }
  return false;
}
 
Example #12
Source File: MuleMavenModuleBuilder.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public void setMuleFacet(Module module) {
    MuleFacetType type = (MuleFacetType)FacetTypeRegistry.getInstance().findFacetType(MuleFacet.ID);
    MuleFacetConfiguration configuration = type.createDefaultConfiguration();
    configuration.setPathToSdk(MuleSdkManager.getInstance().findFromVersion(muleVersion).getMuleHome());
    Facet facet = type.createFacet(module, type.getPresentableName(), configuration, null);
    ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel();
    model.addFacet(facet);
    model.commit();
}
 
Example #13
Source File: QuarkusIconProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
static boolean isQuarkusPropertiesFile(VirtualFile file, Project project) {
    if ("application.properties".equals("application.properties")) {
        Module module = ModuleUtilCore.findModuleForFile(file, project);
        return module != null && FacetManager.getInstance(module).getFacetByType(QuarkusFacet.FACET_TYPE_ID) != null;
    }
    return false;
}
 
Example #14
Source File: BlazeClassJarProviderIntegrationTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetModuleExternalLibraries() {
  // Need AndroidFact for LocalResourceRepository.
  ApplicationManager.getApplication()
      .runWriteAction(
          () -> {
            ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel();
            model.addFacet(new MockAndroidFacet(module));
            model.commit();
          });

  List<File> externalLibraries = classJarProvider.getModuleExternalLibraries(module);
  assertThat(externalLibraries)
      .containsExactly(
          VfsUtilCore.virtualToIoFile(fileSystem.findFile("com/google/example/libimport.jar")),
          VfsUtilCore.virtualToIoFile(
              fileSystem.findFile("com/google/example/transitive/libimport.jar")),
          VfsUtilCore.virtualToIoFile(
              fileSystem.findFile("com/google/example/transitive/libimport2.jar")));

  // Make sure we can generate dynamic classes from all resource packages in dependencies.
  ResourceClassRegistry registry = ResourceClassRegistry.get(getProject());
  AndroidFacet facet = AndroidFacet.getInstance(module);
  assertThat(facet).isNotNull();
  ResourceRepositoryManager repositoryManager = ResourceRepositoryManager.getInstance(facet);
  assertThat(repositoryManager).isNotNull();
  assertThat(registry.findClassDefinition("com.google.example.resource.R", repositoryManager))
      .isNotNull();
  assertThat(
          registry.findClassDefinition("com.google.example.resource.R$string", repositoryManager))
      .isNotNull();
  assertThat(registry.findClassDefinition("com.google.example.resource2.R", repositoryManager))
      .isNotNull();
  assertThat(
          registry.findClassDefinition(
              "com.google.example.resource2.R$layout", repositoryManager))
      .isNotNull();
  assertThat(
          registry.findClassDefinition(
              "com.google.example.transitive.resource.R", repositoryManager))
      .isNotNull();
  assertThat(
          registry.findClassDefinition(
              "com.google.example.transitive.resource.R$style", repositoryManager))
      .isNotNull();

  // And nothing else.
  assertThat(
          registry.findClassDefinition("com.google.example.main.MainActivity", repositoryManager))
      .isNull();
  assertThat(registry.findClassDefinition("com.google.example.resource.Bogus", repositoryManager))
      .isNull();
  assertThat(registry.findClassDefinition("com.google.example.main.R", repositoryManager))
      .isNull();
  assertThat(registry.findClassDefinition("com.google.example.main.R$string", repositoryManager))
      .isNull();
  assertThat(registry.findClassDefinition("com.google.example.java.Java", repositoryManager))
      .isNull();
  assertThat(registry.findClassDefinition("com.google.unrelated.R", repositoryManager)).isNull();
  assertThat(registry.findClassDefinition("com.google.unrelated.R$layout", repositoryManager))
      .isNull();
}
 
Example #15
Source File: BlazePythonSyncPlugin.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
private static LibraryContributingFacet<?> getOrCreatePythonFacet(
    Project project, BlazeContext context, Module module, BlazeProjectData blazeProjectData) {
  LibraryContributingFacet<?> facet = findPythonFacet(module);
  if (facet != null && isValidPythonSdk(PythonFacetUtil.getSdk(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 = getPythonSdk(project, blazeProjectData, context);
  if (sdk == null) {
    String fixDirections =
        "Configure a suitable Python Interpreter for the module \""
            + module.getName()
            + "\" via File->\"Project Structure...\", \"Project Settings\"->\"Facets\", then"
            + " sync the project again.";
    if (PlatformUtils.isCLion()) {
      fixDirections =
          "Configure a suitable Python Interpreter for the module \""
              + module.getName()
              + "\" via File->\"Settings...\", \"Build,"
              + " Execution, Deployment\"->\"Python Interpreter\", then sync the project again.";
    }
    String msg = "Unable to find a compatible Python SDK installed.\n" + fixDirections;
    IssueOutput.error(msg).submit(context);
    return null;
  }

  facet = manager.createFacet(PythonFacetUtil.getFacetType(), "Python", null);
  // This is ugly like this to get around PythonFacet related classes being in different package
  // paths in different IDEs. Thankfully, PythonFacetSettings is in the same packackage path.
  if (facet.getConfiguration() instanceof PythonFacetSettings) {
    ((PythonFacetSettings) facet.getConfiguration()).setSdk(sdk);
  }
  facetModel.addFacet(facet);
  facetModel.commit();
  return facet;
}
 
Example #16
Source File: SlingModuleFacet.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
public static SlingModuleFacet getFacetByModule(@Nullable Module module) {
    if(module == null) return null;
    return FacetManager.getInstance(module).getFacetByType(ID);
}
 
Example #17
Source File: MindMapFacet.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
public static MindMapFacet getInstance(@Nullable final Module module) {
  return module == null || module.isDisposed() ? null : FacetManager.getInstance(module).getFacetByType(ID);
}
 
Example #18
Source File: PolygeneFacet.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Nullable
public static PolygeneFacet getInstance( @NotNull Module module )
{
    return FacetManager.getInstance( module ).getFacetByType( PolygeneFacetType.ID );
}
 
Example #19
Source File: PantsPythonSetupDataService.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void importData(
  @NotNull final Collection<DataNode<PythonSetupData>> toImport,
  @Nullable ProjectData projectData,
  @NotNull Project project,
  @NotNull final IdeModifiableModelsProvider modelsProvider
) {
  final Set<PythonInterpreterInfo> interpreters = ContainerUtil.map2Set(
    toImport,
    node -> node.getData().getInterpreterInfo()
  );

  if (interpreters.isEmpty()) {
    return;
  }

  final Map<PythonInterpreterInfo, Sdk> interpreter2sdk = new HashMap<>();

  /**
   * TODO(yic): to move it to a thread appropriate place.
   *
   *  1) testPyTestRunConfiguration(com.twitter.intellij.pants.execution.OSSPantsPythonRunConfigurationIntegrationTest)
   *  com.intellij.testFramework.LoggedErrorProcessor$TestLoggerAssertionError: Can't update SDK under write action, not allowed in background
   */
  //ExternalSystemApiUtil.executeProjectChangeAction(false, new DisposeAwareProjectChange(project) {
  //  @Override
  //  public void execute() {
  //    for (final PythonInterpreterInfo interpreterInfo : interpreters) {
  //      //final String binFolder = PathUtil.getParentPath(interpreter);
  //      //final String interpreterHome = PathUtil.getParentPath(binFolder);
  //      final String interpreter = interpreterInfo.getBinary();
  //      Sdk pythonSdk = PythonSdkType.findSdkByPath(interpreter);
  //      if (pythonSdk == null) {
  //        final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
  //        pythonSdk = jdkTable.createSdk(PathUtil.getFileName(interpreter), PythonSdkType.getInstance());
  //        jdkTable.addJdk(pythonSdk);
  //        final SdkModificator modificator = pythonSdk.getSdkModificator();
  //        modificator.setHomePath(interpreter);
  //        modificator.commitChanges();
  //        PythonSdkType.getInstance().setupSdkPaths(pythonSdk);
  //      }
  //      interpreter2sdk.put(interpreterInfo, pythonSdk);
  //    }
  //  }
  //});

  for (DataNode<PythonSetupData> dataNode : toImport) {
    final PythonSetupData pythonSetupData = dataNode.getData();
    final Sdk pythonSdk = interpreter2sdk.get(pythonSetupData.getInterpreterInfo());
    final Module module = modelsProvider.findIdeModule(pythonSetupData.getOwnerModuleData());
    if (module == null) {
      return;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    PythonFacet facet = facetManager.getFacetByType(PythonFacetType.getInstance().getId());
    if (facet == null) {
      facet = facetManager.createFacet(PythonFacetType.getInstance(), "Python", null);
      facet.getConfiguration().setSdk(pythonSdk);

      final ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(module);
      facetModel.addFacet(facet);
      TestRunnerService.getInstance(module).setProjectConfiguration("py.test");
    }
  }
}
 
Example #20
Source File: PantsPythonSdkUtil.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public static boolean hasNoPythonSdk(@NotNull Module module) {
  PythonFacet facet = FacetManager.getInstance(module).getFacetByType(PythonFacet.ID);
  return facet == null || facet.getConfiguration().getSdk() == null;
}