com.intellij.facet.ModifiableFacetModel Java Examples

The following examples show how to use com.intellij.facet.ModifiableFacetModel. 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: 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 #2
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 #3
Source File: QuarkusProjectDataService.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private static void ensureQuarkusFacet(Module module, IdeModifiableModelsProvider modelsProvider, ProjectSystemId externalSystemId) {
    FacetType<QuarkusFacet, QuarkusFacetConfiguration> facetType = QuarkusFacet.getQuarkusFacetType();
    ModifiableFacetModel facetModel = modelsProvider.getModifiableFacetModel(module);
    QuarkusFacet facet = facetModel.getFacetByType(facetType.getId());
    if (facet == null) {
        facet = facetType.createFacet(module, facetType.getDefaultFacetName(), facetType.createDefaultConfiguration(), (Facet)null);
        facetModel.addFacet(facet, ExternalSystemApiUtil.toExternalSource(externalSystemId));
    }
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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");
    }
  }
}