use of com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8 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;
}
use of com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8 in project convertigo by convertigo.
the class BuildLocally method processConfigXMLResources.
/**
* Explore "config.xml", handle plugins and copy needed resources to appropriate platforms folders.
* @param wwwDir
* @param platform
* @param cordovaDir
*/
private void processConfigXMLResources(File wwwDir, File cordovaDir) throws Throwable {
try {
File configFile = new File(cordovaDir, "config.xml");
Document doc = XMLUtils.loadXml(configFile);
TwsCachedXPathAPI xpathApi = new TwsCachedXPathAPI();
// Changes icons and splashs src in config.xml file because it was moved to the parent folder
NodeIterator nodeIterator = xpathApi.selectNodeIterator(doc, "//*[local-name()='splash' or local-name()='icon']");
Element singleElement = (Element) nodeIterator.nextNode();
while (singleElement != null) {
String src = singleElement.getAttribute("src");
src = "www/" + src;
File file = new File(cordovaDir, src);
if (file.exists()) {
singleElement.setAttribute("src", src);
}
singleElement = (Element) nodeIterator.nextNode();
}
// ANDROID
if (mobilePlatform instanceof Android) {
singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/name");
if (singleElement != null) {
String name = singleElement.getTextContent();
name = name.replace("\\", "\\\\");
name = name.replace("'", "\\'");
name = name.replace("\"", "\\\"");
singleElement.setTextContent(name);
}
}
// WINPHONE
if (mobilePlatform instanceof WindowsPhone8) {
// Without these width and height the local build doesn't work but with these the remote build doesn't work
singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/platform[@name='wp8']/icon[not(@role)]");
if (singleElement != null) {
singleElement.setAttribute("width", "99");
singleElement.setAttribute("height", "99");
}
singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/platform[@name='wp8']/icon[@role='background']");
if (singleElement != null) {
singleElement.setAttribute("width", "159");
singleElement.setAttribute("height", "159");
}
// /widget/platform[@name='wp8']/splash
singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/platform/splash");
if (singleElement != null) {
singleElement.setAttribute("width", "768");
singleElement.setAttribute("height", "1280");
}
singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/plugin[@name='phonegap-plugin-push']/param[@name='SENDER_ID']");
if (singleElement != null) {
// Remote build needs a node named 'param' and local build needs a node named 'variable'
singleElement.getParentNode().appendChild(cloneNode(singleElement, "variable"));
singleElement.getParentNode().removeChild(singleElement);
}
}
// XMLUtils.saveXml(doc, configFile.getAbsolutePath());
// We have to add the root config.xml all our app's config.xml preferences.
// Cordova will use this file to generates the platform specific config.xml
// Get preferences from current config.xml
NodeIterator preferences = xpathApi.selectNodeIterator(doc, "//preference");
// File configFile = new File(cordovaDir, "config.xml");
// doc = XMLUtils.loadXml(configFile); // The root config.xml
NodeList preferencesList = doc.getElementsByTagName("preference");
// Remove old preferences
while (preferencesList.getLength() > 0) {
Element pathNode = (Element) preferencesList.item(0);
// Remove empty lines
Node prev = pathNode.getPreviousSibling();
if (prev != null && prev.getNodeType() == Node.TEXT_NODE && prev.getNodeValue().trim().length() == 0) {
doc.getDocumentElement().removeChild(prev);
}
doc.getDocumentElement().removeChild(pathNode);
}
for (Element preference = (Element) preferences.nextNode(); preference != null; preference = (Element) preferences.nextNode()) {
String name = preference.getAttribute("name");
String value = preference.getAttribute("value");
Element elt = doc.createElement("preference");
elt.setAttribute("name", name);
elt.setAttribute("value", value);
Engine.logEngine.info("Adding preference'" + name + "' with value '" + value + "'");
doc.getDocumentElement().appendChild(elt);
}
Engine.logEngine.trace("New config.xml is: " + XMLUtils.prettyPrintDOM(doc));
File resXmlFile = new File(cordovaDir, "config.xml");
// FileUtils.deleteQuietly(resXmlFile);
XMLUtils.saveXml(doc, resXmlFile.getAbsolutePath());
// Last part, as all resources has been copied to the correct location, we can remove
// our "www/res" directory before packaging to save build time and size...
// FileUtils.deleteDirectory(new File(wwwDir, "res"));
} catch (Exception e) {
logException(e, "Unable to process config.xml in your project, check the file's validity");
}
}
use of com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8 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);
}
use of com.twinsoft.convertigo.beans.mobileplatforms.WindowsPhone8 in project convertigo by convertigo.
the class XPathToCheck method migrate.
public static void migrate(String projectName) {
try {
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
MobileApplication mobileApplication = project.getMobileApplication();
if (mobileApplication != null) {
TwsCachedXPathAPI xpathApi = new TwsCachedXPathAPI();
// Tags to change for all platforms
List<XPathToCheck> xPathToCheckDefault = new LinkedList<XPathToCheck>();
xPathToCheckDefault.add(new XPathToCheck("/widget/preference[@name='phonegap-version']", "", true));
xPathToCheckDefault.add(new XPathToCheck("/widget/preference[@name='SplashScreen']", "", true));
xPathToCheckDefault.add(new XPathToCheck("/widget/preference[@name='ShowSplashScreenSpinner']", "", true));
String[][] pluginList = new String[][] { { "org.apache.cordova.device", "org.apache.cordova.file", "org.apache.cordova.file-transfer", "org.apache.cordova.splashscreen", "cordova-plugin-whitelist", "org.apache.cordova.console" }, { "cordova-plugin-device", "cordova-plugin-file", "cordova-plugin-file-transfer", "cordova-plugin-splashscreen", "cordova-plugin-whitelist", "cordova-plugin-console" } };
for (int i = 0; i < pluginList[0].length; i++) {
xPathToCheckDefault.add(new XPathToCheck("/widget/*[local-name()='plugin' and @name='" + pluginList[0][i] + "']", "/widget/plugin[@name='" + pluginList[1][i] + "']", true));
xPathToCheckDefault.add(new XPathToCheck("/widget/*[local-name()='plugin' and @name='" + pluginList[1][i] + "']", "/widget/plugin[@name='" + pluginList[1][i] + "']", true));
}
pluginList = new String[][] { { "com.couchbase.lite.phonegap", "org.apache.cordova.battery-status", "org.apache.cordova.camera", "org.apache.cordova.media-capture", "org.apache.cordova.contacts", "org.apache.cordova.device-motion", "org.apache.cordova.device-orientation", "org.apache.cordova.dialogs", "org.apache.cordova.geolocation", "org.apache.cordova.globalization", "org.apache.cordova.inappbrowser", "org.apache.cordova.media", "org.apache.cordova.network-information", "org.apache.cordova.vibration", "org.apache.cordova.statusbar", "com.phonegap.plugins.pushplugin", "com.phonegap.plugins.barcodescanner" }, { "couchbase-lite-phonegap-plugin", "cordova-plugin-battery-status", "cordova-plugin-camera", "cordova-plugin-media-capture", "cordova-plugin-contacts", "cordova-plugin-device-motion", "cordova-plugin-device-orientation", "cordova-plugin-dialogs", "cordova-plugin-geolocation", "cordova-plugin-globalization", "cordova-plugin-inappbrowser", "cordova-plugin-media", "cordova-plugin-network-information", "cordova-plugin-vibration", "cordova-plugin-statusbar", "phonegap-plugin-push", "phonegap-plugin-barcodescanner" } };
// Tags to change only for Android
List<XPathToCheck> xPathToCheckAndroid = new LinkedList<XPathToCheck>();
xPathToCheckAndroid.addAll(xPathToCheckDefault);
xPathToCheckAndroid.add(new XPathToCheck("/widget/platform[@name='android' and not(*)]", "/widget/engine[@name='$(CordovaPlatform)$']", true));
xPathToCheckAndroid.add(new XPathToCheck("/widget/preference[@name='android-minSdkVersion']", "", true));
xPathToCheckAndroid.add(new XPathToCheck("/widget/preference[@name='android-build-tool']", "", true));
String[] androidResList = new String[] { "ldpi", "mdpi", "hdpi", "xhdpi" };
for (String androidRes : androidResList) {
xPathToCheckAndroid.add(new XPathToCheck("/widget/icon[@gap:platform='android' and @gap:qualifier='" + androidRes + "']", "/widget/platform[@name='android']/icon[@density='" + androidRes + "']", false));
}
androidResList = new String[] { "ldpi", "mdpi", "hdpi", "xhdpi", "land-ldpi", "land-mdpi", "land-hdpi", "land-xhdpi" };
for (String androidRes : androidResList) {
xPathToCheckAndroid.add(new XPathToCheck("/widget/splash[@gap:platform='android' and @gap:qualifier='" + androidRes + "']", "/widget/platform[@name='android']/splash[@density='" + androidRes + "']", false));
}
// Tags to change only for iOS
List<XPathToCheck> xPathToCheckIOs = new LinkedList<XPathToCheck>();
xPathToCheckIOs.addAll(xPathToCheckDefault);
xPathToCheckIOs.add(new XPathToCheck("/widget/platform[@name='ios']", "/widget/engine[@name='$(CordovaPlatform)$']", true));
xPathToCheckIOs.add(new XPathToCheck("/widget/preference[@name='target-device' and @value='universal']", null, true));
String[] iosResList = new String[] { "180", "120", "57", "72", "114", "144" };
for (String iosRes : iosResList) {
xPathToCheckIOs.add(new XPathToCheck("/widget/icon[@gap:platform='ios' and @width='" + iosRes + "']", "/widget/platform[@name='ios']/icon[@width='" + iosRes + "']", false));
}
iosResList = new String[] { "2208", "1334", "1136", "1496", "748", "2008", "1004", "960", "480" };
for (String iosRes : iosResList) {
xPathToCheckIOs.add(new XPathToCheck("/widget/splash[@gap:platform='ios' and @height='" + iosRes + "']", "/widget/platform[@name='ios']/splash[@height='" + iosRes + "']", false));
}
xPathToCheckIOs.add(new XPathToCheck("/widget/access", "", true));
// Tags to change only for Windows Phone 8
List<XPathToCheck> xPathToCheckWinPhone8 = new LinkedList<XPathToCheck>();
xPathToCheckWinPhone8.addAll(xPathToCheckDefault);
xPathToCheckWinPhone8.add(new XPathToCheck("/widget/platform[@name='winphone' and not(*)]", "/widget/engine[@name='$(CordovaPlatform)$']", true));
xPathToCheckWinPhone8.add(new XPathToCheck("/widget/icon[@gap:platform='winphone' and not(@gap:role)]", "/widget/platform[@name='wp8']/icon[not(@role)]", false));
xPathToCheckWinPhone8.add(new XPathToCheck("/widget/icon[@gap:platform='winphone' and @gap:role='background']", "/widget/platform[@name='wp8']/icon[@role='background']", false));
xPathToCheckWinPhone8.add(new XPathToCheck("/widget/splash[@gap:platform='winphone']", "/widget/platform[@name='wp8']/splash[@src]", false));
// Iterates on each platforms
List<MobilePlatform> mobilePlatformList = mobileApplication.getMobilePlatformList();
for (MobilePlatform mobilePlatform : mobilePlatformList) {
// Get the config.xml file and load the xml
File configFile = new File(mobilePlatform.getResourceFolder(), "config.xml");
if (configFile.exists()) {
Document oldDoc = XMLUtils.loadXml(configFile);
// Gets the tags to change depending to the platform
List<XPathToCheck> xPathToCheckList = null;
String platformName = null;
if (mobilePlatform instanceof Android) {
xPathToCheckList = xPathToCheckAndroid;
platformName = "Android";
} else if (mobilePlatform instanceof IOs) {
xPathToCheckList = xPathToCheckIOs;
platformName = "IOs";
} else if (mobilePlatform instanceof WindowsPhone8) {
xPathToCheckList = xPathToCheckWinPhone8;
platformName = "WindowsPhone8";
} else {
continue;
}
// Gets the template config.xml file and load the xml
String configTemplatePath = Engine.TEMPLATES_PATH + "/base/DisplayObjects/platforms/" + platformName + "/config.xml";
File configTemplateFile = new File(configTemplatePath);
if (!configTemplateFile.exists()) {
throw new Exception("Can't find template config.xml at " + configTemplatePath);
}
Document templateDoc = XMLUtils.loadXml(configTemplateFile);
for (XPathToCheck xPathToCheck : xPathToCheckList) {
Element oldElement = (Element) xpathApi.selectSingleNode(oldDoc, xPathToCheck.oldXpath);
// If the goal is to remove the old node
if (xPathToCheck.templateXpath == null) {
if (oldElement != null) {
oldElement.getParentNode().removeChild(oldElement);
}
continue;
}
Element templateElement = (Element) xpathApi.selectSingleNode(templateDoc, xPathToCheck.templateXpath);
// Can't do anything if the element is not found in the template file
if (templateElement == null) {
continue;
}
// Replace the old element by the template
if (oldElement != null || xPathToCheck.required) {
// If the template is already in the old config.xml
Element templateOldElement = (Element) xpathApi.selectSingleNode(oldDoc, xPathToCheck.templateXpath);
if (templateOldElement != null && templateElement.isEqualNode(templateOldElement)) {
continue;
}
String xPathTemplateParent = xPathToCheck.templateXpath.substring(0, xPathToCheck.templateXpath.lastIndexOf('/'));
Node parentNode = createSameTree(oldDoc, templateElement.getParentNode(), xPathTemplateParent, xpathApi);
Node newNode = oldDoc.adoptNode(templateElement.cloneNode(true));
if (oldElement != null) {
if (parentNode.isSameNode(oldElement.getParentNode())) {
parentNode.replaceChild(newNode, oldElement);
} else {
parentNode.appendChild(newNode);
oldElement.getParentNode().removeChild(oldElement);
}
} else {
parentNode.appendChild(newNode);
}
}
}
for (int i = 0; i < pluginList[0].length; i++) {
Node comment = xpathApi.selectNode(oldDoc, "//comment()[contains(.,\"" + pluginList[1][i] + "\")]");
if (comment == null) {
comment = xpathApi.selectNode(oldDoc, "//comment()[contains(.,\"" + pluginList[0][i] + "\")]");
}
if (comment != null) {
Node newComment = xpathApi.selectNode(templateDoc, "//comment()[contains(.,\"" + pluginList[1][i] + "\")]");
comment.getParentNode().replaceChild(oldDoc.adoptNode(newComment), comment);
}
}
File oldConfigFile = new File(configFile.getParent(), "config.xml.old");
if (!oldConfigFile.exists()) {
oldConfigFile.createNewFile();
}
FileUtils.copyFile(configFile, oldConfigFile);
File newConfigFile = new File(mobilePlatform.getResourceFolder(), "config.xml");
if (!newConfigFile.exists()) {
newConfigFile.createNewFile();
}
XMLUtils.saveXml(oldDoc, newConfigFile.getAbsolutePath());
}
}
}
} catch (Exception e) {
Engine.logDatabaseObjectManager.error("[Migration 7.4.0] An error occured while migrating project \"" + projectName + "\"", e);
}
}
Aggregations