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;
}
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);
}
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;
}
}
Aggregations