Search in sources :

Example 51 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class ReferencedProjectManager method check.

private boolean check(Map<String, ProjectUrlParser> refs) {
    List<String> loaded = new LinkedList<>();
    for (Entry<String, ProjectUrlParser> entry : refs.entrySet()) {
        String projectName = entry.getKey();
        try {
            ProjectUrlParser parser = entry.getValue();
            Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(parser.getProjectName(), false);
            Project nProject = importProject(parser);
            if (nProject != null && nProject != project) {
                loaded.add(projectName);
            }
        } catch (Exception e) {
            Engine.logEngine.warn("(ReferencedProjectManager) Failed to load '" + projectName + "'", e);
        }
    }
    if (!loaded.isEmpty()) {
        check(loaded);
        return true;
    }
    return false;
}
Also used : ProjectUrlParser(com.twinsoft.convertigo.engine.util.ProjectUrlParser) Project(com.twinsoft.convertigo.beans.core.Project) LinkedList(java.util.LinkedList)

Example 52 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class ReferencedProjectManager method importProject.

public Project importProject(ProjectUrlParser parser, boolean force) throws Exception {
    String projectName = parser.getProjectName();
    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
    File dir = null;
    File prjDir = null;
    boolean cloneDone = false;
    if (parser.getGitRepo() == null) {
        if ((!force && project != null) || parser.getGitUrl() == null) {
            return project;
        } else {
            return Engine.theApp.databaseObjectsManager.deployProject(parser.getGitUrl(), projectName, true);
        }
    }
    if (project != null) {
        prjDir = project.getDirFile();
        dir = GitUtils.getWorkingDir(project.getDirFile());
        if (dir != null) {
            Engine.logEngine.debug("(ReferencedProjectManager) " + projectName + " has repo " + dir);
        } else {
            Engine.logEngine.debug("(ReferencedProjectManager) " + projectName + " exists without repo");
        }
    } else {
        File gitContainer = GitUtils.getGitContainer();
        String suffix = parser.getGitBranch() != null ? "_" + parser.getGitBranch() : "";
        dir = new File(gitContainer, parser.getGitRepo() + suffix);
        synchronized (getLock(dir)) {
            if (dir.exists()) {
                if (GitUtils.asRemoteAndBranch(dir, parser.getGitUrl(), parser.getGitBranch())) {
                    Engine.logEngine.info("(ReferencedProjectManager) folder has remote " + parser.getGitUrl());
                } else {
                    Engine.logEngine.info("(ReferencedProjectManager) folder hasn't remote " + parser.getGitUrl());
                    int i = 1;
                    suffix += "_";
                    while (i > 0 && (dir = new File(gitContainer, parser.getGitRepo() + suffix + i++)).exists()) {
                        if (GitUtils.asRemoteAndBranch(dir, parser.getGitUrl(), parser.getGitBranch())) {
                            i = 0;
                        }
                    }
                    Engine.logEngine.info("(ReferencedProjectManager) new folder " + dir);
                }
            }
            if (!dir.exists()) {
                GitUtils.clone(parser.getGitUrl(), parser.getGitBranch(), dir);
                cloneDone = true;
            } else {
                Engine.logEngine.info("(ReferencedProjectManager) Use repo " + dir);
            }
        }
        if (parser.getProjectPath() != null) {
            prjDir = new File(dir, parser.getProjectPath());
        } else {
            prjDir = dir;
        }
    }
    if (dir != null) {
        if (!cloneDone && parser.isAutoPull() && !Engine.isStudioMode()) {
            synchronized (getLock(dir)) {
                String exRev = GitUtils.getRev(dir);
                GitUtils.fetch(dir);
                GitUtils.reset(dir, parser.getGitBranch());
                String newRev = GitUtils.getRev(dir);
                if (!exRev.equals(newRev)) {
                    project = null;
                }
            }
        }
        if (project == null) {
            project = Engine.theApp.databaseObjectsManager.importProject(new File(prjDir, "c8oProject.yaml"), false);
            if (!projectName.equals(project.getName())) {
                throw new EngineException("Referenced name is '" + projectName + "' but loaded project is '" + project.getName() + "'");
            }
            Engine.logEngine.info("(ReferencedProjectManager) Referenced project is loaded: " + project);
        }
    }
    return project;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) File(java.io.File)

Example 53 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class DatabaseObjectsManager method performWsMigration.

private boolean performWsMigration(String version, String projectName) {
    if (VersionUtils.compare(version, "4.6.0") < 0) {
        try {
            // Retrieve a !clone! of project to perform update
            Project project = getProjectByName(projectName);
            for (Connector connector : project.getConnectorsList()) {
                // Retrieve backup wsdlTypes and store Transaction's schema
                for (Transaction transaction : connector.getTransactionsList()) {
                    try {
                        String xsdTypes = transaction.migrateToXsdTypes();
                        transaction.writeSchemaToFile(xsdTypes);
                        Engine.logDatabaseObjectManager.info("Internal schema stored for \"" + transaction.getName() + "\" transaction");
                    } catch (Exception e) {
                        Engine.logDatabaseObjectManager.error("An error occured while writing schema to file for \"" + transaction.getName() + "\" transaction");
                    }
                }
            }
            // Fix sequence's steps sources
            for (Sequence sequence : project.getSequencesList()) {
                try {
                    List<Step> steps = sequence.getSteps();
                    // Replace source's xpath
                    // replace ./xxx by
                    // ./transaction/document/xxx or by
                    // ./sequence/document/xxx
                    replaceSourceXpath(version, sequence, steps);
                    Engine.logDatabaseObjectManager.info("Step sources updated for sequence \"" + sequence.getName() + "\"");
                } catch (Exception e) {
                    Engine.logDatabaseObjectManager.error("An error occured while updating step sources for sequence \"" + sequence.getName() + "\"");
                }
            }
        } catch (Exception e) {
            Engine.logDatabaseObjectManager.error("An error occured while updating project '" + projectName + "' for XSD", e);
            return false;
        }
    }
    return true;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Step(com.twinsoft.convertigo.beans.core.Step) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ReadFileStep(com.twinsoft.convertigo.beans.steps.ReadFileStep) XMLActionStep(com.twinsoft.convertigo.beans.steps.XMLActionStep) XMLGenerateDatesStep(com.twinsoft.convertigo.beans.steps.XMLGenerateDatesStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 54 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class ApplicationComponentEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    applicationEditorInput = (ApplicationComponentEditorInput) input;
    ApplicationComponent application = applicationEditorInput.application;
    Project project = application.getProject();
    datasetDir = new File(project.getDirPath() + "/dataset");
    datasetDir.mkdirs();
    devicePref = new File(Engine.USER_WORKSPACE_PATH, "studio/device-" + project.getName() + ".json");
    setPartName(project.getName() + " [A: " + application.getName() + "]");
    terminateNode();
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) ApplicationComponent(com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) File(java.io.File)

Example 55 with Project

use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.

the class ApplicationComponentEditor method launchBuilder.

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

        public void run() {
            try {
                ApplicationComponent app = 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(app) || ((ComponentFileEditorInput) editorInput).isChildOf(app)) {
                                    activePage.closeEditor(editorRef.getEditor(false), false);
                                }
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            } catch (Throwable t) {
            }
        }
    });
    // Launch build
    Engine.execute(() -> {
        initLoader();
        project = applicationEditorInput.application.getProject();
        ionicDir = new File(project.getDirPath(), "_private/ionic");
        nodeModules = new File(ionicDir, "node_modules");
        String nodeVersion = ProcessUtils.getNodeVersion(project);
        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(false);
        MobileBuilder mb = project.getMobileBuilder();
        if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
            boolean[] running = { true };
            try {
                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...");
                if (!nodeModules.exists()) {
                    File packageLockTpl = new File(ionicDir, "package-lock-tpl.json");
                    if (packageLockTpl.exists()) {
                        com.twinsoft.convertigo.engine.util.FileUtils.copyFile(packageLockTpl, new File(ionicDir, "package-lock.json"));
                    }
                }
                ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString(), "npm", "install", "--legacy-peer-deps", "--loglevel", "info");
                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);
                    }
                }
                Engine.logStudio.info(line);
                appendOutput("\\o/");
            } catch (Exception e) {
                appendOutput(":( " + e);
            }
            running[0] = false;
        }
        mb.setNeedPkgUpdate(false);
        build(path, buildCount, mb);
    });
}
Also used : Element(com.teamdev.jxbrowser.dom.Element) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) KeyEvent(org.eclipse.swt.events.KeyEvent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) 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) JsAccessible(com.teamdev.jxbrowser.js.JsAccessible) 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) UIControlEvent(com.twinsoft.convertigo.beans.ngx.components.UIControlEvent) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent) JFaceResources(org.eclipse.jface.resource.JFaceResources) IEditorSite(org.eclipse.ui.IEditorSite) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) 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) Engine(com.twinsoft.convertigo.engine.Engine) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) PaletteSource(com.twinsoft.convertigo.eclipse.dnd.PaletteSource) MobileDebugView(com.twinsoft.convertigo.eclipse.views.mobile.MobileDebugView) MobileBuilderBuildMode(com.twinsoft.convertigo.engine.enums.MobileBuilderBuildMode) NgxBuilderBuildMode(com.twinsoft.convertigo.engine.enums.NgxBuilderBuildMode) 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) JSONException(org.codehaus.jettison.json.JSONException) ModifyListener(org.eclipse.swt.events.ModifyListener) FileUtils(com.twinsoft.convertigo.engine.util.FileUtils) IEditorReference(org.eclipse.ui.IEditorReference) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) 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) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) NetworkUtils(com.twinsoft.convertigo.engine.util.NetworkUtils) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Collection(java.util.Collection) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) 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) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) Browser(com.teamdev.jxbrowser.browser.Browser) LinkedList(java.util.LinkedList) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) Response(com.teamdev.jxbrowser.browser.callback.InjectJsCallback.Response) Job(org.eclipse.core.runtime.jobs.Job) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RowLayout(org.eclipse.swt.layout.RowLayout) IResource(org.eclipse.core.resources.IResource) NumberUtils(org.apache.commons.lang3.math.NumberUtils) 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) InputStreamReader(java.io.InputStreamReader) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) 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) IEditorReference(org.eclipse.ui.IEditorReference) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) BufferedReader(java.io.BufferedReader) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

Project (com.twinsoft.convertigo.beans.core.Project)148 EngineException (com.twinsoft.convertigo.engine.EngineException)56 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)47 IOException (java.io.IOException)39 File (java.io.File)37 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 Connector (com.twinsoft.convertigo.beans.core.Connector)33 ArrayList (java.util.ArrayList)29 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)26 JSONException (org.codehaus.jettison.json.JSONException)26 Transaction (com.twinsoft.convertigo.beans.core.Transaction)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 SAXException (org.xml.sax.SAXException)21 CoreException (org.eclipse.core.runtime.CoreException)20 Step (com.twinsoft.convertigo.beans.core.Step)19 Element (org.w3c.dom.Element)19 Shell (org.eclipse.swt.widgets.Shell)18 JSONObject (org.codehaus.jettison.json.JSONObject)17 IProject (org.eclipse.core.resources.IProject)17 Cursor (org.eclipse.swt.graphics.Cursor)17