use of com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk in project intellij-plugins by JetBrains.
the class FlexCompositeSdkProjectViewStructureProvider method modify.
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (!(parent instanceof ExternalLibrariesNode)) {
return children;
}
Set<Sdk> processedSdks = new HashSet<>();
Collection<AbstractTreeNode> result = new ArrayList<>();
for (AbstractTreeNode child : children) {
Object value = child.getValue();
if (!(value instanceof NamedLibraryElement)) {
result.add(child);
continue;
}
NamedLibraryElement libraryElement = (NamedLibraryElement) value;
OrderEntry orderEntry = libraryElement.getOrderEntry();
if (!(orderEntry instanceof JdkOrderEntry)) {
result.add(child);
continue;
}
Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (!(sdk instanceof FlexCompositeSdk)) {
result.add(child);
continue;
}
Sdk[] sdks = ((FlexCompositeSdk) sdk).getSdks();
for (Sdk individualSdk : sdks) {
if (processedSdks.add(individualSdk)) {
IndividualSdkOrderEntry entry = new IndividualSdkOrderEntry(individualSdk, orderEntry.getOwnerModule());
result.add(new NamedLibraryElementNode(parent.getProject(), new NamedLibraryElement(null, entry), ((ExternalLibrariesNode) parent).getSettings()));
}
}
}
return result;
}
use of com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk 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);
}
}
});
}
Aggregations