Search in sources :

Example 1 with MobileBuilderBuildMode

use of com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode in project convertigo by convertigo.

the class ApplicationComponentEditor method dialogBuild.

private void dialogBuild(ToolItem buildModeItem, MenuItem menuItem) {
    MobileBuilderBuildMode newBuildMode = (MobileBuilderBuildMode) menuItem.getData();
    if (dialogBuild(newBuildMode)) {
        buildModeItem.setImage(menuItem.getImage());
        buildModeItem.setToolTipText("Rebuild in: " + buildMode.label() + "\n" + buildMode.description());
        try {
            JSONObject device = new JSONObject(FileUtils.readFileToString(devicePref, "UTF-8"));
            device.put("buildMode", buildMode.name());
            FileUtils.write(devicePref, device.toString(4), "UTF-8");
        } catch (Exception ex) {
            Engine.logStudio.debug("Cannot save build mode", ex);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException)

Example 2 with MobileBuilderBuildMode

use of com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode in project convertigo by convertigo.

the class ApplicationComponentEditor method createToolbar.

private void createToolbar(Composite parent) {
    toolbar = new ToolBar(parent, SWT.VERTICAL);
    GridData gd = new GridData(GridData.FILL, GridData.FILL, false, true);
    gd.verticalSpan = 2;
    gd.verticalIndent = 4;
    toolbar.setLayoutData(gd);
    ToolItem item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select device viewport. Click to toggle the custom device bar.");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/core/images/mobiledevice_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
                devicesMenu.setLocation(pt);
                devicesMenu.setVisible(true);
            } else {
                setDeviceBarVisible(!deviceBar.getVisible());
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Change orientation");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String width = deviceWidth.getText();
            deviceWidth.setText(deviceHeight.getText());
            deviceHeight.setText(width);
            updateBrowserSize();
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Refresh");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/refresh.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doReload();
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Back");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/undo.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                int index = c8oBrowser.getCurrentNavigationEntryIndex();
                if (index > 2) {
                    c8oBrowser.goBack();
                }
            });
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove highlight");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/write_wait_zone.d.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            exHighlightElement = null;
            exHighlightMobileComponent = null;
            C8oBrowser.run(() -> c8oBrowser.executeJavaScriptAndReturnValue("_c8o_remove_all_overlay()"));
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Show debug");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/debug.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(true);
            getSite().getPage().activate(view);
            view.onActivated(ApplicationComponentEditor.this);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Open in default browser");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/statements/images/ContinueWithSiteClipperStatement_color_16x16.png")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            C8oBrowser.run(() -> {
                String url = c8oBrowser.getURL();
                if (url.startsWith("http")) {
                    org.eclipse.swt.program.Program.launch(url);
                }
            });
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.CHECK);
    item.setToolTipText("Toggle auto build");
    item.setSelection(true);
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/accumulate.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MobileBuilder mb = applicationEditorInput.application.getProject().getMobileBuilder();
            mb.setAutoBuild(((ToolItem) e.widget).getSelection());
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Manage modules");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/show_blocks.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MessageDialog dialog = new MessageDialog(null, "Node_module Update / Reinstall", null, "This will update or reinstall all your project's node_module dependencies. Update when you just " + "added a new dependency to your ionicTpl/package.json file, or re-install if you want clean all your node_modules and do a fresh install (takes more time).", MessageDialog.QUESTION, new String[] { "Update", "Re-install", "Cancel" }, 0);
            int result = dialog.open();
            if (result < 2) {
                launchBuilder(true, result == 1);
            }
        }
    });
    final ToolItem buildModeItem = item = new ToolItem(toolbar, SWT.DROP_DOWN);
    final Menu buildModeMenu = new Menu(parent.getShell());
    SelectionListener buildModeListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dialogBuild(buildModeItem, (MenuItem) e.widget);
        }
    };
    for (MobileBuilderBuildMode mode : MobileBuilderBuildMode.values()) {
        MenuItem menuItem = new MenuItem(buildModeMenu, SWT.NONE);
        menuItem.setText(mode.label());
        menuItem.setToolTipText(mode.description());
        menuItem.setData(mode);
        menuItem.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream(mode.icon())));
        menuItem.addSelectionListener(buildModeListener);
        if (mode.equals(buildMode)) {
            item.setImage(menuItem.getImage());
            item.setToolTipText(mode.description());
        }
    }
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.ARROW) {
                ToolItem item = (ToolItem) e.widget;
                Rectangle rect = item.getBounds();
                Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
                buildModeMenu.setLocation(pt);
                buildModeMenu.setVisible(true);
            } else {
                dialogBuild(buildMode);
            }
        }
    });
    new ToolItem(toolbar, SWT.SEPARATOR);
    item = new ToolItem(toolbar, SWT.DROP_DOWN);
    item.setToolTipText("Select dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_show_history.gif")));
    SelectionListener selectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setDataset(((MenuItem) e.widget).getText());
        }
    };
    Image iDataset = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkin.gif"));
    Image iDatasetSelected = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkout.gif"));
    final Menu mDataset = new Menu(toolbar);
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (MenuItem item : mDataset.getItems()) {
                item.dispose();
            }
            MenuItem menuItem = new MenuItem(mDataset, SWT.NONE);
            menuItem.setText("none");
            for (String fDataset : datasetDir.list()) {
                Matcher m = pDatasetFile.matcher(fDataset);
                if (m.matches()) {
                    menuItem = new MenuItem(mDataset, SWT.NONE);
                    menuItem.setText(m.group(1));
                }
            }
            for (MenuItem item : mDataset.getItems()) {
                if (item.getText().equals(dataset)) {
                    item.setImage(iDatasetSelected);
                } else {
                    item.setImage(iDataset);
                }
                item.addSelectionListener(selectionListener);
            }
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
            mDataset.setLocation(pt);
            mDataset.setVisible(true);
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Save dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_add.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] name = { dataset.equals("none") ? "" : dataset };
            String extra = "";
            int response;
            do {
                MessageDialog dialog = new MessageDialog(null, "Dataset name", null, "What is the name of the dataset ?" + extra, MessageDialog.QUESTION, 0, new String[] { "Save", "Cancel" }) {

                    @Override
                    protected Control createCustomArea(Composite parent) {
                        Text t = new Text(parent, SWT.NONE);
                        t.setLayoutData(new GridData(GridData.FILL_BOTH));
                        t.setText(name[0]);
                        t.addModifyListener(new ModifyListener() {

                            @Override
                            public void modifyText(ModifyEvent e) {
                                name[0] = t.getText();
                            }
                        });
                        return t;
                    }
                };
                response = dialog.open();
                extra = "";
                if (response == 0) {
                    if (StringUtils.isBlank(name[0])) {
                        extra = " (cannot be empty)";
                    } else if (name[0].equals("none")) {
                        extra = " (cannot override 'none')";
                    }
                }
            } while (!extra.isEmpty());
            if (response == 0) {
                C8oBrowser.run(() -> {
                    String value = c8oBrowser.executeJavaScriptAndReturnValue("sessionStorage._c8ocafsession_storage_data");
                    try {
                        FileUtils.write(new File(datasetDir, name[0] + ".json"), new JSONArray(value).toString(2), "UTF-8");
                        toast("Dataset '" + name[0] + "' saved !");
                        dataset = name[0];
                    } catch (Exception e1) {
                        toast("Dataset '" + name[0] + "' NOT saved ! " + e1.getMessage());
                    }
                });
            }
        }
    });
    item = new ToolItem(toolbar, SWT.PUSH);
    item.setToolTipText("Remove dataset");
    item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_delete.gif")));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!dataset.equals("none")) {
                boolean ok = MessageDialog.openQuestion(null, "Delete '" + dataset + "' ?", "You really want delete'" + dataset + "' ?");
                if (ok) {
                    new File(datasetDir, dataset + ".json").delete();
                    toast("Dataset '" + dataset + "' removed !");
                    setDataset("none");
                }
            } else {
                toast("No dataset selected !");
            }
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) Matcher(java.util.regex.Matcher) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) JSONArray(org.codehaus.jettison.json.JSONArray) MenuItem(org.eclipse.swt.widgets.MenuItem) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with MobileBuilderBuildMode

use of com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode in project convertigo by convertigo.

the class CLI method generateMobileBuilder.

public void generateMobileBuilder(Project project, String mode) throws Exception {
    MobileBuilder mb = project.getMobileBuilder();
    MobileBuilderBuildMode bm = MobileBuilderBuildMode.production;
    try {
        bm = MobileBuilderBuildMode.valueOf(mode);
    } catch (Exception e) {
    }
    mb.setAppBuildMode(bm);
    List<Project> projects = new ArrayList<>();
    projects.add(project);
    int i = 0;
    do {
        for (Reference ref : projects.get(i).getReferenceList()) {
            if (ref instanceof ProjectSchemaReference) {
                ProjectSchemaReference pref = (ProjectSchemaReference) ref;
                Project p = Engine.theApp.referencedProjectManager.importProject(pref.getParser());
                if (p == null) {
                    Engine.logConvertigo.warn("Failed to import project reference: " + pref.getProjectName() + " (ignored)");
                } else if (!projects.contains(p)) {
                    projects.add(p);
                }
            }
        }
    } while (++i < projects.size());
    Collections.reverse(projects);
    for (Project p : projects) {
        MobileBuilder.initBuilder(p, true);
    }
    Collections.reverse(projects);
    for (Project p : projects) {
        MobileBuilder.releaseBuilder(p, true);
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) ArrayList(java.util.ArrayList) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) IOException(java.io.IOException)

Example 4 with MobileBuilderBuildMode

use of com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode in project convertigo by convertigo.

the class ApplicationComponentEditor method launchBuilder.

public void launchBuilder(boolean forceInstall, boolean forceClean) {
    final MobileBuilderBuildMode buildMode = this.buildMode;
    final int buildCount = ++this.buildCount;
    final boolean isDark = SwtUtils.isDark();
    // Close editors (*.temp.ts) to avoid npm error at build launch
    ConvertigoPlugin.getDisplay().syncExec(new Runnable() {

        public void run() {
            try {
                ApplicationComponent mc = applicationEditorInput.application;
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (activePage != null) {
                    IEditorReference[] editorRefs = activePage.getEditorReferences();
                    for (int i = 0; i < editorRefs.length; i++) {
                        IEditorReference editorRef = (IEditorReference) editorRefs[i];
                        try {
                            IEditorInput editorInput = editorRef.getEditorInput();
                            if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
                                if (((ComponentFileEditorInput) editorInput).is(mc) || ((ComponentFileEditorInput) editorInput).isChildOf(mc)) {
                                    activePage.closeEditor(editorRef.getEditor(false), false);
                                }
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            } catch (Throwable t) {
            }
        }
    });
    // Launch build
    Engine.execute(() -> {
        try {
            String loader = IOUtils.toString(getClass().getResourceAsStream("loader.html"), "UTF-8");
            if (isDark) {
                loader = loader.replace("lightblue", "rgb(47,47,47); color: white");
            }
            c8oBrowser.setText(loader);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        Project project = applicationEditorInput.application.getProject();
        File ionicDir = new File(project.getDirPath(), "_private/ionic");
        File nodeModules = new File(ionicDir, "node_modules");
        String nodeVersion = ProcessUtils.getNodeVersion(project);
        File nodeDir = ProcessUtils.getDefaultNodeDir();
        try {
            nodeDir = ProcessUtils.getNodeDir(nodeVersion, (r, t, x) -> {
                appendOutput("Downloading nodejs " + nodeVersion + ": " + Math.round((r * 100f) / t) + "%");
            });
        } catch (Exception e1) {
        }
        {
            String versions = "Will use nodejs " + ProcessUtils.getNodeVersion(nodeDir) + " and npm " + ProcessUtils.getNpmVersion(nodeDir);
            appendOutput(versions);
            Engine.logStudio.info(versions);
        }
        String path = nodeDir.getAbsolutePath();
        terminateNode();
        MobileBuilder mb = project.getMobileBuilder();
        if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
            boolean[] running = { true };
            try {
                new File(ionicDir, "package-lock.json").delete();
                if (forceClean) {
                    appendOutput("...", "...", "Removing existing node_modules... This can take several seconds...");
                    Engine.logStudio.info("Removing existing node_modules... This can take several seconds...");
                    com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules);
                }
                appendOutput("Installing node_modules... This can take several minutes depending on your network connection speed...");
                Engine.logStudio.info("Installing node_modules... This can take several minutes depending on your network connection speed...");
                long start = System.currentTimeMillis();
                ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", ionicDir.toString(), "--no-shrinkwrap", "--no-package-lock");
                pb.redirectErrorStream(true);
                pb.directory(ionicDir);
                Process p = pb.start();
                Engine.execute(() -> {
                    try {
                        File staging = new File(nodeModules, ".staging");
                        while (running[0] && !staging.exists()) {
                            appendOutput("Resolving dependencies … (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
                            Thread.sleep(1000);
                        }
                        while (running[0] && staging.exists()) {
                            appendOutput("Collecting node_modules: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)) + " (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
                            Engine.logStudio.info("Installing, node_module size is now : " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)));
                            Thread.sleep(1000);
                        }
                    } catch (Exception e) {
                        appendOutput("Something wrong during the install: " + e);
                    }
                });
                processes.add(p);
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    line = pRemoveEchap.matcher(line).replaceAll("");
                    if (StringUtils.isNotBlank(line)) {
                        Engine.logStudio.info(line);
                        appendOutput(line);
                    }
                }
                Engine.logStudio.info(line);
                appendOutput("\\o/");
            } catch (Exception e) {
                appendOutput(":( " + e);
            }
            running[0] = false;
        }
        mb.setNeedPkgUpdate(false);
        Object mutex = new Object();
        mb.setBuildMutex(mutex);
        mb.setAppBuildMode(buildMode);
        try {
            ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException ce) {
        }
        try {
            mb.startBuild();
            File displayObjectsMobile = new File(project.getDirPath(), "DisplayObjects/mobile");
            displayObjectsMobile.mkdirs();
            appendOutput("removing previous build directory");
            for (File f : displayObjectsMobile.listFiles()) {
                if (!f.getName().equals("assets")) {
                    com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(f);
                }
            }
            appendOutput("previous build directory removed");
            this.applicationEditorInput.application.checkFolder();
            try {
                File watchJS = new File(project.getDirPath(), "_private/ionic/node_modules/@ionic/app-scripts/dist/watch.js");
                if (watchJS.exists()) {
                    int ms = ConvertigoPlugin.getMobileBuilderThreshold();
                    String txt = FileUtils.readFileToString(watchJS, "UTF-8");
                    String ntxt = txt.replaceAll("var BUILD_UPDATE_DEBOUNCE_MS = \\d+;", "var BUILD_UPDATE_DEBOUNCE_MS = " + ms + ";");
                    if (!txt.equals(ntxt))
                        ;
                    {
                        FileUtils.writeStringToFile(watchJS, ntxt, "UTF-8");
                    }
                }
            } catch (Exception e) {
                Engine.logStudio.warn("Failed to update DEBOUNCE", e);
            }
            File assets = new File(displayObjectsMobile, "assets");
            if (assets.exists() && assets.isDirectory()) {
                appendOutput("Handle application assets");
                Engine.logStudio.info("Handle application assets");
                File privAssets = new File(ionicDir, "src/assets");
                FileUtils.deleteDirectory(privAssets);
                FileUtils.copyDirectory(assets, privAssets);
            }
            ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "run", buildMode.command(), "--nobrowser");
            if (!MobileBuilderBuildMode.production.equals(buildMode)) {
                List<String> cmd = pb.command();
                synchronized (usedPort) {
                    cmd.add("--port");
                    cmd.add("" + (portNode = NetworkUtils.nextAvailable(8100, usedPort)));
                    cmd.add("--livereload-port");
                    cmd.add("" + (portReload = NetworkUtils.nextAvailable(35729, usedPort)));
                    cmd.add("--dev-logger-port");
                    cmd.add("" + (portLogger = NetworkUtils.nextAvailable(53703, usedPort)));
                }
            }
            pb.redirectErrorStream(true);
            pb.directory(ionicDir);
            Process p = pb.start();
            processes.add(p);
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                line = pRemoveEchap.matcher(line).replaceAll("");
                if (StringUtils.isNotBlank(line)) {
                    Engine.logStudio.info(line);
                    appendOutput(line);
                    if (line.matches(".*build .*finished.*")) {
                        synchronized (mutex) {
                            mutex.notify();
                        }
                        mb.buildFinished();
                    }
                    Matcher m = pIsServerRunning.matcher(line);
                    if (m.matches()) {
                        JSONObject envJSON = new JSONObject();
                        envJSON.put("remoteBase", EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL) + "/projects/" + project.getName() + "/_private");
                        FileUtils.write(new File(displayObjectsMobile, "env.json"), envJSON.toString(4), "UTF-8");
                        baseUrl = m.group(1);
                        synchronized (mutex) {
                            mutex.notify();
                        }
                        mb.buildFinished();
                        doLoad();
                    }
                }
            }
            if (buildCount == this.buildCount) {
                if (MobileBuilderBuildMode.production.equals(buildMode)) {
                    String SERVER_C8O_URL = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
                    baseUrl = SERVER_C8O_URL + "/projects/" + project.getName() + "/DisplayObjects/mobile/index.html";
                    doLoad();
                    toast("Application in production mode");
                }
                appendOutput("\\o/");
            } else {
                appendOutput("previous build canceled !");
            }
        } catch (Exception e) {
            appendOutput(":( " + e);
        } finally {
            synchronized (mutex) {
                mutex.notify();
            }
            mb.setBuildMutex(null);
            mb.buildFinished();
            try {
                ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException ce) {
            }
        }
    });
}
Also used : Element(com.teamdev.jxbrowser.dom.Element) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) KeyEvent(org.eclipse.swt.events.KeyEvent) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IEditorPart(org.eclipse.ui.IEditorPart) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) ToolItem(org.eclipse.swt.widgets.ToolItem) IOUtils(org.apache.commons.io.IOUtils) MenuItem(org.eclipse.swt.widgets.MenuItem) SWT(org.eclipse.swt.SWT) UIActionStack(com.twinsoft.convertigo.beans.mobile.components.UIActionStack) JsAccessible(com.teamdev.jxbrowser.js.JsAccessible) MobileComponent(com.twinsoft.convertigo.beans.mobile.components.MobileComponent) EditorPart(org.eclipse.ui.part.EditorPart) SwtUtils(com.twinsoft.convertigo.eclipse.swt.SwtUtils) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) SelectionListener(org.eclipse.swt.events.SelectionListener) JFaceResources(org.eclipse.jface.resource.JFaceResources) IEditorSite(org.eclipse.ui.IEditorSite) RequestPermissionCallback(com.teamdev.jxbrowser.permission.callback.RequestPermissionCallback) GridData(org.eclipse.swt.layout.GridData) RowData(org.eclipse.swt.layout.RowData) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIDynamicInvoke(com.twinsoft.convertigo.beans.mobile.components.UIDynamicInvoke) Engine(com.twinsoft.convertigo.engine.Engine) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) JsObject(com.teamdev.jxbrowser.js.JsObject) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Node(com.teamdev.jxbrowser.dom.Node) Project(com.twinsoft.convertigo.beans.core.Project) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) JSONException(org.codehaus.jettison.json.JSONException) ModifyListener(org.eclipse.swt.events.ModifyListener) FileUtils(com.twinsoft.convertigo.engine.util.FileUtils) IEditorReference(org.eclipse.ui.IEditorReference) BufferedReader(java.io.BufferedReader) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ProcessUtils(com.twinsoft.convertigo.engine.util.ProcessUtils) GridLayout(org.eclipse.swt.layout.GridLayout) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) ClipboardAction(com.twinsoft.convertigo.eclipse.popup.actions.ClipboardAction) ToolBar(org.eclipse.swt.widgets.ToolBar) VerifyListener(org.eclipse.swt.events.VerifyListener) MobileEventListener(com.twinsoft.convertigo.engine.mobile.MobileEventListener) EnginePropertiesManager(com.twinsoft.convertigo.engine.EnginePropertiesManager) InjectJsCallback(com.teamdev.jxbrowser.browser.callback.InjectJsCallback) NetworkUtils(com.twinsoft.convertigo.engine.util.NetworkUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Collection(java.util.Collection) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) UIControlEvent(com.twinsoft.convertigo.beans.mobile.components.UIControlEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConvertigoPlugin(com.twinsoft.convertigo.eclipse.ConvertigoPlugin) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) List(java.util.List) Pattern(java.util.regex.Pattern) ShowContextMenuCallback(com.teamdev.jxbrowser.browser.callback.ShowContextMenuCallback) Label(org.eclipse.swt.widgets.Label) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Document(com.teamdev.jxbrowser.dom.Document) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) Frame(com.teamdev.jxbrowser.frame.Frame) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) HashSet(java.util.HashSet) PaletteSourceTransfer(com.twinsoft.convertigo.eclipse.dnd.PaletteSourceTransfer) BatchOperationHelper(com.twinsoft.convertigo.engine.helpers.BatchOperationHelper) Charset(java.nio.charset.Charset) Browser(com.teamdev.jxbrowser.browser.Browser) LinkedList(java.util.LinkedList) UIDynamicAction(com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction) Response(com.teamdev.jxbrowser.browser.callback.InjectJsCallback.Response) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RowLayout(org.eclipse.swt.layout.RowLayout) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) IResource(org.eclipse.core.resources.IResource) NumberUtils(org.apache.commons.lang3.math.NumberUtils) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) FocusAdapter(org.eclipse.swt.events.FocusAdapter) C8oBrowser(com.twinsoft.convertigo.eclipse.swt.C8oBrowser) Control(org.eclipse.swt.widgets.Control) Matcher(java.util.regex.Matcher) IEditorReference(org.eclipse.ui.IEditorReference) InputStreamReader(java.io.InputStreamReader) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) Point(org.eclipse.swt.graphics.Point) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) DatabaseObjectFoundException(com.twinsoft.convertigo.engine.DatabaseObjectFoundException) JSONException(org.codehaus.jettison.json.JSONException) Project(com.twinsoft.convertigo.beans.core.Project) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) CoreException(org.eclipse.core.runtime.CoreException) JSONObject(org.codehaus.jettison.json.JSONObject) BufferedReader(java.io.BufferedReader) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) JsObject(com.teamdev.jxbrowser.js.JsObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

MobileBuilderBuildMode (com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode)4 DatabaseObjectFoundException (com.twinsoft.convertigo.engine.DatabaseObjectFoundException)3 Project (com.twinsoft.convertigo.beans.core.Project)2 MobileDebugView (com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView)2 MobileBuilder (com.twinsoft.convertigo.engine.mobile.MobileBuilder)2 JSONException (org.codehaus.jettison.json.JSONException)2 CoreException (org.eclipse.core.runtime.CoreException)2 PartInitException (org.eclipse.ui.PartInitException)2 Browser (com.teamdev.jxbrowser.browser.Browser)1 InjectJsCallback (com.teamdev.jxbrowser.browser.callback.InjectJsCallback)1 Response (com.teamdev.jxbrowser.browser.callback.InjectJsCallback.Response)1 ShowContextMenuCallback (com.teamdev.jxbrowser.browser.callback.ShowContextMenuCallback)1 Document (com.teamdev.jxbrowser.dom.Document)1 Element (com.teamdev.jxbrowser.dom.Element)1 Node (com.teamdev.jxbrowser.dom.Node)1 Frame (com.teamdev.jxbrowser.frame.Frame)1 JsAccessible (com.teamdev.jxbrowser.js.JsAccessible)1 JsObject (com.teamdev.jxbrowser.js.JsObject)1 RequestPermissionCallback (com.teamdev.jxbrowser.permission.callback.RequestPermissionCallback)1 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1