use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.
the class DvcsUtil method getVcsRootForLibraryFile.
@Nullable
private static VirtualFile getVcsRootForLibraryFile(@NotNull Project project, @NotNull VirtualFile file) {
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
// for a file inside .jar/.zip consider the .jar/.zip file itself
VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
if (root != null) {
LOGGER.debug("Found root for zip/jar file: " + root);
return root;
}
// for other libs which don't have jars inside the project dir (such as JDK) take the owner module of the lib
List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
Set<VirtualFile> libraryRoots = new HashSet<>();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
if (moduleRoot != null) {
libraryRoots.add(moduleRoot);
}
}
}
if (libraryRoots.size() == 0) {
LOGGER.debug("No library roots");
return null;
}
// if the lib is used in several modules, take the top module
// (for modules of the same level we can't guess anything => take the first one)
Iterator<VirtualFile> libIterator = libraryRoots.iterator();
VirtualFile topLibraryRoot = libIterator.next();
while (libIterator.hasNext()) {
VirtualFile libRoot = libIterator.next();
if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
topLibraryRoot = libRoot;
}
}
LOGGER.debug("Several library roots, returning " + topLibraryRoot);
return topLibraryRoot;
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class FlexDebugProcess method uniteWithLibrarySourcesOfBC.
private static GlobalSearchScope uniteWithLibrarySourcesOfBC(GlobalSearchScope scope, final Module module, final FlexBuildConfiguration bc, final Collection<FlexBuildConfiguration> processedConfigurations) {
if (!processedConfigurations.add(bc))
return scope;
final Collection<VirtualFile> libSourceRoots = new THashSet<>();
final Sdk sdk = bc.getSdk();
if (sdk != null) {
Collections.addAll(libSourceRoots, sdk.getRootProvider().getFiles(OrderRootType.SOURCES));
}
for (final DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry instanceof BuildConfigurationEntry) {
final Module otherModule = ((BuildConfigurationEntry) entry).findModule();
final FlexBuildConfiguration otherBC = ((BuildConfigurationEntry) entry).findBuildConfiguration();
if (otherModule != null && otherBC != null) {
scope = uniteWithLibrarySourcesOfBC(scope, otherModule, otherBC, processedConfigurations);
}
} else if (entry instanceof ModuleLibraryEntry) {
final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, ModuleRootManager.getInstance(module));
if (orderEntry != null) {
Collections.addAll(libSourceRoots, orderEntry.getFiles(OrderRootType.SOURCES));
}
} else if (entry instanceof SharedLibraryEntry) {
final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
Collections.addAll(libSourceRoots, library.getFiles(OrderRootType.SOURCES));
}
}
}
return libSourceRoots.isEmpty() ? scope : scope.uniteWith(new LibrarySourcesSearchScope(module.getProject(), libSourceRoots));
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class FlexBuildConfigurationsExtension method selectOrderEntry.
@Nullable
public ActionCallback selectOrderEntry(@NotNull final Module module, @Nullable final OrderEntry entry) {
if (ModuleType.get(module) != FlexModuleType.getInstance()) {
return null;
}
if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry) entry).getLibrary();
if (library != null && library.getTable() == null && ((LibraryEx) library).getKind() == FlexLibraryType.FLEX_LIBRARY) {
final String libraryId = FlexProjectRootsUtil.getLibraryId(library);
final List<CompositeConfigurable> configurables = myConfigurator.getBCConfigurables(module);
// several build configurations may depend on the same library, here we select the first one we find
for (CompositeConfigurable configurable : configurables) {
final FlexBCConfigurable bcConfigurable = FlexBCConfigurable.unwrap(configurable);
final Dependencies dependencies = bcConfigurable.getDependenciesConfigurable().getEditableObject();
for (DependencyEntry e : dependencies.getEntries()) {
if (!(e instanceof ModuleLibraryEntry) || !((ModuleLibraryEntry) e).getLibraryId().equals(libraryId)) {
continue;
}
final Place p = FlexProjectStructureUtil.createPlace(bcConfigurable, DependenciesConfigurable.TAB_NAME);
final DependenciesConfigurable.Location.TableEntry tableEntry = DependenciesConfigurable.Location.TableEntry.forModuleLibrary(libraryId);
p.putPath(FlexBCConfigurable.LOCATION_ON_TAB, tableEntry);
return ProjectStructureConfigurable.getInstance(module.getProject()).navigateTo(p, true);
}
}
}
}
return ProjectStructureConfigurable.getInstance(module.getProject()).select(module.getName(), null, true);
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class LibraryCollector method collect.
/**
* We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
*/
public void collect(Module module) {
final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
final Sdk sdk = bc.getSdk();
assert sdk != null;
final SdkType sdkType;
try {
sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
} catch (Exception e) {
throw new RuntimeException(e);
}
final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
if (!isFlexmojosSdk) {
collectSdkLibraries(bc, sdk);
} else {
final String sdkHomePath = sdk.getHomePath();
LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
}
flexSdkVersion = sdk.getVersionString();
assert flexSdkVersion != null;
if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
flexSdkVersion = "4.6";
} else {
flexSdkVersion = flexSdkVersion.substring(0, 3);
}
globalCatalogForTests(bc);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry instanceof ModuleLibraryEntry) {
LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
if (orderEntry != null) {
collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
}
} else if (entry instanceof SharedLibraryEntry) {
com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
}
}
}
// IDEA-71055
// todo css-based themes
final List<String> themes = BCUtils.getThemes(module, bc);
for (String theme : themes) {
if (theme.endsWith(DOT_SWC)) {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
if (file != null && uniqueGuard.add(file)) {
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarFile != null) {
addLibrary(jarFile, true);
}
}
}
}
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-plugins by JetBrains.
the class DependenciesConfigurable method editLibrary.
private void editLibrary(ModuleLibraryItem item) {
if (!item.canEdit())
return;
final LibraryOrderEntry entry = item.orderEntry;
assert entry != null;
Library library = entry.getLibrary();
if (library == null) {
return;
}
LibraryTablePresentation presentation = new LibraryTablePresentation() {
@Override
public String getDisplayName(boolean plural) {
return FlexBundle.message(plural ? "library.editor.title.plural" : "library.editor.title.singular");
}
@Override
public String getDescription() {
return ProjectBundle.message("libraries.node.text.module");
}
@Override
public String getLibraryTableEditorTitle() {
// not used as far as I see
return "Configure Library";
}
};
LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {
public LibraryTable.ModifiableModel getModifiableModel() {
return myConfigEditor.getLibraryModel(myDependencies);
}
};
StructureConfigurableContext context = ModuleStructureConfigurable.getInstance(myProject).getContext();
EditExistingLibraryDialog dialog = EditExistingLibraryDialog.createDialog(myMainPanel, provider, library, myProject, presentation, context);
dialog.setContextModule(myConfigEditor.getModule(myDependencies));
dialog.show();
myTable.refresh();
}
Aggregations