Search in sources :

Example 6 with MobilePlatform

use of com.twinsoft.convertigo.beans.core.MobilePlatform 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 7 with MobilePlatform

use of com.twinsoft.convertigo.beans.core.MobilePlatform 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 8 with MobilePlatform

use of com.twinsoft.convertigo.beans.core.MobilePlatform 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 9 with MobilePlatform

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

the class GetStoreContent method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element root = document.getDocumentElement();
    Element projectsListElement = document.createElement("projects");
    root.appendChild(projectsListElement);
    String requestedPlatform = ServiceUtils.getRequiredParameter(request, "platform");
    HttpSession httpSession = request.getSession();
    boolean bAdminRole = hasRole(httpSession, Role.WEB_ADMIN);
    boolean bAuthRole = hasRole(httpSession, Role.AUTHENTICATED);
    for (String projectName : Engine.theApp.databaseObjectsManager.getAllProjectNamesList()) {
        try {
            Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
            Element projectElement = null;
            MobileApplication mobileApplication = project.getMobileApplication();
            if (mobileApplication != null) {
                Accessibility accessibylity = mobileApplication.getAccessibility();
                if (accessibylity == Accessibility.Public || (accessibylity == Accessibility.Private && bAuthRole) || bAdminRole) {
                    projectElement = createProjectElement(document, mobileApplication, projectName);
                    for (MobilePlatform platform : mobileApplication.getMobilePlatformList()) {
                        if (isRequestedPlatformValid(requestedPlatform, platform)) {
                            projectElement.getLastChild().appendChild(createPlatform(document, platform));
                        }
                    }
                    projectsListElement.appendChild(projectElement);
                }
            }
        } catch (EngineException e) {
            String message = "Unable to get project information ('" + projectName + "')";
            Engine.logAdmin.error(message, e);
        }
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Accessibility(com.twinsoft.convertigo.engine.enums.Accessibility) HttpSession(javax.servlet.http.HttpSession) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 10 with MobilePlatform

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

the class GetTestPlatform method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element root = document.getDocumentElement();
    String projectName = request.getParameter("projectName");
    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
    Element e_project = createDatabaseObjectElement(document, project);
    Connector defaultConnector = project.getDefaultConnector();
    e_project.setAttribute("defaultConnector", defaultConnector.getName());
    e_project.setAttribute("defaultTransaction", defaultConnector.getDefaultTransaction().getName());
    boolean bTpHiddenRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_HIDDEN);
    boolean bTpPrivateRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.TEST_PLATFORM_PRIVATE);
    for (Connector connector : project.getConnectorsList()) {
        Element e_connector = createDatabaseObjectElement(document, connector);
        for (Transaction transaction : connector.getTransactionsList()) {
            // WEB_ADMIN role is allowed to execute all requestables
            if (transaction.isPublicAccessibility() || (transaction.isHiddenAccessibility() && bTpHiddenRole) || bTpPrivateRole) {
                e_connector.appendChild(createRequestableElement(document, transaction));
            }
        }
        e_project.appendChild(e_connector);
    }
    for (Sequence sequence : project.getSequencesList()) {
        // WEB_ADMIN role is allowed to execute all requestables
        if (sequence.isPublicAccessibility() || (sequence.isHiddenAccessibility() && bTpHiddenRole) || bTpPrivateRole) {
            e_project.appendChild(createRequestableElement(document, sequence));
        }
    }
    MobileApplication mobileApplication = project.getMobileApplication();
    if (mobileApplication != null && (mobileApplication.getAccessibility() == Accessibility.Public || (mobileApplication.getAccessibility() == Accessibility.Hidden && bTpHiddenRole) || bTpPrivateRole)) {
        Element e_mobileApplication = createDatabaseObjectElement(document, mobileApplication);
        String applicationID = mobileApplication.getComputedApplicationId();
        e_mobileApplication.setAttribute("applicationID", applicationID);
        String endpoint = mobileApplication.getComputedEndpoint(request);
        e_mobileApplication.setAttribute("endpoint", endpoint);
        String version = mobileApplication.getComputedApplicationVersion();
        e_mobileApplication.setAttribute("applicationVersion", version);
        e_project.appendChild(e_mobileApplication);
        for (MobilePlatform platform : mobileApplication.getMobilePlatformList()) {
            Element e_device = createDatabaseObjectElement(document, platform);
            e_device.setAttribute("classname", platform.getClass().getSimpleName());
            e_device.setAttribute("displayName", CachedIntrospector.getBeanInfo(platform.getClass()).getBeanDescriptor().getDisplayName());
            e_device.setAttribute("packageType", platform.getPackageType());
            e_device.setAttribute("revision", "computing...");
            e_mobileApplication.appendChild(e_device);
        }
        try {
            String mobileProjectName = mobileApplication.getComputedApplicationName();
            e_mobileApplication.setAttribute("mobileProjectName", mobileProjectName);
        } catch (Exception e) {
            Engine.logAdmin.error("Failed to retrieve the application mobile name", e);
        }
        IApplicationComponent app = mobileApplication.getApplicationComponent();
        String msg = app != null ? app.getUnbuiltMessage() : null;
        if (msg != null) {
            e_mobileApplication.setAttribute("unbuiltMessage", msg);
        }
    }
    root.appendChild(e_project);
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Transaction(com.twinsoft.convertigo.beans.core.Transaction) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) Element(org.w3c.dom.Element) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IApplicationComponent(com.twinsoft.convertigo.beans.core.IApplicationComponent)

Aggregations

MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)13 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)9 File (java.io.File)8 Project (com.twinsoft.convertigo.beans.core.Project)6 EngineException (com.twinsoft.convertigo.engine.EngineException)5 IOException (java.io.IOException)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 Transaction (com.twinsoft.convertigo.beans.core.Transaction)4 IOs (com.twinsoft.convertigo.beans.mobileplatforms.IOs)4 Element (org.w3c.dom.Element)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)3 Statement (com.twinsoft.convertigo.beans.core.Statement)3 Step (com.twinsoft.convertigo.beans.core.Step)3 Android (com.twinsoft.convertigo.beans.mobileplatforms.Android)3 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)2 Sequence (com.twinsoft.convertigo.beans.core.Sequence)2 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)2 WindowsPhone8 (com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8)2 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2