Class: Tetra::Package

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Scriptable, Speccable
Defined in:
lib/tetra/packages/package.rb

Overview

represents a Java project packaged in tetra

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scriptable

#_to_script, #generate_aliases

Methods included from Speccable

#_to_spec

Methods included from Generatable

#generate, #template_path

Constructor Details

#initialize(project, pom_path = nil, filter = nil, patches = []) ⇒ Package

Returns a new instance of Package.



21
22
23
24
25
26
27
# File 'lib/tetra/packages/package.rb', line 21

def initialize(project, pom_path = nil, filter = nil, patches = [])
  @project = project
  @kit = Tetra::KitPackage.new(project)
  @pom = Tetra::Pom.new(pom_path)
  @filter = filter
  @patches = patches.map { |f| File.basename(f) }
end

Instance Attribute Details

#patchesObject (readonly)

Returns the value of attribute patches.



10
11
12
# File 'lib/tetra/packages/package.rb', line 10

def patches
  @patches
end

Instance Method Details

#artifact_idsObject



60
61
62
# File 'lib/tetra/packages/package.rb', line 60

def artifact_ids
  @pom.modules.any? ? @pom.modules : [@pom.artifact_id]
end

#cleanup_description(raw, max_length) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/tetra/packages/package.rb', line 81

def cleanup_description(raw, max_length)
  return "" if raw.nil? || raw.strip.empty?

  # Normalize spaces (collapse multiple spaces/newlines to single space)
  clean = raw.gsub(/\s+/, " ").strip

  # Truncate to max_length
  clean = clean[0, max_length]

  # Remove the last word if it looks cut off (ends in letters, not punctuation)
  clean = clean.sub(/\s\w+\z/, "")

  # Remove ALL trailing dots efficiently
  clean = clean.chomp(".") while clean.end_with?(".")

  clean
end

#descriptionObject

a long summary from the POM



70
71
72
# File 'lib/tetra/packages/package.rb', line 70

def description
  cleanup_description(@pom.description, 1500)
end

#licenseObject



29
30
31
# File 'lib/tetra/packages/package.rb', line 29

def license
  Tetra::LicenseMapper.map(@pom.license_name)
end

#license_filesObject

Scans for license files in the src/ directory (Issue #12)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tetra/packages/package.rb', line 34

def license_files
  @project.from_directory do
    # Tetra unpacks sources into 'src/', so we search there.
    # We manually check filenames with Ruby regex to ensure reliable
    # case-insensitive matching across different OS filesystems (Linux vs macOS).

    candidates = Dir.glob("src/*")

    files = candidates.select do |file|
      next unless File.file?(file)

      basename = File.basename(file)

      # Match standard license filenames (case insensitive)
      # Equivalent to: LICENSE*, COPYING*, COPYRIGHT*
      basename.match?(/^LICENSE/i) ||
        basename.match?(/^COPYING/i) ||
        basename.match?(/^COPYRIGHT/i)
    end

    # Return just the filenames (e.g. "LICENSE") so the spec file
    # (which runs inside src/ due to %setup -n src) can reference them directly.
    files.map { |f| File.basename(f) }.uniq.sort
  end
end

#outputsObject

files produced by this package



75
76
77
78
79
# File 'lib/tetra/packages/package.rb', line 75

def outputs
  @project.produced_files.select do |file|
    File.fnmatch?(@filter, File.basename(file))
  end
end

#summaryObject

a short summary from the POM



65
66
67
# File 'lib/tetra/packages/package.rb', line 65

def summary
  cleanup_description(@pom.description, 60)
end

#to_scriptObject



103
104
105
# File 'lib/tetra/packages/package.rb', line 103

def to_script
  _to_script(@project)
end

#to_specObject



99
100
101
# File 'lib/tetra/packages/package.rb', line 99

def to_spec
  _to_spec(@project, name, "package.spec", @project.packages_dir)
end