use of com.intellij.openapi.application.AccessToken in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoProjectModelConverterProvider method convertSdks.
private static void convertSdks() {
ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
Collection<String> globalGoPathUrls = ContainerUtil.newLinkedHashSet();
Collection<Sdk> sdksToDelete = ContainerUtil.newArrayList();
Collection<Sdk> sdksToAdd = ContainerUtil.newArrayList();
GoSdkType sdkType = GoSdkType.getInstance();
for (Sdk sdk : sdkTable.getAllJdks()) {
String sdkTypeName = sdk.getSdkType().getName();
if (isGoSdkType(sdkTypeName)) {
sdksToDelete.add(sdk);
String sdkHome = sdkType.adjustSelectedSdkHome(sdk.getHomePath());
if (sdkType.isValidSdkHome(sdkHome)) {
ProjectJdkImpl newSdk = new ProjectJdkImpl(sdk.getName(), sdkType, sdkHome, sdkType.getVersionString(sdkHome));
sdkType.setupSdkPaths(newSdk);
sdksToAdd.add(newSdk);
for (String classesRoot : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
if (!classesRoot.equals(sdk.getHomePath())) {
globalGoPathUrls.add(classesRoot);
}
}
}
}
}
for (VirtualFile file : GoSdkUtil.getGoPathsRootsFromEnvironment()) {
globalGoPathUrls.remove(file.getUrl());
}
AccessToken l = WriteAction.start();
try {
for (Sdk sdk : sdksToDelete) {
sdkTable.removeJdk(sdk);
}
for (Sdk sdk : sdksToAdd) {
sdkTable.addJdk(sdk);
}
globalGoPathUrls.addAll(GoApplicationLibrariesService.getInstance().getLibraryRootUrls());
GoApplicationLibrariesService.getInstance().setLibraryRootUrls(globalGoPathUrls);
} finally {
l.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project android by JetBrains.
the class ProjectStructureConfigurable method reset.
@Override
public void reset() {
AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure");
try {
mySdksConfigurable.reset();
Configurable toSelect = null;
for (Configurable each : myConfigurables) {
if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) {
toSelect = each;
}
if (each instanceof MasterDetailsComponent) {
((MasterDetailsComponent) each).setHistory(myHistory);
}
each.reset();
}
myHistory.clear();
if (toSelect == null && !myConfigurables.isEmpty()) {
toSelect = myConfigurables.get(0);
}
removeSelected();
navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false);
if (myUiState.proportion > 0) {
mySplitter.setProportion(myUiState.proportion);
}
} finally {
token.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project android by JetBrains.
the class AndroidProjectStructureConfigurable method reset.
@Override
public void reset() {
// Need this to ensure VFS operations will not block because of storage flushing and other maintenance IO tasks run in background.
AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting project structure");
try {
for (Configurable configurable : myConfigurables) {
configurable.reset();
}
if (myUiInitialized) {
validateState();
// Prepare module entries but don't add them until after developer services
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module[] modules = moduleManager.getModules();
Arrays.sort(modules, ModuleTypeComparator.INSTANCE);
List<AndroidModuleConfigurable> moduleConfigurables = Lists.newArrayList();
for (Module module : modules) {
AndroidModuleConfigurable configurable = addModule(module);
if (configurable != null) {
moduleConfigurables.add(configurable);
}
}
// Populate the "Developer Services" section
removeServices();
if (Projects.isBuildWithGradle(myProject)) {
DefaultComboBoxModel moduleList = new DefaultComboBoxModel();
for (AndroidModuleConfigurable moduleConfigurable : moduleConfigurables) {
// Collect only Android modules
if (AndroidFacet.getInstance(moduleConfigurable.getModule()) != null) {
moduleList.addElement(moduleConfigurable.getModule());
}
}
if (!myProject.isDefault() && moduleList.getSize() > 0) {
// into that event.
for (int i = 0; i < moduleList.getSize(); i++) {
Module module = (Module) moduleList.getElementAt(i);
for (DeveloperService service : DeveloperServices.getAll(module)) {
service.getContext().restore();
}
}
Module module = (Module) moduleList.getSelectedItem();
Set<ServiceCategory> categories = Sets.newHashSet();
for (DeveloperService s : DeveloperServices.getAll(module)) {
if (!s.getContext().hiddenFromStructureDialog().get()) {
categories.add(s.getCategory());
}
}
ArrayList<ServiceCategory> categoriesSorted = Lists.newArrayList(categories);
Collections.sort(categoriesSorted);
for (ServiceCategory category : categoriesSorted) {
myConfigurables.add(new ServiceCategoryConfigurable(moduleList, category));
}
}
}
// Populate the "Modules" section.
removeModules();
Module toSelect = null;
for (Module module : modules) {
AndroidModuleConfigurable configurable = addModule(module);
if (configurable != null) {
myConfigurables.add(configurable);
if (configurable.getDisplayName().equals(myUiState.lastSelectedConfigurable)) {
toSelect = module;
}
}
}
if (myUiState.proportion > 0) {
mySplitter.setProportion(myUiState.proportion);
}
mySidePanel.reset();
if (toSelect != null) {
mySidePanel.select(toSelect);
} else {
mySidePanel.selectSdk();
}
}
} finally {
token.finish();
}
}
use of com.intellij.openapi.application.AccessToken in project android by JetBrains.
the class CaptureService method deleteBackingFile.
/**
* Deletes the file associated with this capture.
*/
private void deleteBackingFile(@NotNull CaptureHandle captureHandle, @Nullable Capture capture) {
boolean deleted = false;
if (capture != null) {
AccessToken token = WriteAction.start();
try {
capture.getFile().delete(this);
deleted = true;
} catch (Exception ignored) {
} finally {
token.finish();
}
}
if (!deleted) {
//noinspection ResultOfMethodCallIgnored
captureHandle.getFile().delete();
}
}
use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.
the class LibraryManager method registerModule.
@NotNull
public ProjectComponentReferenceCounter registerModule(@NotNull final Module module, ProblemsHolder problemsHolder, boolean collectLocalStyleHolders) throws InitException {
final Project project = module.getProject();
final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter(16384);
stringWriter.startChange();
final AssetCounter assetCounter = new AssetCounter();
final LibraryCollector libraryCollector = new LibraryCollector(this, new LibraryStyleInfoCollector(assetCounter, problemsHolder, module, stringWriter), module);
final Client client;
try {
final AccessToken token = ReadAction.start();
try {
libraryCollector.collect(module);
} finally {
token.finish();
}
client = Client.getInstance();
if (stringWriter.hasChanges()) {
client.updateStringRegistry(stringWriter);
} else {
stringWriter.commit();
}
} catch (Throwable e) {
stringWriter.rollback();
throw new InitException(e, "error.collect.libraries");
}
assert !libraryCollector.sdkLibraries.isEmpty();
final FlexLibrarySet flexLibrarySet = getOrCreateFlexLibrarySet(libraryCollector, assetCounter);
final InfoMap<Project, ProjectInfo> registeredProjects = client.getRegisteredProjects();
ProjectInfo info = registeredProjects.getNullableInfo(project);
if (info == null) {
info = new ProjectInfo(project);
registeredProjects.add(info);
client.openProject(project);
DesignerApplicationManager.getInstance().projectRegistered(project);
}
LibrarySet librarySet;
if (libraryCollector.externalLibraries.isEmpty()) {
librarySet = null;
} else {
final String key = createKey(libraryCollector.externalLibraries, false);
librarySet = librarySets.get(key);
if (librarySet == null) {
final SortResult sortResult = sortLibraries(new LibrarySorter(), libraryCollector, flexLibrarySet.contains, key, false);
librarySet = new LibrarySet(sortResult.id, flexLibrarySet, sortResult.libraries);
registerLibrarySet(key, librarySet);
}
}
final ModuleInfo moduleInfo = new ModuleInfo(module, librarySet == null ? flexLibrarySet : librarySet, ModuleInfoUtil.isApp(module));
final ProjectComponentReferenceCounter projectComponentReferenceCounter = new ProjectComponentReferenceCounter();
if (collectLocalStyleHolders) {
// client.registerModule finalize it
stringWriter.startChange();
try {
moduleInfo.setLocalStyleHolders(ModuleInfoUtil.collectLocalStyle(moduleInfo, libraryCollector.getFlexSdkVersion(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
} catch (Throwable e) {
stringWriter.rollback();
throw new InitException(e, "error.collect.local.style.holders");
}
}
client.registerModule(project, moduleInfo, stringWriter);
client.fillAssetClassPoolIfNeed(flexLibrarySet);
module.getMessageBus().connect(moduleInfo).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
new Notification(FlashUIDesignerBundle.message("plugin.name"), FlashUIDesignerBundle.message("plugin.name"), "Please reopen your project to update on library changes.", NotificationType.WARNING).notify(project);
}
});
return projectComponentReferenceCounter;
}
Aggregations