Search in sources :

Example 16 with TwsCachedXPathAPI

use of com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI 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)

Example 17 with TwsCachedXPathAPI

use of com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI in project convertigo by convertigo.

the class SmtpStep method preconfigure.

@Override
public void preconfigure(Element element) throws Exception {
    super.preconfigure(element);
    String version = element.getAttribute("version");
    TwsCachedXPathAPI xpath = getXPathAPI();
    if (version != null && VersionUtils.compareMigrationVersion(version, ".m005") < 0) {
        Engine.logBeans.warn("[SmtpStep] The object \"" + getName() + "\" (subject and recipients) has been updated to m005");
        Element prop = (Element) xpath.selectSingleNode(element, "property[@name='smtpSubject']/*");
        prop.setAttribute("value", "\"" + prop.getAttribute("value") + "\"");
        prop = (Element) xpath.selectSingleNode(element, "property[@name='smtpRecipients']/*");
        prop.setAttribute("value", "\"" + prop.getAttribute("value") + "\"");
        hasChanged = true;
    }
    if (version != null && VersionUtils.compareProductVersion(version, "7.5.0") < 0) {
        Engine.logBeans.warn("[SmtpStep] The object \"" + getName() + "\" (sender) has been updated to 7.5.0");
        Element prop = (Element) xpath.selectSingleNode(element, "property[@name='smtpSender']/*");
        prop.setAttribute("value", "\"" + prop.getAttribute("value") + "\"");
        hasChanged = true;
    }
}
Also used : Element(org.w3c.dom.Element) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 18 with TwsCachedXPathAPI

use of com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI in project convertigo by convertigo.

the class XpathEvaluatorCompositeWrap method getXpathData.

public static Document getXpathData(Document document, String xPath) {
    if (document == null) {
        return null;
    }
    if (xPath == null) {
        return null;
    }
    try {
        Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
        Element root = (Element) doc.createElement("root");
        doc.appendChild(root);
        NodeList nl = new TwsCachedXPathAPI().selectNodeList(document, xPath);
        if (nl != null)
            for (int i = 0; i < nl.getLength(); i++) {
                Node node = doc.importNode(nl.item(i), true);
                Element elt = doc.getDocumentElement();
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    elt.appendChild(node);
                }
                if (node.getNodeType() == Node.TEXT_NODE) {
                    elt.appendChild(node);
                }
                if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
                    elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
                }
            }
        return doc;
    } catch (TransformerException e) {
        // ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
        return null;
    }
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Aggregations

TwsCachedXPathAPI (com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)18 Document (org.w3c.dom.Document)13 NodeList (org.w3c.dom.NodeList)11 Element (org.w3c.dom.Element)10 Node (org.w3c.dom.Node)8 TransformerException (javax.xml.transform.TransformerException)7 LinkedList (java.util.LinkedList)5 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)4 Android (com.twinsoft.convertigo.beans.mobileplatforms.Android)4 WindowsPhone8 (com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8)4 EngineException (com.twinsoft.convertigo.engine.EngineException)4 File (java.io.File)4 IOException (java.io.IOException)4 List (java.util.List)4 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)3 MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)3 IOs (com.twinsoft.convertigo.beans.mobileplatforms.IOs)3 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 Project (com.twinsoft.convertigo.beans.core.Project)2 Windows (com.twinsoft.convertigo.beans.mobileplatforms.Windows)2