本文整理汇总了Java中com.intellij.openapi.roots.libraries.LibraryTable类的典型用法代码示例。如果您正苦于以下问题:Java LibraryTable类的具体用法?Java LibraryTable怎么用?Java LibraryTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LibraryTable类属于com.intellij.openapi.roots.libraries包,在下文中一共展示了LibraryTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGlobalLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public void createGlobalLibrary(
@NotNull final IdeModifiableModelsProvider modifiableModelsProvider,
@NotNull final File libraryDirRoot,
@NotNull final String libraryName
) {
final LibraryTable.ModifiableModel libraryTableModifiableModel = modifiableModelsProvider
.getModifiableProjectLibrariesModel();
Library library = libraryTableModifiableModel.getLibraryByName(libraryName);
if (null == library) {
library = libraryTableModifiableModel.createLibrary(libraryName);
}
if (libraryTableModifiableModel instanceof LibrariesModifiableModel) {
final ExistingLibraryEditor existingLibraryEditor = ((LibrariesModifiableModel) libraryTableModifiableModel)
.getLibraryEditor(library);
existingLibraryEditor.addJarDirectory(
VfsUtil.getUrlForLibraryRoot(libraryDirRoot), true, OrderRootType.CLASSES
);
} else {
final Library.ModifiableModel libraryModifiableModel = modifiableModelsProvider
.getModifiableLibraryModel(library);
libraryModifiableModel.addJarDirectory(VfsUtil.getUrlForLibraryRoot(libraryDirRoot), true);
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:26,代码来源:OotbHybrisModuleDescriptor.java
示例2: addLibsToModule
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
private void addLibsToModule(
@NotNull final ModifiableRootModel modifiableRootModel,
@NotNull IdeModifiableModelsProvider modifiableModelsProvider,
@NotNull final String libraryName,
final boolean export
) {
Validate.notNull(modifiableRootModel);
final LibraryTable.ModifiableModel libraryTableModifiableModel = modifiableModelsProvider
.getModifiableProjectLibrariesModel();
Library library = libraryTableModifiableModel.getLibraryByName(libraryName);
if (null == library) {
library = libraryTableModifiableModel.createLibrary(libraryName);
}
modifiableRootModel.addLibraryEntry(library);
if (export) {
setLibraryEntryExported(modifiableRootModel, library);
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:23,代码来源:DefaultLibRootsConfigurator.java
示例3: removeOldProjectData
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
private static void removeOldProjectData(@NotNull final Project project) {
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
for (Module module : moduleModel.getModules()) {
moduleModel.disposeModule(module);
}
final LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(project).getModifiableModel();
for (Library library : libraryModel.getLibraries()) {
libraryModel.removeLibrary(library);
}
ApplicationManager.getApplication().runWriteAction(() -> {
moduleModel.commit();
libraryModel.commit();
});
final GradleSupport gradleSupport = GradleSupport.getInstance();
if (gradleSupport != null) {
gradleSupport.clearLinkedProjectSettings(project);
}
final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project);
for (AntBuildFile antBuildFile : antConfiguration.getBuildFiles()) {
antConfiguration.removeBuildFile(antBuildFile);
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ProjectRefreshAction.java
示例4: testRemoveLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public void testRemoveLibrary() throws IOException {
CamelService service = ServiceManager.getService(myProject, CamelService.class);
assertEquals(0, service.getLibraries().size());
VirtualFile camelCoreVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-core-2.19.0.jar"));
VirtualFile camelSpringVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTestArchive("camel-spring-2.19.0.jar"));
final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
Library springLibrary = addLibraryToModule(camelSpringVirtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-spring:2.19.0-snapshot");
Library coreLibrary = addLibraryToModule(camelCoreVirtualFile, projectLibraryTable, "Maven: org.apache.camel:camel-core:2.19.0-snapshot");
UIUtil.dispatchAllInvocationEvents();
assertEquals(2, service.getLibraries().size());
assertEquals(true, service.isCamelPresent());
ApplicationManager.getApplication().runWriteAction(() -> projectLibraryTable.removeLibrary(springLibrary));
UIUtil.dispatchAllInvocationEvents();
assertEquals(1, service.getLibraries().size());
}
示例5: testAddModule
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public void testAddModule() throws IOException {
CamelService service = ServiceManager.getService(myProject, CamelService.class);
assertEquals(0, service.getLibraries().size());
File camelJar = createTestArchive("camel-core-2.19.0.jar");
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(camelJar);
final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject);
ApplicationManager.getApplication().runWriteAction(() -> {
final Module moduleA = createModule("myNewModel.iml");
Library library = projectLibraryTable.createLibrary("Maven: org.apache.camel:camel-core:2.19.0-snapshot");
final Library.ModifiableModel libraryModifiableModel = library.getModifiableModel();
libraryModifiableModel.addRoot(virtualFile, OrderRootType.CLASSES);
libraryModifiableModel.commit();
ModuleRootModificationUtil.addDependency(moduleA, library);
});
UIUtil.dispatchAllInvocationEvents();
assertEquals(1, service.getLibraries().size());
}
示例6: testDoNotFailOnAbsentAppLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public void testDoNotFailOnAbsentAppLibrary() throws Exception {
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
LibraryTable appTable = LibraryTablesRegistrar.getInstance().getLibraryTable();
Library lib = appTable.createLibrary("foo");
ModuleRootModificationUtil.addDependency(getModule("project"), lib);
appTable.removeLibrary(lib);
}
});
importProject(); // should not fail;
}
示例7: 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();
}
示例8: 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);
});
}
示例9: addProjectLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
private static Library addProjectLibrary(final Module module, final String name, final List<String> jarDirectories, final VirtualFile[] sources) {
return new WriteAction<Library>() {
protected void run(@NotNull final Result<Library> result) {
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject());
Library library = libraryTable.getLibraryByName(name);
if (library == null) {
library = libraryTable.createLibrary(name);
final Library.ModifiableModel model = library.getModifiableModel();
for (String path : jarDirectories) {
String url = VfsUtilCore.pathToUrl(path);
VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
model.addJarDirectory(url, false);
}
for (VirtualFile sourceRoot : sources) {
model.addRoot(sourceRoot, OrderRootType.SOURCES);
}
model.commit();
}
result.setResult(library);
}
}.execute().getResultObject();
}
示例10: removeData
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
@Override
public void removeData(@NotNull final Computable<Collection<Library>> toRemoveComputable,
@NotNull Collection<DataNode<LibraryData>> toIgnore,
@NotNull ProjectData projectData,
@NotNull final Project project,
@NotNull final IdeModifiableModelsProvider modelsProvider) {
final Collection<Library> toRemove = toRemoveComputable.compute();
if (toRemove.isEmpty()) {
return;
}
final LibraryTable.ModifiableModel librariesModel = modelsProvider.getModifiableProjectLibrariesModel();
for (Library library : toRemove) {
String libraryName = library.getName();
if (libraryName != null) {
Library libraryToRemove = librariesModel.getLibraryByName(libraryName);
if (libraryToRemove != null) {
librariesModel.removeLibrary(libraryToRemove);
}
}
}
}
示例11: removeLibrariesAndStoreAttachments
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public static void removeLibrariesAndStoreAttachments(@NotNull Project project) {
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
try {
Map<OrderRootType, Multimap<String, String>> attachmentsByType = Maps.newHashMap();
for (Library library : model.getLibraries()) {
for (OrderRootType type : SUPPORTED_TYPES) {
Multimap<String, String> attachments = ArrayListMultimap.create();
String name = library.getName();
if (name != null) {
String[] urls = library.getUrls(type);
for (String url : urls) {
attachments.put(name, url);
}
}
attachmentsByType.put(type, attachments);
}
model.removeLibrary(library);
}
project.putUserData(LIBRARY_ATTACHMENTS, new LibraryAttachments(project, attachmentsByType));
}
finally {
model.commit();
}
}
示例12: renameLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
private static void renameLibrary(final Sdk sdk, final String previousName) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final LibraryTable.ModifiableModel libraryTableModel =
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(previousName));
if (library != null) {
final Library.ModifiableModel model = library.getModifiableModel();
model.setName(PythonFacet.getFacetLibraryName(sdk.getName()));
model.commit();
}
libraryTableModel.commit();
}
});
}
}, ModalityState.NON_MODAL);
}
示例13: createLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
@Override
public Library createLibrary(@NotNull NewLibraryEditor libraryEditor,
@NotNull LibraryLevel level) {
LibraryTableModifiableModelProvider provider = getProvider(level);
if (provider == null) {
LOG.error("cannot create module library in this context");
}
LibraryTable.ModifiableModel model = provider.getModifiableModel();
final LibraryType<?> type = libraryEditor.getType();
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model), type == null ? null : type.getKind());
ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
createdLibraryEditor.setProperties(libraryEditor.getProperties());
libraryEditor.applyTo(createdLibraryEditor);
return library;
}
示例14: createNewLibrary
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
private LibraryEx createNewLibrary(@NotNull final Module module, final LibraryTable.ModifiableModel modifiableModel) {
RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(
libraryDescription.getGroupId(),
libraryDescription.getArtifactId(),
model.getVersion());
final LibraryEx library = (LibraryEx)modifiableModel.createLibrary(
LibraryEditingUtil.suggestNewLibraryName(modifiableModel, RepositoryLibraryType.getInstance().getDescription(libraryProperties)),
RepositoryLibraryType.REPOSITORY_LIBRARY_KIND);
RepositoryLibraryProperties realLibraryProperties = (RepositoryLibraryProperties)library.getProperties();
realLibraryProperties.setMavenId(libraryProperties.getMavenId());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
modifiableModel.commit();
}
});
RepositoryUtils.loadDependencies(
module.getProject(),
library,
model.isDownloadSources(),
model.isDownloadJavaDocs(),
null);
return library;
}
示例15: createDialog
import com.intellij.openapi.roots.libraries.LibraryTable; //导入依赖的package包/类
public static EditExistingLibraryDialog createDialog(Component parent,
LibraryTableModifiableModelProvider modelProvider,
Library library,
@Nullable Project project,
LibraryTablePresentation presentation,
StructureConfigurableContext context) {
LibraryTable.ModifiableModel modifiableModel = modelProvider.getModifiableModel();
boolean commitChanges = false;
ExistingLibraryEditor libraryEditor;
if (modifiableModel instanceof LibrariesModifiableModel) {
libraryEditor = ((LibrariesModifiableModel)modifiableModel).getLibraryEditor(library);
}
else {
libraryEditor = new ExistingLibraryEditor(library, context);
commitChanges = true;
}
return new EditExistingLibraryDialog(parent, modifiableModel, project, libraryEditor, commitChanges, presentation, context);
}