Search in sources :

Example 1 with FlashUpdateBuildMode

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

the class MobileResourceHelper method preparePackage.

public File preparePackage() throws Exception {
    FlashUpdateBuildMode buildMode = mobileApplication.getBuildMode();
    String finalApplicationName = mobileApplication.getComputedApplicationName();
    JSONObject json = new JSONObject();
    if (buildMode == FlashUpdateBuildMode.full) {
        fixMobileBuilderTimes();
        prepareFiles();
    } else if (buildMode == FlashUpdateBuildMode.light) {
        fixMobileBuilderTimes();
        prepareFiles(new FileFilter() {

            public boolean accept(File pathname) {
                try {
                    File dir;
                    boolean ok = MobileResourceHelper.defaultFilter.accept(pathname) && (new File(currentMobileDir, "index.html").equals(pathname) || new File(currentMobileDir, "config.xml").equals(pathname) || new File(currentMobileDir, "icon.png").equals(pathname) || (dir = new File(currentMobileDir, "res")).equals(pathname) || (dir.exists() && FileUtils.directoryContains(dir, pathname)) || (dir = new File(currentMobileDir, "flashupdate")).equals(pathname) || (dir.exists() && FileUtils.directoryContains(dir, pathname)));
                    return ok;
                } catch (Exception e) {
                    return false;
                }
            }
        });
        json.put("lightBuild", true);
    } else {
        throw new ServiceException("Unknow build mode: " + buildMode);
    }
    // Update config.xml
    File configFile = new File(destDir, "config.xml");
    String configText = FileUtils.readFileToString(configFile, StandardCharsets.UTF_8);
    long revision = destDir.lastModified();
    configText = configText.replace("$(ApplicationID)$", mobileApplication.getComputedApplicationId()).replace("$(ApplicationVersion)$", mobileApplication.getComputedApplicationVersion()).replace("$(ApplicationName)$", StringEscapeUtils.escapeXml11(finalApplicationName)).replace("$(ApplicationDescription)$", StringEscapeUtils.escapeXml11(mobileApplication.getApplicationDescription())).replace("$(ApplicationAuthorName)$", StringEscapeUtils.escapeXml11(mobileApplication.getApplicationAuthorName())).replace("$(ApplicationAuthorEmail)$", mobileApplication.getApplicationAuthorEmail()).replace("$(ApplicationAuthorWebsite)$", mobileApplication.getApplicationAuthorSite()).replace("$(PlatformName)$", mobilePlatform.getName()).replace("$(PlatformType)$", mobilePlatform.getType()).replace("$(CordovaPlatform)$", mobilePlatform.getCordovaPlatform());
    File pluginsFile = new File(destDir, "plugins.txt");
    if (pluginsFile.exists()) {
        String mandatoryPlugins = FileUtils.readFileToString(pluginsFile, StandardCharsets.UTF_8);
        if (!mandatoryPlugins.isEmpty()) {
            mandatoryPlugins = "<!-- Application mandatory plugins -->" + System.lineSeparator() + mandatoryPlugins;
            configText = configText.replace("<!-- Application mandatory plugins -->", mandatoryPlugins);
        }
        FileUtils.deleteQuietly(pluginsFile);
    }
    FileUtils.write(configFile, configText, StandardCharsets.UTF_8);
    configFile.setLastModified(revision);
    destDir.setLastModified(revision);
    listFiles(json);
    write("files.json", json.toString());
    String remoteBase = endpoint + "/projects/" + project.getName() + "/_private/mobile/flashupdate_" + this.mobilePlatform.getName();
    String env = read("env.json");
    try {
        json = new JSONObject(env);
    } catch (Exception e) {
        json = new JSONObject();
    }
    json.put("applicationAuthorName", mobileApplication.getApplicationAuthorName());
    json.put("applicationAuthorEmail", mobileApplication.getApplicationAuthorEmail());
    json.put("applicationAuthorWebsite", mobileApplication.getApplicationAuthorSite());
    json.put("applicationDescription", mobileApplication.getApplicationDescription());
    json.put("applicationId", mobileApplication.getComputedApplicationId());
    json.put("applicationName", finalApplicationName);
    json.put("builtRevision", revision);
    json.put("builtVersion", mobileApplication.getComputedApplicationVersion());
    json.put("currentRevision", revision);
    json.put("currentVersion", mobileApplication.getComputedApplicationVersion());
    json.put("endPoint", endpoint);
    json.put("platform", mobilePlatform.getCordovaPlatform());
    json.put("platformName", mobilePlatform.getName());
    json.put("projectName", project.getName());
    json.put("remoteBase", remoteBase);
    json.put("timeout", mobileApplication.getFlashUpdateTimeout());
    json.put("splashRemoveMode", mobileApplication.getSplashRemoveMode().name());
    write("env.json", json.toString(4));
    destDir.setLastModified(revision);
    return destDir;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) FlashUpdateBuildMode(com.twinsoft.convertigo.beans.core.MobileApplication.FlashUpdateBuildMode) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) FileFilter(java.io.FileFilter) File(java.io.File) ServiceException(com.twinsoft.convertigo.engine.admin.services.ServiceException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

FlashUpdateBuildMode (com.twinsoft.convertigo.beans.core.MobileApplication.FlashUpdateBuildMode)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 ServiceException (com.twinsoft.convertigo.engine.admin.services.ServiceException)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1 TrueFileFilter (org.apache.commons.io.filefilter.TrueFileFilter)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1