Skip to content

Commit

Permalink
Merge branch 'license-text'
Browse files Browse the repository at this point in the history
  • Loading branch information
bcylin committed May 20, 2019
2 parents 2b1f70a + 10a958f commit 1e1c14f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 25 deletions.
34 changes: 28 additions & 6 deletions example/Acknowledgements/Crypto/Crypto.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
Pod::Spec.new do |s|
s.name = "Crypto"
s.version = "0.6.0"
s.summary = "Simple CommonCrypto wrapper for Swift for macOS, iOS, watchOS, and tvOS with Carthage support."
s.homepage = "https://github.com/soffes/Crypto"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = "Sam Soffes"
s.name = "Crypto"
s.version = "0.6.0"
s.summary = "Simple CommonCrypto wrapper for Swift for macOS, iOS, watchOS, and tvOS with Carthage support."
s.homepage = "https://github.com/soffes/Crypto"
s.author = "Sam Soffes"
s.license = { type: "MIT", text: <<-LICENSE
Copyright (c) 2015–2016 Sam Soffes, http://soff.es
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE
}
end
1 change: 0 additions & 1 deletion example/Acknowledgements/Crypto/LICENSE

This file was deleted.

2 changes: 1 addition & 1 deletion lib/cocoapods_acknowledgements/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module AddOns
plist_modifier.add(acknowledgements.map(&:plist_metadata), excluded_names)

settings_plist_modifier = SettingsPlistModifier.new(target)
settings_plist_modifier&.add(acknowledgements.map(&:settings_plist_metadata), excluded_names)
settings_plist_modifier.add(acknowledgements.map(&:settings_plist_metadata), excluded_names)
end
end

Expand Down
42 changes: 32 additions & 10 deletions lib/cocoapods_acknowledgements/addons/acknowledgement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,62 @@ module CocoaPodsAcknowledgements
module AddOns
class Acknowledgement

# Initializes an object that contains the Acknowledgement data.
# @param path [String] the path string to a pod spec.
#
def initialize(file)
return nil unless file and Pathname(file).expand_path.exist?
path = Pathname(file).expand_path if file
directory = path.dirname

@spec = Pod::Specification.from_file(file)

license_file = @spec.license[:file] || "LICENSE"
@license_path = File.join(File.dirname(file), license_file)
@spec = Pod::Specification.from_file(file) if path.exist?
@license_text = license_text(@spec, directory)
end

def license_text
File.read(@license_path)
# @param podspec [Pod::Specification]
# @param directory [Pathname]
#
# @return [String] the text of the license.
# @return [Nil] if it's not found.
#
def license_text(podspec, directory)
return nil unless podspec
text = podspec.license[:text]

if text.nil?
license_file = podspec.license[:file] || "LICENSE"
license_path = directory + license_file
return nil unless license_path.exist?
text = File.read(license_path)
end

text
end

# @return [Hash] the acknowledgement info for the plist.
# @return [Nil] if the license text is missing.
#
def plist_metadata
return nil unless @spec and @license_text
{
name: @spec.name,
version: @spec.version.to_s,
authors: Hash[@spec.authors.map { |k, v| [k, v || ""] }],
socialMediaURL: @spec.social_media_url || "",
summary: @spec.summary,
licenseType: @spec.license[:type],
licenseText: license_text,
licenseText: @license_text,
homepage: @spec.homepage
}
end

# @return [Hash] the acknowledgement info for the Settings.bundle plist.
# @return [Nil] if the license text is missing.
#
def settings_plist_metadata
return nil unless @spec and @license_text
{
Title: @spec.name,
Type: "PSGroupSpecifier",
FooterText: license_text
FooterText: @license_text
}
end

Expand Down
6 changes: 4 additions & 2 deletions lib/cocoapods_acknowledgements/addons/plist_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ module CocoaPodsAcknowledgements
module AddOns
class PlistModifier

# Initializes a PlistModifier with the info of target and CocoaPods sandbox.
# @param target [Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription] the xcodeproj target.
# @param sandbox [Pod::Sandbox] the CocoaPods sandbox
#
def initialize(target, sandbox)
@plist_path = sandbox.root + "#{target.cocoapods_target_label}-metadata.plist"
end

# Adds acknowledgements to the plist except the excluded ones.
#
# @param plist_metadata [Array<Hash>] the array of acknowledgement plist metadata.
# @param excluded_names [Array<String>] the array of names to ignore.
#
def add(plist_metadata, excluded_names)
plist_metadata = [*plist_metadata]
excluded_names = [*excluded_names]
Expand All @@ -28,7 +30,7 @@ def add(plist_metadata, excluded_names)
excluded_names += existing_titles

additions = plist_metadata.map { |metadata|
next if excluded_names.include? metadata[:name]
next if metadata.nil? or excluded_names.include? metadata[:name]
Pod::UI.info "Adding #{metadata[:name]} to #{@plist_path.basename}"
CFPropertyList.guess(metadata)
}.reject(&:nil?)
Expand Down
3 changes: 2 additions & 1 deletion lib/cocoapods_acknowledgements/addons/podspec_accumulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ module CocoaPodsAcknowledgements
module AddOns
class PodspecAccumulator

# Initializes a PodspecAccumulator with a search path.
# @param search_path [Pathname] the directory to look for podspecs.
#
def initialize(search_path = Pathname("").expand_path)
@files = Dir[search_path + "**/*.podspec"]
end

# @return [Array<Acknowledgement>] the array of Acknowledgement objects.
#
def acknowledgements
@files.map { |file| Acknowledgement.new(file) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ module CocoaPodsAcknowledgements
module AddOns
class SettingsPlistModifier

# Initializes a SettingsPlistModifier with the info of target.
# @param target [Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription] the xcodeproj target.
# @return [SettingsPlistModifier] a settings plist modifier or nil when Settings.bundle doesn't exist.
#
def initialize(target)
project = Xcodeproj::Project.open(target.user_project_path)
file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
settings_bundle = file&.real_path

return nil unless settings_bundle&.exist?
return unless settings_bundle&.exist?
@plist_path = settings_bundle + "#{target.cocoapods_target_label}-settings-metadata.plist"
end

# Adds acknowledgements to the plist except the excluded ones.
#
# @param plist_metadata [Array<Hash>] the array of acknowledgement plist metadata.
# @param excluded_names [Array<String>] the array of names to ignore.
#
def add(plist_metadata, excluded_names)
plist_metadata = [*plist_metadata]
excluded_names = [*excluded_names]
Expand All @@ -40,7 +41,7 @@ def add(plist_metadata, excluded_names)
excluded_names += existing_titles

additions = plist_metadata.map { |metadata|
next if excluded_names.include? metadata[:Title]
next if metadata.nil? or excluded_names.include? metadata[:Title]
Pod::UI.info "Adding #{metadata[:Title]} to #{@plist_path.basename}"
CFPropertyList.guess(metadata)
}.reject(&:nil?)
Expand Down

0 comments on commit 1e1c14f

Please sign in to comment.