diff --git a/AUTHORS b/AUTHORS index 30e9ddf..81644d0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,3 +2,4 @@ Andrew Lunny (@alunny) Anis Kadri (@imhotep) Mike Reinstein (@mreinstein) Filip Maj (@filmaj) +Bob Easterday (@bobeast) diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 56e0f89..7dfcc48 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -87,10 +87,11 @@ pbxProject.prototype.addPluginFile = function (path, opt) { file.plugin = true; // durr correctForPluginsPath(file, this); - file.fileRef = this.generateUuid(); + + file.fileRef = this.generateUuid(); - this.addToPbxFileReferenceSection(file); // PBXFileReference - this.addToPluginsPbxGroup(file); // PBXGroup + this.addToPbxFileReferenceSection(file); // PBXFileReference + this.addToPluginsPbxGroup(file); // PBXGroup return file; } @@ -228,8 +229,10 @@ pbxProject.prototype.addStaticLibrary = function (path, opt) { pbxProject.prototype.addToPbxBuildFileSection = function (file) { var commentKey = f("%s_comment", file.uuid); - this.pbxBuildFileSection()[file.uuid] = pbxBuildFileObj(file); - this.pbxBuildFileSection()[commentKey] = pbxBuildFileComment(file); + if (!this.existsInPbxBuildFileSection(file)) { + this.pbxBuildFileSection()[file.uuid] = pbxBuildFileObj(file); + this.pbxBuildFileSection()[commentKey] = pbxBuildFileComment(file); + } } pbxProject.prototype.removeFromPbxBuildFileSection = function (file) { @@ -245,11 +248,26 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function (file) { delete this.pbxBuildFileSection()[commentKey]; } +pbxProject.prototype.existsInPbxBuildFileSection = function (file) { + var retVal = false; + var uuid; + + for(uuid in this.pbxBuildFileSection()) { + if(this.pbxBuildFileSection()[uuid].fileRef_comment == file.basename) { + retVal = true; + break; + } + } + return retVal; +} + pbxProject.prototype.addToPbxFileReferenceSection = function (file) { var commentKey = f("%s_comment", file.fileRef); - this.pbxFileReferenceSection()[file.fileRef] = pbxFileReferenceObj(file); - this.pbxFileReferenceSection()[commentKey] = pbxFileReferenceComment(file); + if (!this.existsInPbxFileReferenceSection(file)) { + this.pbxFileReferenceSection()[file.fileRef] = pbxFileReferenceObj(file); + this.pbxFileReferenceSection()[commentKey] = pbxFileReferenceComment(file); + } } pbxProject.prototype.removeFromPbxFileReferenceSection = function (file) { @@ -272,9 +290,27 @@ pbxProject.prototype.removeFromPbxFileReferenceSection = function (file) { return file; } +pbxProject.prototype.existsInPbxFileReferenceSection = function (file) { + var retVal = false; + var i; + var refObj = pbxFileReferenceObj(file); + for(i in this.pbxFileReferenceSection()) { + if(this.pbxFileReferenceSection()[i].name == refObj.name || + this.pbxFileReferenceSection()[i].path == refObj.path) { + retVal = true; + break; + } + } + + return retVal; +} + pbxProject.prototype.addToPluginsPbxGroup = function (file) { - var pluginsGroup = this.pbxGroupByName('Plugins'); - pluginsGroup.children.push(pbxGroupChild(file)); + + if (!this.existsInPluginsPbxGroup(file)) { + var pluginsGroup = this.pbxGroupByName('Plugins'); + pluginsGroup.children.push(pbxGroupChild(file)); + } } pbxProject.prototype.removeFromPluginsPbxGroup = function (file) { @@ -288,9 +324,24 @@ pbxProject.prototype.removeFromPluginsPbxGroup = function (file) { } } +pbxProject.prototype.existsInPluginsPbxGroup = function (file) { + var retVal = false; + var pluginsGroupChildren = this.pbxGroupByName('Plugins').children, i; + for(i in pluginsGroupChildren) { + if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && + pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + retVal = true; + break; + } + } + return retVal; +} + pbxProject.prototype.addToResourcesPbxGroup = function (file) { - var pluginsGroup = this.pbxGroupByName('Resources'); - pluginsGroup.children.push(pbxGroupChild(file)); + if (!this.existsInResourcesPbxGroup(file)) { + var pluginsGroup = this.pbxGroupByName('Resources'); + pluginsGroup.children.push(pbxGroupChild(file)); + } } pbxProject.prototype.removeFromResourcesPbxGroup = function (file) { @@ -304,10 +355,24 @@ pbxProject.prototype.removeFromResourcesPbxGroup = function (file) { } } +pbxProject.prototype.existsInResourcesPbxGroup = function (file) { + var retVal = false; + var pluginsGroupChildren = this.pbxGroupByName('Resources').children, i; + for(i in pluginsGroupChildren) { + if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && + pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + retVal = true; + break; + } + } + return retVal; +} pbxProject.prototype.addToFrameworksPbxGroup = function (file) { - var pluginsGroup = this.pbxGroupByName('Frameworks'); - pluginsGroup.children.push(pbxGroupChild(file)); + if (!this.existsInFrameworksPbxGroup(file)) { + var pluginsGroup = this.pbxGroupByName('Frameworks'); + pluginsGroup.children.push(pbxGroupChild(file)); + } } pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) { @@ -322,9 +387,25 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function (file) { } } +pbxProject.prototype.existsInFrameworksPbxGroup = function (file) { + var retVal = false; + var pluginsGroupChildren = this.pbxGroupByName('Frameworks').children; + + for(i in pluginsGroupChildren) { + if(pbxGroupChild(file).value == pluginsGroupChildren[i].value && + pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) { + retVal = true; + break; + } + } + return retVal; +} + pbxProject.prototype.addToPbxSourcesBuildPhase = function (file) { - var sources = this.pbxSourcesBuildPhaseObj(); - sources.files.push(pbxBuildPhaseObj(file)); + if (!this.existsInPbxSourcesBuildPhase(file)) { + var sources = this.pbxSourcesBuildPhaseObj(); + sources.files.push(pbxBuildPhaseObj(file)); + } } pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) { @@ -337,9 +418,23 @@ pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) { } } +pbxProject.prototype.existsInPbxSourcesBuildPhase = function (file) { + var retVal = false; + var sources = this.pbxSourcesBuildPhaseObj(), i; + for(i in sources.files) { + if(sources.files[i].comment == longComment(file)) { + retVal = true; + break; + } + } + return retVal; +} + pbxProject.prototype.addToPbxResourcesBuildPhase = function (file) { - var sources = this.pbxResourcesBuildPhaseObj(); - sources.files.push(pbxBuildPhaseObj(file)); + if (!this.existsInPbxResourcesBuildPhase(file)) { + var sources = this.pbxResourcesBuildPhaseObj(); + sources.files.push(pbxBuildPhaseObj(file)); + } } pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) { @@ -353,9 +448,24 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) { } } +pbxProject.prototype.existsInPbxResourcesBuildPhase = function (file) { + var retVal = false; + var sources = this.pbxResourcesBuildPhaseObj(), i; + + for(i in sources.files) { + if(sources.files[i].comment == longComment(file)) { + retVal = true; + break; + } + } + return retVal; +} + pbxProject.prototype.addToPbxFrameworksBuildPhase = function (file) { - var sources = this.pbxFrameworksBuildPhaseObj(); - sources.files.push(pbxBuildPhaseObj(file)); + if (!this.existsInPbxFrameworksBuildPhase(file)) { + var sources = this.pbxFrameworksBuildPhaseObj(); + sources.files.push(pbxBuildPhaseObj(file)); + } } pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) { @@ -368,6 +478,19 @@ pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) { } } +pbxProject.prototype.existsInPbxFrameworksBuildPhase = function (file) { + var retVal = false; + var sources = this.pbxFrameworksBuildPhaseObj(); + for(i in sources.files) { + if(sources.files[i].comment == longComment(file)) { + retVal = true; + break; + } + } + return retVal; +} + + // helper access functions pbxProject.prototype.pbxBuildFileSection = function () { return this.hash.project.objects['PBXBuildFile'];