use of com.twinsoft.convertigo.engine.mobile.MobileBuilder 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) {
}
}
});
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class NgxUIComponentTreeObject method setPropertyValue.
@Override
public void setPropertyValue(Object id, Object value) {
DatabaseObject dbo = getObject();
if (dbo instanceof UIDynamicElement) {
IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
if (ionBean != null) {
if (ionBean.hasProperty((String) id)) {
if (value != null) {
if (value instanceof String) {
value = new MobileSmartSourceType((String) value);
}
Object oldValue = ionBean.getPropertyValue((String) id);
if (!value.equals(oldValue)) {
MobileBuilder mb = null;
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
try {
ionBean.setPropertyValue((String) id, value);
TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
hasBeenModified(true);
viewer.update(this, null);
Engine.logStudio.info("---------------------- SetPropertyValue started: " + (String) id + "----------------------");
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, (String) id, oldValue, value);
ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
BatchOperationHelper.stop();
} catch (Exception e) {
} finally {
BatchOperationHelper.cancel();
Engine.logStudio.info("---------------------- SetPropertyValue ended: " + (String) id + "----------------------");
}
return;
}
}
}
}
}
if (dbo instanceof UIAppGuard) {
UIAppGuard dboGuard = (UIAppGuard) dbo;
if ("guardType".equals(id)) {
String guardType = (String) value;
if (!guardType.equals(dboGuard.getGuardType().name())) {
if (dboGuard.getApplication().hasGuard(AppGuardType.valueOf(guardType))) {
return;
}
}
}
}
super.setPropertyValue(id, value);
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class ConvertigoPartListener method partClosed.
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
*/
public void partClosed(IWorkbenchPart part) {
if (part instanceof ConnectorEditor) {
// close editor properly
((ConnectorEditor) part).close();
}
if (part instanceof SequenceEditor) {
// close editor properly
((SequenceEditor) part).close();
}
if (part instanceof ProjectExplorerView) {
// close view properly
((ProjectExplorerView) part).close();
}
if (part instanceof SourcePickerView) {
// close view properly
((SourcePickerView) part).close();
}
if (part instanceof ConsoleView) {
ConvertigoPlugin convertigoPlugin = ConvertigoPlugin.getDefault();
boolean shuttingDown = convertigoPlugin.isShuttingDown();
if (shuttingDown) {
IConsole[] tabConsoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles();
String openedConsoles = "";
for (IConsole console : tabConsoles) {
if (console instanceof MessageConsole) {
if ((console.equals(convertigoPlugin.engineConsole)) && (openedConsoles.indexOf("engine") == -1))
openedConsoles += (openedConsoles.equals("") ? "" : ",") + "engine";
else if ((console.equals(convertigoPlugin.stdoutConsole)) && (openedConsoles.indexOf("stdout") == -1))
openedConsoles += (openedConsoles.equals("") ? "" : ",") + "stdout";
}
}
ConvertigoPlugin.setProperty(ConvertigoPlugin.PREFERENCE_OPENED_CONSOLES, openedConsoles);
}
}
if (part instanceof EditorPart) {
IEditorInput input = ((EditorPart) part).getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
try {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
mb.removeMobileEventListener((com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor) part);
mb.setAutoBuild(true);
} catch (Exception e) {
e.printStackTrace();
}
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
try {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
mb.removeMobileEventListener((com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditor) part);
mb.setAutoBuild(true);
} catch (Exception e) {
e.printStackTrace();
}
}
if (input instanceof JScriptEditorInput) {
try {
((JScriptEditorInput) input).getFile().getParent().delete(true, null);
} catch (Exception e) {
e.printStackTrace();
}
} else if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) {
try {
((com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) input).getFile().delete(true, null);
} catch (Exception e) {
e.printStackTrace();
}
} else if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) {
try {
((com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) input).getFile().delete(true, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class ConvertigoPartListener method partOpened.
/* (non-Javadoc)
* @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
*/
public void partOpened(IWorkbenchPart part) {
if (part instanceof PropertySheet) {
PropertySheet view = (PropertySheet) part;
if (view != null) {
if (view.getCurrentPage().getControl() instanceof Tree) {
Tree tree = (Tree) view.getCurrentPage().getControl();
if (tree != null) {
if (SwtUtils.isDark()) {
tree.setLinesVisible(false);
}
try {
tree.getColumn(1).setWidth(tree.getBounds().width);
} catch (Exception e) {
}
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent event) {
boolean bCtrl = (((event.stateMask & SWT.CONTROL) != 0) || ((event.stateMask & SWT.CTRL) != 0));
int keyCode = event.keyCode;
char c = event.character;
if (bCtrl) {
if ((c == 's') || (keyCode == 115)) {
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
if (projectExplorerView != null) {
projectExplorerView.projectExplorerSaveAllAction.run();
}
}
}
}
});
}
}
}
}
if (part instanceof EditorPart) {
IEditorInput input = ((EditorPart) part).getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
try {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
mb.addMobileEventListener((com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor) part);
mb.setAutoBuild(true);
} catch (Exception e) {
e.printStackTrace();
}
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
try {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
mb.addMobileEventListener((com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditor) part);
mb.setAutoBuild(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class MyAbstractAction method run.
@Override
public void run(IAction action) {
this.action = action;
MobileBuilder mb = null;
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
try {
Engine.logStudio.info("---------------------- Action started: " + action.getId() + "----------------------");
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
run();
BatchOperationHelper.stop();
} finally {
BatchOperationHelper.cancel();
Engine.logStudio.info("---------------------- Action ended: " + action.getId() + "----------------------");
}
}
Aggregations