use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-plugins by JetBrains.
the class FlexProjectConfigurationEditor method commit.
public void commit() throws ConfigurationException {
final Map<Pair<String, String>, String> renamedConfigs = new HashMap<>();
for (Module module : myModule2Editors.keySet()) {
ModifiableRootModel modifiableModel = myProvider.getModuleModifiableModel(module);
Collection<String> usedModulesLibrariesIds = new ArrayList<>();
// ---------------- SDK and shared libraries entries ----------------------
// Library -> add_library_entry_flag
Map<Library, Boolean> librariesToAdd = new LinkedHashMap<>();
final Collection<String> sdkNames = new HashSet<>();
for (Editor editor : myModule2Editors.get(module)) {
final SdkEntry sdkEntry = editor.getDependencies().getSdkEntry();
if (sdkEntry != null) {
sdkNames.add(sdkEntry.getName());
}
for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
if (dependencyEntry instanceof ModuleLibraryEntry) {
ModuleLibraryEntry moduleLibraryEntry = (ModuleLibraryEntry) dependencyEntry;
usedModulesLibrariesIds.add(moduleLibraryEntry.getLibraryId());
}
if (dependencyEntry instanceof SharedLibraryEntry) {
SharedLibraryEntry sharedLibraryEntry = (SharedLibraryEntry) dependencyEntry;
Library library = myProvider.findSourceLibraryForLiveName(sharedLibraryEntry.getLibraryName(), sharedLibraryEntry.getLibraryLevel());
if (library != null) {
librariesToAdd.put(library, true);
}
}
}
String originalName = editor.getOriginalName();
if (originalName != null && !originalName.equals(editor.getName())) {
renamedConfigs.put(Pair.create(module.getName(), originalName), editor.getName());
}
}
final Sdk sdk;
if (sdkNames.isEmpty()) {
sdk = null;
} else if (sdkNames.size() == 1) {
sdk = FlexSdkUtils.findFlexOrFlexmojosSdk(sdkNames.iterator().next());
} else {
sdk = new FlexCompositeSdk(ArrayUtil.toStringArray(sdkNames));
}
modifiableModel.setSdk(sdk);
Collection<OrderEntry> entriesToRemove = new ArrayList<>();
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
if (((LibraryOrderEntry) orderEntry).isModuleLevel()) {
LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
if (FlexProjectRootsUtil.isFlexLibrary(library) && !usedModulesLibrariesIds.contains(FlexProjectRootsUtil.getLibraryId(library))) {
entriesToRemove.add(orderEntry);
}
} else {
LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
if (librariesToAdd.containsKey(library)) {
// entry already exists for this library
librariesToAdd.put(library, false);
} else if (library != null && FlexProjectRootsUtil.isFlexLibrary(library)) {
entriesToRemove.add(orderEntry);
}
}
}
}
for (OrderEntry e : entriesToRemove) {
modifiableModel.removeOrderEntry(e);
}
for (Library library : librariesToAdd.keySet()) {
if (!((LibraryEx) library).isDisposed() && librariesToAdd.get(library) && myProvider.findSourceLibrary(library.getName(), library.getTable().getTableLevel()) != null) {
modifiableModel.addLibraryEntry(library);
}
}
// ---------------- modules entries ----------------------
final Set<Module> modulesToAdd = new THashSet<>();
for (Editor editor : myModule2Editors.get(module)) {
for (DependencyEntry dependencyEntry : editor.getDependencies().getEntries()) {
if (dependencyEntry instanceof BuildConfigurationEntry) {
final Module dependencyModule = findModuleWithBC((BuildConfigurationEntry) dependencyEntry);
if (dependencyModule != null && dependencyModule != module) {
modulesToAdd.add(dependencyModule);
}
}
}
}
List<OrderEntry> moduleOrderEntriesToRemove = ContainerUtil.filter(modifiableModel.getOrderEntries(), orderEntry -> orderEntry instanceof ModuleOrderEntry && !modulesToAdd.remove(((ModuleOrderEntry) orderEntry).getModule()));
for (OrderEntry orderEntry : moduleOrderEntriesToRemove) {
modifiableModel.removeOrderEntry(orderEntry);
}
for (Module moduleToAdd : modulesToAdd) {
modifiableModel.addModuleOrderEntry(moduleToAdd);
}
for (OrderEntry entry : modifiableModel.getOrderEntries()) {
if (entry instanceof ExportableOrderEntry) {
// transitiveness will be filtered out in FlexOrderEnumeratorHandler if needed
((ExportableOrderEntry) entry).setExported(true);
}
}
}
// ---------------- do commit ----------------------
Collection<Module> modulesWithChangedModifiableModel = ContainerUtil.findAll(myModule2Editors.keySet(), module -> myProvider.getModuleModifiableModel(module).isChanged());
if (!modulesWithChangedModifiableModel.isEmpty()) {
myProvider.commitModifiableModels();
myModulesModelChangeEventDispatcher.getMulticaster().modulesModelsChanged(modulesWithChangedModifiableModel);
}
ApplicationManager.getApplication().runWriteAction(() -> {
for (Module module : myModule2Editors.keySet()) {
Function<Editor, FlexBuildConfigurationImpl> f = editor -> editor.commit();
FlexBuildConfigurationImpl[] current = ContainerUtil.map2Array(myModule2Editors.get(module), FlexBuildConfigurationImpl.class, f);
((FlexBuildConfigurationManagerImpl) FlexBuildConfigurationManager.getInstance(module)).setBuildConfigurations(current);
}
if (myProject != null) {
FlexBuildConfigurationManagerImpl.resetHighlighting(myProject);
if (!renamedConfigs.isEmpty()) {
myProject.getMessageBus().syncPublisher(FlexBuildConfigurationChangeListener.TOPIC).buildConfigurationsRenamed(renamedConfigs);
}
}
});
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-plugins by JetBrains.
the class FlexProjectConfigurationEditor method copyModuleLibrary.
private static LibraryEx copyModuleLibrary(final ModifiableRootModel modifiableModel, final LibraryEx library) {
LibraryTable.ModifiableModel librariesModifiableModel = getTableModifiableModel(modifiableModel);
LibraryEx libraryCopy = (LibraryEx) librariesModifiableModel.createLibrary(library.getName(), library.getKind());
LibraryEx.ModifiableModelEx libraryCopyModel = libraryCopy.getModifiableModel();
// will overwrite library id
LibraryEditingUtil.copyLibrary(library, Collections.emptyMap(), libraryCopyModel);
// do assign unique library id
libraryCopyModel.setProperties(new FlexLibraryProperties(FlexLibraryIdGenerator.generateId()));
libraryCopyModel.commit();
return libraryCopy;
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-plugins by JetBrains.
the class FlexOrderEnumerationHandler method shouldAddDependency.
@NotNull
@Override
public AddDependencyType shouldAddDependency(@NotNull OrderEntry orderEntry, @NotNull OrderEnumeratorSettings settings) {
Module module = orderEntry.getOwnerModule();
if (ModuleType.get(module) != FlexModuleType.getInstance()) {
return super.shouldAddDependency(orderEntry, settings);
}
if (orderEntry instanceof ModuleSourceOrderEntry) {
return AddDependencyType.DEFAULT;
}
if (orderEntry instanceof JdkOrderEntry) {
if (module != myRootModule) {
// never add transitive dependency to Flex SDK
return AddDependencyType.DO_NOT_ADD;
}
if (myActiveConfigurations == null) {
return AddDependencyType.DEFAULT;
}
ModuleData moduleData = myActiveConfigurations.get(module);
for (FlexBuildConfiguration bc : moduleData.bcs) {
if (bc.getSdk() != null) {
return AddDependencyType.DEFAULT;
}
}
return AddDependencyType.DO_NOT_ADD;
}
Collection<FlexBuildConfiguration> accessibleConfigurations;
if (myActiveConfigurations != null) {
ModuleData moduleData = myActiveConfigurations.get(module);
accessibleConfigurations = moduleData != null ? moduleData.bcs : Collections.emptyList();
} else {
// let all configurations be accessible in ProjectOrderEnumerator
accessibleConfigurations = Arrays.asList(FlexBuildConfigurationManager.getInstance(module).getBuildConfigurations());
}
if (orderEntry instanceof LibraryOrderEntry) {
final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
if (library == null) {
return AddDependencyType.DEFAULT;
}
if (library.getKind() == FlexLibraryType.FLEX_LIBRARY) {
return FlexProjectRootsUtil.dependOnLibrary(accessibleConfigurations, library, module != myRootModule, settings.isProductionOnly()) ? AddDependencyType.DEFAULT : AddDependencyType.DO_NOT_ADD;
} else {
// foreign library
return AddDependencyType.DO_NOT_ADD;
}
} else if (orderEntry instanceof ModuleOrderEntry) {
final Module dependencyModule = ((ModuleOrderEntry) orderEntry).getModule();
if (dependencyModule == null) {
return AddDependencyType.DO_NOT_ADD;
}
if (myActiveConfigurations != null) {
ModuleData moduleData = myActiveConfigurations.get(dependencyModule);
return moduleData != null && (moduleData.accessibleInProduction || !settings.isProductionOnly()) ? AddDependencyType.DEFAULT : AddDependencyType.DO_NOT_ADD;
} else {
// let all modules dependencies be accessible in ProjectOrderEnumerator
return AddDependencyType.DEFAULT;
}
} else {
return AddDependencyType.DEFAULT;
}
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-plugins by JetBrains.
the class FlexProjectConfigurationEditor method copyConfiguration.
public ModifiableFlexBuildConfiguration copyConfiguration(ModifiableFlexBuildConfiguration configuration, BuildConfigurationNature newNature) {
assertAlive();
Module module = ((Editor) configuration).myModule;
List<Editor> editors = myModule2Editors.get(module);
FlexBuildConfigurationImpl copy = ((Editor) configuration).getCopy();
DependencyEntry[] entries = copy.getDependencies().getEntries();
ModifiableRootModel modifiableModel = myProvider.getModuleModifiableModel(module);
for (int i = 0; i < entries.length; i++) {
if (entries[i] instanceof ModuleLibraryEntryImpl) {
ModuleLibraryEntryImpl e = (ModuleLibraryEntryImpl) entries[i];
LibraryEx library = findLibrary(modifiableModel, e.getLibraryId());
if (library != null) {
LibraryEx libraryCopy = copyModuleLibrary(modifiableModel, library);
ModuleLibraryEntryImpl entryCopy = new ModuleLibraryEntryImpl(FlexProjectRootsUtil.getLibraryId(libraryCopy));
e.getDependencyType().applyTo(entryCopy.getDependencyType());
copy.getDependencies().getModifiableEntries().set(i, entryCopy);
}
}
}
Editor newConfig = new Editor(module, copy, false);
newConfig.setNature(newNature);
// just to simplify serialized view
resetNonApplicableValuesToDefaults(newConfig);
editors.add(newConfig);
return newConfig;
}
use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-plugins by JetBrains.
the class JstdLibraryUtil method doesCorrectJstdLibExist.
private static boolean doesCorrectJstdLibExist(@NotNull final Project project) {
Boolean correctJstdLibExists = JSTD_LIBRARY_EXISTS;
if (correctJstdLibExists == null) {
correctJstdLibExists = ReadAction.compute(() -> {
VirtualFile libVirtualFile = VfsUtil.findFileByURL(JstdDefaultAssertionFrameworkSrcMarker.class.getResource("TestCase.js"));
if (libVirtualFile == null) {
return false;
}
JSLibraryManager libraryManager = JSLibraryManager.getInstance(project);
for (ScriptingLibraryModel libraryModel : libraryManager.getAllLibraries()) {
if (libraryModel == null) {
continue;
}
String libraryName = libraryModel.getName();
if (libraryName != null && libraryName.startsWith(LIBRARY_NAME)) {
Library library = libraryModel.getOriginalLibrary();
if (library instanceof LibraryEx) {
LibraryEx libraryEx = (LibraryEx) library;
if (libraryEx.isDisposed()) {
continue;
}
}
if (libraryModel.containsFile(libVirtualFile)) {
return true;
}
}
}
return false;
});
JSTD_LIBRARY_EXISTS = correctJstdLibExists;
}
return correctJstdLibExists;
}
Aggregations