This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement Cordova plugin for the iOS tests #771
- Loading branch information
1 parent
460b864
commit 8305465
Showing
14 changed files
with
181 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// this code was taken from https://github.com/Justin-Credible/cordova-plugin-braintree/blob/master/hooks/after_plugin_install.js | ||
// | ||
|
||
var fs = require("fs"); | ||
var path = require("path"); | ||
var child_process = require("child_process"); | ||
|
||
module.exports = function(context) { | ||
|
||
// Temporary hack to run npm install on this plugin's package.json dependencies. | ||
var pluginDir = path.resolve(__dirname, "../"); | ||
|
||
child_process.execSync("npm --prefix " + pluginDir + " install " + pluginDir); | ||
var xcode = require("xcode"); | ||
|
||
// Need a promise so that the install waits for us to complete our project modifications | ||
// before the plugin gets installed. | ||
var Q = context.requireCordovaModule("q"); | ||
var deferral = new Q.defer(); | ||
|
||
var platforms = context.opts.cordova.platforms; | ||
|
||
// We can bail out if the iOS platform isn't present. | ||
if (platforms.indexOf("ios") === -1) { | ||
deferral.resolve(); | ||
return deferral.promise; | ||
} | ||
|
||
// We need to embded frameworks to the project here. | ||
// They need to be embedded binaries and cordova does not yet support that. | ||
// We will use node-xcode directy to add them since that library has | ||
// been upgraded to support embedded binaries. | ||
|
||
// Cordova libs to get the project path and project name so we can locate the xcode project file. | ||
var cordova_util = context.requireCordovaModule("cordova-lib/src/cordova/util"), | ||
ConfigParser = context.requireCordovaModule("cordova-lib").configparser, | ||
projectRoot = cordova_util.isCordova(), | ||
xml = cordova_util.projectConfig(projectRoot), | ||
cfg = new ConfigParser(xml); | ||
|
||
var projectPath = path.join(projectRoot, "platforms", "ios", cfg.name() + ".xcodeproj", "project.pbxproj"); | ||
var xcodeProject = xcode.project(projectPath); | ||
|
||
xcodeProject.parse(function(err) { | ||
|
||
// If we couldn't parse the project, bail out. | ||
if (err) { | ||
deferral.reject("ThaliPluginTests - after_plugin_install: " + JSON.stringify(err)); | ||
return; | ||
} | ||
|
||
// Cordova project should not have more that one target. | ||
var targetUUID = xcodeProject.getFirstTarget().uuid; | ||
|
||
// Remove all of the frameworks because they were not embeded correctly. | ||
var frameworkPath = cfg.name() + "/Plugins/org.thaliproject.p2p-tests/"; | ||
xcodeProject.removeFramework(frameworkPath + "XCTest.framework"); | ||
|
||
// First check to see if the Embed Framework node exists, if not, add it. | ||
// This is all we need to do as they are added to the embedded section by default. | ||
if (!xcodeProject.pbxEmbedFrameworksBuildPhaseObj(targetUUID)) { | ||
buildPhaseResult = xcodeProject.addBuildPhase([], "PBXCopyFilesBuildPhase", "Embed Frameworks", targetUUID, "framework"); | ||
// No idea why, but "Framework" (value 10) is not available in node-xcode, set it here manually so libraries | ||
// embed correctly. If we don't set it, the folder type defaults to "Shared Frameworks". | ||
buildPhaseResult.buildPhase.dstSubfolderSpec = 10; | ||
console.log("Adding Embedded Build Phase"); | ||
} else { | ||
console.log("Embedded Build Phase already added"); | ||
} | ||
|
||
// This is critical to include, otherwise the library loader cannot find the dynamic Braintree libs at runtime | ||
// on a device. | ||
xcodeProject.addBuildProperty("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks\"", "Debug"); | ||
xcodeProject.addBuildProperty("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks\"", "Release"); | ||
|
||
// Add the frameworks again. This time they will have the code-sign option set so they get code signed when being deployed to devices. | ||
xcodeProject.addFramework(frameworkPath + "XCTest.framework", {customFramework: true, embed: true, link: true}); | ||
|
||
// Save the project file back to disk. | ||
fs.writeFileSync(projectPath, xcodeProject.writeSync(), "utf-8"); | ||
deferral.resolve(); | ||
}); | ||
|
||
return deferral.promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "ThaliTests", | ||
"version": "0.0.1", | ||
"description": "ThaliPlugin Tests", | ||
"cordova": { | ||
"id": "org.thaliproject.p2p-tests", | ||
"platforms": [ | ||
"ios" | ||
] | ||
}, | ||
"keywords": [ | ||
"cordova", | ||
"jxcore", | ||
"node.js", | ||
"thali", | ||
"test", | ||
"cordova-ios" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"xcode": "git://github.com/kurtisf/node-xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
id="org.thaliproject.p2p-tests" | ||
version="0.0.1"> | ||
|
||
<name>ThaliTests</name> | ||
<description>ThaliPlugin Tests</description> | ||
<license>MIT</license> | ||
<keywords>cordova,jxcore,node.js,thali,test</keywords> | ||
|
||
<engines> | ||
<engine name="cordova-ios" version=">=3.9.0" /> | ||
</engines> | ||
|
||
<hook type="after_plugin_install" src="hooks/after_plugin_install.js" /> | ||
|
||
<platform name="ios"> | ||
<config-file target="config.xml" parent="/*"> | ||
<feature name="ThaliTests"> | ||
<param name="ios-package" value="ThaliTests" /> | ||
</feature> | ||
</config-file> | ||
|
||
<!-- <framework | ||
src="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework" | ||
arch="ARM" | ||
target-dir="frameworks/iPhoneOS.platform" | ||
custom="true" | ||
/> --> | ||
<framework | ||
src="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks/XCTest.framework" | ||
arch="x86" | ||
target-dir="Frameworks/iPhoneSimulator.platform" | ||
custom="true" | ||
embed="true" | ||
/> | ||
|
||
<header-file src="src/ios/THETestRun.h" /> | ||
<source-file src="src/ios/THETestRun.m" /> | ||
<header-file src="src/ios/THETestRunFailure.h" /> | ||
<source-file src="src/ios/THETestRunFailure.m" /> | ||
<header-file src="src/ios/THETestRunner.h" /> | ||
<source-file src="src/ios/THETestRunner.m" /> | ||
<header-file src="src/ios/THETestRunnerResult.h" /> | ||
<source-file src="src/ios/THETestRunnerResult.m" /> | ||
|
||
</platform> | ||
|
||
</plugin> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,4 @@ NS_ASSUME_NONNULL_BEGIN | |
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
NS_ASSUME_NONNULL_END |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.