use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectManager in project convertigo by convertigo.
the class ConvertigoPlugin method start.
/**
* This method is called upon plug-in activation
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWindow != null) {
IWorkbenchPage activePage = activeWindow.getActivePage();
if (activePage != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
String id = editorRef.getId();
if (id.startsWith("com.twinsoft.convertigo.eclipse.editors") || id.equals("org.eclipse.ui.internal.emptyEditorTab")) {
activePage.closeEditors(new IEditorReference[] { editorRef }, false);
}
}
}
}
// Version check
if (!com.twinsoft.convertigo.eclipse.Version.productVersion.equals(com.twinsoft.convertigo.beans.Version.productVersion)) {
throw new Exception("The product version numbers of Eclipse Plugin and Objects libraries are differents.");
} else if (!com.twinsoft.convertigo.eclipse.Version.productVersion.equals(com.twinsoft.convertigo.engine.Version.productVersion)) {
throw new Exception("The product version numbers of Eclipse Plugin and Engine libraries are differents.");
}
Engine.setStudioMode();
plugin = this;
try {
resourceBundle = ResourceBundle.getBundle("com.twinsoft.convertigo.eclipse.ConvertigoPluginResources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
log = getLog();
projectManager = new ProjectManager();
clipboardManagerSystem = new ClipboardManager();
clipboardManagerDND = new ClipboardManager();
// learnProxy = new LearnProxy();
// Create consoles
createConsoles();
// Redirect stdout and stderr
System.setOut(new StdoutStream());
System.setErr(new StderrStream());
studioLog = new Log(ConvertigoPlugin.getDefault().stdoutConsoleStream);
runAtStartup(() -> {
studioLog = new LogWrapper(Engine.logStudio);
});
studioLog.logLevel = Log.LOGLEVEL_DEBUG;
try {
studioLog.logLevel = Integer.valueOf(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_LOG_LEVEL)).intValue();
} catch (NumberFormatException e) {
studioLog.warning("Unable to retrieve the log level; using default log level (4).");
}
studioLog.message("Starting the Convertigo studio eclipse plugin");
try {
highlightDetectedObject = Boolean.valueOf(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_TREE_HIGHLIGHT_DETECTED)).booleanValue();
} catch (NumberFormatException e) {
studioLog.warning("Unable to retrieve the highlight option; using default highlight option (true).");
}
try {
autoOpenDefaultConnector = Boolean.valueOf(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_AUTO_OPEN_DEFAULT_CONNECTOR)).booleanValue();
} catch (NumberFormatException e) {
studioLog.warning("Unable to retrieve the auto open default connector option; using default (false).");
}
try {
mobileBuilderThreshold = Integer.valueOf(ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_MOBILE_BUILDER_THRESHOLD)).intValue();
} catch (NumberFormatException e) {
studioLog.warning("Unable to retrieve the mobile builder threshold option; using default (200).");
}
// In STUDIO, the Convertigo User Workspace is in the current Eclipse Workspace/.metadata/.plugins/com.twinsoft.convertigo.studio
Engine.USER_WORKSPACE_PATH = getDefault().getStateLocation().toFile().getCanonicalPath();
// In STUDIO, the Convertigo Projects directory is the current Eclipse Workspace
Engine.PROJECTS_PATH = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toFile().getCanonicalPath();
// checkPre_6_2_0_Migration();
// Adds listeners
addListeners();
runAtStartup(() -> {
Engine.theApp.eventManager.addListener(this, ProgressEventListener.class);
Engine.execute(() -> Engine.theApp.couchDbManager.getFullSyncClient());
});
DatabaseObjectsManager.studioProjects = this;
final Exception[] afterPscException = { null };
final Runnable afterPscOk = new Runnable() {
public void run() {
try {
// Create embedded Tomcat
studioLog.message("Starting the embedded Tomcat");
System.setProperty("org.apache.commons.logging.log", "org.apache.commons.logging.impl.Jdk14Logger");
Path path = new Path("tomcat");
URL tomcatHomeUrl = FileLocator.find(context.getBundle(), path, null);
String xulrunner_url = System.getProperty("org.eclipse.swt.browser.XULRunnerPath");
if (xulrunner_url == null || xulrunner_url.equals("")) {
Bundle[] bundles = Platform.getFragments(context.getBundle());
if (bundles != null) {
studioLog.message("Fragments bundles: " + bundles.length);
for (Bundle bundle : bundles) {
String symbolicName = bundle.getSymbolicName();
studioLog.message("Fragment bundle symbolic name: " + symbolicName);
if (symbolicName.startsWith("com.twinsoft.convertigo.studio.xulrunner")) {
URL url = FileLocator.find(bundle, new Path("xulrunner"), null);
studioLog.message("Xulrunner url: " + url);
xulrunner_url = FileLocator.toFileURL(url).getPath();
studioLog.message("Xulrunner xulrunner_url: " + xulrunner_url);
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", xulrunner_url);
break;
}
}
}
}
String tomcatHome = FileLocator.toFileURL(tomcatHomeUrl).getPath();
int index = (System.getProperty("os.name").indexOf("Windows") != -1) ? 1 : 0;
tomcatHome = tomcatHome.substring(index);
embeddedTomcat = new EmbeddedTomcat(tomcatHome);
configureDeployConfiguration();
// displayWaitScreen();
runAtStartup(() -> {
ProjectExplorerView pew = getProjectExplorerView();
pew.initialize();
});
new Thread(embeddedTomcat, "Embedded Tomcat").start();
new Thread(new Runnable() {
public void run() {
int nbRetry = 0;
while (!Engine.isStartFailed && !Engine.isStarted) {
try {
Thread.sleep(500);
nbRetry++;
} catch (InterruptedException e) {
// Ignore
}
// Aborting if too many retries
if (nbRetry > 360)
return;
}
if (Engine.isStartFailed) {
logError("Unable to start engine; see console for more details");
return;
}
// The console threads must be started AFTER the engine
consolePipes.startConsoleThreads();
try {
deploymentConfigurationManager.doMigration();
} catch (Exception e) {
logException(e, "Unable to migrate deployment configurations");
}
studioLog.message("Embedded Tomcat started");
for (Runnable runnable : runAtStartup) {
Display.getDefault().asyncExec(runnable);
}
runAtStartup.clear();
}
}, "Wait Embedded Tomcat started").start();
getDisplay().asyncExec(() -> {
launchStartupPage(true);
});
} catch (Exception e) {
afterPscException[0] = e;
}
}
};
try {
decodePsc();
// Engine.isStartFailed = true;
afterPscOk.run();
if (afterPscException[0] != null) {
throw afterPscException[0];
}
} catch (PscException e) {
studioLog.message("No valid PSC, the Engine will start after the registration wizard.\nFailure message : " + e.getMessage());
Engine.isStartFailed = true;
Display display = getDisplay();
display.asyncExec(new Runnable() {
public void run() {
try {
boolean success = SetupAction.runSetup();
if (success) {
Engine.isStartFailed = false;
new Thread(afterPscOk, "Start embedded Tomcat").start();
} else {
studioLog.message("PSC not validated, please restart the Studio to get the Convertigo Setup wizard again.");
}
} catch (Throwable t) {
studioLog.exception(t, "Failure during the Convertigo setup wizard");
}
}
});
}
runAtStartup(() -> {
String nodeVersion = ProcessUtils.getDefaultNodeVersion();
Job job = Job.create("Retrieve default nodejs " + nodeVersion, monitor -> {
try {
monitor.beginTask("In progress", 120);
monitor.subTask("checking for existing nodejs");
monitor.worked(1);
boolean[] first = { true };
File nodeDir = ProcessUtils.getNodeDir(nodeVersion, new org.apache.commons.fileupload.ProgressListener() {
@Override
public void update(long pBytesRead, long pContentLength, int pItems) {
if (first[0]) {
monitor.worked(10);
monitor.subTask("downloading nodejs [" + (pContentLength / (1024 * 1024)) + " MB]");
first[0] = false;
}
Engine.logConvertigo.info("download NodeJS " + nodeVersion + ": " + Math.round(100f * pBytesRead / pContentLength) + "% [" + pBytesRead + "/" + pContentLength + "]");
monitor.worked(10 + Math.round(100f * pBytesRead / pContentLength));
if (pBytesRead == pContentLength) {
monitor.subTask("installing nodejs");
monitor.worked(110);
}
}
});
monitor.worked(120);
File nodeExe = new File(nodeDir, Engine.isWindows() ? "node.exe" : "node");
Engine.logStudio.warn("node ready: " + nodeExe.getAbsolutePath() + " exists ? " + nodeExe.exists());
System.setProperty("org.eclipse.wildwebdeveloper.nodeJSLocation", nodeExe.getAbsolutePath());
ProcessUtils.setDefaultNodeDir(nodeDir);
monitor.done();
} catch (Exception e) {
Engine.logStudio.error("Failed to init NPM: " + e.getMessage(), e);
}
});
job.schedule();
});
studioLog.message("Convertigo studio started");
}
Aggregations