Search in sources :

Example 16 with MobileApplication

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

the class CLI method downloadRemoteBuild.

public List<File> downloadRemoteBuild(Project project, List<String> platforms, File destinationDir) {
    MobileApplication mobileApplication = project.getMobileApplication();
    List<MobilePlatform> platformList = new ArrayList<>(mobileApplication.getMobilePlatformList());
    List<File> files = new ArrayList<File>(platformList.size());
    boolean hasMore = true;
    while (hasMore) {
        hasMore = false;
        for (Iterator<MobilePlatform> it = platformList.iterator(); it.hasNext(); ) {
            MobilePlatform platform = it.next();
            HttpMethod method = null;
            String platformName = platform.getName();
            if (!platforms.isEmpty() && !platforms.contains(platformName)) {
                it.remove();
                continue;
            }
            try {
                String sResult = GetBuildStatus.perform(mobileApplication, platformName, null);
                Engine.logConvertigo.info("build status: " + sResult);
                if (sResult.contains("status\": \"pending\"")) {
                    hasMore = true;
                } else {
                    it.remove();
                }
                if (sResult.contains("status\": \"complete\"")) {
                    method = GetPackage.perform(mobileApplication, platformName, null);
                    String filename = mobileApplication.getComputedApplicationName() + "_" + platformName + "." + platform.getPackageType();
                    // try {
                    // Engine.logConvertigo.info("ContentDisposition : " + method.getResponseHeader(HeaderName.ContentDisposition.value()));
                    // filename = method.getResponseHeader(HeaderName.ContentDisposition.value()).getValue().replaceFirst(".*filename=\"(.*)\".*", "$1");
                    // } catch (Exception e) {}
                    File file = new File(destinationDir, filename);
                    try (FileOutputStream fos = new FileOutputStream(file)) {
                        IOUtils.copy(method.getResponseBodyAsStream(), fos);
                        files.add(file);
                    }
                }
            } catch (Exception e) {
                it.remove();
                Engine.logConvertigo.error("failed to retrieve " + platformName, e);
            } finally {
                if (method != null) {
                    method.releaseConnection();
                }
            }
        }
        if (hasMore) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 17 with MobileApplication

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

the class CLI method loadProject.

public Project loadProject(File projectDir, String version, String mobileApplicationEndpoint, String gitContainer) throws EngineException {
    File projectFile = new File(projectDir, "c8oProject.yaml");
    if (!projectFile.exists()) {
        throw new EngineException("No Convertigo project here: " + projectDir);
    }
    checkInit();
    Project project;
    Engine.PROJECTS_PATH = projectFile.getParentFile().getParent();
    File testFile;
    boolean ok = false;
    if (gitContainer != null) {
        testFile = new File(gitContainer, "convertigoWriteTest");
        if (ok = testFile.mkdirs()) {
            ok = testFile.delete();
            if (ok) {
                EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
                Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
            }
        }
        if (!ok) {
            Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
        }
    }
    if (!ok) {
        testFile = new File(EnginePropertiesManager.getProperty(PropertyName.GIT_CONTAINER), "convertigoWriteTest");
        if (ok = testFile.mkdirs()) {
            ok = testFile.delete();
            if (ok) {
                Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
            }
        }
        if (!ok) {
            Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
        }
    }
    if (!ok) {
        testFile = new File(Engine.PROJECTS_PATH, "convertigoWriteTest");
        if (ok = testFile.mkdirs()) {
            ok = testFile.delete();
        }
        if (ok) {
            EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
            Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
        }
        if (!ok) {
            Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
        }
    }
    if (!ok) {
        File tmpFile;
        try {
            tmpFile = File.createTempFile("convertigoWriteTest", "Tmp");
            tmpFile.delete();
            testFile = new File(tmpFile, "convertigoWriteTest");
            if (ok = testFile.mkdirs()) {
                ok = testFile.delete();
            }
            if (ok) {
                EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
                Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
            } else {
                Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
            }
        } catch (IOException e) {
        }
    }
    if (!ok) {
        File _private = new File(projectDir, "_private/gitContainer");
        testFile = new File(_private, "convertigoWriteTest");
        if (ok = testFile.mkdirs()) {
            ok = testFile.delete();
        }
        if (ok) {
            EnginePropertiesManager.setProperty(PropertyName.GIT_CONTAINER, testFile.getParent());
            Engine.logConvertigo.info("Use GitContainer to: " + testFile.getParent());
        } else {
            Engine.logConvertigo.info("Cannot write to: " + testFile.getParent());
        }
    }
    try {
        project = Engine.theApp.databaseObjectsManager.importProject(projectFile, false);
    } catch (VersionException e) {
        throw e;
    } catch (Exception e) {
        Engine.logConvertigo.warn("Failed to import the project from '" + projectFile + "' (" + e.getMessage() + ") trying again...");
        project = Engine.theApp.databaseObjectsManager.importProject(projectFile, false);
    }
    if (version != null) {
        project.setVersion(version);
    }
    if (mobileApplicationEndpoint != null) {
        MobileApplication ma = project.getMobileApplication();
        if (ma != null) {
            ma.setEndpoint(mobileApplicationEndpoint);
        }
    }
    return project;
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 18 with MobileApplication

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

the class CLI method installCordova.

public Map<String, BuildLocally> installCordova(Project project, List<String> platforms) throws EngineException {
    List<MobilePlatform> mobilePlatforms;
    MobileApplication mobileApplication = project.getMobileApplication();
    if (platforms == null || platforms.isEmpty()) {
        mobilePlatforms = mobileApplication.getMobilePlatformList();
    } else {
        mobilePlatforms = new ArrayList<>(platforms.size());
        for (String platform : platforms) {
            try {
                mobilePlatforms.add(mobileApplication.getMobilePlatformByName(platform));
            } catch (EngineException e) {
                Engine.logConvertigo.error("Failed to find the mobile platform: " + platform, e);
            }
        }
    }
    Map<String, BuildLocally> localBuilders = new HashMap<>(mobilePlatforms.size());
    for (MobilePlatform platform : mobilePlatforms) {
        if (platform instanceof IOs && !Engine.isMac()) {
            Engine.logConvertigo.info("Skip IOs build because this is not Mac OS.");
            continue;
        }
        BuildLocally localBuilder = new BuildLocally(platform) {

            @Override
            protected void showLocationInstallFile(MobilePlatform mobilePlatform, int exitValue, String errorLines, String buildOption) {
                Engine.logConvertigo.error("BuildLocally location: " + exitValue + " error: " + errorLines + " options: " + buildOption);
            }

            @Override
            protected void logException(Throwable e, String message) {
                Engine.logConvertigo.error("BuildLocally exception: " + message, e);
            }

            @Override
            protected String getLocalBuildAdditionalPath() {
                // TODO Auto-generated method stub
                return null;
            }
        };
        Engine.logConvertigo.info("Checking cordova ...");
        Status status = localBuilder.installCordova();
        Engine.logConvertigo.info("Cordova: " + status);
        localBuilders.put(platform.getName(), localBuilder);
    }
    return localBuilders;
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) Status(com.twinsoft.convertigo.engine.localbuild.BuildLocally.Status) GetBuildStatus(com.twinsoft.convertigo.engine.admin.services.mobiles.GetBuildStatus) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) HashMap(java.util.HashMap) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) IOs(com.twinsoft.convertigo.beans.mobileplatforms.IOs)

Example 19 with MobileApplication

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

the class CLI method launchRemoteBuild.

public void launchRemoteBuild(Project project, List<String> platforms) {
    String buildFolder = "mobile/www";
    MobileApplication mobileApplication = project.getMobileApplication();
    for (MobilePlatform mobilePlatform : mobileApplication.getMobilePlatformList()) {
        String platformName = mobilePlatform.getName();
        try {
            if (platforms.isEmpty() || platforms.contains(platformName)) {
                MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(null, buildFolder, project.getName(), platformName);
                String sResult = LaunchBuild.perform(mobileResourceHelper, null);
                Engine.logConvertigo.info("build: " + sResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Engine.logConvertigo.error("failed to launch build for " + platformName, e);
        }
    }
}
Also used : MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) MobileResourceHelper(com.twinsoft.convertigo.engine.admin.services.mobiles.MobileResourceHelper) IOException(java.io.IOException)

Example 20 with MobileApplication

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

the class LaunchBuild method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    synchronized (buildLock) {
        final MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(request, "mobile/www");
        MobileApplication mobileApplication = mobileResourceHelper.mobileApplication;
        if (mobileApplication == null) {
            throw new ServiceException("no such mobile application");
        } else {
            boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
            if (!bTpPrivateRole && mobileApplication.getAccessibility() == Accessibility.Private) {
                throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
            }
        }
        String sResult = perform(mobileResourceHelper, request);
        JSONObject jsonObject = new JSONObject(sResult);
        Element statusElement = document.createElement("application");
        statusElement.setAttribute("id", jsonObject.getString("id"));
        document.getDocumentElement().appendChild(statusElement);
    }
}
Also used : ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) JSONObject(org.codehaus.jettison.json.JSONObject) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) Element(org.w3c.dom.Element)

Aggregations

MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)36 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)16 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)12 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)8 MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)8 IOException (java.io.IOException)8 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)7 Element (org.w3c.dom.Element)7 Project (com.twinsoft.convertigo.beans.core.Project)6 ApplicationComponent (com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent)6 ServiceException (com.twinsoft.convertigo.engine.admin.services.ServiceException)6 File (java.io.File)6 EngineException (com.twinsoft.convertigo.engine.EngineException)5 IOs (com.twinsoft.convertigo.beans.mobileplatforms.IOs)4 AuthenticationException (com.twinsoft.convertigo.engine.AuthenticationException)4 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)3 Android (com.twinsoft.convertigo.beans.mobileplatforms.Android)3 PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)3 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)3 Cursor (org.eclipse.swt.graphics.Cursor)3