当前位置: 首页>>代码示例>>Java>>正文


Java LibraryTable.createLibrary方法代码示例

本文整理汇总了Java中com.intellij.openapi.roots.libraries.LibraryTable.createLibrary方法的典型用法代码示例。如果您正苦于以下问题:Java LibraryTable.createLibrary方法的具体用法?Java LibraryTable.createLibrary怎么用?Java LibraryTable.createLibrary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.roots.libraries.LibraryTable的用法示例。


在下文中一共展示了LibraryTable.createLibrary方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: commitLibraryModel

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) {
  LibraryTable libraryTable = model.getModuleLibraryTable();
  Library library = libraryTable.createLibrary("test");

  Library.ModifiableModel libraryModel = library.getModifiableModel();
  for (String annotationsDir : libraryPath) {
    String path = testDataPath + "/libs/" + annotationsDir;
    VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
    assertNotNull(libJarLocal);
    VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
    assertNotNull(jarRoot);
    libraryModel.addRoot(jarRoot, jarRoot.getName().contains("-sources") ? OrderRootType.SOURCES 
                                                                         : OrderRootType.CLASSES);
  }
  libraryModel.commit();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ClsGenericsHighlightingTest.java

示例2: testModification

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
public void testModification() throws Exception {
  final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable();
  final Library library = libraryTable.createLibrary("NewLibrary");
  final boolean[] listenerNotifiedOnChange = new boolean[1];
  library.getRootProvider().addRootSetChangedListener(wrapper -> listenerNotifiedOnChange[0] = true);
  final Library.ModifiableModel model1 = library.getModifiableModel();
  model1.addRoot("file://x.jar", OrderRootType.CLASSES);
  model1.addRoot("file://x-src.jar", OrderRootType.SOURCES);
  commit(model1);
  assertTrue(listenerNotifiedOnChange[0]);

  listenerNotifiedOnChange[0] = false;

  final Library.ModifiableModel model2 = library.getModifiableModel();
  model2.setName("library");
  commit(model2);
  assertFalse(listenerNotifiedOnChange[0]);

  ApplicationManager.getApplication().runWriteAction(() -> {
    libraryTable.removeLibrary(library);
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:LibraryTest.java

示例3: testJarDirectoriesSerialization

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
public void testJarDirectoriesSerialization() {
  LibraryTable table = getLibraryTable();
  Library library = table.createLibrary("jarDirs");
  Library.ModifiableModel model = library.getModifiableModel();
  model.addJarDirectory("file://jar-dir", false, OrderRootType.CLASSES);
  model.addJarDirectory("file://jar-dir-src", false, OrderRootType.SOURCES);
  commit(model);

  Element element = serialize(library);
  PlatformTestUtil.assertElementEquals("<root>\n" +
                                       "  <library name=\"jarDirs\">\n" +
                                       "    <CLASSES>\n" +
                                       "      <root url=\"file://jar-dir\" />\n" +
                                       "    </CLASSES>\n" +
                                       "    <JAVADOC />\n" +
                                       "    <SOURCES>\n" +
                                       "      <root url=\"file://jar-dir-src\" />\n" +
                                       "    </SOURCES>\n" +
                                       "    <jarDirectory url=\"file://jar-dir\" recursive=\"false\" />\n" +
                                       "    <jarDirectory url=\"file://jar-dir-src\" recursive=\"false\" type=\"SOURCES\" />\n" +
                                       "  </library>\n" +
                                       "</root>" , element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:LibraryTest.java

示例4: importMissing

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
private void importMissing(@NotNull IdeModifiableModelsProvider modelsProvider,
                           @NotNull Set<LibraryDependencyData> toImport,
                           @NotNull ModifiableRootModel moduleRootModel,
                           @NotNull LibraryTable moduleLibraryTable,
                           @NotNull Module module) {
  for (final LibraryDependencyData dependencyData : toImport) {
    final LibraryData libraryData = dependencyData.getTarget();
    final String libraryName = libraryData.getInternalName();
    switch (dependencyData.getLevel()) {
      case MODULE:
        final Library moduleLib = moduleLibraryTable.createLibrary(libraryName);
        syncExistingLibraryDependency(modelsProvider, dependencyData, moduleLib, moduleRootModel, module);
        break;
      case PROJECT:
        final Library projectLib = modelsProvider.getLibraryByName(libraryName);
        if (projectLib == null) {
          syncExistingLibraryDependency(modelsProvider, dependencyData, moduleLibraryTable.createLibrary(libraryName), moduleRootModel,
                                        module);
          break;
        }
        LibraryOrderEntry orderEntry = moduleRootModel.addLibraryEntry(projectLib);
        setLibraryScope(orderEntry, projectLib, module, dependencyData);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LibraryDependencyDataService.java

示例5: addJarFolderToModuleLibs

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
private void addJarFolderToModuleLibs(
    @NotNull final ModifiableRootModel modifiableRootModel,
    @NotNull final IdeModifiableModelsProvider modifiableModelsProvider,
    @Nullable final VirtualFile sourceCodeRoot,
    @NotNull final JavaLibraryDescriptor javaLibraryDescriptor
) {
    final LibraryTable projectLibraryTable = modifiableRootModel.getModuleLibraryTable();

    final Library library = projectLibraryTable.createLibrary();
    final Library.ModifiableModel libraryModifiableModel = modifiableModelsProvider
        .getModifiableLibraryModel(library);

    libraryModifiableModel.addJarDirectory(
        VfsUtil.getUrlForLibraryRoot(javaLibraryDescriptor.getLibraryFile()), true
    );

    if (null != javaLibraryDescriptor.getSourcesFile()) {
        final VirtualFile srcDirVF = VfsUtil.findFileByIoFile(javaLibraryDescriptor.getSourcesFile(), true);
        if (null != srcDirVF) {
            libraryModifiableModel.addRoot(srcDirVF, OrderRootType.SOURCES);
        }
    }

    if (null != sourceCodeRoot) {
        libraryModifiableModel.addRoot(sourceCodeRoot, OrderRootType.SOURCES);
    }

    if (javaLibraryDescriptor.isExported()) {
        this.setLibraryEntryExported(modifiableRootModel, library);
    }
    setLibraryEntryScope(modifiableRootModel, library, javaLibraryDescriptor.getScope());
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:33,代码来源:DefaultLibRootsConfigurator.java

示例6: testNativePathSerialization

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
public void testNativePathSerialization() {
  LibraryTable table = getLibraryTable();
  Library library = table.createLibrary("native");
  Library.ModifiableModel model = library.getModifiableModel();
  model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
  commit(model);

  Element element = serialize(library);
  PlatformTestUtil.assertElementEquals(
    "<root><library name=\"native\"><CLASSES /><JAVADOC />" +
    "<NATIVE><root url=\"file://native-lib-root\" /></NATIVE>" +
    "<SOURCES /></library></root>",
    element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:LibraryTest.java

示例7: setupRootModel

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
private static void setupRootModel(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final ModifiableRootModel rootModel,
        final Map<LibraryDescriptor, Library> projectLibs) {
    final CompilerModuleExtension compilerModuleExtension =
            rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    rootModel.inheritSdk();

    //Module root model seems to store .iml files root dependencies. (src, test, lib)
    logger.info("Starting setupRootModel in ProjectFromSourcesBuilderImplModified");
    final Set<File> contentRoots = descriptor.getContentRoots();
    for (File contentRoot : contentRoots) {
        final LocalFileSystem lfs = LocalFileSystem.getInstance();
        VirtualFile moduleContentRoot =
                lfs.refreshAndFindFileByPath(
                        FileUtil.toSystemIndependentName(contentRoot.getPath()));
        if (moduleContentRoot != null) {
            final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
            final Collection<DetectedSourceRoot> sourceRoots =
                    descriptor.getSourceRoots(contentRoot);
            for (DetectedSourceRoot srcRoot : sourceRoots) {
                final String srcpath =
                        FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
                final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(
                            sourceRoot,
                            shouldBeTestRoot(srcRoot.getDirectory()),
                            getPackagePrefix(srcRoot));
                }
            }
        }
    }
    logger.info("Inherits compiler output path from project");
    compilerModuleExtension.inheritCompilerOutputPath(true);

    logger.info("Starting to create module level libraries");
    final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
    for (LibraryDescriptor libDescriptor :
            ModuleInsight.getLibraryDependencies(
                    descriptor, projectDescriptor.getLibraries())) {
        final Library projectLib = projectLibs.get(libDescriptor);
        if (projectLib != null) {
            rootModel.addLibraryEntry(projectLib);
        } else {
            // add as module library
            final Collection<File> jars = libDescriptor.getJars();
            for (File file : jars) {
                Library library = moduleLibraryTable.createLibrary();
                Library.ModifiableModel modifiableModel = library.getModifiableModel();
                modifiableModel.addRoot(
                        VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
                modifiableModel.commit();
            }
        }
    }
    logger.info("Ending setupRootModel in ProjectFromSourcesBuilderImplModified");
}
 
开发者ID:testmycode,项目名称:tmc-intellij,代码行数:61,代码来源:ProjectFromSourcesBuilderImplModified.java

示例8: setupRootModel

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
  final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
  compilerModuleExtension.setExcludeOutput(true);
  if (myJdk != null){
    rootModel.setSdk(myJdk);
  } else {
    rootModel.inheritSdk();
  }

  ContentEntry contentEntry = doAddContentEntry(rootModel);
  if (contentEntry != null) {
    final List<Pair<String,String>> sourcePaths = getSourcePaths();

    if (sourcePaths != null) {
      for (final Pair<String, String> sourcePath : sourcePaths) {
        String first = sourcePath.first;
        new File(first).mkdirs();
        final VirtualFile sourceRoot = LocalFileSystem.getInstance()
          .refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
        if (sourceRoot != null) {
          contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
        }
      }
    }
  }

  if (myCompilerOutputPath != null) {
    // should set only absolute paths
    String canonicalPath;
    try {
      canonicalPath = FileUtil.resolveShortWindowsName(myCompilerOutputPath);
    }
    catch (IOException e) {
      canonicalPath = myCompilerOutputPath;
    }
    compilerModuleExtension
      .setCompilerOutputPath(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
  }
  else {
    compilerModuleExtension.inheritCompilerOutputPath(true);
  }

  LibraryTable libraryTable = rootModel.getModuleLibraryTable();
  for (Pair<String, String> libInfo : myModuleLibraries) {
    final String moduleLibraryPath = libInfo.first;
    final String sourceLibraryPath = libInfo.second;
    Library library = libraryTable.createLibrary();
    Library.ModifiableModel modifiableModel = library.getModifiableModel();
    modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES);
    if (sourceLibraryPath != null) {
      modifiableModel.addRoot(getUrlByPath(sourceLibraryPath), OrderRootType.SOURCES);
    }
    modifiableModel.commit();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:56,代码来源:JavaModuleBuilder.java

示例9: testModuleLibraries

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
public void testModuleLibraries() throws Exception {
  File moduleFile = new File(getTestRoot(), "test.iml");
  Module module = createModule(moduleFile);
  final ModuleRootManagerImpl moduleRootManager =
    (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
  final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
  final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();

  final Library unnamedLibrary = moduleLibraryTable.createLibrary();
  final File unnamedLibClasses = new File(getTestRoot(), "unnamedLibClasses");
  final VirtualFile unnamedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(unnamedLibClasses);
  final Library.ModifiableModel libraryModifyableModel = unnamedLibrary.getModifiableModel();
  libraryModifyableModel.addRoot(unnamedLibClassesRoot.getUrl(), OrderRootType.CLASSES);

  final Library namedLibrary = moduleLibraryTable.createLibrary("namedLibrary");
  final File namedLibClasses = new File(getTestRoot(), "namedLibClasses");
  final VirtualFile namedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(namedLibClasses);
  final Library.ModifiableModel namedLibraryModel = namedLibrary.getModifiableModel();
  namedLibraryModel.addRoot(namedLibClassesRoot.getUrl(), OrderRootType.CLASSES);

  ApplicationManager.getApplication().runWriteAction(() -> {
    libraryModifyableModel.commit();
    namedLibraryModel.commit();
  });

  final Iterator libraryIterator = moduleLibraryTable.getLibraryIterator();
  assertEquals(libraryIterator.next(), unnamedLibrary);
  assertEquals(libraryIterator.next(), namedLibrary);

  ApplicationManager.getApplication().runWriteAction(rootModel::commit);
  final Element element = new Element("root");
  moduleRootManager.getState().writeExternal(element);
  assertElementEquals(element,
                      "<root inherit-compiler-output=\"true\">" +
                      "<exclude-output />" +
                      "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" +
                      "<orderEntry type=\"module-library\">" +
                      "<library>" +
                      "<CLASSES><root url=\"file://$MODULE_DIR$/unnamedLibClasses\" /></CLASSES>" +
                      "<JAVADOC />" +
                      "<SOURCES />" +
                      "</library>" +
                      "</orderEntry>" +
                      "<orderEntry type=\"module-library\">" +
                      "<library name=\"namedLibrary\">" +
                      "<CLASSES><root url=\"file://$MODULE_DIR$/namedLibClasses\" /></CLASSES>" +
                      "<JAVADOC />" +
                      "<SOURCES />" +
                      "</library>" +
                      "</orderEntry>" +
                      "</root>", module);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:ModuleRootsExternalizationTest.java

示例10: setupRootModel

import com.intellij.openapi.roots.libraries.LibraryTable; //导入方法依赖的package包/类
private static void setupRootModel(ProjectDescriptor projectDescriptor, final ModuleDescriptor descriptor,
                                   final ModifiableRootModel rootModel, final Map<LibraryDescriptor, Library> projectLibs) {
  final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
  compilerModuleExtension.setExcludeOutput(true);
  rootModel.inheritSdk();

  final Set<File> contentRoots = descriptor.getContentRoots();
  for (File contentRoot : contentRoots) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(contentRoot.getPath()));
    if (moduleContentRoot != null) {
      final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
      final Collection<DetectedSourceRoot> sourceRoots = descriptor.getSourceRoots(contentRoot);
      for (DetectedSourceRoot srcRoot : sourceRoots) {
        final String srcpath = FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
        final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
        if (sourceRoot != null) {
          contentEntry.addSourceFolder(sourceRoot, shouldBeTestRoot(srcRoot.getDirectory()), getPackagePrefix(srcRoot));
        }
      }
    }
  }
  compilerModuleExtension.inheritCompilerOutputPath(true);
  final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
  for (LibraryDescriptor libDescriptor : ModuleInsight.getLibraryDependencies(descriptor, projectDescriptor.getLibraries())) {
    final Library projectLib = projectLibs.get(libDescriptor);
    if (projectLib != null) {
      rootModel.addLibraryEntry(projectLib);
    }
    else {
      // add as module library
      final Collection<File> jars = libDescriptor.getJars();
      for (File file : jars) {
        Library library = moduleLibraryTable.createLibrary();
        Library.ModifiableModel modifiableModel = library.getModifiableModel();
        modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
        modifiableModel.commit();
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:ProjectFromSourcesBuilderImpl.java


注:本文中的com.intellij.openapi.roots.libraries.LibraryTable.createLibrary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。