use of com.intellij.openapi.options.ConfigurationException 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.options.ConfigurationException in project intellij-plugins by JetBrains.
the class FlexBuildTargetScopeProvider method getBuildTargetScopes.
@NotNull
public List<TargetTypeBuildScope> getBuildTargetScopes(@NotNull final CompileScope baseScope, @NotNull final CompilerFilter filter, @NotNull final Project project, boolean forceBuild) {
final RunConfiguration runConfiguration = CompileStepBeforeRun.getRunConfiguration(baseScope);
final Collection<Pair<Module, FlexBuildConfiguration>> bcsToCompileForPackaging = FlexResourceBuildTargetScopeProvider.getBCsToCompileForPackaging(baseScope);
List<String> targetIds = new ArrayList<>();
try {
for (Pair<Module, FlexBuildConfiguration> moduleAndBC : getModulesAndBCsToCompile(baseScope)) {
final Module module = moduleAndBC.first;
final FlexBuildConfiguration bc = moduleAndBC.second;
if (bcsToCompileForPackaging != null && contains(bcsToCompileForPackaging, module, bc)) {
final boolean forcedDebugStatus = getForcedDebugStatus(project, bc);
targetIds.add(FlexCommonUtils.getBuildTargetId(module.getName(), bc.getName(), forcedDebugStatus));
} else if (bc.isTempBCForCompilation()) {
LOG.assertTrue(runConfiguration instanceof FlashRunConfiguration || runConfiguration instanceof FlexUnitRunConfiguration, bc.getName());
final BCBasedRunnerParameters params = runConfiguration instanceof FlashRunConfiguration ? ((FlashRunConfiguration) runConfiguration).getRunnerParameters() : ((FlexUnitRunConfiguration) runConfiguration).getRunnerParameters();
LOG.assertTrue(params.getModuleName().equals(module.getName()), "Module name in run config: " + params.getModuleName() + ", expected: " + module.getName());
LOG.assertTrue(params.getBCName().equals(bc.getName()), "BC name in run config: " + params.getBCName() + ", expected: " + bc.getName());
targetIds.add(FlexCommonUtils.getBuildTargetIdForRunConfig(runConfiguration.getType().getId(), runConfiguration.getName()));
} else {
targetIds.add(FlexCommonUtils.getBuildTargetId(module.getName(), bc.getName(), null));
}
}
} catch (ConfigurationException e) {
// can't happen because checked in ValidateFlashConfigurationsPrecompileTask
LOG.error(e);
}
if (targetIds.isEmpty()) {
return Collections.emptyList();
}
return Collections.singletonList(CmdlineProtoUtil.createTargetsScope(FlexBuildTargetType.INSTANCE.getTypeId(), targetIds, forceBuild));
}
use of com.intellij.openapi.options.ConfigurationException in project intellij-plugins by JetBrains.
the class FlexBuildTargetScopeProvider method getModulesAndBCsToCompile.
static Collection<Pair<Module, FlexBuildConfiguration>> getModulesAndBCsToCompile(final CompileScope scope) throws ConfigurationException {
final Collection<Pair<Module, FlexBuildConfiguration>> result = new HashSet<>();
final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCsToCompile = FlexResourceBuildTargetScopeProvider.getBCsToCompileForPackaging(scope);
final RunConfiguration runConfiguration = CompileStepBeforeRun.getRunConfiguration(scope);
if (modulesAndBCsToCompile != null) {
for (Pair<Module, FlexBuildConfiguration> moduleAndBC : modulesAndBCsToCompile) {
if (!moduleAndBC.second.isSkipCompile()) {
final FlexBuildConfiguration bcWithForcedDebugStatus = forceDebugStatus(moduleAndBC.first.getProject(), moduleAndBC.second);
result.add(Pair.create(moduleAndBC.first, bcWithForcedDebugStatus));
appendBCDependencies(result, moduleAndBC.first, moduleAndBC.second);
}
}
} else if (runConfiguration instanceof FlashRunConfiguration || runConfiguration instanceof FlexUnitRunConfiguration) {
final BCBasedRunnerParameters params = runConfiguration instanceof FlashRunConfiguration ? ((FlashRunConfiguration) runConfiguration).getRunnerParameters() : ((FlexUnitRunConfiguration) runConfiguration).getRunnerParameters();
final Pair<Module, FlexBuildConfiguration> moduleAndBC;
final Ref<RuntimeConfigurationError> exceptionRef = new Ref<>();
moduleAndBC = ApplicationManager.getApplication().runReadAction((NullableComputable<Pair<Module, FlexBuildConfiguration>>) () -> {
try {
return params.checkAndGetModuleAndBC(runConfiguration.getProject());
} catch (RuntimeConfigurationError e) {
exceptionRef.set(e);
return null;
}
});
if (!exceptionRef.isNull()) {
throw new ConfigurationException(exceptionRef.get().getMessage(), FlexBundle.message("run.configuration.0", runConfiguration.getName()));
}
if (!moduleAndBC.second.isSkipCompile()) {
result.add(moduleAndBC);
appendBCDependencies(result, moduleAndBC.first, moduleAndBC.second);
}
} else {
for (final Module module : scope.getAffectedModules()) {
if (module.isDisposed() || ModuleType.get(module) != FlexModuleType.getInstance())
continue;
for (final FlexBuildConfiguration bc : FlexBuildConfigurationManager.getInstance(module).getBuildConfigurations()) {
if (!bc.isSkipCompile()) {
result.add(Pair.create(module, bc));
}
}
}
}
return result;
}
use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.
the class SdkUpdaterConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
myPanel.saveSources();
HtmlBuilder message = new HtmlBuilder();
message.openHtmlBody();
final List<LocalPackage> toDelete = Lists.newArrayList();
final Map<RemotePackage, UpdatablePackage> requestedPackages = Maps.newHashMap();
for (PackageNodeModel model : myPanel.getStates()) {
if (model.getState() == PackageNodeModel.SelectedState.NOT_INSTALLED) {
if (model.getPkg().hasLocal()) {
toDelete.add(model.getPkg().getLocal());
}
} else if (model.getState() == PackageNodeModel.SelectedState.INSTALLED && (model.getPkg().isUpdate() || !model.getPkg().hasLocal())) {
UpdatablePackage pkg = model.getPkg();
requestedPackages.put(pkg.getRemote(), pkg);
}
}
boolean found = false;
if (!toDelete.isEmpty()) {
found = true;
message.add("The following components will be deleted: \n");
message.beginList();
for (LocalPackage item : toDelete) {
message.listItem().add(item.getDisplayName()).add(", Revision: ").add(item.getVersion().toString());
}
message.endList();
}
if (!requestedPackages.isEmpty()) {
found = true;
message.add("The following components will be installed: \n");
message.beginList();
Multimap<RemotePackage, RemotePackage> dependencies = HashMultimap.create();
ProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
RepositoryPackages packages = getRepoManager().getPackages();
for (RemotePackage item : requestedPackages.keySet()) {
List<RemotePackage> packageDependencies = InstallerUtil.computeRequiredPackages(ImmutableList.of(item), packages, progress);
if (packageDependencies == null) {
Messages.showErrorDialog((Project) null, "Unable to resolve dependencies for " + item.getDisplayName(), "Dependency Error");
throw new ConfigurationException("Unable to resolve dependencies.");
}
for (RemotePackage dependency : packageDependencies) {
dependencies.put(dependency, item);
}
message.listItem().add(String.format("%1$s %2$s %3$s", item.getDisplayName(), item.getTypeDetails() instanceof DetailsTypes.ApiDetailsType ? "revision" : "version", item.getVersion()));
}
for (RemotePackage dependency : dependencies.keySet()) {
if (requestedPackages.containsKey(dependency)) {
continue;
}
Set<RemotePackage> requests = Sets.newHashSet(dependencies.get(dependency));
requests.remove(dependency);
if (!requests.isEmpty()) {
message.listItem().add(dependency.getDisplayName()).add(" (Required by ");
Iterator<RemotePackage> requestIterator = requests.iterator();
message.add(requestIterator.next().getDisplayName());
while (requestIterator.hasNext()) {
message.add(", ").add(requestIterator.next().getDisplayName());
}
message.add(")");
}
}
message.endList();
}
message.closeHtmlBody();
if (found) {
if (confirmChange(message)) {
if (!requestedPackages.isEmpty() || !toDelete.isEmpty()) {
ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPackages(myPanel.getComponent(), requestedPackages.values(), toDelete, true);
if (dialog != null) {
dialog.show();
for (RemotePackage remotePackage : requestedPackages.keySet()) {
PackageOperation installer = getRepoManager().getInProgressInstallOperation(remotePackage);
if (installer != null) {
PackageOperation.StatusChangeListener listener = (installer1, progress) -> myPanel.getComponent().repaint();
myListeners.add(listener);
installer.registerStateChangeListener(listener);
}
}
}
}
myPanel.refresh();
} else {
throw new ConfigurationException("Installation was canceled.");
}
} else {
// We didn't have any changes, so just reload (maybe the channel changed).
myChannelChangedCallback.run();
}
}
use of com.intellij.openapi.options.ConfigurationException in project intellij-community by JetBrains.
the class SettingsEditor method updateStatus.
void updateStatus(Configurable configurable) {
myFilter.updateSpotlight(configurable == null);
if (myBanner != null) {
myBanner.setProject(myTreeView.findConfigurableProject(configurable));
myBanner.setText(myTreeView.getPathNames(configurable));
}
if (myEditor != null) {
ConfigurationException exception = myFilter.myContext.getErrors().get(configurable);
myEditor.getApplyAction().setEnabled(!myFilter.myContext.getModified().isEmpty());
myEditor.getResetAction().setEnabled(myFilter.myContext.isModified(configurable) || exception != null);
myEditor.setError(exception);
myEditor.revalidate();
}
if (configurable != null) {
new Alarm().addRequest(() -> {
if (!myDisposed && mySpotlightPainter != null) {
mySpotlightPainter.updateNow();
}
}, 300);
}
}
Aggregations