Search in sources :

Example 41 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.

the class DirectoryWatcherService method hasComp.

private boolean hasComp(String compName) {
    MobileApplication mobileApplication = project.getMobileApplication();
    ApplicationComponent app = (ApplicationComponent) mobileApplication.getApplicationComponent();
    for (UISharedComponent uisc : app.getSharedComponentList()) {
        if (compName.equals(uisc.getName().toLowerCase())) {
            return true;
        }
    }
    return false;
}
Also used : MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)

Example 42 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.

the class NgxBuilder method writeFunctionTempTsFile.

@Override
public void writeFunctionTempTsFile(final IUIComponent uiComponent, String functionMarker) throws EngineException {
    UIComponent uic = (UIComponent) uiComponent;
    try {
        IScriptComponent main = uic.getMainScriptComponent();
        if (main != null) {
            String tempTsFileName = null, tsContent = null;
            File tempTsDir = null;
            UIActionStack sharedAction = null;
            if (main instanceof ApplicationComponent) {
                sharedAction = uic.getSharedAction();
                tempTsDir = sharedAction == null ? appDir : servicesDir;
                tempTsFileName = sharedAction == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
                File appTsFile = sharedAction == null ? new File(appDir, "app.component.ts") : new File(servicesDir, "actionbeans.service.ts");
                synchronized (writtenFiles) {
                    if (writtenFiles.contains(appTsFile)) {
                        File appTsFileTmp = toTmpFile(appTsFile);
                        if (appTsFileTmp.exists()) {
                            appTsFile = appTsFileTmp;
                        }
                    }
                }
                tsContent = FileUtils.readFileToString(appTsFile, "UTF-8");
            }
            if (main instanceof PageComponent) {
                PageComponent page = (PageComponent) main;
                String pageName = page.getName();
                tempTsDir = pageDir(page);
                tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
                if (page.isEnabled()) {
                    File pageTsFile = new File(tempTsDir, pageName.toLowerCase() + ".ts");
                    synchronized (writtenFiles) {
                        if (writtenFiles.contains(pageTsFile)) {
                            File pageTsFileTmp = toTmpFile(pageTsFile);
                            if (pageTsFileTmp.exists()) {
                                pageTsFile = pageTsFileTmp;
                            }
                        }
                    }
                    tsContent = FileUtils.readFileToString(pageTsFile, "UTF-8");
                } else {
                    tsContent = getPageTsContent(page);
                }
            }
            if (main instanceof UISharedComponent) {
                UISharedComponent comp = (UISharedComponent) main;
                String compName = comp.getName();
                tempTsDir = compDir(comp);
                tempTsFileName = compName.toLowerCase() + ".function.temp.ts";
                boolean isEnabled = true;
                if (isEnabled) {
                    File compTsFile = new File(tempTsDir, compName.toLowerCase() + ".ts");
                    synchronized (writtenFiles) {
                        if (writtenFiles.contains(compTsFile)) {
                            File compTsFileTmp = toTmpFile(compTsFile);
                            if (compTsFileTmp.exists()) {
                                compTsFile = compTsFileTmp;
                            }
                        }
                    }
                    tsContent = FileUtils.readFileToString(compTsFile, "UTF-8");
                } else {
                    tsContent = getCompTsContent(comp);
                }
            }
            // Replace all Begin_c8o_XXX, End_c8o_XXX except for functionMarker
            Pattern pattern = Pattern.compile("/\\*Begin_c8o_(.+)\\*/");
            Matcher matcher = pattern.matcher(tsContent);
            while (matcher.find()) {
                String markerId = matcher.group(1);
                if (!markerId.equals(functionMarker)) {
                    String beginMarker = "/*Begin_c8o_" + markerId + "*/";
                    String endMarker = "/*End_c8o_" + markerId + "*/";
                    tsContent = tsContent.replace(beginMarker, "//---" + markerId + "---");
                    tsContent = tsContent.replace(endMarker, "//---" + markerId + "---");
                }
            }
            // CustomAction : reduce code lines (action's function only)
            if (tempTsDir != null && tempTsFileName != null) {
                if (uiComponent instanceof UICustomAction) {
                    UICustomAction uica = (UICustomAction) uic;
                    tempTsFileName = "CTS" + uica.priority + ".temp.ts";
                    int index = tsContent.indexOf("export class ");
                    if (index != -1) {
                        String classType = uica.getMainClassType();
                        String sImport = "";
                        if (main instanceof ApplicationComponent) {
                            if (uic.getSharedAction() == null) {
                                sImport = "import { " + classType + " } from './app.component';";
                            }
                        } else if (main instanceof PageComponent) {
                            sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
                        } else if (main instanceof UISharedComponent) {
                            sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
                        }
                        int i = tsContent.indexOf("{", index);
                        tsContent = tsContent.substring(0, i + 1) + System.lineSeparator() + uica.getActionCode() + System.lineSeparator() + "}" + System.lineSeparator();
                        tsContent = tsContent.replace("@Component", sImport + System.lineSeparator() + "@Component");
                        tsContent = tsContent.replace("export class " + classType + " ", "export class _Type_ ");
                    }
                }
            }
            // Write file (do not need delay)
            tsContent = LsPattern.matcher(tsContent).replaceAll(System.lineSeparator());
            File tempTsFile = new File(tempTsDir, tempTsFileName);
            FileUtils.write(tempTsFile, tsContent, "UTF-8");
        }
    } catch (Exception e) {
        throw new EngineException("Unable to write function temp ts file", e);
    }
}
Also used : Pattern(java.util.regex.Pattern) IScriptComponent(com.twinsoft.convertigo.beans.ngx.components.IScriptComponent) Matcher(java.util.regex.Matcher) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) IUIComponent(com.twinsoft.convertigo.beans.core.IUIComponent) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UICustomAction(com.twinsoft.convertigo.beans.ngx.components.UICustomAction) File(java.io.File)

Example 43 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.

the class NgxBuilder method appTemplateChanged.

@Override
public void appTemplateChanged(final IApplicationComponent appComponent) throws EngineException {
    ApplicationComponent app = (ApplicationComponent) appComponent;
    if (app != null && initDone) {
        synchronized (app) {
            writeAppTemplate(app);
            moveFiles();
            Engine.logEngine.trace("(MobileBuilder) Handled 'appTemplateChanged'");
        }
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent)

Example 44 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.

the class NgxBuilder method init.

@Override
protected synchronized void init() throws EngineException {
    if (initDone) {
        return;
    }
    ApplicationComponent application = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
    String tplName = application.getTplProjectName();
    if (!project.getName().equals(tplName)) {
        try {
            Engine.theApp.referencedProjectManager.getReferenceFromProject(project, tplName);
            Engine.theApp.referencedProjectManager.importProjectFrom(project, tplName);
        } catch (Exception e) {
            throw new EngineException("Failed to import referenced template: " + tplName + " :" + e.getMessage(), e);
        }
    }
    ionicTplDir = application.getIonicTplDir();
    if (!ionicTplDir.exists()) {
        throw new EngineException("Missing template project '" + application.getTplProjectName() + "'\nThe template folder should be in: " + ionicTplDir.getPath());
    }
    if (isIonicTemplateBased()) {
        if (eventHelper == null) {
            eventHelper = new EventHelper();
        }
        setNeedPkgUpdate(false);
        // Clean directories
        cleanDirectories();
        // Copy template directory to working directory
        copyTemplateFiles();
        // Copy template assets to build directory
        copyAssetsToBuildDir();
        // Modify configuration files
        updateConfigurationFiles();
        // Tpl version
        updateTplVersion();
        // Modify env.json
        initEnvFile();
        // PWA
        configurePwaApp(application);
        // Write source files (based on bean components)
        updateSourceFiles();
        // Studio mode : start worker for build process
        if (Engine.isStudioMode() || Engine.isCliMode()) {
            if (pushedFiles == null) {
                pushedFiles = new HashMap<String, CharSequence>();
            }
            if (queue == null) {
                queue = new LinkedBlockingQueue<Map<String, CharSequence>>();
            }
            if (worker == null) {
                worker = new MbWorker(queue);
                if (Engine.isStudioMode()) {
                    worker.start();
                } else {
                    worker.process();
                }
            }
            if (watcherService == null) {
                updateConsumer();
                updateConsumers();
                if (Engine.isStudioMode()) {
                    try {
                        watcherService = new DirectoryWatcherService(project, true);
                        watcherService.start();
                    } catch (Exception e) {
                        Engine.logEngine.warn(e.getMessage());
                    }
                }
            }
        }
        initDone = true;
        Engine.logEngine.debug("(MobileBuilder) Initialized builder for ionic project '" + project.getName() + "'");
    }
}
Also used : ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) EventHelper(com.twinsoft.convertigo.engine.util.EventHelper) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 45 with ApplicationComponent

use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.

the class NgxBuilder method updateSourceFiles.

private void updateSourceFiles() throws EngineException {
    try {
        MobileApplication mobileApplication = project.getMobileApplication();
        if (mobileApplication != null) {
            ApplicationComponent application = (ApplicationComponent) mobileApplication.getApplicationComponent();
            if (application != null) {
                String appTplVersion = application.requiredTplVersion();
                if (compareVersions(tplVersion, appTplVersion) >= 0) {
                    for (UISharedComponent comp : application.getSharedComponentList()) {
                        if (comp.isRegular()) {
                            writeCompSourceFiles(comp);
                        }
                    }
                    for (PageComponent page : getEnabledPages(application)) {
                        writePageSourceFiles(page);
                    }
                    writeAppSourceFiles(application);
                    removeUselessPages(application);
                    Engine.logEngine.trace("(MobileBuilder) Application source files updated for ionic project '" + project.getName() + "'");
                } else {
                    cleanDirectories();
                    throw new EngineException("Template project minimum " + appTplVersion + " is required for this project.\n" + "You can change template by configuring the 'Template project' property of your project's 'Application' object.\n" + "Then, be sure to update the project node modules packages (Application Right Click->Update packages and execute) \n");
                }
            }
        }
    } catch (EngineException e) {
        throw e;
    } catch (Exception e) {
        throw new EngineException("Unable to update application source files for ionic project '" + project.getName() + "'", e);
    }
}
Also used : MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent) EngineException(com.twinsoft.convertigo.engine.EngineException) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) IPageComponent(com.twinsoft.convertigo.beans.core.IPageComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)49 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)25 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)18 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)16 EngineException (com.twinsoft.convertigo.engine.EngineException)13 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)12 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)12 File (java.io.File)12 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)10 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)8 JSONException (org.codehaus.jettison.json.JSONException)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)7 PartInitException (org.eclipse.ui.PartInitException)7 UICustomAction (com.twinsoft.convertigo.beans.ngx.components.UICustomAction)6 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)5 Project (com.twinsoft.convertigo.beans.core.Project)5 IScriptComponent (com.twinsoft.convertigo.beans.ngx.components.IScriptComponent)5