Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3673417A0D for ; Fri, 13 Feb 2015 00:53:58 +0000 (UTC) Received: (qmail 64424 invoked by uid 500); 13 Feb 2015 00:53:58 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 64249 invoked by uid 500); 13 Feb 2015 00:53:58 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 64118 invoked by uid 99); 13 Feb 2015 00:53:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2015 00:53:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B4E13E0540; Fri, 13 Feb 2015 00:53:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Fri, 13 Feb 2015 00:53:59 -0000 Message-Id: <25658f5a9a784420b08d4385a4724383@git.apache.org> In-Reply-To: <95c922dc21194a5fa1e4703a7d6cf641@git.apache.org> References: <95c922dc21194a5fa1e4703a7d6cf641@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/12] cordova-lib git commit: CB-8123 Rename windows platform related files. CB-8123 Rename windows platform related files. Renames `windows8` plugin platform folders in tests to `windows`. Renames `jsproj.js` to `jsprojManager.js`. Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/48852eef Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/48852eef Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/48852eef Branch: refs/heads/CB-8416 Commit: 48852eefb20840149fa9ada28082e6cb0a2ff208 Parents: 8b6f7b9 Author: Tim Barham Authored: Wed Jan 28 11:30:27 2015 -0800 Committer: Tim Barham Committed: Wed Jan 28 11:30:27 2015 -0800 ---------------------------------------------------------------------- .../spec-plugman/platforms/windows8.spec.js | 20 +- .../org.test.plugins.dummyplugin/plugin.xml | 18 +- .../src/windows/dummer.js | 1 + .../src/windows/dummy1.dll | 0 .../src/windows/dummy1.vcxproj | 7 + .../src/windows/dummy2.dll | 0 .../src/windows/dummy2.vcxproj | 7 + .../src/windows/dummy3.dll | 0 .../src/windows/dummy3.vcxproj | 7 + .../src/windows/dummy4.dll | 0 .../src/windows/dummy4.vcxproj | 7 + .../src/windows8/dummer.js | 1 - .../src/windows8/dummy1.dll | 0 .../src/windows8/dummy1.vcxproj | 7 - .../src/windows8/dummy2.dll | 0 .../src/windows8/dummy2.vcxproj | 7 - .../src/windows8/dummy3.dll | 0 .../src/windows8/dummy3.vcxproj | 7 - .../src/windows8/dummy4.dll | 0 .../src/windows8/dummy4.vcxproj | 7 - .../org.test.plugins.faultyplugin/plugin.xml | 6 +- .../src/windows/faultyPlugin.js | 1 + .../src/windows8/faultyPlugin.js | 1 - cordova-lib/src/plugman/platforms/windows.js | 2 +- cordova-lib/src/util/windows/jsproj.js | 533 ------------------- cordova-lib/src/util/windows/jsprojManager.js | 533 +++++++++++++++++++ 26 files changed, 586 insertions(+), 586 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/platforms/windows8.spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/platforms/windows8.spec.js b/cordova-lib/spec-plugman/platforms/windows8.spec.js index 3d0215a..444c987 100644 --- a/cordova-lib/spec-plugman/platforms/windows8.spec.js +++ b/cordova-lib/spec-plugman/platforms/windows8.spec.js @@ -165,13 +165,13 @@ beforeEach(function () { var source = copyArray(valid_source); var s = spyOn(common, 'copyFile'); windows['source-file'].install(source[0], dummyplugin, cordovaProjectWindowsPlatformDir, dummy_id, null, proj_files); - expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows8/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); + expect(s).toHaveBeenCalledWith(dummyplugin, 'src/windows/dummer.js', cordovaProjectWindowsPlatformDir, path.join('plugins', 'org.test.plugins.dummyplugin', 'dummer.js'), false); }); it('should throw if source-file src cannot be found', function () { var source = copyArray(invalid_source); expect(function () { windows['source-file'].install(source[1], faultyplugin, cordovaProjectWindowsPlatformDir, faulty_id, null, proj_files); - }).toThrow('"' + path.resolve(faultyplugin, 'src/windows8/NotHere.js') + '" not found!'); + }).toThrow('"' + path.resolve(faultyplugin, 'src/windows/NotHere.js') + '" not found!'); }); it('should throw if source-file target already exists', function () { var source = copyArray(valid_source); @@ -243,16 +243,16 @@ beforeEach(function () { var frameworks = copyArray(valid_frameworks); it('should write to correct project files when conditions are specified', function () { - var xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows8\\dummy1.vcxproj"][@Condition="\'$(Platform)\'==\'x64\'"]'; + var xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy1.vcxproj"][@Condition="\'$(Platform)\'==\'x64\'"]'; validateInstalledProjects('framework', frameworks[4], xpath, ['all']); - xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows8\\dummy2.vcxproj"]'; + xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy2.vcxproj"]'; validateInstalledProjects('framework', frameworks[5], xpath, ['windows8']); - xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows8\\dummy3.vcxproj"]'; + xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy3.vcxproj"]'; validateInstalledProjects('framework', frameworks[6], xpath, ['windows', 'windows8']); - xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows8\\dummy4.vcxproj"][@Condition="\'$(Platform)\'==\'x86\'"]'; + xpath = 'ProjectReference[@Include="' + dummyplugin + '\\src\\windows\\dummy4.vcxproj"][@Condition="\'$(Platform)\'==\'x86\'"]'; validateInstalledProjects('framework', frameworks[7], xpath, ['windows', 'phone']); }); }); @@ -390,19 +390,19 @@ beforeEach(function () { install('windows', cordovaProjectWindowsPlatformDir, dummyplugin, cordovaProjectPluginsDir, {}) .then(function () { var path = 'ItemGroup/ProjectReference'; - var incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows8\\dummy1.vcxproj'; + var incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy1.vcxproj'; var targetConditions = {versions: undefined, target: undefined, arch: 'x64'}; validateUninstalledProjects('framework', frameworks[4], path, incText, targetConditions, ['all']); - incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows8\\dummy2.vcxproj'; + incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy2.vcxproj'; targetConditions = {versions: '<8.1', target: undefined, arch: undefined}; validateUninstalledProjects('framework', frameworks[5], path, incText, targetConditions, ['windows8']); - incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows8\\dummy3.vcxproj'; + incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy3.vcxproj'; targetConditions = {versions: undefined, target: 'win', arch: undefined}; validateUninstalledProjects('framework', frameworks[6], path, incText, targetConditions, ['windows', 'windows8']); - incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows8\\dummy4.vcxproj'; + incText = cordovaProjectPluginsDir + "\\" + dummy_id + '\\src\\windows\\dummy4.vcxproj'; targetConditions = {versions: '8.1', target: 'all', arch: 'x86'}; validateUninstalledProjects('framework', frameworks[7], path, incText, targetConditions, ['windows', 'phone']); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml index 1f265dd..b378b58 100644 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml @@ -178,22 +178,22 @@ - + - - - - + + + + - - - - + + + + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummer.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummer.js b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummer.js new file mode 100644 index 0000000..48388bc --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummer.js @@ -0,0 +1 @@ +./org.test.plugins.dummyplugin/src/windows8/dummer.js http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.dll new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.vcxproj new file mode 100644 index 0000000..c454905 --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy1.vcxproj @@ -0,0 +1,7 @@ + + + + {ef7dd979-6f12-4bdf-8754-9468ce799c4d} + dummy1 + + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.dll new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.vcxproj new file mode 100644 index 0000000..8edd706 --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy2.vcxproj @@ -0,0 +1,7 @@ + + + + {6a760eea-8c27-442e-b98b-a487964ded42} + dummy2 + + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.dll new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.vcxproj new file mode 100644 index 0000000..600167c --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy3.vcxproj @@ -0,0 +1,7 @@ + + + + {5318c3c8-0921-4870-b4ad-8cce06c88238} + dummy3 + + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.dll new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.vcxproj new file mode 100644 index 0000000..d7acf04 --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows/dummy4.vcxproj @@ -0,0 +1,7 @@ + + + + {8e430a1b-094b-4c27-8b76-fdd7021dbfe9} + dummy4 + + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummer.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummer.js b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummer.js deleted file mode 100644 index 48388bc..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummer.js +++ /dev/null @@ -1 +0,0 @@ -./org.test.plugins.dummyplugin/src/windows8/dummer.js http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.dll deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.vcxproj deleted file mode 100644 index c454905..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy1.vcxproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - {ef7dd979-6f12-4bdf-8754-9468ce799c4d} - dummy1 - - http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.dll deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.vcxproj deleted file mode 100644 index 8edd706..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy2.vcxproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - {6a760eea-8c27-442e-b98b-a487964ded42} - dummy2 - - http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.dll deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.vcxproj deleted file mode 100644 index 600167c..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy3.vcxproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - {5318c3c8-0921-4870-b4ad-8cce06c88238} - dummy3 - - http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.dll ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.dll b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.dll deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.vcxproj ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.vcxproj b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.vcxproj deleted file mode 100644 index d7acf04..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/src/windows8/dummy4.vcxproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - {8e430a1b-094b-4c27-8b76-fdd7021dbfe9} - dummy4 - - http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/plugin.xml ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/plugin.xml b/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/plugin.xml index 1b38414..8ff99c4 100644 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/plugin.xml +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/plugin.xml @@ -135,17 +135,17 @@ - + - + - + http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows/faultyPlugin.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows/faultyPlugin.js b/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows/faultyPlugin.js new file mode 100644 index 0000000..784b850 --- /dev/null +++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows/faultyPlugin.js @@ -0,0 +1 @@ +./org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js b/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js deleted file mode 100644 index 784b850..0000000 --- a/cordova-lib/spec-plugman/plugins/org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js +++ /dev/null @@ -1 +0,0 @@ -./org.test.plugins.faultyplugin/src/windows8/faultyPlugin.js http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/src/plugman/platforms/windows.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/plugman/platforms/windows.js b/cordova-lib/src/plugman/platforms/windows.js index 07186cb..7b5b061 100644 --- a/cordova-lib/src/plugman/platforms/windows.js +++ b/cordova-lib/src/plugman/platforms/windows.js @@ -26,7 +26,7 @@ var common = require('./common'), path = require('path'), fs = require('fs'), glob = require('glob'), - jsprojManager = require('../../util/windows/jsproj'), + jsprojManager = require('../../util/windows/jsprojManager'), events = require('../../events'), xml_helpers = require('../../util/xml-helpers'); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/src/util/windows/jsproj.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/util/windows/jsproj.js b/cordova-lib/src/util/windows/jsproj.js deleted file mode 100644 index 57642ba..0000000 --- a/cordova-lib/src/util/windows/jsproj.js +++ /dev/null @@ -1,533 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -/* jshint quotmark:false, unused:false */ - -/* - Helper for dealing with Windows Store JS app .jsproj files - */ - - -var util = require('util'), - xml_helpers = require('../../util/xml-helpers'), - et = require('elementtree'), - fs = require('fs'), - glob = require('glob'), - shell = require('shelljs'), - events = require('../../events'), - path = require('path'), - semver = require('semver'); - -var WinCSharpProjectTypeGUID = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"; // .csproj -var WinCplusplusProjectTypeGUID = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; // .vcxproj - -// Match a JavaScript Project -var JsProjectRegEx = /(Project\("\{262852C6-CD72-467D-83FE-5EEB1973A190}"\)\s*=\s*"[^"]+",\s*"[^"]+",\s*"\{[0-9a-f\-]+}"[^\r\n]*[\r\n]*)/gi; - -// Chars in a string that need to be escaped when used in a RegExp -var RegExpEscRegExp = /([.?*+\^$\[\]\\(){}|\-])/g; - -function jsprojManager(location) { - this.isUniversalWindowsApp = path.extname(location).toLowerCase() === ".projitems"; - this.projects = []; - this.master = this.isUniversalWindowsApp ? new proj(location) : new jsproj(location); - this.projectFolder = path.dirname(location); - -} - -jsprojManager.prototype = { - _projects: null, - - write: function () { - this.master.write(); - if (this._projects) { - var that = this; - this._projects.forEach(function (project) { - if (project !== that.master && project.touched) { - project.write(); - } - }); - } - }, - - addSDKRef: function (incText, targetConditions) { - events.emit('verbose', 'jsprojManager.addSDKRef(incText: ' + incText + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - var item = createReferenceElement('ItemGroup/SDKReference', incText, targetConditions); - this._getMatchingProjects(targetConditions).forEach(function (project) { - project.appendToRoot(item); - }); - }, - - removeSDKRef: function (incText, targetConditions) { - events.emit('verbose', 'jsprojManager.removeSDKRef(incText: ' + incText + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - this._getMatchingProjects(targetConditions).forEach(function (project) { - project.removeReferenceElementItemGroup('ItemGroup/SDKReference', incText, targetConditions); - }); - }, - - addReference: function (relPath, targetConditions) { - events.emit('verbose', 'jsprojManager.addReference(incText: ' + relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - // add hint path with full path - var hint_path = new et.Element('HintPath'); - hint_path.text = relPath; - var children = [hint_path]; - - var extName = path.extname(relPath); - if (extName === ".winmd") { - var mdFileTag = new et.Element("IsWinMDFile"); - mdFileTag.text = "true"; - children.push(mdFileTag); - } - - var item = createReferenceElement('ItemGroup/Reference', path.basename(relPath, extName), targetConditions, children); - this._getMatchingProjects(targetConditions).forEach(function (project) { - project.appendToRoot(item); - }); - - }, - - removeReference: function (relPath, targetConditions) { - events.emit('verbose', 'jsprojManager.removeReference(incText: ' + relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - var extName = path.extname(relPath); - var includeText = path.basename(relPath, extName); - - this._getMatchingProjects(targetConditions).forEach(function (project) { - project.removeReferenceElementItemGroup('ItemGroup/Reference', includeText, targetConditions); - }); - }, - - addSourceFile: function (relative_path) { - events.emit('verbose', 'jsprojManager.addSourceFile(relative_path: ' + relative_path + ')'); - this.master.addSourceFile(relative_path); - }, - - removeSourceFile: function (relative_path) { - events.emit('verbose', 'jsprojManager.removeSourceFile(incText: ' + relative_path + ')'); - this.master.removeSourceFile(relative_path); - }, - - addProjectReference: function (relative_path, targetConditions) { - events.emit('verbose', 'jsprojManager.addProjectReference(incText: ' + relative_path + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - relative_path = relative_path.split('/').join('\\'); - - var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path); - - // find the guid + name of the referenced project - var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text; - var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text; - - // get the project type - var projectTypeGuid = getProjectTypeGuid(relative_path); - if (!projectTypeGuid) { - throw new Error("unrecognized project type"); - } - - var preInsertText = "\tProjectSection(ProjectDependencies) = postProject\r\n" + - "\t\t" + projectGuid + "=" + projectGuid + "\r\n" + - "\tEndProjectSection\r\n"; - var postInsertText = '\r\nProject("' + projectTypeGuid + '") = "' + - projName + '", "' + relative_path + '", ' + - '"' + projectGuid + '"\r\nEndProject'; - - var matchingProjects = this._getMatchingProjects(targetConditions); - if (matchingProjects.length === 0) { - // No projects meet the specified target and version criteria, so nothing to do. - return; - } - - // Will we be writing into the .projitems file rather than individual .jsproj files? - var useProjItems = this.isUniversalWindowsApp && matchingProjects.length === 1 && matchingProjects[0] === this.master; - - // There may be multiple solution files (for different VS versions) - process them all - getSolutionPaths(this.projectFolder).forEach(function (solutionPath) { - var solText = fs.readFileSync(solutionPath, {encoding: "utf8"}); - - if (useProjItems) { - // Insert a project dependency into every jsproj in the solution. - var jsProjectFound = false; - solText = solText.replace(JsProjectRegEx, function (match) { - jsProjectFound = true; - return match + preInsertText; - }); - - if (!jsProjectFound) { - throw new Error("no jsproj found in solution"); - } - } else { - // Insert a project dependency only for projects that match specified target and version - matchingProjects.forEach(function (project) { - solText = solText.replace(getJsProjRegExForProject(path.basename(project.location)), function (match) { - return match + preInsertText; - }); - }); - } - - // Add the project after existing projects. Note that this fairly simplistic check should be fine, since the last - // EndProject in the file should actually be an EndProject (and not an EndProjectSection, for example). - var pos = solText.lastIndexOf("EndProject"); - if (pos === -1) { - throw new Error("no EndProject found in solution"); - } - pos += 10; // Move pos to the end of EndProject text - solText = solText.slice(0, pos) + postInsertText + solText.slice(pos); - - fs.writeFileSync(solutionPath, solText, {encoding: "utf8"}); - }); - - // Add the ItemGroup/ProjectReference to each matching cordova project : - // - var item = createReferenceElement('ItemGroup/ProjectReference', relative_path, targetConditions); - matchingProjects.forEach(function (project) { - project.appendToRoot(item); - }); - }, - - removeProjectReference: function (relative_path, targetConditions) { - events.emit('verbose', 'jsprojManager.removeProjectReference(incText: ' + relative_path + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); - - // find the guid + name of the referenced project - var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path); - var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text; - var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text; - - // get the project type - var projectTypeGuid = getProjectTypeGuid(relative_path); - if (!projectTypeGuid) { - throw new Error("unrecognized project type"); - } - - var preInsertTextRegExp = getProjectReferencePreInsertRegExp(projectGuid); - var postInsertTextRegExp = getProjectReferencePostInsertRegExp(projName, projectGuid, relative_path, projectTypeGuid); - - // There may be multiple solutions (for different VS versions) - process them all - getSolutionPaths(this.projectFolder).forEach(function (solutionPath) { - var solText = fs.readFileSync(solutionPath, {encoding: "utf8"}); - - // To be safe (to handle subtle changes in formatting, for example), use a RegExp to find and remove - // preInsertText and postInsertText - - solText = solText.replace(preInsertTextRegExp, function () { - return ""; - }); - - solText = solText.replace(postInsertTextRegExp, function () { - return ""; - }); - - fs.writeFileSync(solutionPath, solText, {encoding: "utf8"}); - }); - - this._getMatchingProjects(targetConditions).forEach(function (project) { - project.removeReferenceElementItemGroup('ItemGroup/ProjectReference', relative_path, targetConditions); - }); - }, - - _getMatchingProjects: function (targetConditions) { - // If specified, target can be 'all' (default), 'phone' or 'windows'. Ultimately should probably allow a comma - // separated list, but not needed now. - var target = getTarget(targetConditions); - var versions = getVersions(targetConditions); - - if (target || versions) { - var matchingProjects = this.projects.filter(function (project) { - return (!target || target === project.target) && (!versions || semver.satisfies(project.version, versions, /* loose */ true)); - }); - - if (matchingProjects.length < this.projects.length) { - return matchingProjects; - } - } - - // All projects match. If this is a universal project, return the projitems file. Otherwise return our single - // project. - return [this.master]; - }, - - get projects() { - var projects = this._projects; - if (!projects) { - projects = []; - this._projects = projects; - - if (this.isUniversalWindowsApp) { - var projectPath = this.projectFolder; - var projectFiles = glob.sync('*.jsproj', {cwd: projectPath}); - projectFiles.forEach(function (projectFile) { - projects.push(new jsproj(path.join(projectPath, projectFile))); - }); - } else { - this.projects.push(this.master); - } - } - - return projects; - } -}; - -function getProjectReferencePreInsertRegExp(projectGuid) { - projectGuid = escapeRegExpString(projectGuid); - return new RegExp("\\s*ProjectSection\\(ProjectDependencies\\)\\s*=\\s*postProject\\s*" + projectGuid + "\\s*=\\s*" + projectGuid + "\\s*EndProjectSection", "gi"); -} - -function getProjectReferencePostInsertRegExp(projName, projectGuid, relative_path, projectTypeGuid) { - projName = escapeRegExpString(projName); - projectGuid = escapeRegExpString(projectGuid); - relative_path = escapeRegExpString(relative_path); - projectTypeGuid = escapeRegExpString(projectTypeGuid); - return new RegExp('\\s*Project\\("' + projectTypeGuid + '"\\)\\s*=\\s*"' + projName + '"\\s*,\\s*"' + relative_path + '"\\s*,\\s*"' + projectGuid + '"\\s*EndProject', 'gi'); -} - -function getSolutionPaths(projectFolder) { - return shell.ls(path.join(projectFolder, "*.sln")); // TODO:error handling -} - -function escapeRegExpString(regExpString) { - return regExpString.replace(RegExpEscRegExp, "\\$1"); -} - -function getJsProjRegExForProject(projectFile) { - projectFile = escapeRegExpString(projectFile); - return new RegExp('(Project\\("\\{262852C6-CD72-467D-83FE-5EEB1973A190}"\\)\\s*=\\s*"[^"]+",\\s*"' + projectFile + '",\\s*"\\{[0-9a-f\\-]+}"[^\\r\\n]*[\\r\\n]*)', 'gi'); -} - -function getProjectTypeGuid(projectPath) { - switch (path.extname(projectPath)) { - case ".vcxproj": - return WinCplusplusProjectTypeGUID; - - case ".csproj": - return WinCSharpProjectTypeGUID; - } - return null; -} - -function createReferenceElement(path, incText, targetConditions, children) { - path = path.split('/'); - path.reverse(); - - var lastElement = null; - path.forEach(function (elementName) { - var element = new et.Element(elementName); - if (lastElement) { - element.append(lastElement); - } else { - element.attrib.Include = incText; - - var condition = createConditionAttrib(targetConditions); - if (condition) { - element.attrib.Condition = condition; - } - - if (children) { - children.forEach(function (child) { - element.append(child); - }); - } - } - lastElement = element; - }); - - return lastElement; -} - -function getTarget(targetConditions) { - var target = targetConditions.target; - if (target) { - target = target.toLowerCase().trim(); - if (target === "all") { - target = null; - } else if (target === "win") { - // Allow "win" as alternative to "windows" - target = "windows"; - } else if (target !== 'phone' && target !== 'windows') { - throw new Error('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): ' + target); - } - } - return target; -} - -function getVersions(targetConditions) { - var versions = targetConditions.versions; - if (versions && !semver.validRange(versions, /* loose */ true)) { - throw new Error('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): ' + versions); - } - return versions; -} - - -/* proj */ - -function proj(location) { - // Class to handle simple project xml operations - if (!location) { - throw new Error('Project file location can\'t be null or empty'); - } - this.location = location; - this.xml = xml_helpers.parseElementtreeSync(location); -} - -proj.prototype = { - write: function () { - fs.writeFileSync(this.location, this.xml.write({indent: 4}), 'utf-8'); - }, - - appendToRoot: function (element) { - this.touched = true; - this.xml.getroot().append(element); - }, - - removeReferenceElementItemGroup: function (path, incText, targetConditions) { - var xpath = path + '[@Include="' + incText + '"]'; - var condition = createConditionAttrib(targetConditions); - if (condition) { - xpath += '[@Condition="' + condition + '"]'; - } - xpath += '/..'; - - var itemGroup = this.xml.find(xpath); - if (itemGroup) { - this.touched = true; - this.xml.getroot().remove(0, itemGroup); - } - }, - - addSourceFile: function (relative_path) { - // we allow multiple paths to be passed at once as array so that - // we don't create separate ItemGroup for each source file, CB-6874 - if (!(relative_path instanceof Array)) { - relative_path = [relative_path]; - } - - // make ItemGroup to hold file. - var item = new et.Element('ItemGroup'); - - relative_path.forEach(function (filePath) { - filePath = filePath.split('/').join('\\'); - - var content = new et.Element('Content'); - content.attrib.Include = filePath; - item.append(content); - }); - - this.appendToRoot(item); - }, - - removeSourceFile: function (relative_path) { - var isRegexp = relative_path instanceof RegExp; - if (!isRegexp) { - // path.normalize(relative_path);// ?? - relative_path = relative_path.split('/').join('\\'); - } - - var root = this.xml.getroot(); - var that = this; - // iterate through all ItemGroup/Content elements and remove all items matched - this.xml.findall('ItemGroup').forEach(function (group) { - // matched files in current ItemGroup - var filesToRemove = group.findall('Content').filter(function (item) { - if (!item.attrib.Include) { - return false; - } - return isRegexp ? item.attrib.Include.match(relative_path) : item.attrib.Include === relative_path; - }); - - // nothing to remove, skip.. - if (filesToRemove.length < 1) { - return; - } - - filesToRemove.forEach(function (file) { - // remove file reference - group.remove(0, file); - }); - // remove ItemGroup if empty - if (group.findall('*').length < 1) { - that.touched = true; - root.remove(0, group); - } - }); - } -}; - - -/* jsproj */ - -function jsproj(location) { - function targetPlatformIdentifierToDevice(jsprojPlatform) { - var index = ["Windows", "WindowsPhoneApp"].indexOf(jsprojPlatform); - if (index < 0) { - throw new Error("Unknown TargetPlatformIdentifier '" + jsprojPlatform + "' in project file '" + location + "'"); - } - return ["windows", "phone"][index]; - } - - function validateVersion(version) { - version = version.split('.'); - while (version.length < 3) { - version.push("0"); - } - return version.join("."); - } - - // Class to handle a jsproj file - proj.call(this, location); - - var propertyGroup = this.xml.find('PropertyGroup[TargetPlatformIdentifier]'); - if (!propertyGroup) { - throw new Error("Unable to find PropertyGroup/TargetPlatformIdentifier in project file '" + this.location + "'"); - } - - var jsprojPlatform = propertyGroup.find('TargetPlatformIdentifier').text; - this.target = targetPlatformIdentifierToDevice(jsprojPlatform); - - var version = propertyGroup.find('TargetPlatformVersion'); - if (!version) { - throw new Error("Unable to find PropertyGroup/TargetPlatformVersion in project file '" + this.location + "'"); - } - this.version = validateVersion(version.text); -} - -util.inherits(jsproj, proj); - -jsproj.prototype.target = null; -jsproj.prototype.version = null; - -/* Common support functions */ - -function createConditionAttrib(targetConditions) { - var arch = targetConditions.arch; - if (arch) { - if (arch === "arm") { - // Specifcally allow "arm" as alternative to "ARM" - arch = "ARM"; - } else if (arch !== "x86" && arch !== "x64" && arch !== "ARM") { - throw new Error('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): ' + arch); - } - return "'$(Platform)'=='" + arch + "'"; - } - return null; -} - - -module.exports = jsprojManager; http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/48852eef/cordova-lib/src/util/windows/jsprojManager.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/util/windows/jsprojManager.js b/cordova-lib/src/util/windows/jsprojManager.js new file mode 100644 index 0000000..57642ba --- /dev/null +++ b/cordova-lib/src/util/windows/jsprojManager.js @@ -0,0 +1,533 @@ +/** + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +/* jshint quotmark:false, unused:false */ + +/* + Helper for dealing with Windows Store JS app .jsproj files + */ + + +var util = require('util'), + xml_helpers = require('../../util/xml-helpers'), + et = require('elementtree'), + fs = require('fs'), + glob = require('glob'), + shell = require('shelljs'), + events = require('../../events'), + path = require('path'), + semver = require('semver'); + +var WinCSharpProjectTypeGUID = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"; // .csproj +var WinCplusplusProjectTypeGUID = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; // .vcxproj + +// Match a JavaScript Project +var JsProjectRegEx = /(Project\("\{262852C6-CD72-467D-83FE-5EEB1973A190}"\)\s*=\s*"[^"]+",\s*"[^"]+",\s*"\{[0-9a-f\-]+}"[^\r\n]*[\r\n]*)/gi; + +// Chars in a string that need to be escaped when used in a RegExp +var RegExpEscRegExp = /([.?*+\^$\[\]\\(){}|\-])/g; + +function jsprojManager(location) { + this.isUniversalWindowsApp = path.extname(location).toLowerCase() === ".projitems"; + this.projects = []; + this.master = this.isUniversalWindowsApp ? new proj(location) : new jsproj(location); + this.projectFolder = path.dirname(location); + +} + +jsprojManager.prototype = { + _projects: null, + + write: function () { + this.master.write(); + if (this._projects) { + var that = this; + this._projects.forEach(function (project) { + if (project !== that.master && project.touched) { + project.write(); + } + }); + } + }, + + addSDKRef: function (incText, targetConditions) { + events.emit('verbose', 'jsprojManager.addSDKRef(incText: ' + incText + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + var item = createReferenceElement('ItemGroup/SDKReference', incText, targetConditions); + this._getMatchingProjects(targetConditions).forEach(function (project) { + project.appendToRoot(item); + }); + }, + + removeSDKRef: function (incText, targetConditions) { + events.emit('verbose', 'jsprojManager.removeSDKRef(incText: ' + incText + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + this._getMatchingProjects(targetConditions).forEach(function (project) { + project.removeReferenceElementItemGroup('ItemGroup/SDKReference', incText, targetConditions); + }); + }, + + addReference: function (relPath, targetConditions) { + events.emit('verbose', 'jsprojManager.addReference(incText: ' + relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + // add hint path with full path + var hint_path = new et.Element('HintPath'); + hint_path.text = relPath; + var children = [hint_path]; + + var extName = path.extname(relPath); + if (extName === ".winmd") { + var mdFileTag = new et.Element("IsWinMDFile"); + mdFileTag.text = "true"; + children.push(mdFileTag); + } + + var item = createReferenceElement('ItemGroup/Reference', path.basename(relPath, extName), targetConditions, children); + this._getMatchingProjects(targetConditions).forEach(function (project) { + project.appendToRoot(item); + }); + + }, + + removeReference: function (relPath, targetConditions) { + events.emit('verbose', 'jsprojManager.removeReference(incText: ' + relPath + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + var extName = path.extname(relPath); + var includeText = path.basename(relPath, extName); + + this._getMatchingProjects(targetConditions).forEach(function (project) { + project.removeReferenceElementItemGroup('ItemGroup/Reference', includeText, targetConditions); + }); + }, + + addSourceFile: function (relative_path) { + events.emit('verbose', 'jsprojManager.addSourceFile(relative_path: ' + relative_path + ')'); + this.master.addSourceFile(relative_path); + }, + + removeSourceFile: function (relative_path) { + events.emit('verbose', 'jsprojManager.removeSourceFile(incText: ' + relative_path + ')'); + this.master.removeSourceFile(relative_path); + }, + + addProjectReference: function (relative_path, targetConditions) { + events.emit('verbose', 'jsprojManager.addProjectReference(incText: ' + relative_path + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + relative_path = relative_path.split('/').join('\\'); + + var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path); + + // find the guid + name of the referenced project + var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text; + var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text; + + // get the project type + var projectTypeGuid = getProjectTypeGuid(relative_path); + if (!projectTypeGuid) { + throw new Error("unrecognized project type"); + } + + var preInsertText = "\tProjectSection(ProjectDependencies) = postProject\r\n" + + "\t\t" + projectGuid + "=" + projectGuid + "\r\n" + + "\tEndProjectSection\r\n"; + var postInsertText = '\r\nProject("' + projectTypeGuid + '") = "' + + projName + '", "' + relative_path + '", ' + + '"' + projectGuid + '"\r\nEndProject'; + + var matchingProjects = this._getMatchingProjects(targetConditions); + if (matchingProjects.length === 0) { + // No projects meet the specified target and version criteria, so nothing to do. + return; + } + + // Will we be writing into the .projitems file rather than individual .jsproj files? + var useProjItems = this.isUniversalWindowsApp && matchingProjects.length === 1 && matchingProjects[0] === this.master; + + // There may be multiple solution files (for different VS versions) - process them all + getSolutionPaths(this.projectFolder).forEach(function (solutionPath) { + var solText = fs.readFileSync(solutionPath, {encoding: "utf8"}); + + if (useProjItems) { + // Insert a project dependency into every jsproj in the solution. + var jsProjectFound = false; + solText = solText.replace(JsProjectRegEx, function (match) { + jsProjectFound = true; + return match + preInsertText; + }); + + if (!jsProjectFound) { + throw new Error("no jsproj found in solution"); + } + } else { + // Insert a project dependency only for projects that match specified target and version + matchingProjects.forEach(function (project) { + solText = solText.replace(getJsProjRegExForProject(path.basename(project.location)), function (match) { + return match + preInsertText; + }); + }); + } + + // Add the project after existing projects. Note that this fairly simplistic check should be fine, since the last + // EndProject in the file should actually be an EndProject (and not an EndProjectSection, for example). + var pos = solText.lastIndexOf("EndProject"); + if (pos === -1) { + throw new Error("no EndProject found in solution"); + } + pos += 10; // Move pos to the end of EndProject text + solText = solText.slice(0, pos) + postInsertText + solText.slice(pos); + + fs.writeFileSync(solutionPath, solText, {encoding: "utf8"}); + }); + + // Add the ItemGroup/ProjectReference to each matching cordova project : + // + var item = createReferenceElement('ItemGroup/ProjectReference', relative_path, targetConditions); + matchingProjects.forEach(function (project) { + project.appendToRoot(item); + }); + }, + + removeProjectReference: function (relative_path, targetConditions) { + events.emit('verbose', 'jsprojManager.removeProjectReference(incText: ' + relative_path + ', targetConditions: ' + JSON.stringify(targetConditions) + ')'); + + // find the guid + name of the referenced project + var pluginProjectXML = xml_helpers.parseElementtreeSync(relative_path); + var projectGuid = pluginProjectXML.find("PropertyGroup/ProjectGuid").text; + var projName = pluginProjectXML.find("PropertyGroup/ProjectName").text; + + // get the project type + var projectTypeGuid = getProjectTypeGuid(relative_path); + if (!projectTypeGuid) { + throw new Error("unrecognized project type"); + } + + var preInsertTextRegExp = getProjectReferencePreInsertRegExp(projectGuid); + var postInsertTextRegExp = getProjectReferencePostInsertRegExp(projName, projectGuid, relative_path, projectTypeGuid); + + // There may be multiple solutions (for different VS versions) - process them all + getSolutionPaths(this.projectFolder).forEach(function (solutionPath) { + var solText = fs.readFileSync(solutionPath, {encoding: "utf8"}); + + // To be safe (to handle subtle changes in formatting, for example), use a RegExp to find and remove + // preInsertText and postInsertText + + solText = solText.replace(preInsertTextRegExp, function () { + return ""; + }); + + solText = solText.replace(postInsertTextRegExp, function () { + return ""; + }); + + fs.writeFileSync(solutionPath, solText, {encoding: "utf8"}); + }); + + this._getMatchingProjects(targetConditions).forEach(function (project) { + project.removeReferenceElementItemGroup('ItemGroup/ProjectReference', relative_path, targetConditions); + }); + }, + + _getMatchingProjects: function (targetConditions) { + // If specified, target can be 'all' (default), 'phone' or 'windows'. Ultimately should probably allow a comma + // separated list, but not needed now. + var target = getTarget(targetConditions); + var versions = getVersions(targetConditions); + + if (target || versions) { + var matchingProjects = this.projects.filter(function (project) { + return (!target || target === project.target) && (!versions || semver.satisfies(project.version, versions, /* loose */ true)); + }); + + if (matchingProjects.length < this.projects.length) { + return matchingProjects; + } + } + + // All projects match. If this is a universal project, return the projitems file. Otherwise return our single + // project. + return [this.master]; + }, + + get projects() { + var projects = this._projects; + if (!projects) { + projects = []; + this._projects = projects; + + if (this.isUniversalWindowsApp) { + var projectPath = this.projectFolder; + var projectFiles = glob.sync('*.jsproj', {cwd: projectPath}); + projectFiles.forEach(function (projectFile) { + projects.push(new jsproj(path.join(projectPath, projectFile))); + }); + } else { + this.projects.push(this.master); + } + } + + return projects; + } +}; + +function getProjectReferencePreInsertRegExp(projectGuid) { + projectGuid = escapeRegExpString(projectGuid); + return new RegExp("\\s*ProjectSection\\(ProjectDependencies\\)\\s*=\\s*postProject\\s*" + projectGuid + "\\s*=\\s*" + projectGuid + "\\s*EndProjectSection", "gi"); +} + +function getProjectReferencePostInsertRegExp(projName, projectGuid, relative_path, projectTypeGuid) { + projName = escapeRegExpString(projName); + projectGuid = escapeRegExpString(projectGuid); + relative_path = escapeRegExpString(relative_path); + projectTypeGuid = escapeRegExpString(projectTypeGuid); + return new RegExp('\\s*Project\\("' + projectTypeGuid + '"\\)\\s*=\\s*"' + projName + '"\\s*,\\s*"' + relative_path + '"\\s*,\\s*"' + projectGuid + '"\\s*EndProject', 'gi'); +} + +function getSolutionPaths(projectFolder) { + return shell.ls(path.join(projectFolder, "*.sln")); // TODO:error handling +} + +function escapeRegExpString(regExpString) { + return regExpString.replace(RegExpEscRegExp, "\\$1"); +} + +function getJsProjRegExForProject(projectFile) { + projectFile = escapeRegExpString(projectFile); + return new RegExp('(Project\\("\\{262852C6-CD72-467D-83FE-5EEB1973A190}"\\)\\s*=\\s*"[^"]+",\\s*"' + projectFile + '",\\s*"\\{[0-9a-f\\-]+}"[^\\r\\n]*[\\r\\n]*)', 'gi'); +} + +function getProjectTypeGuid(projectPath) { + switch (path.extname(projectPath)) { + case ".vcxproj": + return WinCplusplusProjectTypeGUID; + + case ".csproj": + return WinCSharpProjectTypeGUID; + } + return null; +} + +function createReferenceElement(path, incText, targetConditions, children) { + path = path.split('/'); + path.reverse(); + + var lastElement = null; + path.forEach(function (elementName) { + var element = new et.Element(elementName); + if (lastElement) { + element.append(lastElement); + } else { + element.attrib.Include = incText; + + var condition = createConditionAttrib(targetConditions); + if (condition) { + element.attrib.Condition = condition; + } + + if (children) { + children.forEach(function (child) { + element.append(child); + }); + } + } + lastElement = element; + }); + + return lastElement; +} + +function getTarget(targetConditions) { + var target = targetConditions.target; + if (target) { + target = target.toLowerCase().trim(); + if (target === "all") { + target = null; + } else if (target === "win") { + // Allow "win" as alternative to "windows" + target = "windows"; + } else if (target !== 'phone' && target !== 'windows') { + throw new Error('Invalid lib-file target attribute (must be "all", "phone", "windows" or "win"): ' + target); + } + } + return target; +} + +function getVersions(targetConditions) { + var versions = targetConditions.versions; + if (versions && !semver.validRange(versions, /* loose */ true)) { + throw new Error('Invalid lib-file versions attribute (must be a valid a valid node semantic version range): ' + versions); + } + return versions; +} + + +/* proj */ + +function proj(location) { + // Class to handle simple project xml operations + if (!location) { + throw new Error('Project file location can\'t be null or empty'); + } + this.location = location; + this.xml = xml_helpers.parseElementtreeSync(location); +} + +proj.prototype = { + write: function () { + fs.writeFileSync(this.location, this.xml.write({indent: 4}), 'utf-8'); + }, + + appendToRoot: function (element) { + this.touched = true; + this.xml.getroot().append(element); + }, + + removeReferenceElementItemGroup: function (path, incText, targetConditions) { + var xpath = path + '[@Include="' + incText + '"]'; + var condition = createConditionAttrib(targetConditions); + if (condition) { + xpath += '[@Condition="' + condition + '"]'; + } + xpath += '/..'; + + var itemGroup = this.xml.find(xpath); + if (itemGroup) { + this.touched = true; + this.xml.getroot().remove(0, itemGroup); + } + }, + + addSourceFile: function (relative_path) { + // we allow multiple paths to be passed at once as array so that + // we don't create separate ItemGroup for each source file, CB-6874 + if (!(relative_path instanceof Array)) { + relative_path = [relative_path]; + } + + // make ItemGroup to hold file. + var item = new et.Element('ItemGroup'); + + relative_path.forEach(function (filePath) { + filePath = filePath.split('/').join('\\'); + + var content = new et.Element('Content'); + content.attrib.Include = filePath; + item.append(content); + }); + + this.appendToRoot(item); + }, + + removeSourceFile: function (relative_path) { + var isRegexp = relative_path instanceof RegExp; + if (!isRegexp) { + // path.normalize(relative_path);// ?? + relative_path = relative_path.split('/').join('\\'); + } + + var root = this.xml.getroot(); + var that = this; + // iterate through all ItemGroup/Content elements and remove all items matched + this.xml.findall('ItemGroup').forEach(function (group) { + // matched files in current ItemGroup + var filesToRemove = group.findall('Content').filter(function (item) { + if (!item.attrib.Include) { + return false; + } + return isRegexp ? item.attrib.Include.match(relative_path) : item.attrib.Include === relative_path; + }); + + // nothing to remove, skip.. + if (filesToRemove.length < 1) { + return; + } + + filesToRemove.forEach(function (file) { + // remove file reference + group.remove(0, file); + }); + // remove ItemGroup if empty + if (group.findall('*').length < 1) { + that.touched = true; + root.remove(0, group); + } + }); + } +}; + + +/* jsproj */ + +function jsproj(location) { + function targetPlatformIdentifierToDevice(jsprojPlatform) { + var index = ["Windows", "WindowsPhoneApp"].indexOf(jsprojPlatform); + if (index < 0) { + throw new Error("Unknown TargetPlatformIdentifier '" + jsprojPlatform + "' in project file '" + location + "'"); + } + return ["windows", "phone"][index]; + } + + function validateVersion(version) { + version = version.split('.'); + while (version.length < 3) { + version.push("0"); + } + return version.join("."); + } + + // Class to handle a jsproj file + proj.call(this, location); + + var propertyGroup = this.xml.find('PropertyGroup[TargetPlatformIdentifier]'); + if (!propertyGroup) { + throw new Error("Unable to find PropertyGroup/TargetPlatformIdentifier in project file '" + this.location + "'"); + } + + var jsprojPlatform = propertyGroup.find('TargetPlatformIdentifier').text; + this.target = targetPlatformIdentifierToDevice(jsprojPlatform); + + var version = propertyGroup.find('TargetPlatformVersion'); + if (!version) { + throw new Error("Unable to find PropertyGroup/TargetPlatformVersion in project file '" + this.location + "'"); + } + this.version = validateVersion(version.text); +} + +util.inherits(jsproj, proj); + +jsproj.prototype.target = null; +jsproj.prototype.version = null; + +/* Common support functions */ + +function createConditionAttrib(targetConditions) { + var arch = targetConditions.arch; + if (arch) { + if (arch === "arm") { + // Specifcally allow "arm" as alternative to "ARM" + arch = "ARM"; + } else if (arch !== "x86" && arch !== "x64" && arch !== "ARM") { + throw new Error('Invalid lib-file arch attribute (must be "x86", "x64" or "ARM"): ' + arch); + } + return "'$(Platform)'=='" + arch + "'"; + } + return null; +} + + +module.exports = jsprojManager; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org