Search in sources :

Example 1 with ProjectComponentReferenceCounter

use of com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter in project intellij-plugins by JetBrains.

the class AppTestBase method launchAndInitializeApplication.

private void launchAndInitializeApplication() throws Exception {
    if (DesignerApplicationManager.getInstance().isApplicationClosed()) {
        changeServicesImplementation();
        new DesignerApplicationLauncher(myModule, new DesignerApplicationLauncher.PostTask() {

            @Override
            public boolean run(Module module, ProjectComponentReferenceCounter projectComponentReferenceCounter, ProgressIndicator indicator, ProblemsHolder problemsHolder) {
                assertTrue(DocumentProblemManager.getInstance().toString(problemsHolder.getProblems()), problemsHolder.isEmpty());
                client = (TestClient) Client.getInstance();
                client.flush();
                try {
                    assertAfterInitLibrarySets(projectComponentReferenceCounter.unregistered);
                } catch (IOException e) {
                    throw new AssertionError(e);
                }
                return true;
            }
        }).run(new EmptyProgressIndicator());
    } else {
        client = (TestClient) Client.getInstance();
        ProblemsHolder problemsHolder = new ProblemsHolder();
        ProjectComponentReferenceCounter projectComponentReferenceCounter = LibraryManager.getInstance().registerModule(myModule, problemsHolder, isRequireLocalStyleHolder());
        assertTrue(problemsHolder.isEmpty());
        assertAfterInitLibrarySets(projectComponentReferenceCounter.unregistered);
    }
    socketInputHandler = (TestSocketInputHandler) SocketInputHandler.getInstance();
    applicationLaunchedAndInitialized();
}
Also used : ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) Module(com.intellij.openapi.module.Module)

Example 2 with ProjectComponentReferenceCounter

use of com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter in project intellij-plugins by JetBrains.

the class ModuleInfoUtil method collectApplicationLocalStyle.

@Nullable
private static List<LocalStyleHolder> collectApplicationLocalStyle(final Module module, String flexSdkVersion, final ProblemsHolder problemsHolder, StringWriter stringWriter, ProjectComponentReferenceCounter projectComponentReferenceCounter, final AssetCounter assetCounter) {
    GlobalSearchScope moduleWithDependenciesAndLibrariesScope = module.getModuleWithDependenciesAndLibrariesScope(false);
    final List<JSClass> holders = new ArrayList<>(2);
    if (flexSdkVersion.charAt(0) > '3') {
        JSClass clazz = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.SPARK_APPLICATION, moduleWithDependenciesAndLibrariesScope));
        // it is not legal case, but user can use patched/modified Flex SDK
        if (clazz != null) {
            holders.add(clazz);
        }
    }
    JSClass mxApplicationClass = ((JSClass) ActionScriptClassResolver.findClassByQNameStatic(FlexCommonTypeNames.MX_APPLICATION, moduleWithDependenciesAndLibrariesScope));
    // if null, mx.swc is not added to module dependencies
    if (mxApplicationClass != null) {
        holders.add(mxApplicationClass);
    }
    if (holders.isEmpty()) {
        return null;
    }
    final StyleTagWriter styleTagWriter = new StyleTagWriter(new LocalCssWriter(stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
    final List<LocalStyleHolder> result = new ArrayList<>();
    final Processor<JSClass> processor = jsClass -> {
        PsiFile psiFile = jsClass.getNavigationElement().getContainingFile();
        if (!(psiFile instanceof XmlFile)) {
            return true;
        }
        XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if (rootTag == null) {
            return true;
        }
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        problemsHolder.setCurrentFile(virtualFile);
        try {
            for (final XmlTag subTag : rootTag.getSubTags()) {
                if (subTag.getNamespace().equals(JavaScriptSupportLoader.MXML_URI3) && subTag.getLocalName().equals(FlexPredefinedTagNames.STYLE)) {
                    try {
                        LocalStyleHolder localStyleHolder = styleTagWriter.write(subTag, module, virtualFile);
                        if (localStyleHolder != null) {
                            result.add(localStyleHolder);
                        }
                    } catch (InvalidPropertyException e) {
                        problemsHolder.add(e);
                    }
                }
            }
        } finally {
            problemsHolder.setCurrentFile(null);
        }
        return true;
    };
    final GlobalSearchScope moduleScope = module.getModuleScope(false);
    for (JSClass holder : holders) {
        JSClassSearch.searchClassInheritors(holder, true, moduleScope).forEach(processor);
    }
    return result;
}
Also used : StringWriter(com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Application(com.intellij.openapi.application.Application) JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) XmlFile(com.intellij.psi.xml.XmlFile) FlexPredefinedTagNames(com.intellij.javascript.flex.FlexPredefinedTagNames) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FlexCommonTypeNames(com.intellij.javascript.flex.mxml.FlexCommonTypeNames) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) JSClassSearch(com.intellij.lang.javascript.search.JSClassSearch) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) AccessToken(com.intellij.openapi.application.AccessToken) MxmlUtil(com.intellij.flex.uiDesigner.mxml.MxmlUtil) Semaphore(com.intellij.util.concurrency.Semaphore) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) Project(com.intellij.openapi.project.Project) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Module(com.intellij.openapi.module.Module) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StylesheetFile(com.intellij.psi.css.StylesheetFile) XmlTag(com.intellij.psi.xml.XmlTag) DumbService(com.intellij.openapi.project.DumbService) XmlAttribute(com.intellij.psi.xml.XmlAttribute) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Library(com.intellij.flex.uiDesigner.libraries.Library) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Collections(java.util.Collections) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalCssWriter(com.intellij.flex.uiDesigner.css.LocalCssWriter) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ProjectComponentReferenceCounter

use of com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter 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;
}
Also used : ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) Notification(com.intellij.notification.Notification) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) SortResult(com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ProjectComponentReferenceCounter

use of com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter in project intellij-plugins by JetBrains.

the class DesignerApplicationLauncher method doRun.

@Override
protected boolean doRun(@NotNull final ProgressIndicator indicator) throws IOException, java.util.concurrent.ExecutionException, InterruptedException, TimeoutException {
    indicator.setText(FlashUIDesignerBundle.message("copying.app.files"));
    copyAppFiles();
    indicator.setText(FlashUIDesignerBundle.message("finding.suitable.air.runtime"));
    List<AdlRunConfiguration> adlRunConfigurations = getSuitableAdlRunConfigurations();
    if (adlRunConfigurations.isEmpty()) {
        notifyNoSuitableSdkToLaunch();
        return false;
    }
    indicator.checkCanceled();
    DesignerApplicationManager.getInstance().setApplication(new DesignerApplication());
    runInitializeLibrariesAndModuleThread();
    if (debug && !runAndWaitDebugger()) {
        return false;
    }
    indicator.checkCanceled();
    MessageSocketManager messageSocketManager = new MessageSocketManager(this, DesignerApplicationManager.APP_DIR);
    Disposer.register(DesignerApplicationManager.getApplication(), messageSocketManager);
    final List<String> arguments = new ArrayList<>();
    arguments.add(Integer.toString(messageSocketManager.listen()));
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        arguments.add("-p");
        arguments.add(DebugPathManager.resolveTestArtifactPath("test-1.0-SNAPSHOT.swf"));
    }
    AdlProcessHandler adlProcessHandler = null;
    final Ref<Boolean> found = new Ref<>(true);
    for (AdlRunConfiguration adlRunConfiguration : adlRunConfigurations) {
        found.set(true);
        adlRunConfiguration.arguments = arguments;
        try {
            final String appClassifierVersion;
            if (StringUtil.compareVersionNumbers(adlRunConfiguration.getRuntimeVersion(), "3.0") < 0 || !(SystemInfo.isMac || SystemInfo.isWindows)) {
                appClassifierVersion = "2.6";
            } else {
                appClassifierVersion = "3.0";
            }
            adlProcessHandler = runAdl(adlRunConfiguration, DesignerApplicationManager.APP_DIR.getPath() + File.separatorChar + "descriptor-air" + appClassifierVersion + ".xml", exitCode -> {
                found.set(false);
                if (!indicator.isCanceled()) {
                    LOG.info(describeAdlExit(exitCode));
                    semaphore.up();
                }
            });
        } catch (ExecutionException e) {
            adlProcessHandler = null;
            LOG.error(e);
            continue;
        }
        semaphore.down();
        try {
            if (!semaphore.waitForUnsafe(60 * 1000)) {
                found.set(false);
                LOG.warn("Client not opened in 60 seconds");
                if (checkStartupError()) {
                    return false;
                }
            }
        } catch (InterruptedException e) {
            if (indicator.isCanceled()) {
                return false;
            }
            LOG.warn(e);
            continue;
        }
        indicator.checkCanceled();
        if (found.get()) {
            break;
        }
    }
    if (!found.get()) {
        if (!checkStartupError()) {
            notifyNoSuitableSdkToLaunch();
        }
        return false;
    }
    ProjectComponentReferenceCounter projectComponentReferenceCounter = initializeTask.get(DebugPathManager.IS_DEV ? 999 : 60, TimeUnit.SECONDS);
    indicator.checkCanceled();
    final DesignerApplication application = DesignerApplicationManager.getApplication();
    LOG.assertTrue(adlProcessHandler != null && application != null);
    application.setProcessHandler(adlProcessHandler);
    DesignerApplicationManager.getInstance().attachProjectAndModuleListeners(application);
    return postTask.run(module, projectComponentReferenceCounter, indicator, problemsHolder);
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IOUtil(com.intellij.flex.uiDesigner.io.IOUtil) Semaphore(com.intellij.util.concurrency.Semaphore) InitException(com.intellij.flex.uiDesigner.libraries.InitException) Disposer(com.intellij.openapi.util.Disposer) FileUtil(com.intellij.openapi.util.io.FileUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) Module(com.intellij.openapi.module.Module) OutputStream(java.io.OutputStream) DumbService(com.intellij.openapi.project.DumbService) ProjectJdksEditor(com.intellij.openapi.projectRoots.ui.ProjectJdksEditor) StringUtil(com.intellij.openapi.util.text.StringUtil) MessageSocketManager(com.intellij.flex.uiDesigner.io.MessageSocketManager) WindowManager(com.intellij.openapi.wm.WindowManager) IOException(java.io.IOException) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) LibraryManager(com.intellij.flex.uiDesigner.libraries.LibraryManager) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AdlUtil(com.intellij.flex.uiDesigner.AdlUtil) Ref(com.intellij.openapi.util.Ref) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) ArrayList(java.util.ArrayList) MessageSocketManager(com.intellij.flex.uiDesigner.io.MessageSocketManager) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Ref(com.intellij.openapi.util.Ref) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with ProjectComponentReferenceCounter

use of com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter in project intellij-plugins by JetBrains.

the class ComplexRenderAction method updateLocalStyleSources.

private void updateLocalStyleSources(final Client client, final THashMap<ModuleInfo, List<LocalStyleHolder>> localStyleSources) {
    final ProblemsHolder problemsHolder = new ProblemsHolder();
    final ProjectComponentReferenceCounter projectComponentReferenceCounter = new ProjectComponentReferenceCounter();
    localStyleSources.forEachEntry(new TObjectObjectProcedure<ModuleInfo, List<LocalStyleHolder>>() {

        @Override
        public boolean execute(ModuleInfo moduleInfo, List<LocalStyleHolder> b) {
            try {
                List<LocalStyleHolder> oldList = moduleInfo.getLocalStyleHolders();
                if (oldList == null) {
                    oldList = Collections.emptyList();
                }
                FlexLibrarySet flexLibrarySet = moduleInfo.getFlexLibrarySet();
                final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter();
                stringWriter.startChange();
                try {
                    List<LocalStyleHolder> list = ModuleInfoUtil.collectLocalStyle(moduleInfo, flexLibrarySet.getVersion(), stringWriter, problemsHolder, projectComponentReferenceCounter, flexLibrarySet.assetCounterInfo.demanded);
                    // todo we shouldn't create list, we should check while collecting
                    boolean hasChanges = true;
                    if (list.size() == oldList.size()) {
                        int diff = list.size();
                        for (LocalStyleHolder holder : list) {
                            if (oldList.contains(holder)) {
                                diff--;
                            }
                        }
                        hasChanges = diff != 0;
                    }
                    if (hasChanges) {
                        moduleInfo.setLocalStyleHolders(list);
                        client.fillAssetClassPoolIfNeed(flexLibrarySet);
                        client.updateLocalStyleHolders(localStyleSources, stringWriter);
                        if (projectComponentReferenceCounter.hasUnregistered()) {
                            client.registerDocumentReferences(projectComponentReferenceCounter.unregistered, null, problemsHolder);
                        }
                    } else {
                        stringWriter.rollback();
                        localStyleSources.remove(moduleInfo);
                    }
                } catch (Throwable e) {
                    stringWriter.rollback();
                    LOG.error(e);
                }
            } catch (Throwable e) {
                LOG.error(e);
            }
            return true;
        }
    });
    if (!problemsHolder.isEmpty() && reportProblems) {
        DocumentProblemManager.getInstance().report(null, problemsHolder);
    }
}
Also used : ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) FlexLibrarySet(com.intellij.flex.uiDesigner.libraries.FlexLibrarySet) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 StringRegistry (com.intellij.flex.uiDesigner.io.StringRegistry)3 AccessToken (com.intellij.openapi.application.AccessToken)3 Module (com.intellij.openapi.module.Module)3 NotNull (org.jetbrains.annotations.NotNull)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 DumbService (com.intellij.openapi.project.DumbService)2 Project (com.intellij.openapi.project.Project)2 Semaphore (com.intellij.util.concurrency.Semaphore)2 IOException (java.io.IOException)2 ExecutionException (com.intellij.execution.ExecutionException)1 AdlUtil (com.intellij.flex.uiDesigner.AdlUtil)1 LocalCssWriter (com.intellij.flex.uiDesigner.css.LocalCssWriter)1 IOUtil (com.intellij.flex.uiDesigner.io.IOUtil)1 MessageSocketManager (com.intellij.flex.uiDesigner.io.MessageSocketManager)1 StringWriter (com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter)1