Search in sources :

Example 1 with Windows

use of com.twinsoft.convertigo.beans.mobileplatforms.Windows in project convertigo by convertigo.

the class Migration7_0_0 method migrate.

public static Element migrate(Document document, Element projectNode) throws EngineException {
    try {
        NodeList mobileDevicesNodeList = XMLUtils.findElements(projectNode, "/mobiledevice");
        if (mobileDevicesNodeList != null) {
            MobileApplication mobileApplication = new MobileApplication();
            Element mobileApplicationElement = mobileApplication.toXml(document);
            projectNode.appendChild(mobileApplicationElement);
            Node[] mobileDeviceNodes = XMLUtils.toNodeArray(mobileDevicesNodeList);
            boolean hasAndroid = false;
            boolean hasIOs = false;
            for (Node mobileDeviceNode : mobileDeviceNodes) {
                Element mobileDevice = (Element) mobileDeviceNode;
                String classname = mobileDevice.getAttribute("classname");
                if (classname == null) {
                // may never arrived
                } else if (classname.equals("com.twinsoft.convertigo.beans.mobiledevices.Android")) {
                    hasAndroid = true;
                } else if (classname.startsWith("com.twinsoft.convertigo.beans.mobiledevices.IP")) {
                    hasIOs = true;
                }
                projectNode.removeChild(mobileDevice);
            }
            if (hasAndroid) {
                mobileApplicationElement.appendChild(new Android().toXml(document));
            }
            if (hasIOs) {
                mobileApplicationElement.appendChild(new IOs().toXml(document));
            }
            if (hasAndroid && hasIOs) {
                mobileApplicationElement.appendChild(new WindowsPhone8().toXml(document));
                mobileApplicationElement.appendChild(new Windows().toXml(document));
            }
            String projectName = "" + XMLUtils.findPropertyValue(projectNode, "name");
            File mobileFolder = new File(Engine.projectDir(projectName) + "/DisplayObjects/mobile");
            if (mobileFolder.exists()) {
                FileUtils.write(new File(mobileFolder, "mobile_project_migrated.txt"), "Your mobile project has been migrated.\n" + "Now, we make per platform configuration and resources.\n" + "You may customize your config.xml (the existing one will never used) and dispatch your existing specific resources per platform (see the 'platforms' folder).\n" + "You can delete this file after reading it.", "UTF-8");
            }
        }
    } catch (Exception e) {
        throw new EngineException("[Migration 7.0.0] Unable to migrate project", e);
    }
    return projectNode;
}
Also used : WindowsPhone8(com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8) NodeList(org.w3c.dom.NodeList) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) Windows(com.twinsoft.convertigo.beans.mobileplatforms.Windows) IOs(com.twinsoft.convertigo.beans.mobileplatforms.IOs) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) Android(com.twinsoft.convertigo.beans.mobileplatforms.Android) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) File(java.io.File)

Example 2 with Windows

use of com.twinsoft.convertigo.beans.mobileplatforms.Windows in project convertigo by convertigo.

the class BuildLocally method getAbsolutePathOfBuiltFile.

/**
 * Return the absolute path of built application file
 * @param mobilePlatform
 * @param buildMode
 * @return
 */
protected File getAbsolutePathOfBuiltFile(MobilePlatform mobilePlatform, String buildMode) {
    String cordovaPlatform = mobilePlatform.getCordovaPlatform();
    String builtPath = File.separator + "platforms" + File.separator + cordovaPlatform + File.separator;
    String buildMd = buildMode.equals("debug") ? "Debug" : "Release";
    String extension = "";
    File f = new File(getCordovaDir(), builtPath);
    if (f.exists()) {
        // Android
        if (mobilePlatform instanceof Android) {
            builtPath = builtPath + "ant-build" + File.separator;
            File f2 = new File(getCordovaDir(), builtPath);
            if (!f2.exists()) {
                builtPath = File.separator + "platforms" + File.separator + cordovaPlatform + File.separator + "build" + File.separator + "outputs" + File.separator + "apk" + File.separator;
            }
            extension = "apk";
        // iOS
        } else if (mobilePlatform instanceof IOs) {
            extension = "xcodeproj";
        // Windows Phone 8
        } else if (mobilePlatform instanceof WindowsPhone8) {
            builtPath = builtPath + "Bin" + File.separator + buildMd + File.separator;
            extension = "xap";
        // Windows 8
        } else if (mobilePlatform instanceof Windows) {
        // TODO : Handle Windows 8
        } else {
            return null;
        }
    }
    f = new File(getCordovaDir(), builtPath);
    if (f.exists()) {
        String[] filesNames = f.list();
        int i = filesNames.length - 1;
        boolean find = false;
        while (i > 0 && !find && !extension.isEmpty()) {
            String fileName = filesNames[i];
            if (fileName.endsWith(extension)) {
                builtPath += fileName;
                find = true;
            }
            i--;
        }
    } else {
        builtPath = File.separator + "platforms" + File.separator + cordovaPlatform + File.separator;
    }
    return new File(getCordovaDir(), builtPath);
}
Also used : WindowsPhone8(com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8) Windows(com.twinsoft.convertigo.beans.mobileplatforms.Windows) IOs(com.twinsoft.convertigo.beans.mobileplatforms.IOs) File(java.io.File) Android(com.twinsoft.convertigo.beans.mobileplatforms.Android)

Example 3 with Windows

use of com.twinsoft.convertigo.beans.mobileplatforms.Windows in project convertigo by convertigo.

the class BuildLocally method runBuild.

public Status runBuild(String option, boolean run, String target) {
    try {
        File cordovaDir = getCordovaDir();
        File wwwDir = new File(cordovaDir, "www");
        wwwDir.mkdirs();
        if (!wwwDir.exists()) {
            throw new EngineException("Cannot create the build folder '" + wwwDir.getAbsolutePath() + "', check the current user can create files or change the Eclipse preference: 'Convertigo/Studio/Local Build Folder'.");
        }
        // Cordova environment is already created, we have to build
        // Step 1: Call Mobile packager to prepare the source package
        MobileResourceHelper mobileResourceHelper = new MobileResourceHelper(mobilePlatform, wwwDir.getAbsolutePath());
        wwwDir = mobileResourceHelper.preparePackage();
        // Step 2: Add platform and read config.xml to copy needed icons and splash resources
        String cordovaPlatform = mobilePlatform.getCordovaPlatform();
        // 
        FileUtils.copyFile(new File(wwwDir, "config.xml"), new File(cordovaDir, "config.xml"));
        FileUtils.deleteQuietly(new File(wwwDir, "config.xml"));
        if (iosProvisioningProfileUUID != null) {
            boolean release = "release".equals(option);
            JSONObject json = new JSONObject();
            if (iosSignIdentity != null) {
                json.put("codeSignIdentity", iosSignIdentity);
            } else {
                json.put("codeSignIdentity", release ? "iPhone Distribution" : "iPhone Developer");
            }
            json.put("provisioningProfile", iosProvisioningProfileUUID);
            json = new JSONObject().put(release ? "release" : "debug", json);
            json = new JSONObject().put("ios", json);
            FileUtils.write(new File(cordovaDir, "build.json"), json.toString(2), "utf-8");
        }
        if (androidKeystore != null) {
            boolean release = "release".equals(option);
            JSONObject json = new JSONObject();
            json.put("keystore", androidKeystore.getAbsolutePath());
            json.put("storePassword", androidKeystorePassword);
            json.put("alias", androidAlias);
            json.put("password", androidPassword);
            json.put("keystoreType", "");
            json = new JSONObject().put(release ? "release" : "debug", json);
            json = new JSONObject().put("android", json);
            FileUtils.write(new File(cordovaDir, "build.json"), json.toString(2), "utf-8");
        }
        processConfigXMLResources(wwwDir, cordovaDir);
        List<String> commandsList = new LinkedList<String>();
        if (mobilePlatform instanceof Windows) {
            File configFile = new File(cordovaDir, "config.xml");
            Document doc = XMLUtils.loadXml(configFile);
            TwsCachedXPathAPI xpathApi = new TwsCachedXPathAPI();
            Element singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/engine[@name='windows']");
            if (singleElement == null) {
                throw new Exception("The tag 'engine' is not specified in the file config.xml.");
            }
            String appx = singleElement.getAttribute("appx");
            String archs = singleElement.getAttribute("archs");
            if (appx == null || archs == null || appx.isEmpty() || archs.isEmpty()) {
                throw new Exception("The attributes 'appx' and 'archs' are not specified in the tag engine.");
            }
            commandsList.add("--");
            commandsList.add("--appx=" + appx);
            commandsList.add("--archs=" + archs);
        }
        jdk8Dir = null;
        if ("android".equals(mobilePlatform.getCordovaPlatform())) {
            Engine.logEngine.info("Check or install for the JDK8 to build the Android application");
            jdk8Dir = ProcessUtils.getJDK8((pBytesRead, pContentLength, pItems) -> {
                Engine.logEngine.info("download JDK8: " + Math.round(100f * pBytesRead / pContentLength) + "% [" + pBytesRead + "/" + pContentLength + "]");
            });
            androidSdkDir = ProcessUtils.getAndroidSDK(preferedAndroidBuildTools, (pBytesRead, pContentLength, pItems) -> {
                Engine.logEngine.info("download Android SDK: " + Math.round(100f * pBytesRead / pContentLength) + "% [" + pBytesRead + "/" + pContentLength + "]");
            });
            gradleDir = ProcessUtils.getGradle((pBytesRead, pContentLength, pItems) -> {
                Engine.logEngine.info("download Gradle: " + Math.round(100f * pBytesRead / pContentLength) + "% [" + pBytesRead + "/" + pContentLength + "]");
            });
        }
        runCordovaCommand(cordovaDir, "prepare", cordovaPlatform);
        // Step 3: Build or Run using Cordova the specific platform.
        if (run) {
            commandsList.add(0, "run");
            commandsList.add(1, cordovaPlatform);
            commandsList.add(2, "--" + option);
            commandsList.add(3, "--" + target);
            runCordovaCommand(cordovaDir, commandsList);
        } else {
            commandsList.add(0, "build");
            commandsList.add(1, cordovaPlatform);
            commandsList.add(2, "--" + option);
            commandsList.add(3, "--" + target);
            String out = runCordovaCommand(cordovaDir, commandsList);
            Matcher m = Pattern.compile("[^\\s]+(?:\\.apk|/build/device)").matcher(out);
            if (m.find()) {
                File pkg;
                do {
                    pkg = new File(m.group());
                    if (pkg.exists()) {
                        if (pkg.getName().equals("device")) {
                            for (File f : pkg.listFiles()) {
                                if (f.getName().endsWith(".ipa")) {
                                    pkg = f;
                                    break;
                                }
                            }
                        }
                        mobilePackage = pkg;
                    }
                } while (m.find());
            }
            // Step 4: Show dialog with path to apk/ipa/xap
            if (!processCanceled) {
                showLocationInstallFile(mobilePlatform, process.exitValue(), errorLines, option);
            }
        }
        return Status.OK;
    } catch (Throwable e) {
        logException(e, "Error when processing Cordova build: " + e);
        return Status.CANCEL;
    }
}
Also used : TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI) IOs(com.twinsoft.convertigo.beans.mobileplatforms.IOs) Attr(org.w3c.dom.Attr) Matcher(java.util.regex.Matcher) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) NamedNodeMap(org.w3c.dom.NamedNodeMap) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) Windows(com.twinsoft.convertigo.beans.mobileplatforms.Windows) Engine(com.twinsoft.convertigo.engine.Engine) JSONObject(org.codehaus.jettison.json.JSONObject) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) WindowsPhone8(com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8) File(java.io.File) Android(com.twinsoft.convertigo.beans.mobileplatforms.Android) List(java.util.List) Element(org.w3c.dom.Element) NodeIterator(org.w3c.dom.traversal.NodeIterator) MobileResourceHelper(com.twinsoft.convertigo.engine.admin.services.mobiles.MobileResourceHelper) XMLUtils(com.twinsoft.convertigo.engine.util.XMLUtils) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) EngineException(com.twinsoft.convertigo.engine.EngineException) Collections(java.util.Collections) ProcessUtils(com.twinsoft.convertigo.engine.util.ProcessUtils) Matcher(java.util.regex.Matcher) Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) Windows(com.twinsoft.convertigo.beans.mobileplatforms.Windows) MobileResourceHelper(com.twinsoft.convertigo.engine.admin.services.mobiles.MobileResourceHelper) Document(org.w3c.dom.Document) LinkedList(java.util.LinkedList) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException) JSONObject(org.codehaus.jettison.json.JSONObject) File(java.io.File) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Aggregations

Android (com.twinsoft.convertigo.beans.mobileplatforms.Android)3 IOs (com.twinsoft.convertigo.beans.mobileplatforms.IOs)3 Windows (com.twinsoft.convertigo.beans.mobileplatforms.Windows)3 WindowsPhone8 (com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8)3 File (java.io.File)3 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 IOException (java.io.IOException)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)1 Engine (com.twinsoft.convertigo.engine.Engine)1 MobileResourceHelper (com.twinsoft.convertigo.engine.admin.services.mobiles.MobileResourceHelper)1 ProcessUtils (com.twinsoft.convertigo.engine.util.ProcessUtils)1 TwsCachedXPathAPI (com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)1 XMLUtils (com.twinsoft.convertigo.engine.util.XMLUtils)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1