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();
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations