[
https://issues.apache.org/jira/browse/CB-10654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15155407#comment-15155407
]
ASF GitHub Bot commented on CB-10654:
-------------------------------------
Github user bso-intel commented on a diff in the pull request:
https://github.com/apache/cordova-lib/pull/395#discussion_r53545261
--- Diff: cordova-lib/src/cordova/platform.js ---
@@ -79,148 +79,156 @@ function addHelper(cmd, hooksRunner, projectRoot,
targets, opts) {
var platformsDir = path.join(projectRoot, 'platforms');
shell.mkdir('-p', platformsDir);
- return hooksRunner.fire('before_platform_' + cmd, opts)
- .then(function() {
- return promiseutil.Q_chainmap(targets, function(target) {
- // For each platform, download it and call its helper script.
- var parts = target.split('@');
- var platform = parts[0];
- var spec = parts[1];
-
- return Q.when().then(function() {
- if (!(platform in platforms)) {
- spec = platform;
- platform = null;
- }
+ return promiseutil.Q_chainmap(targets, function(target) {
+ // For each platform, download it and call its helper script.
+ var parts = target.split('@');
+ var platform = parts[0];
+ var spec = parts[1];
+ var platDetails = '';
+
+ return Q.when().then(function() {
+ if (!(platform in platforms)) {
+ spec = platform;
+ platform = null;
+ }
- if(platform === 'amazon-fireos') {
- events.emit('warn', 'amazon-fireos has been
deprecated. Please use android instead.');
- }
- if(platform === 'wp8') {
- events.emit('warn', 'wp8 has been deprecated. Please
use windows instead.');
- }
- if (platform && !spec && cmd == 'add') {
- events.emit('verbose', 'No version supplied.
Retrieving version from config.xml...');
- spec = getVersionFromConfigFile(platform, cfg);
- }
+ if(platform === 'amazon-fireos') {
+ events.emit('warn', 'amazon-fireos has been deprecated.
Please use android instead.');
+ }
+ if(platform === 'wp8') {
+ events.emit('warn', 'wp8 has been deprecated. Please use
windows instead.');
+ }
+ if (platform && !spec && cmd == 'add') {
+ events.emit('verbose', 'No version supplied. Retrieving
version from config.xml...');
+ spec = getVersionFromConfigFile(platform, cfg);
+ }
+
+ // If --save/autosave on && no version specified, use the
pinned version
+ // e.g: 'cordova platform add android --save', 'cordova
platform update android --save'
+ if( (opts.save || autosave) && !spec ){
+ spec = platforms[platform].version;
+ }
- // If --save/autosave on && no version specified, use the
pinned version
- // e.g: 'cordova platform add android --save', 'cordova
platform update android --save'
- if( (opts.save || autosave) && !spec ){
- spec = platforms[platform].version;
+ if (spec) {
+ var maybeDir = cordova_util.fixRelativePath(spec);
+ if (cordova_util.isDirectory(maybeDir)) {
+ return getPlatformDetailsFromDir(maybeDir, platform);
+ }
+ }
+ return downloadPlatform(projectRoot, platform, spec, opts);
+ }).then(function(platformDetails) {
+ platDetails = platformDetails;
+ var hookOpts = {
+ platforms :[platDetails.platform],
+ nohooks :[opts.nohooks]
+ };
+ return hooksRunner.fire('before_platform_' + cmd, hookOpts);
--- End diff --
Now, the behavior is a little different than before.
Previously, the before_platform_add hook ran only once for all target
platforms.
This hook could be platform agnostic.
However, by moving the hookRunner inside per platform, this hook will run
every time each platform is added.
Not sure whether this is an issue or not, though.
> _platform_add hooks not executed when platform added from repo or directory
> ---------------------------------------------------------------------------
>
> Key: CB-10654
> URL: https://issues.apache.org/jira/browse/CB-10654
> Project: Apache Cordova
> Issue Type: Bug
> Components: CordovaLib
> Affects Versions: Master
> Reporter: Tony Homer
> Assignee: Tony Homer
> Attachments: CB-10654.zip
>
>
> platform-specific before_platform_add and after_platform_add hooks are not
> executed when platforms are added from directory or repo.
> e.g., hooks defined in config.xml as follows
> {code}
> <platform name="android">
> <hook type="before_platform_add"
> src="scripts/before_platform_add/android/001_test.js" />
> <hook type="after_platform_add"
> src="scripts/after_platform_add/android/001_test.js" />
> </platform>
> {code}
> This is because the matching logic in platform.js depends on the targets
> specified in command line arguments.
> It seems that the matching logic should be deferred until the platform can be
> determined via getPlatformDetailsFromDir.
> This would require that the before_platform_add hook not be executed until
> after the platform has been downloaded.
> Steps to reproduce
> # create a project with platform-specific hooks for before_platform_add
> and/or after_platform_add defined in config.xml
> # add platform from npm, e.g.
> {code}
> cordova platform add android
> {code}
> # hooks get executed
> # add platform from repo or local dir, e.g.
> {code}
> cordova platform add https://github.com/apache/cordova-android
> cordova platform add my-local-copy-of-cordova-android
> {code}
> # hooks do not get executed
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]