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;
}
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;
}
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;
}
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();
}
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);
});
}
Aggregations