Search in sources :

Example 1 with ProjectException

use of org.moe.document.pbxproj.ProjectException in project moe-ide-integration by multi-os-engine.

the class XcodeEditor method initManagers.

private void initManagers(VirtualFile virtualFile) {
    this.fileDocumentManager = FileDocumentManager.getInstance();
    this.xcodeProjectDocument = fileDocumentManager.getDocument(virtualFile);
    xcodeProjectDocument.addDocumentListener(new com.intellij.openapi.editor.event.DocumentListener() {

        @Override
        public void beforeDocumentChange(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
        }

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
            reloadXcodeProjectFile();
        }
    });
    try {
        this.xcodeEditorManager = new XcodeEditorManager(null, xcodeProjectDocument.getText());
    } catch (ProjectException e) {
        e.printStackTrace();
    }
    xcodeEditorManager.setListener(new DocumentChangeListener() {

        @Override
        public void documentChanged() {
            saveXcodeDocument();
        }
    });
    this.projectName = EditorUtil.getXcodeProjectName(new File(virtualFile.getPath()));
    xcodeEditorManager.setProjectName(projectName);
    String root = virtualFile.getParent().getParent().getPath();
    File mainInfoPlist = getFileFromXcodeConfiguration(root, xcodeEditorManager.getInfoMainPlist());
    VirtualFile mainInfoVirtualFile = project.getBaseDir().getFileSystem().findFileByPath(mainInfoPlist.getAbsolutePath());
    this.mainInfoPlistDocument = fileDocumentManager.getDocument(mainInfoVirtualFile);
    try {
        this.mainInfoPlistManager = new InfoPlistManager(mainInfoPlistDocument.getText());
    } catch (Exception e) {
        LOG.error("Unable read main Info.plist", e);
    }
    mainInfoPlistManager.setListener(new DocumentChangeListener() {

        @Override
        public void documentChanged() {
            saveMainInfoPlistDocument();
        }
    });
    mainInfoPlistDocument.addDocumentListener(new com.intellij.openapi.editor.event.DocumentListener() {

        @Override
        public void beforeDocumentChange(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
        }

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
            reloadMainInfoPlist();
        }
    });
    File testInfoPlist = getFileFromXcodeConfiguration(root, xcodeEditorManager.getInfoTestPlist());
    VirtualFile testInfoVirtualFile = project.getBaseDir().getFileSystem().findFileByPath(testInfoPlist.getAbsolutePath());
    this.testInfoPlistDocument = fileDocumentManager.getDocument(testInfoVirtualFile);
    try {
        this.testInfoPlistManager = new InfoPlistManager(testInfoPlistDocument.getText());
    } catch (Exception e) {
        LOG.error("Unable read test Info.plist", e);
    }
    testInfoPlistManager.setListener(new DocumentChangeListener() {

        @Override
        public void documentChanged() {
            saveTestInfoPlistDocument();
        }
    });
    testInfoPlistDocument.addDocumentListener(new com.intellij.openapi.editor.event.DocumentListener() {

        @Override
        public void beforeDocumentChange(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
        }

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent documentEvent) {
            reloadTestInfoPlist();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectException(org.moe.document.pbxproj.ProjectException) ProjectException(org.moe.document.pbxproj.ProjectException) XcodeEditorManager(org.moe.editors.XcodeEditorManager) DocumentChangeListener(org.moe.editors.DocumentChangeListener) InfoPlistManager(org.moe.editors.InfoPlistManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with ProjectException

use of org.moe.document.pbxproj.ProjectException in project moe-ide-integration by multi-os-engine.

the class GeneratorRunner method run.

private void run() {
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {

        @Override
        public void run() {
            ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
            if (progress == null) {
                progress = new EmptyProgressIndicator();
            }
            progress.pushState();
            try {
                progress.setText(ACTION_PROGRESS_LABEL);
                runInternal(progress);
            } catch (final Throwable t) {
                t.printStackTrace(System.err);
                UIUtil.invokeLaterIfNeeded(new Runnable() {

                    @Override
                    public void run() {
                        String message = t.getMessage();
                        if (message == null || message.length() == 0) {
                            message = "Unknown error";
                        }
                        String title = test ? "Test Binding Error" : "Generate Binding Error";
                        Messages.showErrorDialog(message, title);
                    }
                });
            } finally {
                progress.popState();
            }
        }

        private void runInternal(final ProgressIndicator progress) throws ProjectException, IOException {
            String s = null;
            final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
            toolWindow.clear();
            progress.setFraction(0.1);
            final StringBuilder errorBuilder = new StringBuilder();
            String modulePath = ModuleUtils.getModulePath(module);
            File moduleFile = new File(modulePath);
            progress.setFraction(0.2);
            GradleExec exec = new GradleExec(moduleFile);
            exec.getArguments().add("moeNatJGen");
            exec.getArguments().add("-Draw-binding-output");
            exec.getArguments().add("-Dmoe.binding.conf=" + coonfigurationFile.getPath());
            if (test) {
                exec.getArguments().add("-Dmoe.natjgen.testrun=true");
            }
            if (keep) {
                exec.getArguments().add("-Dmoe.keep.natjgen");
            }
            ExecRunner runner = exec.getRunner();
            runner.getBuilder().directory(moduleFile);
            runner.setListener(new ExecRunnerBase.ExecRunnerListener() {

                @Override
                public void stdout(String line) {
                    toolWindow.printNormalMessage(line + "\n");
                }

                @Override
                public void stderr(String line) {
                    toolWindow.printErrorMessage(line + "\n");
                    errorBuilder.append(line);
                    errorBuilder.append("\n");
                }
            });
            runner.run(new IKillListener() {

                @Override
                public boolean needsKill() {
                    return progress.isCanceled();
                }
            });
            progress.setFraction(0.9);
            module.getProject().getBaseDir().getFileSystem().refresh(true);
            progress.setFraction(1.0);
            final String errorMessage = errorBuilder.toString();
            if (errorMessage == null || errorMessage.isEmpty()) {
                String format = test ? "Test successful" : "Generate successful";
                toolWindow.balloon(MessageType.INFO, format);
            } else {
                String format = test ? "Test Error" : "Generate Error";
                toolWindow.balloon(MessageType.INFO, format);
                UIUtil.invokeLaterIfNeeded(new Runnable() {

                    @Override
                    public void run() {
                        String title = test ? "Test Binding Error" : "Generate Binding Error";
                        Messages.showErrorDialog(errorMessage, title);
                    }
                });
            }
        }
    }, ACTION_TITLE, true, module.getProject());
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IOException(java.io.IOException) ProjectException(org.moe.document.pbxproj.ProjectException) MOEToolWindow(org.moe.idea.ui.MOEToolWindow) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) File(java.io.File)

Aggregations

File (java.io.File)2 ProjectException (org.moe.document.pbxproj.ProjectException)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1 DocumentChangeListener (org.moe.editors.DocumentChangeListener)1 InfoPlistManager (org.moe.editors.InfoPlistManager)1 XcodeEditorManager (org.moe.editors.XcodeEditorManager)1 MOEToolWindow (org.moe.idea.ui.MOEToolWindow)1