com.intellij.openapi.roots.impl.libraries.LibraryEx Java Examples

The following examples show how to use com.intellij.openapi.roots.impl.libraries.LibraryEx. 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: LibraryGroupNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static VirtualFile[] getLibraryRoots(@Nonnull LibraryOrderEntry orderEntry) {
  Library library = orderEntry.getLibrary();
  if (library == null) return VirtualFile.EMPTY_ARRAY;
  OrderRootType[] rootTypes = LibraryType.getDefaultExternalRootTypes();
  if (library instanceof LibraryEx) {
    if (((LibraryEx)library).isDisposed()) return VirtualFile.EMPTY_ARRAY;
    PersistentLibraryKind<?> libKind = ((LibraryEx)library).getKind();
    if (libKind != null) {
      rootTypes = LibraryType.findByKind(libKind).getExternalRootTypes();
    }
  }
  final ArrayList<VirtualFile> files = new ArrayList<VirtualFile>();
  for (OrderRootType rootType : rootTypes) {
    files.addAll(Arrays.asList(library.getFiles(rootType)));
  }
  return VfsUtilCore.toVirtualFileArray(files);
}
 
Example #2
Source File: MuleSdk.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String getMuleHome(@NotNull Module module) {
    if (!DumbService.isDumb(module.getProject())) {
        final OrderEnumerator enumerator = ModuleRootManager.getInstance(module)
                .orderEntries().recursively().librariesOnly().exportedOnly();
        final String[] home = new String[1];
        enumerator.forEachLibrary(library -> {
            if (MuleLibraryKind.MULE_LIBRARY_KIND.equals(((LibraryEx) library).getKind()) &&
                    library.getFiles(OrderRootType.CLASSES) != null &&
                    library.getFiles(OrderRootType.CLASSES).length > 0) {
                home[0] = getMuleHome(library.getFiles(OrderRootType.CLASSES)[0]);
                return false;
            } else {
                return true;
            }
        });

        return home[0];
    }
    return null;
}
 
Example #3
Source File: BaseLibrariesConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Object o = getSelectedObject();
  if (o instanceof LibraryEx) {
    final LibraryEx selected = (LibraryEx)o;
    final String newName = Messages.showInputDialog("Enter library name:", "Copy Library", null, selected.getName() + "2", new NonEmptyInputValidator());
    if (newName == null) return;

    BaseLibrariesConfigurable configurable = BaseLibrariesConfigurable.this;
    final LibraryEx library = (LibraryEx)myContext.getLibrary(selected.getName(), myLevel);
    LOG.assertTrue(library != null);

    final LibrariesModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
    final Library lib = libsModel.createLibrary(newName, library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)libsModel.getLibraryEditor(lib).getModel();
    LibraryEditingUtil.copyLibrary(library, Collections.<String, String>emptyMap(), model);
  }
}
 
Example #4
Source File: CreateNewLibraryAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Library createLibrary(@Nullable final LibraryType type,
                                    @Nonnull final JComponent parentComponent,
                                    @Nonnull final Project project,
                                    @Nonnull final LibrariesModifiableModel modifiableModel) {
  final NewLibraryConfiguration configuration = createNewLibraryConfiguration(type, parentComponent, project);
  if (configuration == null) return null;
  final LibraryType<?> libraryType = configuration.getLibraryType();
  final Library library = modifiableModel
    .createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()),
                   libraryType != null ? libraryType.getKind() : null);

  final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties());
  configuration.addRoots(editor);
  final Library.ModifiableModel model = library.getModifiableModel();
  editor.applyTo((LibraryEx.ModifiableModelEx)model);
  WriteAction.run(model::commit);
  return library;
}
 
Example #5
Source File: ProjectStructureValidator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showDialogAndAddLibraryToDependencies(final Library library, final Project project, boolean allowEmptySelection) {
  for (ProjectStructureValidator validator : EP_NAME.getExtensions()) {
    if (validator.addLibraryToDependencies(library, project, allowEmptySelection)) {
      return;
    }
  }

  final ModuleStructureConfigurable moduleStructureConfigurable = ModuleStructureConfigurable.getInstance(project);
  final List<Module> modules = LibraryEditingUtil.getSuitableModules(moduleStructureConfigurable, ((LibraryEx)library).getKind(), library);
  if (modules.isEmpty()) return;
  final ChooseModulesDialog
    dlg = new ChooseModulesDialog(moduleStructureConfigurable.getProject(), modules, ProjectBundle.message("choose.modules.dialog.title"),
                                  ProjectBundle
                                    .message("choose.modules.dialog.description", library.getName()));
  dlg.show();
  if (dlg.isOK()) {
    final List<Module> chosenModules = dlg.getChosenElements();
    for (Module module : chosenModules) {
      moduleStructureConfigurable.addLibraryOrderEntry(module, library);
    }
  }
}
 
Example #6
Source File: FileOrDirectoryDependencyTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Library createLibraryFromRoots(ModifiableModuleRootLayer layer, List<OrderRoot> roots, @Nullable final LibraryType libraryType) {
  final LibraryTable.ModifiableModel moduleLibraryModel = layer.getModuleLibraryTable().getModifiableModel();

  final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
  final Library library = ((LibraryTableBase.ModifiableModelEx)moduleLibraryModel).createLibrary(null, kind);
  final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();

  for (OrderRoot root : roots) {
    if (root.isJarDirectory()) {
      libModel.addJarDirectory(root.getFile(), false, root.getType());
    }
    else {
      libModel.addRoot(root.getFile(), root.getType());
    }
  }
  libModel.commit();
  return library;
}
 
Example #7
Source File: ModuleLibraryOrderEntryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public String getPresentableName() {
  final String name = myLibrary.getName();
  if (name != null) {
    return name;
  }
  else {
    if (myLibrary instanceof LibraryEx && ((LibraryEx)myLibrary).isDisposed()) {
      return "<unknown>";
    }

    final String[] urls = myLibrary.getUrls(BinariesOrderRootType.getInstance());
    if (urls.length > 0) {
      String url = urls[0];
      return PathUtil.toPresentableUrl(url);
    }
    else {
      return ProjectBundle.message("library.empty.library.item");
    }
  }
}
 
Example #8
Source File: LibrarySourceItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void render(@Nonnull PresentationData presentationData, SimpleTextAttributes mainAttributes,
                   SimpleTextAttributes commentAttributes) {
  final String name = myLibrary.getName();
  if (name != null) {
    presentationData.setIcon(AllIcons.Nodes.PpLib);
    presentationData.addText(name, mainAttributes);
    presentationData.addText(LibraryElementPresentation.getLibraryTableComment(myLibrary), commentAttributes);
  }
  else {
    if (((LibraryEx)myLibrary).isDisposed()) {
      //todo[nik] disposed library should not be shown in the tree
      presentationData.addText("Invalid Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
      return;
    }
    final VirtualFile[] files = myLibrary.getFiles(BinariesOrderRootType.getInstance());
    if (files.length > 0) {
      final VirtualFile file = files[0];
      presentationData.setIcon(VirtualFilePresentation.getIcon(file));
      presentationData.addText(file.getName(), mainAttributes);
    }
    else {
      presentationData.addText("Empty Library", SimpleTextAttributes.ERROR_ATTRIBUTES);
    }
  }
}
 
Example #9
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private void setupLibraries(Project project, ModifiableModelsProvider modelsProvider, ModulesProvider modulesProvider, List<LibraryData> libraries) {
  LibraryTable.ModifiableModel librariesModel = modelsProvider.getLibraryTableModifiableModel(project);

  for(LibraryData lib:libraries) {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(lib.getClasspath());
    if(root != null) {
      LibraryImpl library = (LibraryImpl)librariesModel.createLibrary(lib.getName());
      LibraryEx.ModifiableModelEx model = library.getModifiableModel();
      model.setKind(HaxeLibraryType.HAXE_LIBRARY);
      model.addRoot(root, OrderRootType.CLASSES);
      model.addRoot(root, OrderRootType.SOURCES);
      model.commit();

      for(Module module:modulesProvider.getModules()) {
        ModifiableRootModel moduleModel = modelsProvider.getModuleModifiableModel(module);
        moduleModel.addLibraryEntry(library);
        moduleModel.commit();
      }
    }
  }

  librariesModel.commit();
}
 
Example #10
Source File: LibraryClasspathTableItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getTooltipText() {
  final Library library = myEntry.getLibrary();
  if (library == null) return null;

  final String name = library.getName();
  if (name != null) {
    final List<String> invalidUrls = ((LibraryEx)library).getInvalidRootUrls(BinariesOrderRootType.getInstance());
    if (!invalidUrls.isEmpty()) {
      return ProjectBundle.message("project.roots.tooltip.library.has.broken.paths", name, invalidUrls.size());
    }
  }

  final List<String> descriptions = LibraryPresentationManager.getInstance().getDescriptions(library, myContext);
  if (descriptions.isEmpty()) return null;

  return XmlStringUtil.wrapInHtml(StringUtil.join(descriptions, "<br>"));
}
 
Example #11
Source File: ModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object object, Method method, Object[] params) throws Throwable {
  try {
    final Object result = method.invoke(myDelegateLibrary, unwrapParams(params));
    if (result instanceof LibraryEx.ModifiableModelEx) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryEx.ModifiableModelEx.class},
                                    new LibraryModifiableModelInvocationHandler((LibraryEx.ModifiableModelEx)result));
    }
    return result;
  }
  catch (InvocationTargetException e) {
    throw e.getCause();
  }
}
 
Example #12
Source File: ModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object object, Method method, Object[] params) throws Throwable {
  final boolean needUpdate = METHOD_COMMIT.equals(method.getName());
  try {
    Object result = method.invoke(myDelegateModel, unwrapParams(params));
    if (result instanceof Library[]) {
      Library[] libraries = (Library[])result;
      for (int idx = 0; idx < libraries.length; idx++) {
        Library library = libraries[idx];
        libraries[idx] =
        (Library)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryEx.class},
                                        new LibraryInvocationHandler(library));
      }
    }
    if (result instanceof Library) {
      result =
      Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryEx.class},
                             new LibraryInvocationHandler((Library)result));
    }
    return result;
  }
  catch (InvocationTargetException e) {
    throw e.getCause();
  }
  finally {
    if (needUpdate) {
      fireModuleStateChanged();
    }
  }
}
 
Example #13
Source File: ModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object object, Method method, Object[] params) throws Throwable {
  final boolean needUpdate = myCheckedNames.contains(method.getName());
  try {
    final Object result = method.invoke(myDelegateTable, unwrapParams(params));
    if (result instanceof Library) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{result instanceof LibraryEx ? LibraryEx.class : Library.class},
                                    new LibraryInvocationHandler((Library)result));
    }
    else if (result instanceof LibraryTable.ModifiableModel) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryTableBase.ModifiableModelEx.class},
                                    new LibraryTableModelInvocationHandler((LibraryTable.ModifiableModel)result));
    }
    if (result instanceof Library[]) {
      Library[] libraries = (Library[])result;
      for (int idx = 0; idx < libraries.length; idx++) {
        Library library = libraries[idx];
        libraries[idx] =
        (Library)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{library instanceof LibraryEx ? LibraryEx.class : Library.class},
                                        new LibraryInvocationHandler(library));
      }
    }
    return result;
  }
  catch (InvocationTargetException e) {
    throw e.getCause();
  }
  finally {
    if (needUpdate) {
      fireModuleStateChanged();
    }
  }
}
 
Example #14
Source File: CreateNewLibraryDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Library createLibrary() {
  final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel();
  final LibraryType<?> type = myLibraryEditor.getType();
  final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  myLibraryEditor.applyTo(model);
  WriteAction.run(model::commit);
  return library;
}
 
Example #15
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public LibraryType<?> getType() {
  final LibraryKind kind = ((LibraryEx)myLibrary).getKind();
  if (kind != null) {
    return LibraryType.findByKind(kind);
  }
  return detectType();
}
 
Example #16
Source File: LibraryEditingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void copyLibrary(LibraryEx from, Map<String, String> rootMapping, LibraryEx.ModifiableModelEx target) {
  target.setProperties(from.getProperties());
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    final String[] urls = from.getUrls(type);
    for (String url : urls) {
      final String protocol = VirtualFileManager.extractProtocol(url);
      if (protocol == null) continue;
      final String fullPath = VirtualFileManager.extractPath(url);
      final int sep = fullPath.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR);
      String localPath;
      String pathInJar;
      if (sep != -1) {
        localPath = fullPath.substring(0, sep);
        pathInJar = fullPath.substring(sep);
      }
      else {
        localPath = fullPath;
        pathInJar = "";
      }
      final String targetPath = rootMapping.get(localPath);
      String targetUrl = targetPath != null ? VirtualFileManager.constructUrl(protocol, targetPath + pathInJar) : url;

      if (from.isJarDirectory(url, type)) {
        target.addJarDirectory(targetUrl, false, type);
      }
      else {
        target.addRoot(targetUrl, type);
      }
    }
  }
}
 
Example #17
Source File: LibraryPresentationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static VirtualFile[] getLibraryFiles(@Nonnull Library library, @Nullable StructureConfigurableContext context) {
  if (((LibraryEx)library).isDisposed()) {
    return VirtualFile.EMPTY_ARRAY;
  }
  return context != null ? context.getLibraryFiles(library, BinariesOrderRootType.getInstance()) : library.getFiles(BinariesOrderRootType.getInstance());
}
 
Example #18
Source File: LibraryPresentationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLibraryOfKind(@Nonnull Library library,
                               @Nonnull LibrariesContainer librariesContainer,
                               @Nonnull final Set<? extends LibraryKind> acceptedKinds) {
  final LibraryKind type = ((LibraryEx)library).getKind();
  if (type != null && acceptedKinds.contains(type)) return true;

  final VirtualFile[] files = librariesContainer.getLibraryFiles(library, BinariesOrderRootType.getInstance());
  return !LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
    @Override
    public <P extends LibraryProperties> boolean processProperties(@Nonnull LibraryKind processedKind, @Nonnull P properties) {
      return !acceptedKinds.contains(processedKind);
    }
  });
}
 
Example #19
Source File: LibraryPresentationManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Image getCustomIcon(@Nonnull Library library, StructureConfigurableContext context) {
  final LibraryKind kind = ((LibraryEx)library).getKind();
  if (kind != null) {
    return LibraryType.findByKind(kind).getIcon();
  }
  final List<Image> icons = getCustomIcons(library, context);
  if (icons.size() == 1) {
    return icons.get(0);
  }
  return null;
}
 
Example #20
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Library createLibraryInTable(final @Nonnull NewLibraryEditor editor, final LibraryTable table) {
  LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx) table.getModifiableModel();
  final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
  final LibraryType<?> type = editor.getType();
  Library library = modifiableModel.createLibrary(name, type == null ? null : type.getKind());
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  editor.applyTo(model);
  model.commit();
  modifiableModel.commit();
  return library;
}
 
Example #21
Source File: AddLibraryToModuleDependenciesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  final ProjectStructureElement element = myConfigurable.getSelectedElement();
  boolean visible = false;
  if (element instanceof LibraryProjectStructureElement) {
    final LibraryEx library = (LibraryEx)((LibraryProjectStructureElement)element).getLibrary();
    visible = !LibraryEditingUtil.getSuitableModules(ModuleStructureConfigurable.getInstance(myProject), library.getKind(), library).isEmpty();
  }
  e.getPresentation().setVisible(visible);
}
 
Example #22
Source File: LibraryProjectStructureElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reportInvalidRoots(ProjectStructureProblemsHolder problemsHolder, LibraryEx library,
                                final OrderRootType type, String rootName, final ProjectStructureProblemType problemType) {
  final List<String> invalidUrls = library.getInvalidRootUrls(type);
  if (!invalidUrls.isEmpty()) {
    final String description = createInvalidRootsDescription(invalidUrls, rootName, library.getName());
    final PlaceInProjectStructure place = createPlace();
    final String message = ProjectBundle.message("project.roots.error.message.invalid.roots", rootName, invalidUrls.size());
    ProjectStructureProblemDescription.ProblemLevel level = library.getTable().getTableLevel().equals(LibraryTablesRegistrar.PROJECT_LEVEL)
                                                            ? ProjectStructureProblemDescription.ProblemLevel.PROJECT : ProjectStructureProblemDescription.ProblemLevel.GLOBAL;
    problemsHolder.registerProblem(new ProjectStructureProblemDescription(message, description, place,
                                                                          problemType, level,
                                                                          Collections.singletonList(new RemoveInvalidRootsQuickFix(library, type, invalidUrls)),
                                                                          true));
  }
}
 
Example #23
Source File: LibraryProjectStructureElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void check(ProjectStructureProblemsHolder problemsHolder) {
  if (((LibraryEx)myLibrary).isDisposed()) return;
  final LibraryEx library = (LibraryEx)myContext.getLibraryModel(myLibrary);
  if (library == null || library.isDisposed()) return;

  reportInvalidRoots(problemsHolder, library, BinariesOrderRootType.getInstance(), "classes", ProjectStructureProblemType.error("library-invalid-classes-path"));
  final String libraryName = library.getName();
  if (libraryName == null || !libraryName.startsWith("Maven: ")) {
    reportInvalidRoots(problemsHolder, library, SourcesOrderRootType.getInstance(), "sources",
                       ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
    reportInvalidRoots(problemsHolder, library, DocumentationOrderRootType.getInstance(), "javadoc",
                       ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
  }
}
 
Example #24
Source File: LibraryUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getPresentableName(@Nonnull Library library) {
  final String name = library.getName();
  if (name != null) {
    return name;
  }
  if (library instanceof LibraryEx && ((LibraryEx)library).isDisposed()) {
    return "Disposed Library";
  }
  String[] urls = library.getUrls(BinariesOrderRootType.getInstance());
  if (urls.length > 0) {
    return PathUtil.getFileName(VfsUtilCore.urlToPath(urls[0]));
  }
  return "Empty Library";
}
 
Example #25
Source File: LibraryOrderEntryBaseImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEquivalentTo(@Nonnull OrderEntry other) {
  LOGGER.assertTrue(this instanceof LibraryOrderEntry);

  LibraryOrderEntry libraryOrderEntry1 = (LibraryOrderEntry)this;
  LibraryOrderEntry libraryOrderEntry2 = (LibraryOrderEntry)other;
  boolean equal = Comparing.equal(libraryOrderEntry1.getLibraryName(), libraryOrderEntry2.getLibraryName()) &&
                  Comparing.equal(libraryOrderEntry1.getLibraryLevel(), libraryOrderEntry2.getLibraryLevel());
  if (!equal) return false;

  Library library1 = libraryOrderEntry1.getLibrary();
  Library library2 = libraryOrderEntry2.getLibrary();
  if (library1 != null && library2 != null) {
    if (!Arrays.equals(((LibraryEx)library1).getExcludedRootUrls(), ((LibraryEx)library2).getExcludedRootUrls())) {
      return false;
    }
  }
  final List<OrderRootType> allTypes = OrderRootType.getAllTypes();
  for (OrderRootType type : allTypes) {
    final String[] orderedRootUrls1 = getUrls(type);
    final String[] orderedRootUrls2 = other.getUrls(type);
    if (!Arrays.equals(orderedRootUrls1, orderedRootUrls2)) {
      return false;
    }
  }
  return true;
}
 
Example #26
Source File: LibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid() {
  if (isDisposed()) {
    return false;
  }
  Library library = getLibrary();
  return library != null && !((LibraryEx)library).isDisposed();
}
 
Example #27
Source File: MuleFrameworkConfigurable.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel modifiableRootModel, @NotNull ModifiableModelsProvider modifiableModelsProvider) {

    String muleHome = null;

    Library[] libs = modifiableModelsProvider.getLibraryTableModifiableModel().getLibraries();
    for (Library nextLib : libs) {
        LibraryEx libraryEx = (LibraryEx)nextLib;
        if (muleHome == null && MuleLibraryKind.MULE_LIBRARY_KIND.equals(libraryEx.getKind())) {
            MuleLibraryProperties properties = (MuleLibraryProperties)libraryEx.getProperties();
            if (properties != null && properties.getState() != null) {
                muleHome = properties.getState().getMuleHome();
                break;
            }
        }
    }

    //Project myProject = module.getProject();
    //if (!MuleConfigUtils.isMuleProject(myProject)) {

    if (!hasFacet(module)) {
        MuleFacetType type = (MuleFacetType) FacetTypeRegistry.getInstance().findFacetType(MuleFacet.ID);
        MuleFacetConfiguration configuration = type.createDefaultConfiguration();
        if (muleHome != null)
            configuration.setPathToSdk(muleHome);
        Facet facet = type.createFacet(module, type.getPresentableName(), configuration, null);
        ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel();
        model.addFacet(facet);
        model.commit();
    }
}
 
Example #28
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ExistingLibraryEditor(@Nonnull Library library, @Nullable LibraryEditorListener listener) {
  myLibrary = (LibraryEx)library;
  myListener = listener;
}
 
Example #29
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LibraryEx.ModifiableModelEx getModel() {
  if (myModel == null) {
    myModel = myLibrary.getModifiableModel();
  }
  return myModel;
}
 
Example #30
Source File: NewLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void applyTo(@Nonnull LibraryEx.ModifiableModelEx model) {
  model.setProperties(myProperties);
  exportRoots(model::getUrls, model::isValid, model::removeRoot, model::addRoot, model::addJarDirectory, model::addExcludedRoot);
}