module RJack::TarPit::SpecHelper

Helper mixin for Gem::Specification, adding Manifest awareness, maven strategy, jars and other #generated_files declarations, as well as several convenience methods and defaults. Many of these were Hoe inspired or remain compatible with Hoe.spec

Attributes

assembly_name[RW]

The name of the assembly (default: name)

assembly_version[RW]

The version of the assembly, which might be static, i.e. “1.0”, if the pom is not shared (dependency jars only) (default: version)

generated_files[RW]

Any additional generated files to be included. (default: nil)

history_file[RW]

The filename for the project History (default: History.rdoc or History.txt if present)

jar_dest[RW]

Destination path for any jar links (default: lib/<name>)

jars[W]

The set of jar file names (without path) to include. May be auto-computed for :no_assembly (default_jar) or :jars_from_assembly (from Manifest.txt) maven_strategy.

maven_strategy[RW]

Strategy for interacting with maven (default: nil, none )

:jars_from_assembly

jars will be found in assembly rather then set in Rakefile.

:no_assembly

One jar created from source, jars=, no assembly setup in maven.

readme_file[RW]

The filename for the project README (default: README.rdoc or README.txt if present)

version_file[RW]

The canonical file containing the version number, where changes should trigger Manifest.txt (re-)generation. (default: lib/<name>/base.rb or lib/<name>/version.rb if present)

Public Instance Methods

add_developer( author, email = nil ) click to toggle source

Add developer with optional email.

# File lib/rjack-tarpit/spec.rb, line 191
def add_developer( author, email = nil )
  ( self.authors ||= [] ) << author
  ( self.email   ||= [] ) << email if email
end
check_generate_manifest() click to toggle source
# File lib/rjack-tarpit/spec.rb, line 243
def check_generate_manifest
  # FIXME: How about diffent aproach: Always build new manifest
  # list, compare, and report and write if change from read in
  # list?

  unless ManifestTracker.generated?( name )
    if File.exist?( 'Manifest.static' )
      mtime = [ 'Manifest.static', version_file ].
        compact.
        map { |f| File.stat( f ).mtime }.
        max

      if ( !File.exist?( 'Manifest.txt' ) ||
           mtime > File.stat( 'Manifest.txt' ).mtime )
        generate_manifest
        self.files = Util::read_file_list( 'Manifest.txt' )
      end
    end
  end
end
depend( name, *args ) click to toggle source

Add a dependencies by name, version requirements, and a final optional :dev or :development symbol indicating its for development.

# File lib/rjack-tarpit/spec.rb, line 199
def depend( name, *args )
  if args.last == :dev || args.last == :development
    args.pop
    add_development_dependency( name, *args )
  else
    add_dependency( name, *args )
  end
end
description=( val ) click to toggle source

Set description. This override cleans up whitespace.

Calls superclass method
# File lib/rjack-tarpit/spec.rb, line 214
def description=( val )
  super( val.gsub( /\s+/, ' ' ).strip )
end
generate_manifest() click to toggle source

Generate Manifest.txt

# File lib/rjack-tarpit/spec.rb, line 265
def generate_manifest
  ManifestTracker.once( name ) do
    remove_dest_jars

    m = []
    if File.exist?( 'Manifest.static' )
      m += Util::read_file_list( 'Manifest.static' )
    end
    m += Util::clean_list( generated_files ).sort
    m += dest_jars

    puts "TARPIT: Regenerating #{ File.expand_path( 'Manifest.txt' ) }"
    open( 'Manifest.txt', 'w' ) { |out| out.puts m }
  end
end
jar_from() click to toggle source

The target/assembly path from which jars are linked

# File lib/rjack-tarpit/spec.rb, line 288
def jar_from
  dirs = [ 'target' ]

  unless maven_strategy == :no_assembly
    dirs << [ assembly_name,
              assembly_version,
              'bin.dir' ].join( '-' )
  end

  File.join( dirs )
end
jars() click to toggle source

Return set or defaulted jar file names (without path)

# File lib/rjack-tarpit/spec.rb, line 228
def jars
  if @jars.nil? && ( maven_strategy == :jars_from_assembly )

    # Extract jar files from saved Manifest state, since neither
    # from or dest jars may be available at call time.
    @jars =
      Util::read_file_list( 'Manifest.txt' ).
      select { |f| f =~ /\.jar$/ }.
      map    { |f| File.basename( f ) }

    #FIXME: Test Manifest.txt exists yet?
  end
  @jars ||= Array( @jars )
end
platform=( val ) click to toggle source

Override Gem::Specification to support simple platform symbol/string, i.e. :java

Calls superclass method
# File lib/rjack-tarpit/spec.rb, line 220
def platform=( val )
  if val.is_a?( Symbol ) || val.is_a?( String )
    val = Gem::Platform.new( val.to_s )
  end
  super( val )
end
remove_dest_jars() click to toggle source

Remove jars in #jar_dest by wildcard expression

# File lib/rjack-tarpit/spec.rb, line 282
def remove_dest_jars
  jars = Dir[ File.join( jar_dest, "*.jar" ) ].sort
  FileUtils::rm_f jars unless jars.empty?
end
summary=( val ) click to toggle source

Set summary. This override cleans up whitespace.

Calls superclass method
# File lib/rjack-tarpit/spec.rb, line 209
def summary=( val )
  super( val.gsub( /\s+/, ' ' ).strip )
end
tarpit_specify() { |self| ... } click to toggle source

Set defaults, yields self to block, and finalizes

# File lib/rjack-tarpit/spec.rb, line 128
def tarpit_specify

  # Better defaults
  if File.exist?( 'Manifest.txt' )
    self.files = Util::read_file_list( 'Manifest.txt' )
  end

  self.executables =
    self.files.grep( /^bin\/.+/ ) { |f| File.basename( f ) }

  @readme_file  = existing( %w[ README.rdoc README.txt ] )
  @history_file = existing( %w[ History.rdoc History.txt ] )

  self.extra_rdoc_files += [ Dir[ '*.rdoc' ],
                             @readme_file,
                             @history_file ].flatten.compact.sort.uniq

  self.rdoc_options += [ '--main', @readme_file ] if @readme_file

  @jars            = nil
  @jar_dest        = nil
  @generated_files = nil
  @maven_strategy  = nil

  parse_readme( @readme_file ) if @readme_file

  yield self if block_given?

  raise "No default or specified name" unless name

  @assembly_name ||= name
  @assembly_version ||= version

  version_candidates = %w[ base version ].map do |f|
    File.join( 'lib', name, "#{f}.rb" )
  end
  @version_file ||= existing( version_candidates )

  @jar_dest ||= File.join( 'lib', name )

  @jars = Array( @jars ).compact
  @jars = nil if @jars.empty?

  if ( @jars.nil? &&
       ( ( @maven_strategy == :no_assembly ) ||
         ( @maven_strategy.nil? && File.exist?( 'pom.xml' ) ) ) )
    @jars = [ default_jar ]
  end

  # The platform must be java if jars are specified.
  self.platform = :java if !jars.empty?

  # Add tarpit as dev dependency unless already present
  unless ( name == 'rjack-tarpit' ||
           dependencies.find { |d| d.name == 'rjack-tarpit' } )
    depend( 'rjack-tarpit', "~> #{ RJack::TarPit::MINOR_VERSION }", :dev )
  end

  check_generate_manifest

end