module Omnibus

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Copyright

Copyright © 2012 Opscode, Inc.

License

Apache License, Version 2.0

Licensed 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.

Constants

DEFAULT_CONFIG_FILENAME
VERSION

Public Class Methods

config() click to toggle source

Convenience method for access to the Omnibus::Config object. Provided for backward compatibility.

@ return [Omnibus::Config]

@deprecated Just refer to {Omnibus::Config} directly.

# File lib/omnibus.rb, line 64
def self.config
  Config
end
configure() click to toggle source

Configure Omnibus.

After this has been called, the {Omnibus::Config} object is available as ‘Omnibus.config`.

@return [void]

@deprecated Use {#load_configuration} if you need to process a

config file, followed by {#process_configuration} to act upon it.
# File lib/omnibus.rb, line 53
def self.configure
  load_configuration
  process_configuration
end
load_configuration(file=nil) click to toggle source

Load in an Omnibus configuration file. Values will be merged with and override the defaults defined in {Omnibus::Config}.

@param file [String] path to a configuration file to load

@return [void]

# File lib/omnibus.rb, line 74
def self.load_configuration(file=nil)
  if file
    Config.from_file(file)
  end
end
omnibus_software_root() click to toggle source

The source root is the path to the root directory of the ‘omnibus-software` gem.

@return [Pathname]

# File lib/omnibus.rb, line 133
def self.omnibus_software_root
  @omnibus_software_root ||= begin
    if spec = Gem::Specification.find_all_by_name('omnibus-software').first
      Pathname.new(spec.gem_dir)
    else
      nil
    end
  end
end
process_configuration() click to toggle source

Processes the configuration to construct the dependency tree of projects and software.

@return [void]

# File lib/omnibus.rb, line 84
def self.process_configuration
  Config.validate
  process_dsl_files
  generate_extra_rake_tasks
end
project(name) click to toggle source

Load the {Omnibus::Project} instance with the given name.

@param name [String] @return {Omnibus::Project}

# File lib/omnibus.rb, line 108
def self.project(name)
  projects.find{ |p| p.name == name}
end
project_files() click to toggle source

Return paths to all configured {Omnibus::Project} DSL files.

@return [Array<String>]

# File lib/omnibus.rb, line 146
def self.project_files
  ruby_files(File.join(project_root, Config.project_dir))
end
project_names() click to toggle source

Names of all the {Omnibus::Project} instances that have been created.

@return [Array<String>]

# File lib/omnibus.rb, line 100
def self.project_names
  projects.map{|p| p.name}
end
project_root() click to toggle source

The absolute path to the Omnibus project/repository directory.

@return [String]

@deprecated Call {Omnibus::Config.project_root} instead. We need

to be able to easily tweak this at runtime via the CLI tool.
# File lib/omnibus.rb, line 118
def self.project_root
  Config.project_root
end
Also aliased as: root
projects() click to toggle source

All {Omnibus::Project} instances that have been created.

@return [Array<Omnibus::Project>]

# File lib/omnibus.rb, line 93
def self.projects
  @projects ||= []
end
root()
Alias for: project_root
software_files() click to toggle source

Return paths to all configured {Omnibus::Software} DSL files.

@return [Array<String>]

# File lib/omnibus.rb, line 153
def self.software_files
  ruby_files(File.join(project_root, Config.software_dir))
end
source_root() click to toggle source

The source root is the path to the root directory of the ‘omnibus` gem.

@return [Pathname]

# File lib/omnibus.rb, line 125
def self.source_root
  @source_root ||= Pathname.new(File.expand_path("../..", __FILE__))
end

Private Class Methods

expand_projects() click to toggle source

Generates {Omnibus::Project}s for each project DSL file in ‘project_specs`. All projects are then accessible at {Omnibus#projects}

@return [void]

@see Omnibus::Project

# File lib/omnibus.rb, line 173
def self.expand_projects
  project_files.each do |spec|
    Omnibus.projects << Omnibus::Project.load(spec)
  end
end
expand_software(overrides, software_map) click to toggle source

Generate {Omnibus::Software} objects for all software DSL files in ‘software_specs`.

@param overrides [Hash] a hash of version override information. @param software_files [Array<String>] @return [void]

@see Omnibus::Overrides#overrides

# File lib/omnibus.rb, line 187
def self.expand_software(overrides, software_map)
  unless overrides.is_a? Hash
    raise ArgumentError, "Overrides argument must be a hash!  You passed #{overrides.inspect}."
  end

  Omnibus.projects.each do |project|
    project.dependencies.each do |dependency|
      recursively_load_dependency(dependency, project, overrides, software_map)
    end
  end
end
generate_extra_rake_tasks() click to toggle source

Creates some additional Rake tasks beyond those generated in the process of reading in the DSL files.

@return [void]

@todo Not so sure I like how this is being done, but at least it

isolates the Rake stuff.
# File lib/omnibus.rb, line 223
def self.generate_extra_rake_tasks
  require 'omnibus/clean_tasks'
end
omnibus_software_files() click to toggle source

Retrieve the fully-qualified paths to every software definition file bundled in the {github.com/opscode/omnibus-software omnibus-software} gem.

@return [Array<String>] the list of paths. Will be empty if the

`omnibus-software` gem is not in the gem path.
# File lib/omnibus.rb, line 241
def self.omnibus_software_files
  if omnibus_software_root
    Dir.glob(File.join(omnibus_software_root, 'config', 'software', '*.rb'))
  else
    []
  end
end
prefer_local_software(omnibus_files, local_files) click to toggle source

Given a list of software definitions from ‘omnibus-software` itself, and a list of software files local to the current project, create a single list of software definitions. If the software was defined in both sets, the locally-defined one ends up in the final list.

The base name of the software file determines what software it defines.

@param omnibus_files [Array<String>] @param local_files [Array<String>] @return [Array<String>]

# File lib/omnibus.rb, line 260
def self.prefer_local_software(omnibus_files, local_files)
  base = software_map(omnibus_files)
  local = software_map(local_files)
  base.merge(local)
end
process_dsl_files() click to toggle source

Processes all configured {Omnibus::Project} and {Omnibus::Software} DSL files.

@return [void]

# File lib/omnibus.rb, line 203
def self.process_dsl_files
  # Do projects first
  expand_projects

  # Then do software
  final_software_map = prefer_local_software(omnibus_software_files,
                                         software_files)

  overrides = Config.override_file ? Omnibus::Overrides.overrides : {}

  expand_software(overrides, final_software_map)
end
recursively_load_dependency(dependency_name, project, overrides, software_map) click to toggle source

Loads a project’s dependency recursively, ensuring all transitive dependencies are also loaded.

@param dependency_name [String] @param project [Omnibus::Project] @param overrides [Hash] a hash of version override information. @param software_map [Hash<String, String>]

@return [void]

# File lib/omnibus.rb, line 287
def self.recursively_load_dependency(dependency_name, project, overrides, software_map)
  dep_file = software_map[dependency_name]

  unless dep_file
    raise MissingProjectDependency.new(dependency_name,
                                       [File.join(project_root, Config.software_dir),
                                        File.join(omnibus_software_root, 'config', 'software')])
  end

  dep_software = Omnibus::Software.load(dep_file, project, overrides)
  project.library.component_added(dep_software)

  # load any transitive deps for the component into the library also
  dep_software.dependencies.each do |dep|
    recursively_load_dependency(dep, project, overrides, software_map)
  end
end
ruby_files(dir) click to toggle source

Return a list of all the Ruby files (i.e., those with an “rb” extension) in the given directory

@param dir [String] @return [Array<String>]

# File lib/omnibus.rb, line 232
def self.ruby_files(dir)
  Dir.glob("#{dir}/*.rb")
end
software_map(files) click to toggle source

Given a list of file paths, create a map of the basename (without extension) to the complete path.

@param files [Array<String>] @return [Hash<String, String>]

# File lib/omnibus.rb, line 271
def self.software_map(files)
  files.each_with_object({}) do |file, collection|
    software_name = File.basename(file, ".*")
    collection[software_name] = file
  end
end