Skip to content

Commit

Permalink
Revert "chore!: Remove podspec support from framework tag (apache#1340)"
Browse files Browse the repository at this point in the history
This reverts commit 76e33d9.
  • Loading branch information
deanylev committed Apr 24, 2024
1 parent 64c3051 commit f4b4b86
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 5 deletions.
69 changes: 65 additions & 4 deletions lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class Api {
.then(() => {
if (plugin != null) {
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : [];
return this.addPodSpecs(plugin, podSpecs, installOptions);
const frameworkTags = plugin.getFrameworks(this.platform);
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
}
})
// CB-11022 Return truthy value to prevent running prepare after
Expand Down Expand Up @@ -322,7 +324,9 @@ class Api {
.then(() => {
if (plugin != null) {
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : [];
return this.removePodSpecs(plugin, podSpecs, uninstallOptions);
const frameworkTags = plugin.getFrameworks(this.platform);
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
}
})
// CB-11022 Return truthy value to prevent running prepare after
Expand All @@ -335,9 +339,10 @@ class Api {
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform)
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
* @return {Promise} Return a promise
*/
addPodSpecs (plugin, podSpecs, installOptions) {
addPodSpecs (plugin, podSpecs, frameworkPods, installOptions) {
const project_dir = this.locations.root;
const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop();
const minDeploymentTarget = this.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios');
Expand Down Expand Up @@ -404,7 +409,36 @@ class Api {
});
}
});
}

if (frameworkPods.length) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"');
frameworkPods.forEach(obj => {
const spec = getVariableSpec(obj.spec, installOptions);
const podJson = {
name: obj.src,
type: obj.type,
spec
};

const val = podsjsonFile.getLibrary(podJson.name);
if (val) { // found
if (podJson.spec !== val.spec) { // exists, different spec, print warning
events.emit('warn', `${plugin.id} depends on ${podJson.name}@${podJson.spec}, which conflicts with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`);
}
// increment count, but don't add in Podfile because it already exists
podsjsonFile.incrementLibrary(podJson.name);
} else { // not found, write new
podJson.count = 1;
podsjsonFile.setJsonLibrary(podJson.name, podJson);
// add to Podfile
podfileFile.addSpec(podJson.name, podJson.spec);
}
});
}

if (podSpecs.length > 0 || frameworkPods.length > 0) {
// now that all the pods have been processed, write to pods.json
podsjsonFile.write();

Expand All @@ -429,10 +463,11 @@ class Api {
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
* that will be installed.
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform)
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
* @return {Promise} Return a promise
*/

removePodSpecs (plugin, podSpecs, uninstallOptions) {
removePodSpecs (plugin, podSpecs, frameworkPods, uninstallOptions) {
const project_dir = this.locations.root;
const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop();

Expand Down Expand Up @@ -495,7 +530,33 @@ class Api {
}
});
});
}

if (frameworkPods.length) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */
frameworkPods.forEach(obj => {
const spec = getVariableSpec(obj.spec, uninstallOptions);
const podJson = {
name: obj.src,
type: obj.type,
spec
};

const val = podsjsonFile.getLibrary(podJson.name);
if (val) { // found, decrement count
podsjsonFile.decrementLibrary(podJson.name);
} else { // not found (perhaps a sync error)
const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */
events.emit('verbose', message);
}

// always remove from the Podfile
podfileFile.removeSpec(podJson.name);
});
}

if (podSpecs.length > 0 || frameworkPods.length > 0) {
// now that all the pods have been processed, write to pods.json
podsjsonFile.write();

Expand Down
2 changes: 1 addition & 1 deletion lib/plugman/pluginHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const handlers = {

if (keepFrameworks.indexOf(src) < 0) {
if (obj.type === 'podspec') {
events.emit('error', '"framework" tag with type "podspec" is no longer supported. Please use the "podspec" tag.');
// podspec handled in Api.js
} else {
project.frameworks[src] = project.frameworks[src] || 0;
project.frameworks[src]++;
Expand Down
64 changes: 64 additions & 0 deletions tests/spec/unit/Api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,70 @@ describe('Platform Api', () => {
});
});
});
describe('with frameworks of `podspec` type', () => {
let podsjson_mock;
let podfile_mock;
const my_pod_json = {
type: 'podspec',
src: 'podsource!',
spec: 'podspec!'
};
beforeEach(() => {
podsjson_mock = jasmine.createSpyObj('podsjson mock', ['getLibrary', 'incrementLibrary', 'write', 'setJsonLibrary']);
podfile_mock = jasmine.createSpyObj('podfile mock', ['isDirty', 'addSpec', 'write', 'install']);
spyOn(my_plugin, 'getFrameworks').and.returnValue([my_pod_json]);
PodsJson_mod.PodsJson.and.returnValue(podsjson_mock);
Podfile_mod.Podfile.and.returnValue(podfile_mock);
});
// TODO: a little help with clearly labeling / describing the tests below? :(
it('should warn if Pods JSON contains name/src but differs in spec', () => {
podsjson_mock.getLibrary.and.returnValue({
spec: `something different from ${my_pod_json.spec}`
});
spyOn(events, 'emit');
return api.addPlugin(my_plugin)
.then(() => {
expect(events.emit).toHaveBeenCalledWith('warn', jasmine.stringMatching(/which conflicts with another plugin/g));
});
});
it('should increment Pods JSON file if pod name/src already exists in file', () => {
podsjson_mock.getLibrary.and.returnValue({
spec: my_pod_json.spec
});
return api.addPlugin(my_plugin)
.then(() => {
expect(podsjson_mock.incrementLibrary).toHaveBeenCalledWith('podsource!');
});
});
it('on a new framework/pod name/src/key, it should add a new json to podsjson and add a new spec to podfile', () => {
return api.addPlugin(my_plugin)
.then(() => {
expect(podsjson_mock.setJsonLibrary).toHaveBeenCalledWith(my_pod_json.src, jasmine.any(Object));
expect(podfile_mock.addSpec).toHaveBeenCalledWith(my_pod_json.src, my_pod_json.spec);
});
});
it('should write out podfile and install if podfile was changed', () => {
podfile_mock.isDirty.and.returnValue(true);
podfile_mock.install.and.returnValue({ then: function () { } });
return api.addPlugin(my_plugin)
.then(() => {
expect(podfile_mock.write).toHaveBeenCalled();
expect(podfile_mock.install).toHaveBeenCalled();
});
});
it('if two frameworks with the same name are added, should honour the spec of the first-installed plugin', () => {
podsjson_mock.getLibrary.and.returnValue({
spec: `something different from ${my_pod_json.spec}`
});
return api.addPlugin(my_plugin)
.then(() => {
// Increment will non-destructively set the spec to keep it as it was...
expect(podsjson_mock.incrementLibrary).toHaveBeenCalledWith(my_pod_json.src);
// ...whereas setJson would overwrite it completely.
expect(podsjson_mock.setJsonLibrary).not.toHaveBeenCalled();
});
});
});
});
describe('removePlugin', () => {
const my_plugin = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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="sample-cocoapod-plugin-no-spec-overlapping-dependency"
version="1.1.3-dev">

<name>Test Plugin</name>

<asset src="www/test.js" target="test.js" />
<platform name="ios">
<framework src="AFNetworking" weak="false" type="podspec"/>
</platform>
</plugin>

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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="sample-cordova-plugin-with-spec"
version="1.1.3-dev">

<name>Test Plugin</name>

<asset src="www/test.js" target="test.js" />
<platform name="ios">
<framework src="AFNetworking" spec="~> 2.0" weak="false" type="podspec"/>
</platform>
</plugin>

Empty file.

0 comments on commit f4b4b86

Please sign in to comment.